@@ -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
}
@@ -1021,7 +1021,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1021
1021
// so desugar to
1022
1022
//
1023
1023
// fn foo() -> impl Iterator<Item = impl Debug>
1024
- ImplTraitContext :: OpaqueTy ( _ ) => ( true , itctx) ,
1024
+ ImplTraitContext :: OpaqueTy ( .. ) => ( true , itctx) ,
1025
1025
1026
1026
// We are in the argument position, but within a dyn type:
1027
1027
//
@@ -1030,7 +1030,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1030
1030
// so desugar to
1031
1031
//
1032
1032
// fn foo(x: dyn Iterator<Item = impl Debug>)
1033
- ImplTraitContext :: Universal ( _ ) if self . is_in_dyn_type => ( true , itctx) ,
1033
+ ImplTraitContext :: Universal ( .. ) if self . is_in_dyn_type => ( true , itctx) ,
1034
1034
1035
1035
// In `type Foo = dyn Iterator<Item: Debug>` we desugar to
1036
1036
// `type Foo = dyn Iterator<Item = impl Debug>` but we have to override the
@@ -1039,7 +1039,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1039
1039
//
1040
1040
// FIXME: this is only needed until `impl Trait` is allowed in type aliases.
1041
1041
ImplTraitContext :: Disallowed ( _) if self . is_in_dyn_type => {
1042
- ( true , ImplTraitContext :: OpaqueTy ( None ) )
1042
+ ( true , ImplTraitContext :: OpaqueTy ( None , hir :: OpaqueTyOrigin :: Misc ) )
1043
1043
}
1044
1044
1045
1045
// We are in the parameter position, but not within a dyn type:
@@ -1274,8 +1274,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1274
1274
TyKind :: ImplTrait ( def_node_id, ref bounds) => {
1275
1275
let span = t. span ;
1276
1276
match itctx {
1277
- ImplTraitContext :: OpaqueTy ( fn_def_id) => {
1278
- self . lower_opaque_impl_trait ( span, fn_def_id, def_node_id, |this| {
1277
+ ImplTraitContext :: OpaqueTy ( fn_def_id, origin ) => {
1278
+ self . lower_opaque_impl_trait ( span, fn_def_id, origin , def_node_id, |this| {
1279
1279
this. lower_param_bounds ( bounds, itctx)
1280
1280
} )
1281
1281
}
@@ -1354,6 +1354,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1354
1354
& mut self ,
1355
1355
span : Span ,
1356
1356
fn_def_id : Option < DefId > ,
1357
+ origin : hir:: OpaqueTyOrigin ,
1357
1358
opaque_ty_node_id : NodeId ,
1358
1359
lower_bounds : impl FnOnce ( & mut Self ) -> hir:: GenericBounds < ' hir > ,
1359
1360
) -> hir:: TyKind < ' hir > {
@@ -1395,7 +1396,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1395
1396
} ,
1396
1397
bounds : hir_bounds,
1397
1398
impl_trait_fn : fn_def_id,
1398
- origin : hir :: OpaqueTyOrigin :: FnReturn ,
1399
+ origin,
1399
1400
} ;
1400
1401
1401
1402
trace ! ( "lower_opaque_impl_trait: {:#?}" , opaque_ty_def_index) ;
@@ -1627,7 +1628,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1627
1628
self . lower_ty (
1628
1629
t,
1629
1630
if self . sess . features_untracked ( ) . impl_trait_in_bindings {
1630
- ImplTraitContext :: OpaqueTy ( Some ( parent_def_id) )
1631
+ ImplTraitContext :: OpaqueTy ( Some ( parent_def_id) , hir :: OpaqueTyOrigin :: Misc )
1631
1632
} else {
1632
1633
ImplTraitContext :: Disallowed ( ImplTraitPosition :: Binding )
1633
1634
} ,
@@ -1728,9 +1729,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1728
1729
} else {
1729
1730
match decl. output {
1730
1731
FunctionRetTy :: Ty ( ref ty) => match in_band_ty_params {
1731
- Some ( ( def_id, _) ) if impl_trait_return_allow => hir:: FunctionRetTy :: Return (
1732
- self . lower_ty ( ty, ImplTraitContext :: OpaqueTy ( Some ( def_id) ) ) ,
1733
- ) ,
1732
+ Some ( ( def_id, _) ) if impl_trait_return_allow => {
1733
+ hir:: FunctionRetTy :: Return ( self . lower_ty (
1734
+ ty,
1735
+ ImplTraitContext :: OpaqueTy ( Some ( def_id) , hir:: OpaqueTyOrigin :: FnReturn ) ,
1736
+ ) )
1737
+ }
1734
1738
_ => hir:: FunctionRetTy :: Return (
1735
1739
self . lower_ty ( ty, ImplTraitContext :: disallowed ( ) ) ,
1736
1740
) ,
@@ -1962,7 +1966,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1962
1966
) -> hir:: GenericBound < ' hir > {
1963
1967
// Compute the `T` in `Future<Output = T>` from the return type.
1964
1968
let output_ty = match output {
1965
- FunctionRetTy :: Ty ( ty) => self . lower_ty ( ty, ImplTraitContext :: OpaqueTy ( Some ( fn_def_id) ) ) ,
1969
+ FunctionRetTy :: Ty ( ty) => self . lower_ty (
1970
+ ty,
1971
+ ImplTraitContext :: OpaqueTy ( Some ( fn_def_id) , hir:: OpaqueTyOrigin :: FnReturn ) ,
1972
+ ) ,
1966
1973
FunctionRetTy :: Default ( ret_ty_span) => self . arena . alloc ( self . ty_tup ( * ret_ty_span, & [ ] ) ) ,
1967
1974
} ;
1968
1975
@@ -2107,9 +2114,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
2107
2114
}
2108
2115
2109
2116
let kind = hir:: GenericParamKind :: Type {
2110
- default : default
2111
- . as_ref ( )
2112
- . map ( |x| self . lower_ty ( x, ImplTraitContext :: OpaqueTy ( None ) ) ) ,
2117
+ default : default. as_ref ( ) . map ( |x| {
2118
+ self . lower_ty (
2119
+ x,
2120
+ ImplTraitContext :: OpaqueTy ( None , hir:: OpaqueTyOrigin :: Misc ) ,
2121
+ )
2122
+ } ) ,
2113
2123
synthetic : param
2114
2124
. attrs
2115
2125
. iter ( )
0 commit comments