]> git.lizzy.rs Git - rust.git/commitdiff
Add more information to `impl Trait` deny error
authorMichael Goulet <michael@errs.io>
Wed, 12 Jan 2022 03:00:34 +0000 (19:00 -0800)
committerMichael Goulet <michael@errs.io>
Fri, 18 Feb 2022 02:45:53 +0000 (18:45 -0800)
34 files changed:
compiler/rustc_ast_lowering/src/block.rs
compiler/rustc_ast_lowering/src/expr.rs
compiler/rustc_ast_lowering/src/item.rs
compiler/rustc_ast_lowering/src/lib.rs
compiler/rustc_ast_lowering/src/pat.rs
compiler/rustc_ast_lowering/src/path.rs
src/test/ui/feature-gates/feature-gate-associated_type_bounds.rs
src/test/ui/feature-gates/feature-gate-associated_type_bounds.stderr
src/test/ui/impl-trait/issues/issue-54600.rs
src/test/ui/impl-trait/issues/issue-54600.stderr
src/test/ui/impl-trait/issues/issue-54840.rs
src/test/ui/impl-trait/issues/issue-54840.stderr
src/test/ui/impl-trait/issues/issue-58504.rs
src/test/ui/impl-trait/issues/issue-58504.stderr
src/test/ui/impl-trait/issues/issue-58956.rs
src/test/ui/impl-trait/issues/issue-58956.stderr
src/test/ui/impl-trait/issues/issue-70971.rs
src/test/ui/impl-trait/issues/issue-70971.stderr
src/test/ui/impl-trait/issues/issue-79099.rs
src/test/ui/impl-trait/issues/issue-79099.stderr
src/test/ui/impl-trait/issues/issue-83929-impl-trait-in-generic-default.rs
src/test/ui/impl-trait/issues/issue-83929-impl-trait-in-generic-default.stderr
src/test/ui/impl-trait/issues/issue-84919.rs
src/test/ui/impl-trait/issues/issue-84919.stderr
src/test/ui/impl-trait/issues/issue-86642.rs
src/test/ui/impl-trait/issues/issue-86642.stderr
src/test/ui/impl-trait/issues/issue-87295.rs
src/test/ui/impl-trait/issues/issue-87295.stderr
src/test/ui/impl-trait/nested_impl_trait.stderr
src/test/ui/impl-trait/where-allowed.rs
src/test/ui/impl-trait/where-allowed.stderr
src/test/ui/issues/issue-47715.stderr
src/test/ui/type-alias-impl-trait/type-alias-impl-trait-fn-type.rs
src/test/ui/type-alias-impl-trait/type-alias-impl-trait-fn-type.stderr

index 082c5bb783347a2dbffe4dcb33b42d38559d55a8..3a7e0a70585f125e53d264d2e16e8e3e70043141 100644 (file)
@@ -97,7 +97,7 @@ fn lower_local(&mut self, l: &Local) -> &'hir hir::Local<'hir> {
         let ty = l
             .ty
             .as_ref()
-            .map(|t| self.lower_ty(t, ImplTraitContext::Disallowed(ImplTraitPosition::Binding)));
+            .map(|t| self.lower_ty(t, ImplTraitContext::Disallowed(ImplTraitPosition::Variable)));
         let init = l.kind.init().map(|init| self.lower_expr(init));
         let hir_id = self.lower_node_id(l.id);
         let pat = self.lower_pat(&l.pat);
@@ -127,7 +127,7 @@ fn lower_let_else(
         let ty = local
             .ty
             .as_ref()
-            .map(|t| self.lower_ty(t, ImplTraitContext::Disallowed(ImplTraitPosition::Binding)));
+            .map(|t| self.lower_ty(t, ImplTraitContext::Disallowed(ImplTraitPosition::Variable)));
         let span = self.lower_span(local.span);
         let span = self.mark_span_with_reason(DesugaringKind::LetElse, span, None);
         let init = self.lower_expr(init);
index 17bc8d7591b406e766d4a7bb4fe2a4a2bf745273..d48ff10b97d9181145efb0f6f32e8fddcd3cbf36 100644 (file)
@@ -1,3 +1,5 @@
+use crate::{FnDeclKind, ImplTraitPosition};
+
 use super::{ImplTraitContext, LoweringContext, ParamMode, ParenthesizedGenericArgs};
 
 use rustc_ast::attr;
@@ -53,7 +55,7 @@ pub(super) fn lower_expr_mut(&mut self, e: &Expr) -> hir::Expr<'hir> {
                         ParamMode::Optional,
                         0,
                         ParenthesizedGenericArgs::Err,
-                        ImplTraitContext::disallowed(),
+                        ImplTraitContext::Disallowed(ImplTraitPosition::Path),
                     ));
                     let args = self.lower_exprs(args);
                     hir::ExprKind::MethodCall(hir_seg, args, self.lower_span(span))
@@ -74,12 +76,14 @@ pub(super) fn lower_expr_mut(&mut self, e: &Expr) -> hir::Expr<'hir> {
                 }
                 ExprKind::Cast(ref expr, ref ty) => {
                     let expr = self.lower_expr(expr);
-                    let ty = self.lower_ty(ty, ImplTraitContext::disallowed());
+                    let ty =
+                        self.lower_ty(ty, ImplTraitContext::Disallowed(ImplTraitPosition::Type));
                     hir::ExprKind::Cast(expr, ty)
                 }
                 ExprKind::Type(ref expr, ref ty) => {
                     let expr = self.lower_expr(expr);
-                    let ty = self.lower_ty(ty, ImplTraitContext::disallowed());
+                    let ty =
+                        self.lower_ty(ty, ImplTraitContext::Disallowed(ImplTraitPosition::Type));
                     hir::ExprKind::Type(expr, ty)
                 }
                 ExprKind::AddrOf(k, m, ref ohs) => {
@@ -203,7 +207,7 @@ pub(super) fn lower_expr_mut(&mut self, e: &Expr) -> hir::Expr<'hir> {
                         qself,
                         path,
                         ParamMode::Optional,
-                        ImplTraitContext::disallowed(),
+                        ImplTraitContext::Disallowed(ImplTraitPosition::Path),
                     );
                     hir::ExprKind::Path(qpath)
                 }
@@ -239,7 +243,7 @@ pub(super) fn lower_expr_mut(&mut self, e: &Expr) -> hir::Expr<'hir> {
                             &se.qself,
                             &se.path,
                             ParamMode::Optional,
-                            ImplTraitContext::disallowed(),
+                            ImplTraitContext::Disallowed(ImplTraitPosition::Path),
                         )),
                         self.arena
                             .alloc_from_iter(se.fields.iter().map(|x| self.lower_expr_field(x))),
@@ -538,7 +542,9 @@ pub(super) fn make_async_expr(
         body: impl FnOnce(&mut Self) -> hir::Expr<'hir>,
     ) -> hir::ExprKind<'hir> {
         let output = match ret_ty {
-            Some(ty) => hir::FnRetTy::Return(self.lower_ty(&ty, ImplTraitContext::disallowed())),
+            Some(ty) => hir::FnRetTy::Return(
+                self.lower_ty(&ty, ImplTraitContext::Disallowed(ImplTraitPosition::AsyncBlock)),
+            ),
             None => hir::FnRetTy::DefaultReturn(self.lower_span(span)),
         };
 
@@ -827,7 +833,7 @@ fn lower_expr_closure(
         });
 
         // Lower outside new scope to preserve `is_in_loop_condition`.
-        let fn_decl = self.lower_fn_decl(decl, None, false, None);
+        let fn_decl = self.lower_fn_decl(decl, None, FnDeclKind::Closure, None);
 
         hir::ExprKind::Closure(
             capture_clause,
@@ -919,7 +925,7 @@ fn lower_expr_async_closure(
         // We need to lower the declaration outside the new scope, because we
         // have to conserve the state of being inside a loop condition for the
         // closure argument types.
-        let fn_decl = self.lower_fn_decl(&outer_decl, None, false, None);
+        let fn_decl = self.lower_fn_decl(&outer_decl, None, FnDeclKind::Closure, None);
 
         hir::ExprKind::Closure(
             capture_clause,
@@ -1064,7 +1070,7 @@ fn destructure_assign_mut(
                         qself,
                         path,
                         ParamMode::Optional,
-                        ImplTraitContext::disallowed(),
+                        ImplTraitContext::Disallowed(ImplTraitPosition::Path),
                     );
                     // Destructure like a tuple struct.
                     let tuple_struct_pat =
@@ -1089,7 +1095,7 @@ fn destructure_assign_mut(
                     &se.qself,
                     &se.path,
                     ParamMode::Optional,
-                    ImplTraitContext::disallowed(),
+                    ImplTraitContext::Disallowed(ImplTraitPosition::Path),
                 );
                 let fields_omitted = match &se.rest {
                     StructRest::Base(e) => {
index f48cf212a984bca1cbc3511f1c4cb2568674a7d9..6489c729cfe50dcbb9e4c8e31f62d10c681cbc1b 100644 (file)
@@ -1,6 +1,6 @@
 use super::{AnonymousLifetimeMode, LoweringContext, ParamMode};
 use super::{ImplTraitContext, ImplTraitPosition};
-use crate::Arena;
+use crate::{Arena, FnDeclKind};
 
 use rustc_ast::ptr::P;
 use rustc_ast::visit::{self, AssocCtxt, FnCtxt, FnKind, Visitor};
@@ -246,7 +246,12 @@ fn lower_item_kind(
                         AnonymousLifetimeMode::PassThrough,
                         |this, idty| {
                             let ret_id = asyncness.opt_return_id();
-                            this.lower_fn_decl(&decl, Some((fn_def_id, idty)), true, ret_id)
+                            this.lower_fn_decl(
+                                &decl,
+                                Some((fn_def_id, idty)),
+                                FnDeclKind::Fn,
+                                ret_id,
+                            )
                         },
                     );
                     let sig = hir::FnSig {
@@ -287,12 +292,18 @@ fn lower_item_kind(
                         capturable_lifetimes: &mut FxHashSet::default(),
                     },
                 );
-                let generics = self.lower_generics(generics, ImplTraitContext::disallowed());
+                let generics = self.lower_generics(
+                    generics,
+                    ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
+                );
                 hir::ItemKind::TyAlias(ty, generics)
             }
             ItemKind::TyAlias(box TyAlias { ref generics, ty: None, .. }) => {
                 let ty = self.arena.alloc(self.ty(span, hir::TyKind::Err));
-                let generics = self.lower_generics(generics, ImplTraitContext::disallowed());
+                let generics = self.lower_generics(
+                    generics,
+                    ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
+                );
                 hir::ItemKind::TyAlias(ty, generics)
             }
             ItemKind::Enum(ref enum_definition, ref generics) => hir::ItemKind::Enum(
@@ -301,20 +312,29 @@ fn lower_item_kind(
                         enum_definition.variants.iter().map(|x| self.lower_variant(x)),
                     ),
                 },
-                self.lower_generics(generics, ImplTraitContext::disallowed()),
+                self.lower_generics(
+                    generics,
+                    ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
+                ),
             ),
             ItemKind::Struct(ref struct_def, ref generics) => {
                 let struct_def = self.lower_variant_data(hir_id, struct_def);
                 hir::ItemKind::Struct(
                     struct_def,
-                    self.lower_generics(generics, ImplTraitContext::disallowed()),
+                    self.lower_generics(
+                        generics,
+                        ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
+                    ),
                 )
             }
             ItemKind::Union(ref vdata, ref generics) => {
                 let vdata = self.lower_variant_data(hir_id, vdata);
                 hir::ItemKind::Union(
                     vdata,
-                    self.lower_generics(generics, ImplTraitContext::disallowed()),
+                    self.lower_generics(
+                        generics,
+                        ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
+                    ),
                 )
             }
             ItemKind::Impl(box Impl {
@@ -347,10 +367,14 @@ fn lower_item_kind(
                     AnonymousLifetimeMode::CreateParameter,
                     |this, _| {
                         let trait_ref = trait_ref.as_ref().map(|trait_ref| {
-                            this.lower_trait_ref(trait_ref, ImplTraitContext::disallowed())
+                            this.lower_trait_ref(
+                                trait_ref,
+                                ImplTraitContext::Disallowed(ImplTraitPosition::Trait),
+                            )
                         });
 
-                        let lowered_ty = this.lower_ty(ty, ImplTraitContext::disallowed());
+                        let lowered_ty = this
+                            .lower_ty(ty, ImplTraitContext::Disallowed(ImplTraitPosition::Type));
 
                         (trait_ref, lowered_ty)
                     },
@@ -390,21 +414,33 @@ fn lower_item_kind(
                 ref bounds,
                 ref items,
             }) => {
-                let bounds = self.lower_param_bounds(bounds, ImplTraitContext::disallowed());
+                let bounds = self.lower_param_bounds(
+                    bounds,
+                    ImplTraitContext::Disallowed(ImplTraitPosition::Bound),
+                );
                 let items = self
                     .arena
                     .alloc_from_iter(items.iter().map(|item| self.lower_trait_item_ref(item)));
                 hir::ItemKind::Trait(
                     is_auto,
                     self.lower_unsafety(unsafety),
-                    self.lower_generics(generics, ImplTraitContext::disallowed()),
+                    self.lower_generics(
+                        generics,
+                        ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
+                    ),
                     bounds,
                     items,
                 )
             }
             ItemKind::TraitAlias(ref generics, ref bounds) => hir::ItemKind::TraitAlias(
-                self.lower_generics(generics, ImplTraitContext::disallowed()),
-                self.lower_param_bounds(bounds, ImplTraitContext::disallowed()),
+                self.lower_generics(
+                    generics,
+                    ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
+                ),
+                self.lower_param_bounds(
+                    bounds,
+                    ImplTraitContext::Disallowed(ImplTraitPosition::Bound),
+                ),
             ),
             ItemKind::MacroDef(MacroDef { ref body, macro_rules }) => {
                 let body = P(self.lower_mac_args(body));
@@ -423,7 +459,7 @@ fn lower_const_item(
         span: Span,
         body: Option<&Expr>,
     ) -> (&'hir hir::Ty<'hir>, hir::BodyId) {
-        let ty = self.lower_ty(ty, ImplTraitContext::Disallowed(ImplTraitPosition::Binding));
+        let ty = self.lower_ty(ty, ImplTraitContext::Disallowed(ImplTraitPosition::Type));
         (ty, self.lower_const_body(span, body))
     }
 
@@ -667,7 +703,7 @@ fn lower_foreign_item(&mut self, i: &ForeignItem) -> &'hir hir::ForeignItem<'hir
                         |this, _| {
                             (
                                 // Disallow `impl Trait` in foreign items.
-                                this.lower_fn_decl(fdec, None, false, None),
+                                this.lower_fn_decl(fdec, None, FnDeclKind::ExternFn, None),
                                 this.lower_fn_params_to_names(fdec),
                             )
                         },
@@ -676,7 +712,8 @@ fn lower_foreign_item(&mut self, i: &ForeignItem) -> &'hir hir::ForeignItem<'hir
                     hir::ForeignItemKind::Fn(fn_dec, fn_args, generics)
                 }
                 ForeignItemKind::Static(ref t, m, _) => {
-                    let ty = self.lower_ty(t, ImplTraitContext::disallowed());
+                    let ty =
+                        self.lower_ty(t, ImplTraitContext::Disallowed(ImplTraitPosition::Type));
                     hir::ForeignItemKind::Static(ty, m)
                 }
                 ForeignItemKind::TyAlias(..) => hir::ForeignItemKind::Type,
@@ -744,11 +781,11 @@ fn lower_field_def(&mut self, (index, f): (usize, &FieldDef)) -> hir::FieldDef<'
                 qself,
                 path,
                 ParamMode::ExplicitNamed, // no `'_` in declarations (Issue #61124)
-                ImplTraitContext::disallowed(),
+                ImplTraitContext::Disallowed(ImplTraitPosition::Path),
             );
             self.arena.alloc(t)
         } else {
-            self.lower_ty(&f.ty, ImplTraitContext::disallowed())
+            self.lower_ty(&f.ty, ImplTraitContext::Disallowed(ImplTraitPosition::Type))
         };
         let hir_id = self.lower_node_id(f.id);
         self.lower_attrs(hir_id, &f.attrs);
@@ -771,14 +808,19 @@ fn lower_trait_item(&mut self, i: &AssocItem) -> &'hir hir::TraitItem<'hir> {
 
         let (generics, kind) = match i.kind {
             AssocItemKind::Const(_, ref ty, ref default) => {
-                let ty = self.lower_ty(ty, ImplTraitContext::disallowed());
+                let ty = self.lower_ty(ty, ImplTraitContext::Disallowed(ImplTraitPosition::Type));
                 let body = default.as_ref().map(|x| self.lower_const_body(i.span, Some(x)));
                 (hir::Generics::empty(), hir::TraitItemKind::Const(ty, body))
             }
             AssocItemKind::Fn(box Fn { ref sig, ref generics, body: None, .. }) => {
                 let names = self.lower_fn_params_to_names(&sig.decl);
-                let (generics, sig) =
-                    self.lower_method_sig(generics, sig, trait_item_def_id, false, None);
+                let (generics, sig) = self.lower_method_sig(
+                    generics,
+                    sig,
+                    trait_item_def_id,
+                    FnDeclKind::Trait,
+                    None,
+                );
                 (generics, hir::TraitItemKind::Fn(sig, hir::TraitFn::Required(names)))
             }
             AssocItemKind::Fn(box Fn { ref sig, ref generics, body: Some(ref body), .. }) => {
@@ -789,16 +831,24 @@ fn lower_trait_item(&mut self, i: &AssocItem) -> &'hir hir::TraitItem<'hir> {
                     generics,
                     sig,
                     trait_item_def_id,
-                    false,
+                    FnDeclKind::Trait,
                     asyncness.opt_return_id(),
                 );
                 (generics, hir::TraitItemKind::Fn(sig, hir::TraitFn::Provided(body_id)))
             }
             AssocItemKind::TyAlias(box TyAlias { ref generics, ref bounds, ref ty, .. }) => {
-                let ty = ty.as_ref().map(|x| self.lower_ty(x, ImplTraitContext::disallowed()));
-                let generics = self.lower_generics(generics, ImplTraitContext::disallowed());
+                let ty = ty.as_ref().map(|x| {
+                    self.lower_ty(x, ImplTraitContext::Disallowed(ImplTraitPosition::Type))
+                });
+                let generics = self.lower_generics(
+                    generics,
+                    ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
+                );
                 let kind = hir::TraitItemKind::Type(
-                    self.lower_param_bounds(bounds, ImplTraitContext::disallowed()),
+                    self.lower_param_bounds(
+                        bounds,
+                        ImplTraitContext::Disallowed(ImplTraitPosition::Bound),
+                    ),
                     ty,
                 );
 
@@ -850,7 +900,7 @@ fn lower_impl_item(&mut self, i: &AssocItem) -> &'hir hir::ImplItem<'hir> {
 
         let (generics, kind) = match &i.kind {
             AssocItemKind::Const(_, ty, expr) => {
-                let ty = self.lower_ty(ty, ImplTraitContext::disallowed());
+                let ty = self.lower_ty(ty, ImplTraitContext::Disallowed(ImplTraitPosition::Type));
                 (
                     hir::Generics::empty(),
                     hir::ImplItemKind::Const(ty, self.lower_const_body(i.span, expr.as_deref())),
@@ -861,19 +911,21 @@ fn lower_impl_item(&mut self, i: &AssocItem) -> &'hir hir::ImplItem<'hir> {
                 let asyncness = sig.header.asyncness;
                 let body_id =
                     self.lower_maybe_async_body(i.span, &sig.decl, asyncness, body.as_deref());
-                let impl_trait_return_allow = !self.is_in_trait_impl;
                 let (generics, sig) = self.lower_method_sig(
                     generics,
                     sig,
                     impl_item_def_id,
-                    impl_trait_return_allow,
+                    if self.is_in_trait_impl { FnDeclKind::Impl } else { FnDeclKind::Inherent },
                     asyncness.opt_return_id(),
                 );
 
                 (generics, hir::ImplItemKind::Fn(sig, body_id))
             }
             AssocItemKind::TyAlias(box TyAlias { generics, ty, .. }) => {
-                let generics = self.lower_generics(generics, ImplTraitContext::disallowed());
+                let generics = self.lower_generics(
+                    generics,
+                    ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
+                );
                 let kind = match ty {
                     None => {
                         let ty = self.arena.alloc(self.ty(i.span, hir::TyKind::Err));
@@ -1248,7 +1300,7 @@ fn lower_method_sig(
         generics: &Generics,
         sig: &FnSig,
         fn_def_id: LocalDefId,
-        impl_trait_return_allow: bool,
+        kind: FnDeclKind,
         is_async: Option<NodeId>,
     ) -> (hir::Generics<'hir>, hir::FnSig<'hir>) {
         let header = self.lower_fn_header(sig.header);
@@ -1256,14 +1308,7 @@ fn lower_method_sig(
             generics,
             fn_def_id,
             AnonymousLifetimeMode::PassThrough,
-            |this, idty| {
-                this.lower_fn_decl(
-                    &sig.decl,
-                    Some((fn_def_id, idty)),
-                    impl_trait_return_allow,
-                    is_async,
-                )
-            },
+            |this, idty| this.lower_fn_decl(&sig.decl, Some((fn_def_id, idty)), kind, is_async),
         );
         (generics, hir::FnSig { header, decl, span: self.lower_span(sig.span) })
     }
@@ -1409,11 +1454,19 @@ fn lower_where_predicate(&mut self, pred: &WherePredicate) -> hir::WherePredicat
                 span,
             }) => self.with_in_scope_lifetime_defs(&bound_generic_params, |this| {
                 hir::WherePredicate::BoundPredicate(hir::WhereBoundPredicate {
-                    bound_generic_params: this
-                        .lower_generic_params(bound_generic_params, ImplTraitContext::disallowed()),
-                    bounded_ty: this.lower_ty(bounded_ty, ImplTraitContext::disallowed()),
+                    bound_generic_params: this.lower_generic_params(
+                        bound_generic_params,
+                        ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
+                    ),
+                    bounded_ty: this.lower_ty(
+                        bounded_ty,
+                        ImplTraitContext::Disallowed(ImplTraitPosition::Type),
+                    ),
                     bounds: this.arena.alloc_from_iter(bounds.iter().map(|bound| {
-                        this.lower_param_bound(bound, ImplTraitContext::disallowed())
+                        this.lower_param_bound(
+                            bound,
+                            ImplTraitContext::Disallowed(ImplTraitPosition::Bound),
+                        )
                     })),
                     span: this.lower_span(span),
                 })
@@ -1425,13 +1478,18 @@ fn lower_where_predicate(&mut self, pred: &WherePredicate) -> hir::WherePredicat
             }) => hir::WherePredicate::RegionPredicate(hir::WhereRegionPredicate {
                 span: self.lower_span(span),
                 lifetime: self.lower_lifetime(lifetime),
-                bounds: self.lower_param_bounds(bounds, ImplTraitContext::disallowed()),
+                bounds: self.lower_param_bounds(
+                    bounds,
+                    ImplTraitContext::Disallowed(ImplTraitPosition::Bound),
+                ),
             }),
             WherePredicate::EqPredicate(WhereEqPredicate { id, ref lhs_ty, ref rhs_ty, span }) => {
                 hir::WherePredicate::EqPredicate(hir::WhereEqPredicate {
                     hir_id: self.lower_node_id(id),
-                    lhs_ty: self.lower_ty(lhs_ty, ImplTraitContext::disallowed()),
-                    rhs_ty: self.lower_ty(rhs_ty, ImplTraitContext::disallowed()),
+                    lhs_ty: self
+                        .lower_ty(lhs_ty, ImplTraitContext::Disallowed(ImplTraitPosition::Type)),
+                    rhs_ty: self
+                        .lower_ty(rhs_ty, ImplTraitContext::Disallowed(ImplTraitPosition::Type)),
                     span: self.lower_span(span),
                 })
             }
index 60b5aeb52b18f8a7b70726e6d686f8ba45e85947..803c93c259eebffaca97036540d90cc03d576448 100644 (file)
@@ -256,19 +256,28 @@ enum ImplTraitContext<'b, 'a> {
 /// Position in which `impl Trait` is disallowed.
 #[derive(Debug, Copy, Clone, PartialEq, Eq)]
 enum ImplTraitPosition {
-    /// Disallowed in `let` / `const` / `static` bindings.
-    Binding,
-
-    /// All other positions.
-    Other,
+    Path,
+    Variable,
+    Type,
+    Trait,
+    AsyncBlock,
+    Bound,
+    Generic,
+    ExternFnParam,
+    ClosureParam,
+    PointerParam,
+    FnTraitParam,
+    TraitParam,
+    ImplParam,
+    ExternFnReturn,
+    ClosureReturn,
+    PointerReturn,
+    FnTraitReturn,
+    TraitReturn,
+    ImplReturn,
 }
 
 impl<'a> ImplTraitContext<'_, 'a> {
-    #[inline]
-    fn disallowed() -> Self {
-        ImplTraitContext::Disallowed(ImplTraitPosition::Other)
-    }
-
     fn reborrow<'this>(&'this mut self) -> ImplTraitContext<'this, 'a> {
         use self::ImplTraitContext::*;
         match self {
@@ -284,6 +293,54 @@ fn reborrow<'this>(&'this mut self) -> ImplTraitContext<'this, 'a> {
     }
 }
 
+impl std::fmt::Display for ImplTraitPosition {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        let name = match self {
+            ImplTraitPosition::Path => "path",
+            ImplTraitPosition::Variable => "variable",
+            ImplTraitPosition::Type => "type",
+            ImplTraitPosition::Trait => "trait",
+            ImplTraitPosition::AsyncBlock => "async block",
+            ImplTraitPosition::Bound => "bound",
+            ImplTraitPosition::Generic => "generic",
+            ImplTraitPosition::ExternFnParam => "`extern fn` param",
+            ImplTraitPosition::ClosureParam => "closure param",
+            ImplTraitPosition::PointerParam => "`fn` pointer param",
+            ImplTraitPosition::FnTraitParam => "`Fn` trait param",
+            ImplTraitPosition::TraitParam => "trait method param",
+            ImplTraitPosition::ImplParam => "`impl` method param",
+            ImplTraitPosition::ExternFnReturn => "`extern fn` return",
+            ImplTraitPosition::ClosureReturn => "closure return",
+            ImplTraitPosition::PointerReturn => "`fn` pointer return",
+            ImplTraitPosition::FnTraitReturn => "`Fn` trait return",
+            ImplTraitPosition::TraitReturn => "trait method return",
+            ImplTraitPosition::ImplReturn => "`impl` method return",
+        };
+
+        write!(f, "{}", name)
+    }
+}
+
+#[derive(Debug)]
+enum FnDeclKind {
+    Fn,
+    Inherent,
+    ExternFn,
+    Closure,
+    Pointer,
+    Trait,
+    Impl,
+}
+
+impl FnDeclKind {
+    fn impl_trait_return_allowed(&self) -> bool {
+        match self {
+            FnDeclKind::Fn | FnDeclKind::Inherent => true,
+            _ => false,
+        }
+    }
+}
+
 pub fn lower_crate<'a, 'hir>(
     sess: &'a Session,
     krate: &'a Crate,
@@ -1232,11 +1289,11 @@ fn lower_ty_direct(&mut self, t: &Ty, mut itctx: ImplTraitContext<'_, 'hir>) ->
                     hir::TyKind::BareFn(this.arena.alloc(hir::BareFnTy {
                         generic_params: this.lower_generic_params(
                             &f.generic_params,
-                            ImplTraitContext::disallowed(),
+                            ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
                         ),
                         unsafety: this.lower_unsafety(f.unsafety),
                         abi: this.lower_extern(f.ext),
-                        decl: this.lower_fn_decl(&f.decl, None, false, None),
+                        decl: this.lower_fn_decl(&f.decl, None, FnDeclKind::Pointer, None),
                         param_names: this.lower_fn_params_to_names(&f.decl),
                     }))
                 })
@@ -1357,14 +1414,15 @@ fn lower_ty_direct(&mut self, t: &Ty, mut itctx: ImplTraitContext<'_, 'hir>) ->
                             }),
                         ))
                     }
-                    ImplTraitContext::Disallowed(_) => {
+                    ImplTraitContext::Disallowed(position) => {
                         let mut err = struct_span_err!(
                             self.sess,
                             t.span,
                             E0562,
-                            "`impl Trait` not allowed outside of {}",
-                            "function and method return types",
+                            "`impl Trait` not allowed outside of \
+                            function and inherent method return types",
                         );
+                        err.note(&format!("found `impl Trait` in {}", position));
                         err.emit();
                         hir::TyKind::Err
                     }
@@ -1528,16 +1586,16 @@ fn lower_fn_decl(
         &mut self,
         decl: &FnDecl,
         mut in_band_ty_params: Option<(LocalDefId, &mut Vec<hir::GenericParam<'hir>>)>,
-        impl_trait_return_allow: bool,
+        kind: FnDeclKind,
         make_ret_async: Option<NodeId>,
     ) -> &'hir hir::FnDecl<'hir> {
         debug!(
             "lower_fn_decl(\
             fn_decl: {:?}, \
             in_band_ty_params: {:?}, \
-            impl_trait_return_allow: {}, \
+            kind: {:?}, \
             make_ret_async: {:?})",
-            decl, in_band_ty_params, impl_trait_return_allow, make_ret_async,
+            decl, in_band_ty_params, kind, make_ret_async,
         );
         let lt_mode = if make_ret_async.is_some() {
             // In `async fn`, argument-position elided lifetimes
@@ -1567,7 +1625,19 @@ fn lower_fn_decl(
                         ImplTraitContext::Universal(ibty, this.current_hir_id_owner),
                     )
                 } else {
-                    this.lower_ty_direct(&param.ty, ImplTraitContext::disallowed())
+                    this.lower_ty_direct(
+                        &param.ty,
+                        ImplTraitContext::Disallowed(match kind {
+                            FnDeclKind::Fn | FnDeclKind::Inherent => {
+                                unreachable!("fn should allow in-band lifetimes")
+                            }
+                            FnDeclKind::ExternFn => ImplTraitPosition::ExternFnParam,
+                            FnDeclKind::Closure => ImplTraitPosition::ClosureParam,
+                            FnDeclKind::Pointer => ImplTraitPosition::PointerParam,
+                            FnDeclKind::Trait => ImplTraitPosition::TraitParam,
+                            FnDeclKind::Impl => ImplTraitPosition::ImplParam,
+                        }),
+                    )
                 }
             }))
         });
@@ -1582,13 +1652,22 @@ fn lower_fn_decl(
             match decl.output {
                 FnRetTy::Ty(ref ty) => {
                     let context = match in_band_ty_params {
-                        Some((def_id, _)) if impl_trait_return_allow => {
+                        Some((def_id, _)) if kind.impl_trait_return_allowed() => {
                             ImplTraitContext::ReturnPositionOpaqueTy {
                                 fn_def_id: def_id,
                                 origin: hir::OpaqueTyOrigin::FnReturn(def_id),
                             }
                         }
-                        _ => ImplTraitContext::disallowed(),
+                        _ => ImplTraitContext::Disallowed(match kind {
+                            FnDeclKind::Fn | FnDeclKind::Inherent => {
+                                unreachable!("fn should allow in-band lifetimes")
+                            }
+                            FnDeclKind::ExternFn => ImplTraitPosition::ExternFnReturn,
+                            FnDeclKind::Closure => ImplTraitPosition::ClosureReturn,
+                            FnDeclKind::Pointer => ImplTraitPosition::PointerReturn,
+                            FnDeclKind::Trait => ImplTraitPosition::TraitReturn,
+                            FnDeclKind::Impl => ImplTraitPosition::ImplReturn,
+                        }),
                     };
                     hir::FnRetTy::Return(self.lower_ty(ty, context))
                 }
@@ -1915,7 +1994,7 @@ fn lower_generic_param(
             GenericParamKind::Type { ref default, .. } => {
                 let kind = hir::GenericParamKind::Type {
                     default: default.as_ref().map(|x| {
-                        self.lower_ty(x, ImplTraitContext::Disallowed(ImplTraitPosition::Other))
+                        self.lower_ty(x, ImplTraitContext::Disallowed(ImplTraitPosition::Type))
                     }),
                     synthetic: false,
                 };
@@ -1923,9 +2002,9 @@ fn lower_generic_param(
                 (hir::ParamName::Plain(self.lower_ident(param.ident)), kind)
             }
             GenericParamKind::Const { ref ty, kw_span: _, ref default } => {
-                let ty = self
-                    .with_anonymous_lifetime_mode(AnonymousLifetimeMode::ReportError, |this| {
-                        this.lower_ty(&ty, ImplTraitContext::disallowed())
+                let ty =
+                    self.with_anonymous_lifetime_mode(AnonymousLifetimeMode::ReportError, |this| {
+                        this.lower_ty(&ty, ImplTraitContext::Disallowed(ImplTraitPosition::Type))
                     });
                 let default = default.as_ref().map(|def| self.lower_anon_const(def));
                 (
index ebae77984330ffeec58114301f859be28d39017c..2c331767b8958541be83947dd6ef7ee9918bc6e5 100644 (file)
@@ -1,3 +1,5 @@
+use crate::ImplTraitPosition;
+
 use super::{ImplTraitContext, LoweringContext, ParamMode};
 
 use rustc_ast::ptr::P;
@@ -33,7 +35,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
                             qself,
                             path,
                             ParamMode::Optional,
-                            ImplTraitContext::disallowed(),
+                            ImplTraitContext::Disallowed(ImplTraitPosition::Path),
                         );
                         let (pats, ddpos) = self.lower_pat_tuple(pats, "tuple struct");
                         break hir::PatKind::TupleStruct(qpath, pats, ddpos);
@@ -49,7 +51,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
                             qself,
                             path,
                             ParamMode::Optional,
-                            ImplTraitContext::disallowed(),
+                            ImplTraitContext::Disallowed(ImplTraitPosition::Path),
                         );
                         break hir::PatKind::Path(qpath);
                     }
@@ -59,7 +61,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
                             qself,
                             path,
                             ParamMode::Optional,
-                            ImplTraitContext::disallowed(),
+                            ImplTraitContext::Disallowed(ImplTraitPosition::Path),
                         );
 
                         let fs = self.arena.alloc_from_iter(fields.iter().map(|f| hir::PatField {
index 79262235cd9f250584e1556c7145a415eb2cf982..b35e3a071619af307dfa7df01533a02d6c2487dd 100644 (file)
@@ -1,3 +1,5 @@
+use crate::ImplTraitPosition;
+
 use super::{AnonymousLifetimeMode, ImplTraitContext, LoweringContext, ParamMode};
 use super::{GenericArgsCtor, ParenthesizedGenericArgs};
 
@@ -184,7 +186,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
                     param_mode,
                     0,
                     ParenthesizedGenericArgs::Err,
-                    ImplTraitContext::disallowed(),
+                    ImplTraitContext::Disallowed(ImplTraitPosition::Path),
                 )
             })),
             span: self.lower_span(p.span),
@@ -392,11 +394,15 @@ fn lower_parenthesized_parameter_data(
         // we generally don't permit such things (see #51008).
         self.with_anonymous_lifetime_mode(AnonymousLifetimeMode::PassThrough, |this| {
             let ParenthesizedArgs { span, inputs, inputs_span, output } = data;
-            let inputs = this.arena.alloc_from_iter(
-                inputs.iter().map(|ty| this.lower_ty_direct(ty, ImplTraitContext::disallowed())),
-            );
+            let inputs = this.arena.alloc_from_iter(inputs.iter().map(|ty| {
+                this.lower_ty_direct(
+                    ty,
+                    ImplTraitContext::Disallowed(ImplTraitPosition::FnTraitParam),
+                )
+            }));
             let output_ty = match output {
-                FnRetTy::Ty(ty) => this.lower_ty(&ty, ImplTraitContext::disallowed()),
+                FnRetTy::Ty(ty) => this
+                    .lower_ty(&ty, ImplTraitContext::Disallowed(ImplTraitPosition::FnTraitReturn)),
                 FnRetTy::Default(_) => this.arena.alloc(this.ty_tup(*span, &[])),
             };
             let args = smallvec![GenericArg::Type(this.ty_tup(*inputs_span, inputs))];
index 1e48996acb83346f9cd4390423146d6b2601a428..38be85ff8201ed77a5840269e0acacd6ef558284 100644 (file)
@@ -57,20 +57,20 @@ fn _rpit_dyn() -> Box<dyn Tr1<As1: Copy>> { Box::new(S1) }
 
 const _cdef: impl Tr1<As1: Copy> = S1;
 //~^ ERROR associated type bounds are unstable
-//~| ERROR `impl Trait` not allowed outside of function and method return types [E0562]
+//~| ERROR `impl Trait` not allowed outside of function and inherent method return types [E0562]
 // FIXME: uncomment when `impl_trait_in_bindings` feature is fixed.
 // const _cdef_dyn: &dyn Tr1<As1: Copy> = &S1;
 
 static _sdef: impl Tr1<As1: Copy> = S1;
 //~^ ERROR associated type bounds are unstable
-//~| ERROR `impl Trait` not allowed outside of function and method return types [E0562]
+//~| ERROR `impl Trait` not allowed outside of function and inherent method return types [E0562]
 // FIXME: uncomment when `impl_trait_in_bindings` feature is fixed.
 // static _sdef_dyn: &dyn Tr1<As1: Copy> = &S1;
 
 fn main() {
     let _: impl Tr1<As1: Copy> = S1;
     //~^ ERROR associated type bounds are unstable
-    //~| ERROR `impl Trait` not allowed outside of function and method return types [E0562]
+    //~| ERROR `impl Trait` not allowed outside of function and inherent method return types [E0562]
     // FIXME: uncomment when `impl_trait_in_bindings` feature is fixed.
     // let _: &dyn Tr1<As1: Copy> = &S1;
 }
index 8c5d72d7efefb37fcc3b8694e136a372de15fc4e..26f10622344da5aa95a81698727f7b333d18b3f6 100644 (file)
@@ -115,23 +115,29 @@ LL |     let _: impl Tr1<As1: Copy> = S1;
    = note: see issue #52662 <https://github.com/rust-lang/rust/issues/52662> for more information
    = help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable
 
-error[E0562]: `impl Trait` not allowed outside of function and method return types
+error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
   --> $DIR/feature-gate-associated_type_bounds.rs:58:14
    |
 LL | const _cdef: impl Tr1<As1: Copy> = S1;
    |              ^^^^^^^^^^^^^^^^^^^
+   |
+   = note: found `impl Trait` in type
 
-error[E0562]: `impl Trait` not allowed outside of function and method return types
+error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
   --> $DIR/feature-gate-associated_type_bounds.rs:64:15
    |
 LL | static _sdef: impl Tr1<As1: Copy> = S1;
    |               ^^^^^^^^^^^^^^^^^^^
+   |
+   = note: found `impl Trait` in type
 
-error[E0562]: `impl Trait` not allowed outside of function and method return types
+error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
   --> $DIR/feature-gate-associated_type_bounds.rs:71:12
    |
 LL |     let _: impl Tr1<As1: Copy> = S1;
    |            ^^^^^^^^^^^^^^^^^^^
+   |
+   = note: found `impl Trait` in variable
 
 error[E0277]: the trait bound `<<Self as _Tr3>::A as Iterator>::Item: Copy` is not satisfied
   --> $DIR/feature-gate-associated_type_bounds.rs:15:28
index 7a64799302332c6a7ce5fba3ca6e212642c018dd..e0e8f274017383868c44554dff6b262f4da72221 100644 (file)
@@ -2,6 +2,6 @@
 
 fn main() {
     let x: Option<impl Debug> = Some(44_u32);
-    //~^ `impl Trait` not allowed outside of function and method return types
+    //~^ `impl Trait` not allowed outside of function and inherent method return types
     println!("{:?}", x);
 }
index 4d0c32c6bb708ac05a5de9a1c665733a18a6f67c..c9626175ff511c00348a7feeaf754a0248e80918 100644 (file)
@@ -1,8 +1,10 @@
-error[E0562]: `impl Trait` not allowed outside of function and method return types
+error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
   --> $DIR/issue-54600.rs:4:19
    |
 LL |     let x: Option<impl Debug> = Some(44_u32);
    |                   ^^^^^^^^^^
+   |
+   = note: found `impl Trait` in variable
 
 error: aborting due to previous error
 
index 030d5715d5739e7f01d0f4fcf79174158bb46a62..8756d1c7de394eb127abca5f41995e0b71d942ab 100644 (file)
@@ -3,5 +3,5 @@
 fn main() {
     let i: i32 = 0;
     let j: &impl Add = &i;
-    //~^ `impl Trait` not allowed outside of function and method return types
+    //~^ `impl Trait` not allowed outside of function and inherent method return types
 }
index b8046b7482f72ab9de8ef3618b42ddce5b1dfc14..a947e0fc46d47605c0975b64d3e160dd89d06b79 100644 (file)
@@ -1,8 +1,10 @@
-error[E0562]: `impl Trait` not allowed outside of function and method return types
+error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
   --> $DIR/issue-54840.rs:5:13
    |
 LL |     let j: &impl Add = &i;
    |             ^^^^^^^^
+   |
+   = note: found `impl Trait` in variable
 
 error: aborting due to previous error
 
index aac33b3b3e5c5c5869fed9c7b0ac1c2fcb9c39e4..ccbe187cef68533fd66eabf07f8a12cef7a4c787 100644 (file)
@@ -8,5 +8,5 @@ fn mk_gen() -> impl Generator<Return=!, Yield=()> {
 
 fn main() {
     let gens: [impl Generator<Return=!, Yield=()>;2] = [ mk_gen(), mk_gen() ];
-    //~^ `impl Trait` not allowed outside of function and method return types
+    //~^ `impl Trait` not allowed outside of function and inherent method return types
 }
index ff1010f0661823dd0e19a6638ea7cd2803a65f6c..6c59bcfa11da206591209c94776163bccdb5df36 100644 (file)
@@ -1,8 +1,10 @@
-error[E0562]: `impl Trait` not allowed outside of function and method return types
+error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
   --> $DIR/issue-58504.rs:10:16
    |
 LL |     let gens: [impl Generator<Return=!, Yield=()>;2] = [ mk_gen(), mk_gen() ];
    |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: found `impl Trait` in variable
 
 error: aborting due to previous error
 
index 5fe18b6e9b54a15d6ca029303d3594a20a045f1c..615dc5b2f29c47001af9fb2f19b51fd3228f5068 100644 (file)
@@ -5,9 +5,9 @@ impl Lam for B {}
 pub struct Wrap<T>(T);
 
 const _A: impl Lam = {
-    //~^ `impl Trait` not allowed outside of function and method return types
+    //~^ `impl Trait` not allowed outside of function and inherent method return types
     let x: Wrap<impl Lam> = Wrap(B);
-    //~^ `impl Trait` not allowed outside of function and method return types
+    //~^ `impl Trait` not allowed outside of function and inherent method return types
     x.0
 };
 
index 00ebf170ab2febbf0130360c9316a457c2418a34..f9bcb94d49d2d4bbf47b6d1576e1c8b2641a6738 100644 (file)
@@ -1,14 +1,18 @@
-error[E0562]: `impl Trait` not allowed outside of function and method return types
+error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
   --> $DIR/issue-58956.rs:7:11
    |
 LL | const _A: impl Lam = {
    |           ^^^^^^^^
+   |
+   = note: found `impl Trait` in type
 
-error[E0562]: `impl Trait` not allowed outside of function and method return types
+error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
   --> $DIR/issue-58956.rs:9:17
    |
 LL |     let x: Wrap<impl Lam> = Wrap(B);
    |                 ^^^^^^^^
+   |
+   = note: found `impl Trait` in variable
 
 error: aborting due to 2 previous errors
 
index d4dc2fd877b67683141c81f7787ff0a613b6239e..4329cf626447692743bf1693fda983bb05f2856e 100644 (file)
@@ -1,4 +1,4 @@
 fn main() {
     let x : (impl Copy,) = (true,);
-    //~^ `impl Trait` not allowed outside of function and method return types
+    //~^ `impl Trait` not allowed outside of function and inherent method return types
 }
index 31993da3e32f3474417c8aad8ba666ba1845fb59..831c0980068c366c3a15ec6b828a0ef9df81cd0d 100644 (file)
@@ -1,8 +1,10 @@
-error[E0562]: `impl Trait` not allowed outside of function and method return types
+error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
   --> $DIR/issue-70971.rs:2:14
    |
 LL |     let x : (impl Copy,) = (true,);
    |              ^^^^^^^^^
+   |
+   = note: found `impl Trait` in variable
 
 error: aborting due to previous error
 
index f72533d42e1fac0af149bac595366154954c2f03..add2d72907cd4e1275f3a8e64ce51a4108fb3763 100644 (file)
@@ -1,7 +1,7 @@
 struct Bug {
     V1: [(); {
         let f: impl core::future::Future<Output = u8> = async { 1 };
-        //~^ `impl Trait` not allowed outside of function and method return types
+        //~^ `impl Trait` not allowed outside of function and inherent method return types
         //~| expected identifier
         1
     }],
index 394b697a2504b13cf6e2a3efe0dc6c8765b26907..c70eb5a1e9d80dc7c553d4448cabf607020c28f7 100644 (file)
@@ -9,11 +9,13 @@ LL |         let f: impl core::future::Future<Output = u8> = async { 1 };
    = help: set `edition = "2021"` in `Cargo.toml`
    = note: for more on editions, read https://doc.rust-lang.org/edition-guide
 
-error[E0562]: `impl Trait` not allowed outside of function and method return types
+error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
   --> $DIR/issue-79099.rs:3:16
    |
 LL |         let f: impl core::future::Future<Output = u8> = async { 1 };
    |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: found `impl Trait` in variable
 
 error: aborting due to 2 previous errors
 
index 773cd0b81cc53ff6a2960ebee538d402a094ce3b..d9d2e3929b10c2cd3778b12f1527a6dbe814e09e 100644 (file)
@@ -1,8 +1,8 @@
 struct Foo<T = impl Copy>(T);
-//~^ ERROR `impl Trait` not allowed outside of function and method return types
+//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
 
 type Result<T, E = impl std::error::Error> = std::result::Result<T, E>;
-//~^ ERROR `impl Trait` not allowed outside of function and method return types
+//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
 
 // should not cause ICE
 fn x() -> Foo {
index d44dcf1f7fa2377c70220369bcab8dc95cb071de..1cac44e796b2c39f909c7c680a7ce3d8a5807181 100644 (file)
@@ -1,14 +1,18 @@
-error[E0562]: `impl Trait` not allowed outside of function and method return types
+error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
   --> $DIR/issue-83929-impl-trait-in-generic-default.rs:1:16
    |
 LL | struct Foo<T = impl Copy>(T);
    |                ^^^^^^^^^
+   |
+   = note: found `impl Trait` in type
 
-error[E0562]: `impl Trait` not allowed outside of function and method return types
+error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
   --> $DIR/issue-83929-impl-trait-in-generic-default.rs:4:20
    |
 LL | type Result<T, E = impl std::error::Error> = std::result::Result<T, E>;
    |                    ^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: found `impl Trait` in type
 
 error: aborting due to 2 previous errors
 
index 479bad97cdf32e214d46aa9f17045a945ae5105b..6abe3cd7ea5c1ecc475e5bc036d49208cbd1da14 100644 (file)
@@ -3,7 +3,7 @@ impl Trait for () {}
 
 fn foo<'a: 'a>() {
     let _x: impl Trait = ();
-    //~^ `impl Trait` not allowed outside of function and method return types
+    //~^ `impl Trait` not allowed outside of function and inherent method return types
 }
 
 fn main() {}
index bb1bcfefe64ee1834f7d9807068aea4deef64681..36fc750cf87b049d14224dca31893262585cbd76 100644 (file)
@@ -1,8 +1,10 @@
-error[E0562]: `impl Trait` not allowed outside of function and method return types
+error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
   --> $DIR/issue-84919.rs:5:13
    |
 LL |     let _x: impl Trait = ();
    |             ^^^^^^^^^^
+   |
+   = note: found `impl Trait` in variable
 
 error: aborting due to previous error
 
index 8953ff8158148f7a952eebdfa1fbd3137b4cd4fb..c7e4045f43205786cfcdb526c73d5a356955ac91 100644 (file)
@@ -1,5 +1,5 @@
 static x: impl Fn(&str) -> Result<&str, ()> = move |source| {
-    //~^ `impl Trait` not allowed outside of function and method return types
+    //~^ `impl Trait` not allowed outside of function and inherent method return types
     let res = (move |source| Ok(source))(source);
     let res = res.or((move |source| Ok(source))(source));
     res
index 2fc0a6fe1f50e6da6320d6d2ed5982bdbb0ffe18..d12f0f3d2a9f3fb1f505cd75e55bd0afc8aa9e00 100644 (file)
@@ -1,8 +1,10 @@
-error[E0562]: `impl Trait` not allowed outside of function and method return types
+error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
   --> $DIR/issue-86642.rs:1:11
    |
 LL | static x: impl Fn(&str) -> Result<&str, ()> = move |source| {
    |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: found `impl Trait` in type
 
 error: aborting due to previous error
 
index 2f2bfe147bd6659df0a31072ea42e857e045f54c..da75e777398f58c837b3e5f37bfab2fdbedda66b 100644 (file)
@@ -14,5 +14,5 @@ pub fn new(_: F) -> Self {
 
 fn main() {
     let _do_not_waste: Struct<impl Trait<Output = i32>> = Struct::new(());
-    //~^ `impl Trait` not allowed outside of function and method return types
+    //~^ `impl Trait` not allowed outside of function and inherent method return types
 }
index f5c7603ce49181735f7e8e2efd42d3b7717cf16b..6bdc356b6a4067faedff25161cc6043afe0e4257 100644 (file)
@@ -1,8 +1,10 @@
-error[E0562]: `impl Trait` not allowed outside of function and method return types
+error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
   --> $DIR/issue-87295.rs:16:31
    |
 LL |     let _do_not_waste: Struct<impl Trait<Output = i32>> = Struct::new(());
    |                               ^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: found `impl Trait` in variable
 
 error: aborting due to previous error
 
index 59c7e4d5f4e92b8aa0a8867f5e04120567f9a026..c6a56ea0e302fe2e9af0c06e866f8157f013f87d 100644 (file)
@@ -34,17 +34,21 @@ LL |     fn bad(x: impl Into<u32>) -> impl Into<impl Debug> { x }
    |                                  |         nested `impl Trait` here
    |                                  outer `impl Trait`
 
-error[E0562]: `impl Trait` not allowed outside of function and method return types
+error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
   --> $DIR/nested_impl_trait.rs:8:32
    |
 LL | fn bad_in_fn_syntax(x: fn() -> impl Into<impl Debug>) {}
    |                                ^^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: found `impl Trait` in `fn` pointer return
 
-error[E0562]: `impl Trait` not allowed outside of function and method return types
+error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
   --> $DIR/nested_impl_trait.rs:25:42
    |
 LL | fn allowed_in_ret_type() -> impl Fn() -> impl Into<u32> {
    |                                          ^^^^^^^^^^^^^^
+   |
+   = note: found `impl Trait` in `Fn` trait return
 
 error: aborting due to 6 previous errors
 
index 35fb42d6213226918f687979944f6812db7d6278..07d28dbd025ace1cecb5a593c39e89991cb83eff 100644 (file)
@@ -13,61 +13,61 @@ fn in_adt_in_parameters(_: Vec<impl Debug>) { panic!() }
 
 // Disallowed
 fn in_fn_parameter_in_parameters(_: fn(impl Debug)) { panic!() }
-//~^ ERROR `impl Trait` not allowed outside of function and method return types
+//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
 
 // Disallowed
 fn in_fn_return_in_parameters(_: fn() -> impl Debug) { panic!() }
-//~^ ERROR `impl Trait` not allowed outside of function and method return types
+//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
 
 // Disallowed
 fn in_fn_parameter_in_return() -> fn(impl Debug) { panic!() }
-//~^ ERROR `impl Trait` not allowed outside of function and method return types
+//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
 
 // Disallowed
 fn in_fn_return_in_return() -> fn() -> impl Debug { panic!() }
-//~^ ERROR `impl Trait` not allowed outside of function and method return types
+//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
 
 // Disallowed
 fn in_dyn_Fn_parameter_in_parameters(_: &dyn Fn(impl Debug)) { panic!() }
-//~^ ERROR `impl Trait` not allowed outside of function and method return types
+//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
 
 // Disallowed
 fn in_dyn_Fn_return_in_parameters(_: &dyn Fn() -> impl Debug) { panic!() }
-//~^ ERROR `impl Trait` not allowed outside of function and method return types
+//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
 
 // Disallowed
 fn in_dyn_Fn_parameter_in_return() -> &'static dyn Fn(impl Debug) { panic!() }
-//~^ ERROR `impl Trait` not allowed outside of function and method return types
+//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
 
 // Disallowed
 fn in_dyn_Fn_return_in_return() -> &'static dyn Fn() -> impl Debug { panic!() }
-//~^ ERROR `impl Trait` not allowed outside of function and method return types
+//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
 
 // Disallowed
 fn in_impl_Fn_parameter_in_parameters(_: &impl Fn(impl Debug)) { panic!() }
-//~^ ERROR `impl Trait` not allowed outside of function and method return types
+//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
 //~^^ ERROR nested `impl Trait` is not allowed
 
 // Disallowed
 fn in_impl_Fn_return_in_parameters(_: &impl Fn() -> impl Debug) { panic!() }
-//~^ ERROR `impl Trait` not allowed outside of function and method return types
+//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
 
 // Disallowed
 fn in_impl_Fn_parameter_in_return() -> &'static impl Fn(impl Debug) { panic!() }
-//~^ ERROR `impl Trait` not allowed outside of function and method return types
+//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
 //~| ERROR nested `impl Trait` is not allowed
 
 // Disallowed
 fn in_impl_Fn_return_in_return() -> &'static impl Fn() -> impl Debug { panic!() }
-//~^ ERROR `impl Trait` not allowed outside of function and method return types
+//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
 
 // Disallowed
 fn in_Fn_parameter_in_generics<F: Fn(impl Debug)> (_: F) { panic!() }
-//~^ ERROR `impl Trait` not allowed outside of function and method return types
+//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
 
 // Disallowed
 fn in_Fn_return_in_generics<F: Fn() -> impl Debug> (_: F) { panic!() }
-//~^ ERROR `impl Trait` not allowed outside of function and method return types
+//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
 
 
 // Allowed
@@ -80,22 +80,22 @@ fn in_impl_Trait_in_return() -> impl IntoIterator<Item = impl IntoIterator> {
 
 // Disallowed
 struct InBraceStructField { x: impl Debug }
-//~^ ERROR `impl Trait` not allowed outside of function and method return types
+//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
 
 // Disallowed
 struct InAdtInBraceStructField { x: Vec<impl Debug> }
-//~^ ERROR `impl Trait` not allowed outside of function and method return types
+//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
 
 // Disallowed
 struct InTupleStructField(impl Debug);
-//~^ ERROR `impl Trait` not allowed outside of function and method return types
+//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
 
 // Disallowed
 enum InEnum {
     InBraceVariant { x: impl Debug },
-    //~^ ERROR `impl Trait` not allowed outside of function and method return types
+    //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
     InTupleVariant(impl Debug),
-    //~^ ERROR `impl Trait` not allowed outside of function and method return types
+    //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
 }
 
 // Allowed
@@ -106,7 +106,7 @@ trait InTraitDefnParameters {
 // Disallowed
 trait InTraitDefnReturn {
     fn in_return() -> impl Debug;
-    //~^ ERROR `impl Trait` not allowed outside of function and method return types
+    //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
 }
 
 // Allowed and disallowed in trait impls
@@ -123,7 +123,7 @@ fn in_trait_impl_parameter(_: impl Debug) { }
     // Allowed
 
     fn in_trait_impl_return() -> impl Debug { () }
-    //~^ ERROR `impl Trait` not allowed outside of function and method return types
+    //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
 }
 
 // Allowed
@@ -136,10 +136,10 @@ fn in_inherent_impl_return() -> impl Debug { () }
 // Disallowed
 extern "C" {
     fn in_foreign_parameters(_: impl Debug);
-    //~^ ERROR `impl Trait` not allowed outside of function and method return types
+    //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
 
     fn in_foreign_return() -> impl Debug;
-    //~^ ERROR `impl Trait` not allowed outside of function and method return types
+    //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
 }
 
 // Allowed
@@ -155,97 +155,97 @@ extern "C" fn in_extern_fn_return() -> impl Debug {
 //~^ ERROR `impl Trait` in type aliases is unstable
 
 type InReturnInTypeAlias<R> = fn() -> impl Debug;
-//~^ ERROR `impl Trait` not allowed outside of function and method return types
+//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
 //~| ERROR `impl Trait` in type aliases is unstable
 
 // Disallowed in impl headers
 impl PartialEq<impl Debug> for () {
-    //~^ ERROR `impl Trait` not allowed outside of function and method return types
+    //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
 }
 
 // Disallowed in impl headers
 impl PartialEq<()> for impl Debug {
-    //~^ ERROR `impl Trait` not allowed outside of function and method return types
+    //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
 }
 
 // Disallowed in inherent impls
 impl impl Debug {
-    //~^ ERROR `impl Trait` not allowed outside of function and method return types
+    //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
 }
 
 // Disallowed in inherent impls
 struct InInherentImplAdt<T> { t: T }
 impl InInherentImplAdt<impl Debug> {
-    //~^ ERROR `impl Trait` not allowed outside of function and method return types
+    //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
 }
 
 // Disallowed in where clauses
 fn in_fn_where_clause()
     where impl Debug: Debug
-//~^ ERROR `impl Trait` not allowed outside of function and method return types
+//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
 {
 }
 
 // Disallowed in where clauses
 fn in_adt_in_fn_where_clause()
     where Vec<impl Debug>: Debug
-//~^ ERROR `impl Trait` not allowed outside of function and method return types
+//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
 {
 }
 
 // Disallowed
 fn in_trait_parameter_in_fn_where_clause<T>()
     where T: PartialEq<impl Debug>
-//~^ ERROR `impl Trait` not allowed outside of function and method return types
+//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
 {
 }
 
 // Disallowed
 fn in_Fn_parameter_in_fn_where_clause<T>()
     where T: Fn(impl Debug)
-//~^ ERROR `impl Trait` not allowed outside of function and method return types
+//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
 {
 }
 
 // Disallowed
 fn in_Fn_return_in_fn_where_clause<T>()
     where T: Fn() -> impl Debug
-//~^ ERROR `impl Trait` not allowed outside of function and method return types
+//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
 {
 }
 
 // Disallowed
 struct InStructGenericParamDefault<T = impl Debug>(T);
-//~^ ERROR `impl Trait` not allowed outside of function and method return types
+//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
 
 // Disallowed
 enum InEnumGenericParamDefault<T = impl Debug> { Variant(T) }
-//~^ ERROR `impl Trait` not allowed outside of function and method return types
+//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
 
 // Disallowed
 trait InTraitGenericParamDefault<T = impl Debug> {}
-//~^ ERROR `impl Trait` not allowed outside of function and method return types
+//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
 
 // Disallowed
 type InTypeAliasGenericParamDefault<T = impl Debug> = T;
-//~^ ERROR `impl Trait` not allowed outside of function and method return types
+//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
 
 // Disallowed
 impl <T = impl Debug> T {}
 //~^ ERROR defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions
 //~| WARNING this was previously accepted by the compiler but is being phased out
-//~| ERROR `impl Trait` not allowed outside of function and method return types
+//~| ERROR `impl Trait` not allowed outside of function and inherent method return types
 //~| ERROR no nominal type found
 
 // Disallowed
 fn in_method_generic_param_default<T = impl Debug>(_: T) {}
 //~^ ERROR defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions
 //~| WARNING this was previously accepted by the compiler but is being phased out
-//~| ERROR `impl Trait` not allowed outside of function and method return types
+//~| ERROR `impl Trait` not allowed outside of function and inherent method return types
 
 fn main() {
     let _in_local_variable: impl Fn() = || {};
-    //~^ ERROR `impl Trait` not allowed outside of function and method return types
+    //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
     let _in_return_in_local_variable = || -> impl Fn() { || {} };
-    //~^ ERROR `impl Trait` not allowed outside of function and method return types
+    //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
 }
index 236cf449e85fa5050893e64709a4a507ec310fc0..579c7d2ff79ba1d10319f3c19ef9b9c8e59fd622 100644 (file)
@@ -43,251 +43,333 @@ LL | type InReturnInTypeAlias<R> = fn() -> impl Debug;
    = note: see issue #63063 <https://github.com/rust-lang/rust/issues/63063> for more information
    = help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable
 
-error[E0562]: `impl Trait` not allowed outside of function and method return types
+error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
   --> $DIR/where-allowed.rs:15:40
    |
 LL | fn in_fn_parameter_in_parameters(_: fn(impl Debug)) { panic!() }
    |                                        ^^^^^^^^^^
+   |
+   = note: found `impl Trait` in `fn` pointer param
 
-error[E0562]: `impl Trait` not allowed outside of function and method return types
+error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
   --> $DIR/where-allowed.rs:19:42
    |
 LL | fn in_fn_return_in_parameters(_: fn() -> impl Debug) { panic!() }
    |                                          ^^^^^^^^^^
+   |
+   = note: found `impl Trait` in `fn` pointer return
 
-error[E0562]: `impl Trait` not allowed outside of function and method return types
+error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
   --> $DIR/where-allowed.rs:23:38
    |
 LL | fn in_fn_parameter_in_return() -> fn(impl Debug) { panic!() }
    |                                      ^^^^^^^^^^
+   |
+   = note: found `impl Trait` in `fn` pointer param
 
-error[E0562]: `impl Trait` not allowed outside of function and method return types
+error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
   --> $DIR/where-allowed.rs:27:40
    |
 LL | fn in_fn_return_in_return() -> fn() -> impl Debug { panic!() }
    |                                        ^^^^^^^^^^
+   |
+   = note: found `impl Trait` in `fn` pointer return
 
-error[E0562]: `impl Trait` not allowed outside of function and method return types
+error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
   --> $DIR/where-allowed.rs:31:49
    |
 LL | fn in_dyn_Fn_parameter_in_parameters(_: &dyn Fn(impl Debug)) { panic!() }
    |                                                 ^^^^^^^^^^
+   |
+   = note: found `impl Trait` in `Fn` trait param
 
-error[E0562]: `impl Trait` not allowed outside of function and method return types
+error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
   --> $DIR/where-allowed.rs:35:51
    |
 LL | fn in_dyn_Fn_return_in_parameters(_: &dyn Fn() -> impl Debug) { panic!() }
    |                                                   ^^^^^^^^^^
+   |
+   = note: found `impl Trait` in `Fn` trait return
 
-error[E0562]: `impl Trait` not allowed outside of function and method return types
+error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
   --> $DIR/where-allowed.rs:39:55
    |
 LL | fn in_dyn_Fn_parameter_in_return() -> &'static dyn Fn(impl Debug) { panic!() }
    |                                                       ^^^^^^^^^^
+   |
+   = note: found `impl Trait` in `Fn` trait param
 
-error[E0562]: `impl Trait` not allowed outside of function and method return types
+error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
   --> $DIR/where-allowed.rs:43:57
    |
 LL | fn in_dyn_Fn_return_in_return() -> &'static dyn Fn() -> impl Debug { panic!() }
    |                                                         ^^^^^^^^^^
+   |
+   = note: found `impl Trait` in `Fn` trait return
 
-error[E0562]: `impl Trait` not allowed outside of function and method return types
+error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
   --> $DIR/where-allowed.rs:47:51
    |
 LL | fn in_impl_Fn_parameter_in_parameters(_: &impl Fn(impl Debug)) { panic!() }
    |                                                   ^^^^^^^^^^
+   |
+   = note: found `impl Trait` in `Fn` trait param
 
-error[E0562]: `impl Trait` not allowed outside of function and method return types
+error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
   --> $DIR/where-allowed.rs:52:53
    |
 LL | fn in_impl_Fn_return_in_parameters(_: &impl Fn() -> impl Debug) { panic!() }
    |                                                     ^^^^^^^^^^
+   |
+   = note: found `impl Trait` in `Fn` trait return
 
-error[E0562]: `impl Trait` not allowed outside of function and method return types
+error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
   --> $DIR/where-allowed.rs:56:57
    |
 LL | fn in_impl_Fn_parameter_in_return() -> &'static impl Fn(impl Debug) { panic!() }
    |                                                         ^^^^^^^^^^
+   |
+   = note: found `impl Trait` in `Fn` trait param
 
-error[E0562]: `impl Trait` not allowed outside of function and method return types
+error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
   --> $DIR/where-allowed.rs:61:59
    |
 LL | fn in_impl_Fn_return_in_return() -> &'static impl Fn() -> impl Debug { panic!() }
    |                                                           ^^^^^^^^^^
+   |
+   = note: found `impl Trait` in `Fn` trait return
 
-error[E0562]: `impl Trait` not allowed outside of function and method return types
+error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
   --> $DIR/where-allowed.rs:65:38
    |
 LL | fn in_Fn_parameter_in_generics<F: Fn(impl Debug)> (_: F) { panic!() }
    |                                      ^^^^^^^^^^
+   |
+   = note: found `impl Trait` in `Fn` trait param
 
-error[E0562]: `impl Trait` not allowed outside of function and method return types
+error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
   --> $DIR/where-allowed.rs:69:40
    |
 LL | fn in_Fn_return_in_generics<F: Fn() -> impl Debug> (_: F) { panic!() }
    |                                        ^^^^^^^^^^
+   |
+   = note: found `impl Trait` in `Fn` trait return
 
-error[E0562]: `impl Trait` not allowed outside of function and method return types
+error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
   --> $DIR/where-allowed.rs:82:32
    |
 LL | struct InBraceStructField { x: impl Debug }
    |                                ^^^^^^^^^^
+   |
+   = note: found `impl Trait` in type
 
-error[E0562]: `impl Trait` not allowed outside of function and method return types
+error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
   --> $DIR/where-allowed.rs:86:41
    |
 LL | struct InAdtInBraceStructField { x: Vec<impl Debug> }
    |                                         ^^^^^^^^^^
+   |
+   = note: found `impl Trait` in path
 
-error[E0562]: `impl Trait` not allowed outside of function and method return types
+error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
   --> $DIR/where-allowed.rs:90:27
    |
 LL | struct InTupleStructField(impl Debug);
    |                           ^^^^^^^^^^
+   |
+   = note: found `impl Trait` in type
 
-error[E0562]: `impl Trait` not allowed outside of function and method return types
+error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
   --> $DIR/where-allowed.rs:95:25
    |
 LL |     InBraceVariant { x: impl Debug },
    |                         ^^^^^^^^^^
+   |
+   = note: found `impl Trait` in type
 
-error[E0562]: `impl Trait` not allowed outside of function and method return types
+error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
   --> $DIR/where-allowed.rs:97:20
    |
 LL |     InTupleVariant(impl Debug),
    |                    ^^^^^^^^^^
+   |
+   = note: found `impl Trait` in type
 
-error[E0562]: `impl Trait` not allowed outside of function and method return types
+error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
   --> $DIR/where-allowed.rs:108:23
    |
 LL |     fn in_return() -> impl Debug;
    |                       ^^^^^^^^^^
+   |
+   = note: found `impl Trait` in trait method return
 
-error[E0562]: `impl Trait` not allowed outside of function and method return types
+error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
   --> $DIR/where-allowed.rs:125:34
    |
 LL |     fn in_trait_impl_return() -> impl Debug { () }
    |                                  ^^^^^^^^^^
+   |
+   = note: found `impl Trait` in `impl` method return
 
-error[E0562]: `impl Trait` not allowed outside of function and method return types
+error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
   --> $DIR/where-allowed.rs:138:33
    |
 LL |     fn in_foreign_parameters(_: impl Debug);
    |                                 ^^^^^^^^^^
+   |
+   = note: found `impl Trait` in `extern fn` param
 
-error[E0562]: `impl Trait` not allowed outside of function and method return types
+error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
   --> $DIR/where-allowed.rs:141:31
    |
 LL |     fn in_foreign_return() -> impl Debug;
    |                               ^^^^^^^^^^
+   |
+   = note: found `impl Trait` in `extern fn` return
 
-error[E0562]: `impl Trait` not allowed outside of function and method return types
+error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
   --> $DIR/where-allowed.rs:157:39
    |
 LL | type InReturnInTypeAlias<R> = fn() -> impl Debug;
    |                                       ^^^^^^^^^^
+   |
+   = note: found `impl Trait` in `fn` pointer return
 
-error[E0562]: `impl Trait` not allowed outside of function and method return types
+error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
   --> $DIR/where-allowed.rs:162:16
    |
 LL | impl PartialEq<impl Debug> for () {
    |                ^^^^^^^^^^
+   |
+   = note: found `impl Trait` in trait
 
-error[E0562]: `impl Trait` not allowed outside of function and method return types
+error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
   --> $DIR/where-allowed.rs:167:24
    |
 LL | impl PartialEq<()> for impl Debug {
    |                        ^^^^^^^^^^
+   |
+   = note: found `impl Trait` in type
 
-error[E0562]: `impl Trait` not allowed outside of function and method return types
+error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
   --> $DIR/where-allowed.rs:172:6
    |
 LL | impl impl Debug {
    |      ^^^^^^^^^^
+   |
+   = note: found `impl Trait` in type
 
-error[E0562]: `impl Trait` not allowed outside of function and method return types
+error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
   --> $DIR/where-allowed.rs:178:24
    |
 LL | impl InInherentImplAdt<impl Debug> {
    |                        ^^^^^^^^^^
+   |
+   = note: found `impl Trait` in type
 
-error[E0562]: `impl Trait` not allowed outside of function and method return types
+error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
   --> $DIR/where-allowed.rs:184:11
    |
 LL |     where impl Debug: Debug
    |           ^^^^^^^^^^
+   |
+   = note: found `impl Trait` in type
 
-error[E0562]: `impl Trait` not allowed outside of function and method return types
+error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
   --> $DIR/where-allowed.rs:191:15
    |
 LL |     where Vec<impl Debug>: Debug
    |               ^^^^^^^^^^
+   |
+   = note: found `impl Trait` in type
 
-error[E0562]: `impl Trait` not allowed outside of function and method return types
+error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
   --> $DIR/where-allowed.rs:198:24
    |
 LL |     where T: PartialEq<impl Debug>
    |                        ^^^^^^^^^^
+   |
+   = note: found `impl Trait` in bound
 
-error[E0562]: `impl Trait` not allowed outside of function and method return types
+error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
   --> $DIR/where-allowed.rs:205:17
    |
 LL |     where T: Fn(impl Debug)
    |                 ^^^^^^^^^^
+   |
+   = note: found `impl Trait` in `Fn` trait param
 
-error[E0562]: `impl Trait` not allowed outside of function and method return types
+error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
   --> $DIR/where-allowed.rs:212:22
    |
 LL |     where T: Fn() -> impl Debug
    |                      ^^^^^^^^^^
+   |
+   = note: found `impl Trait` in `Fn` trait return
 
-error[E0562]: `impl Trait` not allowed outside of function and method return types
+error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
   --> $DIR/where-allowed.rs:218:40
    |
 LL | struct InStructGenericParamDefault<T = impl Debug>(T);
    |                                        ^^^^^^^^^^
+   |
+   = note: found `impl Trait` in type
 
-error[E0562]: `impl Trait` not allowed outside of function and method return types
+error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
   --> $DIR/where-allowed.rs:222:36
    |
 LL | enum InEnumGenericParamDefault<T = impl Debug> { Variant(T) }
    |                                    ^^^^^^^^^^
+   |
+   = note: found `impl Trait` in type
 
-error[E0562]: `impl Trait` not allowed outside of function and method return types
+error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
   --> $DIR/where-allowed.rs:226:38
    |
 LL | trait InTraitGenericParamDefault<T = impl Debug> {}
    |                                      ^^^^^^^^^^
+   |
+   = note: found `impl Trait` in type
 
-error[E0562]: `impl Trait` not allowed outside of function and method return types
+error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
   --> $DIR/where-allowed.rs:230:41
    |
 LL | type InTypeAliasGenericParamDefault<T = impl Debug> = T;
    |                                         ^^^^^^^^^^
+   |
+   = note: found `impl Trait` in type
 
-error[E0562]: `impl Trait` not allowed outside of function and method return types
+error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
   --> $DIR/where-allowed.rs:234:11
    |
 LL | impl <T = impl Debug> T {}
    |           ^^^^^^^^^^
+   |
+   = note: found `impl Trait` in type
 
-error[E0562]: `impl Trait` not allowed outside of function and method return types
+error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
   --> $DIR/where-allowed.rs:241:40
    |
 LL | fn in_method_generic_param_default<T = impl Debug>(_: T) {}
    |                                        ^^^^^^^^^^
+   |
+   = note: found `impl Trait` in type
 
-error[E0562]: `impl Trait` not allowed outside of function and method return types
+error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
   --> $DIR/where-allowed.rs:247:29
    |
 LL |     let _in_local_variable: impl Fn() = || {};
    |                             ^^^^^^^^^
+   |
+   = note: found `impl Trait` in variable
 
-error[E0562]: `impl Trait` not allowed outside of function and method return types
+error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
   --> $DIR/where-allowed.rs:249:46
    |
 LL |     let _in_return_in_local_variable = || -> impl Fn() { || {} };
    |                                              ^^^^^^^^^
+   |
+   = note: found `impl Trait` in closure return
 
 error: defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions
   --> $DIR/where-allowed.rs:234:7
index 63a28d997e11a04be36bc02d32df4544a2fc00f8..5cccc7f3432be5682228232ed431c0512887d79f 100644 (file)
@@ -1,26 +1,34 @@
-error[E0562]: `impl Trait` not allowed outside of function and method return types
+error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
   --> $DIR/issue-47715.rs:9:37
    |
 LL | struct Container<T: Iterable<Item = impl Foo>> {
    |                                     ^^^^^^^^
+   |
+   = note: found `impl Trait` in generic
 
-error[E0562]: `impl Trait` not allowed outside of function and method return types
+error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
   --> $DIR/issue-47715.rs:14:30
    |
 LL | enum Enum<T: Iterable<Item = impl Foo>> {
    |                              ^^^^^^^^
+   |
+   = note: found `impl Trait` in generic
 
-error[E0562]: `impl Trait` not allowed outside of function and method return types
+error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
   --> $DIR/issue-47715.rs:19:32
    |
 LL | union Union<T: Iterable<Item = impl Foo> + Copy> {
    |                                ^^^^^^^^
+   |
+   = note: found `impl Trait` in generic
 
-error[E0562]: `impl Trait` not allowed outside of function and method return types
+error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
   --> $DIR/issue-47715.rs:24:30
    |
 LL | type Type<T: Iterable<Item = impl Foo>> = T;
    |                              ^^^^^^^^
+   |
+   = note: found `impl Trait` in generic
 
 error: aborting due to 4 previous errors
 
index 299bdf562dc41e372cbeaff0c5ff823f6d2b8f7f..35b2e0fe7d9882813c06670d372b6a9e092c721d 100644 (file)
@@ -4,7 +4,7 @@
 // FIXME: this is ruled out for now but should work
 
 type Foo = fn() -> impl Send;
-//~^ ERROR: `impl Trait` not allowed outside of function and method return types
+//~^ ERROR: `impl Trait` not allowed outside of function and inherent method return types
 
 fn make_foo() -> Foo {
     || 15
index 1c5d57d4af76154532d16604da7cbc82f2aa76d7..89235215643c3eb7124c41e826ba4a5268b6c9b1 100644 (file)
@@ -1,8 +1,10 @@
-error[E0562]: `impl Trait` not allowed outside of function and method return types
+error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
   --> $DIR/type-alias-impl-trait-fn-type.rs:6:20
    |
 LL | type Foo = fn() -> impl Send;
    |                    ^^^^^^^^^
+   |
+   = note: found `impl Trait` in `fn` pointer return
 
 error: aborting due to previous error