@@ -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 }
@@ -1010,7 +1010,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
10101010 // so desugar to
10111011 //
10121012 // fn foo() -> impl Iterator<Item = impl Debug>
1013- ImplTraitContext :: OpaqueTy ( _ ) => ( true , itctx) ,
1013+ ImplTraitContext :: OpaqueTy ( .. ) => ( true , itctx) ,
10141014
10151015 // We are in the argument position, but within a dyn type:
10161016 //
@@ -1019,7 +1019,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
10191019 // so desugar to
10201020 //
10211021 // 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) ,
10231023
10241024 // In `type Foo = dyn Iterator<Item: Debug>` we desugar to
10251025 // `type Foo = dyn Iterator<Item = impl Debug>` but we have to override the
@@ -1028,7 +1028,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
10281028 //
10291029 // FIXME: this is only needed until `impl Trait` is allowed in type aliases.
10301030 ImplTraitContext :: Disallowed ( _) if self . is_in_dyn_type => {
1031- ( true , ImplTraitContext :: OpaqueTy ( None ) )
1031+ ( true , ImplTraitContext :: OpaqueTy ( None , hir :: OpaqueTyOrigin :: Misc ) )
10321032 }
10331033
10341034 // We are in the parameter position, but not within a dyn type:
@@ -1269,8 +1269,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
12691269 TyKind :: ImplTrait ( def_node_id, ref bounds) => {
12701270 let span = t. span ;
12711271 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| {
12741274 this. lower_param_bounds ( bounds, itctx)
12751275 } )
12761276 }
@@ -1349,6 +1349,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
13491349 & mut self ,
13501350 span : Span ,
13511351 fn_def_id : Option < DefId > ,
1352+ origin : hir:: OpaqueTyOrigin ,
13521353 opaque_ty_node_id : NodeId ,
13531354 lower_bounds : impl FnOnce ( & mut Self ) -> hir:: GenericBounds < ' hir > ,
13541355 ) -> hir:: TyKind < ' hir > {
@@ -1390,7 +1391,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
13901391 } ,
13911392 bounds : hir_bounds,
13921393 impl_trait_fn : fn_def_id,
1393- origin : hir :: OpaqueTyOrigin :: FnReturn ,
1394+ origin,
13941395 } ;
13951396
13961397 trace ! ( "lower_opaque_impl_trait: {:#?}" , opaque_ty_def_index) ;
@@ -1622,7 +1623,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
16221623 self . lower_ty (
16231624 t,
16241625 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 )
16261627 } else {
16271628 ImplTraitContext :: Disallowed ( ImplTraitPosition :: Binding )
16281629 } ,
@@ -1723,9 +1724,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
17231724 } else {
17241725 match decl. output {
17251726 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+ }
17291733 _ => hir:: FunctionRetTy :: Return (
17301734 self . lower_ty ( ty, ImplTraitContext :: disallowed ( ) ) ,
17311735 ) ,
@@ -1957,7 +1961,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
19571961 ) -> hir:: GenericBound < ' hir > {
19581962 // Compute the `T` in `Future<Output = T>` from the return type.
19591963 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+ ) ,
19611968 FunctionRetTy :: Default ( ret_ty_span) => self . arena . alloc ( self . ty_tup ( * ret_ty_span, & [ ] ) ) ,
19621969 } ;
19631970
@@ -2102,9 +2109,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
21022109 }
21032110
21042111 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+ } ) ,
21082118 synthetic : param
21092119 . attrs
21102120 . iter ( )
0 commit comments