@@ -222,7 +222,7 @@ enum ImplTraitContext<'b, 'a> {
222
222
/// We optionally store a `DefId` for the parent item here so we can look up necessary
223
223
/// information later. It is `None` when no information about the context should be stored
224
224
/// (e.g., for consts and statics).
225
- OpaqueTy ( Option < DefId > /* fn def-ID */ ) ,
225
+ OpaqueTy ( Option < DefId > /* fn def-ID */ , hir :: OpaqueTyOrigin ) ,
226
226
227
227
/// `impl Trait` is not accepted in this position.
228
228
Disallowed ( ImplTraitPosition ) ,
@@ -248,7 +248,7 @@ impl<'a> ImplTraitContext<'_, 'a> {
248
248
use self :: ImplTraitContext :: * ;
249
249
match self {
250
250
Universal ( params) => Universal ( params) ,
251
- OpaqueTy ( fn_def_id) => OpaqueTy ( * fn_def_id) ,
251
+ OpaqueTy ( fn_def_id, origin ) => OpaqueTy ( * fn_def_id, * origin ) ,
252
252
Disallowed ( pos) => Disallowed ( * pos) ,
253
253
}
254
254
}
@@ -1010,7 +1010,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1010
1010
// so desugar to
1011
1011
//
1012
1012
// fn foo() -> impl Iterator<Item = impl Debug>
1013
- ImplTraitContext :: OpaqueTy ( _ ) => ( true , itctx) ,
1013
+ ImplTraitContext :: OpaqueTy ( .. ) => ( true , itctx) ,
1014
1014
1015
1015
// We are in the argument position, but within a dyn type:
1016
1016
//
@@ -1019,7 +1019,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1019
1019
// so desugar to
1020
1020
//
1021
1021
// fn foo(x: dyn Iterator<Item = impl Debug>)
1022
- ImplTraitContext :: Universal ( _ ) if self . is_in_dyn_type => ( true , itctx) ,
1022
+ ImplTraitContext :: Universal ( .. ) if self . is_in_dyn_type => ( true , itctx) ,
1023
1023
1024
1024
// In `type Foo = dyn Iterator<Item: Debug>` we desugar to
1025
1025
// `type Foo = dyn Iterator<Item = impl Debug>` but we have to override the
@@ -1028,7 +1028,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1028
1028
//
1029
1029
// FIXME: this is only needed until `impl Trait` is allowed in type aliases.
1030
1030
ImplTraitContext :: Disallowed ( _) if self . is_in_dyn_type => {
1031
- ( true , ImplTraitContext :: OpaqueTy ( None ) )
1031
+ ( true , ImplTraitContext :: OpaqueTy ( None , hir :: OpaqueTyOrigin :: Misc ) )
1032
1032
}
1033
1033
1034
1034
// We are in the parameter position, but not within a dyn type:
@@ -1269,8 +1269,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1269
1269
TyKind :: ImplTrait ( def_node_id, ref bounds) => {
1270
1270
let span = t. span ;
1271
1271
match itctx {
1272
- ImplTraitContext :: OpaqueTy ( fn_def_id) => {
1273
- self . lower_opaque_impl_trait ( span, fn_def_id, def_node_id, |this| {
1272
+ ImplTraitContext :: OpaqueTy ( fn_def_id, origin ) => {
1273
+ self . lower_opaque_impl_trait ( span, fn_def_id, origin , def_node_id, |this| {
1274
1274
this. lower_param_bounds ( bounds, itctx)
1275
1275
} )
1276
1276
}
@@ -1349,6 +1349,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1349
1349
& mut self ,
1350
1350
span : Span ,
1351
1351
fn_def_id : Option < DefId > ,
1352
+ origin : hir:: OpaqueTyOrigin ,
1352
1353
opaque_ty_node_id : NodeId ,
1353
1354
lower_bounds : impl FnOnce ( & mut Self ) -> hir:: GenericBounds < ' hir > ,
1354
1355
) -> hir:: TyKind < ' hir > {
@@ -1390,7 +1391,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1390
1391
} ,
1391
1392
bounds : hir_bounds,
1392
1393
impl_trait_fn : fn_def_id,
1393
- origin : hir :: OpaqueTyOrigin :: FnReturn ,
1394
+ origin,
1394
1395
} ;
1395
1396
1396
1397
trace ! ( "lower_opaque_impl_trait: {:#?}" , opaque_ty_def_index) ;
@@ -1622,7 +1623,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1622
1623
self . lower_ty (
1623
1624
t,
1624
1625
if self . sess . features_untracked ( ) . impl_trait_in_bindings {
1625
- ImplTraitContext :: OpaqueTy ( Some ( parent_def_id) )
1626
+ ImplTraitContext :: OpaqueTy ( Some ( parent_def_id) , hir :: OpaqueTyOrigin :: Misc )
1626
1627
} else {
1627
1628
ImplTraitContext :: Disallowed ( ImplTraitPosition :: Binding )
1628
1629
} ,
@@ -1723,9 +1724,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1723
1724
} else {
1724
1725
match decl. output {
1725
1726
FunctionRetTy :: Ty ( ref ty) => match in_band_ty_params {
1726
- Some ( ( def_id, _) ) if impl_trait_return_allow => hir:: FunctionRetTy :: Return (
1727
- self . lower_ty ( ty, ImplTraitContext :: OpaqueTy ( Some ( def_id) ) ) ,
1728
- ) ,
1727
+ Some ( ( def_id, _) ) if impl_trait_return_allow => {
1728
+ hir:: FunctionRetTy :: Return ( self . lower_ty (
1729
+ ty,
1730
+ ImplTraitContext :: OpaqueTy ( Some ( def_id) , hir:: OpaqueTyOrigin :: FnReturn ) ,
1731
+ ) )
1732
+ }
1729
1733
_ => hir:: FunctionRetTy :: Return (
1730
1734
self . lower_ty ( ty, ImplTraitContext :: disallowed ( ) ) ,
1731
1735
) ,
@@ -1957,7 +1961,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1957
1961
) -> hir:: GenericBound < ' hir > {
1958
1962
// Compute the `T` in `Future<Output = T>` from the return type.
1959
1963
let output_ty = match output {
1960
- FunctionRetTy :: Ty ( ty) => self . lower_ty ( ty, ImplTraitContext :: OpaqueTy ( Some ( fn_def_id) ) ) ,
1964
+ FunctionRetTy :: Ty ( ty) => self . lower_ty (
1965
+ ty,
1966
+ ImplTraitContext :: OpaqueTy ( Some ( fn_def_id) , hir:: OpaqueTyOrigin :: FnReturn ) ,
1967
+ ) ,
1961
1968
FunctionRetTy :: Default ( ret_ty_span) => self . arena . alloc ( self . ty_tup ( * ret_ty_span, & [ ] ) ) ,
1962
1969
} ;
1963
1970
@@ -2102,9 +2109,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
2102
2109
}
2103
2110
2104
2111
let kind = hir:: GenericParamKind :: Type {
2105
- default : default
2106
- . as_ref ( )
2107
- . map ( |x| self . lower_ty ( x, ImplTraitContext :: OpaqueTy ( None ) ) ) ,
2112
+ default : default. as_ref ( ) . map ( |x| {
2113
+ self . lower_ty (
2114
+ x,
2115
+ ImplTraitContext :: OpaqueTy ( None , hir:: OpaqueTyOrigin :: Misc ) ,
2116
+ )
2117
+ } ) ,
2108
2118
synthetic : param
2109
2119
. attrs
2110
2120
. iter ( )
0 commit comments