@@ -222,7 +222,7 @@ enum ImplTraitContext<'b, 'a> {
222222 /// We optionally store a `DefId` for the parent item here so we can look up necessary
223223 /// information later. It is `None` when no information about the context should be stored
224224 /// (e.g., for consts and statics).
225- OpaqueTy ( Option < DefId > /* fn def-ID */ ) ,
225+ OpaqueTy ( Option < DefId > /* fn def-ID */ , hir :: OpaqueTyOrigin ) ,
226226
227227 /// `impl Trait` is not accepted in this position.
228228 Disallowed ( ImplTraitPosition ) ,
@@ -248,7 +248,7 @@ impl<'a> ImplTraitContext<'_, 'a> {
248248 use self :: ImplTraitContext :: * ;
249249 match self {
250250 Universal ( params) => Universal ( params) ,
251- OpaqueTy ( fn_def_id) => OpaqueTy ( * fn_def_id) ,
251+ OpaqueTy ( fn_def_id, origin ) => OpaqueTy ( * fn_def_id, * origin ) ,
252252 Disallowed ( pos) => Disallowed ( * pos) ,
253253 }
254254 }
@@ -1021,7 +1021,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
10211021 // so desugar to
10221022 //
10231023 // fn foo() -> impl Iterator<Item = impl Debug>
1024- ImplTraitContext :: OpaqueTy ( _ ) => ( true , itctx) ,
1024+ ImplTraitContext :: OpaqueTy ( .. ) => ( true , itctx) ,
10251025
10261026 // We are in the argument position, but within a dyn type:
10271027 //
@@ -1030,7 +1030,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
10301030 // so desugar to
10311031 //
10321032 // 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) ,
10341034
10351035 // In `type Foo = dyn Iterator<Item: Debug>` we desugar to
10361036 // `type Foo = dyn Iterator<Item = impl Debug>` but we have to override the
@@ -1039,7 +1039,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
10391039 //
10401040 // FIXME: this is only needed until `impl Trait` is allowed in type aliases.
10411041 ImplTraitContext :: Disallowed ( _) if self . is_in_dyn_type => {
1042- ( true , ImplTraitContext :: OpaqueTy ( None ) )
1042+ ( true , ImplTraitContext :: OpaqueTy ( None , hir :: OpaqueTyOrigin :: Misc ) )
10431043 }
10441044
10451045 // We are in the parameter position, but not within a dyn type:
@@ -1274,8 +1274,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
12741274 TyKind :: ImplTrait ( def_node_id, ref bounds) => {
12751275 let span = t. span ;
12761276 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| {
12791279 this. lower_param_bounds ( bounds, itctx)
12801280 } )
12811281 }
@@ -1354,6 +1354,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
13541354 & mut self ,
13551355 span : Span ,
13561356 fn_def_id : Option < DefId > ,
1357+ origin : hir:: OpaqueTyOrigin ,
13571358 opaque_ty_node_id : NodeId ,
13581359 lower_bounds : impl FnOnce ( & mut Self ) -> hir:: GenericBounds < ' hir > ,
13591360 ) -> hir:: TyKind < ' hir > {
@@ -1395,7 +1396,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
13951396 } ,
13961397 bounds : hir_bounds,
13971398 impl_trait_fn : fn_def_id,
1398- origin : hir :: OpaqueTyOrigin :: FnReturn ,
1399+ origin,
13991400 } ;
14001401
14011402 trace ! ( "lower_opaque_impl_trait: {:#?}" , opaque_ty_def_index) ;
@@ -1627,7 +1628,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
16271628 self . lower_ty (
16281629 t,
16291630 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 )
16311632 } else {
16321633 ImplTraitContext :: Disallowed ( ImplTraitPosition :: Binding )
16331634 } ,
@@ -1728,9 +1729,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
17281729 } else {
17291730 match decl. output {
17301731 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+ }
17341738 _ => hir:: FunctionRetTy :: Return (
17351739 self . lower_ty ( ty, ImplTraitContext :: disallowed ( ) ) ,
17361740 ) ,
@@ -1962,7 +1966,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
19621966 ) -> hir:: GenericBound < ' hir > {
19631967 // Compute the `T` in `Future<Output = T>` from the return type.
19641968 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+ ) ,
19661973 FunctionRetTy :: Default ( ret_ty_span) => self . arena . alloc ( self . ty_tup ( * ret_ty_span, & [ ] ) ) ,
19671974 } ;
19681975
@@ -2107,9 +2114,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
21072114 }
21082115
21092116 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+ } ) ,
21132123 synthetic : param
21142124 . attrs
21152125 . iter ( )
0 commit comments