Skip to content

Commit cf91584

Browse files
author
Alexander Regueiro
committed
Lower impl Trait types in locals.
1 parent 5c875d9 commit cf91584

File tree

12 files changed

+262
-176
lines changed

12 files changed

+262
-176
lines changed

src/librustc/diagnostics.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1739,7 +1739,7 @@ specified exit code, use `std::process::exit`.
17391739

17401740
E0562: r##"
17411741
Abstract return types (written `impl Trait` for some trait `Trait`) are only
1742-
allowed as function return types.
1742+
allowed as function and inherent impl return types or binding types.
17431743
17441744
Erroneous code example:
17451745
@@ -1754,7 +1754,8 @@ fn main() {
17541754
}
17551755
```
17561756
1757-
Make sure `impl Trait` only appears in return-type position.
1757+
Make sure `impl Trait` only appears in return-type position or as the type of a
1758+
binding.
17581759
17591760
```
17601761
fn count_to_n(n: usize) -> impl Iterator<Item=usize> {

src/librustc/hir/def_id.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ pub struct DefIndex(u32);
131131
/// thanks to `NodeCollector::new`.
132132
pub const CRATE_DEF_INDEX: DefIndex = DefIndex(0);
133133

134-
135134
impl fmt::Debug for DefIndex {
136135
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
137136
write!(f,

src/librustc/hir/lowering.rs

Lines changed: 187 additions & 114 deletions
Large diffs are not rendered by default.

src/librustc/hir/map/def_collector.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ impl<'a> DefCollector<'a> {
102102
visit::walk_fn_decl(this, decl);
103103

104104
let closure_def = this.create_def(closure_id,
105-
DefPathData::ClosureExpr,
106-
REGULAR_SPACE,
107-
span);
105+
DefPathData::ClosureExpr,
106+
REGULAR_SPACE,
107+
span);
108108
this.with_parent(closure_def, |this| {
109109
visit::walk_block(this, body);
110110
})

src/librustc/infer/opaque_types/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ impl<'a, 'gcx, 'tcx> Instantiator<'a, 'gcx, 'tcx> {
736736

737737
debug!(
738738
"instantiate_opaque_types_in_map: \
739-
encountered opaque outside it's definition scope \
739+
encountered opaque outside its definition scope \
740740
def_id={:?}",
741741
def_id,
742742
);
@@ -808,8 +808,8 @@ impl<'a, 'gcx, 'tcx> Instantiator<'a, 'gcx, 'tcx> {
808808

809809
for predicate in bounds.predicates {
810810
// Change the predicate to refer to the type variable,
811-
// which will be the concrete type, instead of the Opaque.
812-
// This also instantiates nested `impl Trait`.
811+
// which will be the concrete type instead of the opaque type.
812+
// This also instantiates nested instances of `impl Trait`.
813813
let predicate = self.instantiate_opaque_types_in_map(&predicate);
814814

815815
let cause = traits::ObligationCause::new(span, self.body_id, traits::SizedReturnType);

src/librustc/ty/sty.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ impl BoundRegion {
7979
}
8080
}
8181

82-
/// NB: If you change this, you'll probably want to change the corresponding
83-
/// AST structure in libsyntax/ast.rs as well.
82+
/// N.B., If you change this, you'll probably want to change the corresponding
83+
/// AST structure in `libsyntax/ast.rs` as well.
8484
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, RustcEncodable, RustcDecodable)]
8585
pub enum TyKind<'tcx> {
8686
/// The primitive boolean type. Written as `bool`.
@@ -158,7 +158,7 @@ pub enum TyKind<'tcx> {
158158
Projection(ProjectionTy<'tcx>),
159159

160160
/// Opaque (`impl Trait`) type found in a return type.
161-
/// The DefId comes either from
161+
/// The `DefId` comes either from
162162
/// * the `impl Trait` ast::Ty node,
163163
/// * or the `existential type` declaration
164164
/// The substitutions are for the generics of the function in question.
@@ -168,7 +168,7 @@ pub enum TyKind<'tcx> {
168168
/// A type parameter; for example, `T` in `fn f<T>(x: T) {}
169169
Param(ParamTy),
170170

171-
/// A type variable used during type-checking.
171+
/// A type variable used during type checking.
172172
Infer(InferTy),
173173

174174
/// A placeholder for a type which could not be computed; this is

src/librustc_mir/borrow_check/nll/type_check/input_output.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
//! are supplied to us before normalization and may contain existential
1515
//! `impl Trait` instances. In contrast, the input/output types found in
1616
//! the MIR (specifically, in the special local variables for the
17-
//! `RETURN_PLACE` the MIR arguments) are always fully normalize (and
17+
//! `RETURN_PLACE` the MIR arguments) are always fully normalized (and
1818
//! contain revealed `impl Trait` values).
1919
2020
use borrow_check::nll::renumber;

src/librustc_mir/borrow_check/nll/type_check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ mod relate_tys;
9898
/// to outlive; should represent the fn body
9999
/// - `input_tys` -- fully liberated, but **not** normalized, expected types of the arguments;
100100
/// the types of the input parameters found in the MIR itself will be equated with these
101-
/// - `output_ty` -- fully liberaetd, but **not** normalized, expected return type;
101+
/// - `output_ty` -- fully liberated, but **not** normalized, expected return type;
102102
/// the type for the RETURN_PLACE will be equated with this
103103
/// - `liveness` -- results of a liveness computation on the MIR; used to create liveness
104104
/// constraints for the regions in the types of variables

src/librustc_typeck/check/_match.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
235235
.pat_binding_modes_mut()
236236
.insert(pat.hir_id, bm);
237237
debug!("check_pat_walk: pat.hir_id={:?} bm={:?}", pat.hir_id, bm);
238-
let typ = self.local_ty(pat.span, pat.id);
238+
let local_ty = self.local_ty(pat.span, pat.id).decl_ty;
239239
match bm {
240240
ty::BindByReference(mutbl) => {
241241
// if the binding is like
@@ -249,28 +249,28 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
249249
// `x` is assigned a value of type `&M T`, hence `&M T <: typeof(x)` is
250250
// required. However, we use equality, which is stronger. See (*) for
251251
// an explanation.
252-
self.demand_eqtype(pat.span, region_ty, typ);
252+
self.demand_eqtype(pat.span, region_ty, local_ty);
253253
}
254254
// otherwise the type of x is the expected type T
255255
ty::BindByValue(_) => {
256256
// As above, `T <: typeof(x)` is required but we
257257
// use equality, see (*) below.
258-
self.demand_eqtype(pat.span, expected, typ);
258+
self.demand_eqtype(pat.span, expected, local_ty);
259259
}
260260
}
261261

262262
// if there are multiple arms, make sure they all agree on
263263
// what the type of the binding `x` ought to be
264264
if var_id != pat.id {
265-
let vt = self.local_ty(pat.span, var_id);
266-
self.demand_eqtype(pat.span, vt, typ);
265+
let vt = self.local_ty(pat.span, var_id).decl_ty;
266+
self.demand_eqtype(pat.span, vt, local_ty);
267267
}
268268

269269
if let Some(ref p) = *sub {
270270
self.check_pat_walk(&p, expected, def_bm, true);
271271
}
272272

273-
typ
273+
local_ty
274274
}
275275
PatKind::TupleStruct(ref qpath, ref subpats, ddpos) => {
276276
self.check_pat_tuple_struct(pat, qpath, &subpats, ddpos, expected, def_bm)

src/librustc_typeck/check/coercion.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,8 +1039,8 @@ impl<'gcx, 'tcx, 'exprs, E> CoerceMany<'gcx, 'tcx, 'exprs, E>
10391039
}
10401040

10411041
/// Indicates that the value generated by `expression`, which is
1042-
/// of type `expression_ty`, is one of the possibility that we
1043-
/// could coerce from. This will record `expression` and later
1042+
/// of type `expression_ty`, is one of the possibilities that we
1043+
/// could coerce from. This will record `expression`, and later
10441044
/// calls to `coerce` may come back and add adjustments and things
10451045
/// if necessary.
10461046
pub fn coerce<'a>(&mut self,

0 commit comments

Comments
 (0)