diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/generics.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/generics.rs index f5a64ede398ea..bc919fe4d0295 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/generics.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/generics.rs @@ -64,9 +64,9 @@ fn generic_arg_mismatch_err( ) => match path.res { Res::Err => { add_braces_suggestion(arg, &mut err); - return err - .with_primary_message("unresolved item provided when a constant was expected") - .emit(); + err.primary_message("unresolved item provided when a constant was expected"); + // A resolve error will already have been emitted pointing at this. + return err.delay_as_bug(); } Res::Def(DefKind::TyParam, src_def_id) => { if let Some(param_local_id) = param.def_id.as_local() { diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index f1a03d5a06109..55890ca4efb80 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -424,6 +424,8 @@ pub(crate) enum AliasPossibility { pub(crate) enum PathSource<'a, 'ast, 'ra> { /// Type paths `Path`. Type, + /// Type or constant in a `PathSegment` argument. + TypeParam, /// Trait paths in bounds or impls. Trait(AliasPossibility), /// Expression paths `path`, with optional parent context. @@ -453,6 +455,7 @@ impl PathSource<'_, '_, '_> { fn namespace(self) -> Namespace { match self { PathSource::Type + | PathSource::TypeParam | PathSource::Trait(_) | PathSource::Struct(_) | PathSource::DefineOpaques => TypeNS, @@ -469,6 +472,7 @@ impl PathSource<'_, '_, '_> { fn defer_to_typeck(self) -> bool { match self { PathSource::Type + | PathSource::TypeParam | PathSource::Expr(..) | PathSource::Pat | PathSource::Struct(_) @@ -486,6 +490,7 @@ impl PathSource<'_, '_, '_> { match &self { PathSource::DefineOpaques => "type alias or associated type with opaqaue types", PathSource::Type => "type", + PathSource::TypeParam => "type or constant", PathSource::Trait(_) => "trait", PathSource::Pat => "unit struct, unit variant or constant", PathSource::Struct(_) => "struct, variant or union type", @@ -560,6 +565,29 @@ impl PathSource<'_, '_, '_> { | Res::SelfTyParam { .. } | Res::SelfTyAlias { .. } ), + PathSource::TypeParam => matches!( + res, + Res::Def( + DefKind::Struct + | DefKind::Union + | DefKind::Enum + | DefKind::Trait + | DefKind::TraitAlias + | DefKind::TyAlias + | DefKind::AssocTy + | DefKind::TyParam + | DefKind::OpaqueTy + | DefKind::AnonConst + | DefKind::AssocConst + | DefKind::Const + | DefKind::ConstParam + | DefKind::InlineConst + | DefKind::ForeignTy, + _, + ) | Res::PrimTy(..) + | Res::SelfTyParam { .. } + | Res::SelfTyAlias { .. } + ), PathSource::Trait(AliasPossibility::No) => matches!(res, Res::Def(DefKind::Trait, _)), PathSource::Trait(AliasPossibility::Maybe) => { matches!(res, Res::Def(DefKind::Trait | DefKind::TraitAlias, _)) @@ -621,8 +649,8 @@ impl PathSource<'_, '_, '_> { match (self, has_unexpected_resolution) { (PathSource::Trait(_), true) => E0404, (PathSource::Trait(_), false) => E0405, - (PathSource::Type | PathSource::DefineOpaques, true) => E0573, - (PathSource::Type | PathSource::DefineOpaques, false) => E0425, + (PathSource::Type | PathSource::DefineOpaques | PathSource::TypeParam, true) => E0573, + (PathSource::Type | PathSource::DefineOpaques | PathSource::TypeParam, false) => E0425, (PathSource::Struct(_), true) => E0574, (PathSource::Struct(_), false) => E0422, (PathSource::Expr(..), true) | (PathSource::Delegation, true) => E0423, @@ -2129,6 +2157,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { PathSource::Trait(..) | PathSource::TraitItem(..) | PathSource::Type + | PathSource::TypeParam | PathSource::PreciseCapturingArg(..) | PathSource::ReturnTypeNotation => false, PathSource::Expr(..) diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index 2b85639376d97..8d3727bba6cc6 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -769,9 +769,11 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> { Ok(s.get(start - 1..start) == Some("{")) }); if let Ok(true) = field_is_format_named_arg { - err.help( - format!("you might have meant to use the available field in a format string: `\"{{}}\", self.{}`", segment.ident.name), - ); + err.help(format!( + "you might have meant to use the available field in a format \ + string: `\"{{}}\", self.{}`", + segment.ident.name, + )); } else { err.span_suggestion_verbose( span.shrink_to_lo(), @@ -1026,13 +1028,19 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> { fn suggest_typo( &mut self, err: &mut Diag<'_>, - source: PathSource<'_, 'ast, 'ra>, + mut source: PathSource<'_, 'ast, 'ra>, path: &[Segment], following_seg: Option<&Segment>, span: Span, base_error: &BaseError, suggested_candidates: FxHashSet, ) -> bool { + if self.diag_metadata.currently_processing_generic_args + && matches!(source, PathSource::Type) + { + source = PathSource::TypeParam; + } + let is_expected = &|res| source.is_expected(res); let ident_span = path.last().map_or(span, |ident| ident.ident.span); let typo_sugg = diff --git a/compiler/rustc_trait_selection/src/error_reporting/infer/need_type_info.rs b/compiler/rustc_trait_selection/src/error_reporting/infer/need_type_info.rs index 0a2442b71e78f..2b85e91422d82 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/infer/need_type_info.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/infer/need_type_info.rs @@ -498,6 +498,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { None }; + let mut delay_as_bug = false; let mut infer_subdiags = Vec::new(); let mut multi_suggestions = Vec::new(); match kind { @@ -513,7 +514,11 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { type_name: ty_to_string(self, ty, def_id), }); } - InferSourceKind::ClosureArg { insert_span, ty, .. } => { + InferSourceKind::ClosureArg { insert_span, ty, kind, .. } => { + if let PatKind::Err(_) = kind { + // We will have already emitted an error about this pattern. + delay_as_bug = true; + } infer_subdiags.push(SourceKindSubdiag::LetLike { span: insert_span, name: String::new(), @@ -532,7 +537,17 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { def_id: _, generic_args, have_turbofish, + hir_id, } => { + if let hir::Node::PathSegment(segment) = self.tcx.hir_node(hir_id) + && let Some(args) = segment.args + && let Some(hir::GenericArg::Type(ty)) = args.args.get(argument_index) + && let hir::TyKind::Path(hir::QPath::Resolved(_, path)) = ty.kind + && let Res::Err = path.res + { + // We have already emitted a name resolution error. + delay_as_bug = true; + } let generics = self.tcx.generics_of(generics_def_id); let is_type = term.as_type().is_some(); @@ -653,8 +668,8 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { }), }; *err.long_ty_path() = long_ty_path; - if let InferSourceKind::ClosureArg { kind: PatKind::Err(_), .. } = kind { - // We will have already emitted an error about this pattern. + if delay_as_bug { + // We have already emitted an earlier more relevant error. err.downgrade_to_delayed_bug(); } err @@ -687,6 +702,7 @@ enum InferSourceKind<'tcx> { def_id: DefId, generic_args: &'tcx [GenericArg<'tcx>], have_turbofish: bool, + hir_id: HirId, }, FullyQualifiedMethodCall { receiver: &'tcx Expr<'tcx>, @@ -751,6 +767,7 @@ struct InsertableGenericArgs<'tcx> { generics_def_id: DefId, def_id: DefId, have_turbofish: bool, + hir_id: HirId, } /// A visitor which searches for the "best" spot to use in the inference error. @@ -1013,6 +1030,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> { generics_def_id: def_id, def_id, have_turbofish: false, + hir_id: expr.hir_id, } }; return Box::new(insertable.into_iter()); @@ -1052,6 +1070,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> { generics_def_id, def_id: path.res.def_id(), have_turbofish, + hir_id: path.segments.last().unwrap().hir_id, } }; @@ -1072,6 +1091,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> { generics_def_id, def_id: res.def_id(), have_turbofish, + hir_id: segment.hir_id, }) }) .chain(last_segment_using_path_data) @@ -1106,6 +1126,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> { generics_def_id: def_id, def_id, have_turbofish: false, + hir_id: segment.hir_id, } }; @@ -1233,6 +1254,7 @@ impl<'a, 'tcx> Visitor<'tcx> for FindInferSourceVisitor<'a, 'tcx> { generics_def_id, def_id, have_turbofish, + hir_id, } = args; let generics = tcx.generics_of(generics_def_id); if let Some(mut argument_index) = generics @@ -1260,6 +1282,7 @@ impl<'a, 'tcx> Visitor<'tcx> for FindInferSourceVisitor<'a, 'tcx> { def_id, generic_args, have_turbofish, + hir_id, }, }); } diff --git a/tests/ui/const-generics/assoc_const_as_type_argument.rs b/tests/ui/const-generics/assoc_const_as_type_argument.rs index ffc7f116a94ef..7947aa93611e8 100644 --- a/tests/ui/const-generics/assoc_const_as_type_argument.rs +++ b/tests/ui/const-generics/assoc_const_as_type_argument.rs @@ -7,7 +7,6 @@ fn bar() {} fn foo() { bar::<::ASSOC>(); //~^ ERROR: expected associated type, found associated constant `Trait::ASSOC` - //~| ERROR: unresolved item provided when a constant was expected } fn main() {} diff --git a/tests/ui/const-generics/assoc_const_as_type_argument.stderr b/tests/ui/const-generics/assoc_const_as_type_argument.stderr index ac00954613506..225a7eb55337a 100644 --- a/tests/ui/const-generics/assoc_const_as_type_argument.stderr +++ b/tests/ui/const-generics/assoc_const_as_type_argument.stderr @@ -4,18 +4,6 @@ error[E0575]: expected associated type, found associated constant `Trait::ASSOC` LL | bar::<::ASSOC>(); | ^^^^^^^^^^^^^^^^^^^ not a associated type -error[E0747]: unresolved item provided when a constant was expected - --> $DIR/assoc_const_as_type_argument.rs:8:11 - | -LL | bar::<::ASSOC>(); - | ^^^^^^^^^^^^^^^^^^^ - | -help: if this generic argument was intended as a const parameter, surround it with braces - | -LL | bar::<{ ::ASSOC }>(); - | + + - -error: aborting due to 2 previous errors +error: aborting due to 1 previous error -Some errors have detailed explanations: E0575, E0747. -For more information about an error, try `rustc --explain E0575`. +For more information about this error, try `rustc --explain E0575`. diff --git a/tests/ui/const-generics/const-arg-in-const-arg.min.stderr b/tests/ui/const-generics/const-arg-in-const-arg.min.stderr index ebb3e821e07b7..a2d783e6efe7a 100644 --- a/tests/ui/const-generics/const-arg-in-const-arg.min.stderr +++ b/tests/ui/const-generics/const-arg-in-const-arg.min.stderr @@ -17,7 +17,7 @@ LL | let _: [u8; bar::()]; = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations - --> $DIR/const-arg-in-const-arg.rs:18:23 + --> $DIR/const-arg-in-const-arg.rs:17:23 | LL | let _: [u8; faz::<'a>(&())]; | ^^ cannot perform const operation using `'a` @@ -26,7 +26,7 @@ LL | let _: [u8; faz::<'a>(&())]; = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations - --> $DIR/const-arg-in-const-arg.rs:20:23 + --> $DIR/const-arg-in-const-arg.rs:19:23 | LL | let _: [u8; baz::<'a>(&())]; | ^^ cannot perform const operation using `'a` @@ -35,7 +35,7 @@ LL | let _: [u8; baz::<'a>(&())]; = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations - --> $DIR/const-arg-in-const-arg.rs:21:23 + --> $DIR/const-arg-in-const-arg.rs:20:23 | LL | let _: [u8; faz::<'b>(&())]; | ^^ cannot perform const operation using `'b` @@ -44,7 +44,7 @@ LL | let _: [u8; faz::<'b>(&())]; = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations - --> $DIR/const-arg-in-const-arg.rs:23:23 + --> $DIR/const-arg-in-const-arg.rs:22:23 | LL | let _: [u8; baz::<'b>(&())]; | ^^ cannot perform const operation using `'b` @@ -53,7 +53,7 @@ LL | let _: [u8; baz::<'b>(&())]; = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations - --> $DIR/const-arg-in-const-arg.rs:27:23 + --> $DIR/const-arg-in-const-arg.rs:26:23 | LL | let _ = [0; bar::()]; | ^ cannot perform const operation using `N` @@ -62,7 +62,7 @@ LL | let _ = [0; bar::()]; = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations - --> $DIR/const-arg-in-const-arg.rs:29:23 + --> $DIR/const-arg-in-const-arg.rs:27:23 | LL | let _ = [0; faz::<'a>(&())]; | ^^ cannot perform const operation using `'a` @@ -71,7 +71,7 @@ LL | let _ = [0; faz::<'a>(&())]; = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations - --> $DIR/const-arg-in-const-arg.rs:31:23 + --> $DIR/const-arg-in-const-arg.rs:29:23 | LL | let _ = [0; baz::<'a>(&())]; | ^^ cannot perform const operation using `'a` @@ -80,7 +80,7 @@ LL | let _ = [0; baz::<'a>(&())]; = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations - --> $DIR/const-arg-in-const-arg.rs:32:23 + --> $DIR/const-arg-in-const-arg.rs:30:23 | LL | let _ = [0; faz::<'b>(&())]; | ^^ cannot perform const operation using `'b` @@ -89,7 +89,7 @@ LL | let _ = [0; faz::<'b>(&())]; = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations - --> $DIR/const-arg-in-const-arg.rs:34:23 + --> $DIR/const-arg-in-const-arg.rs:32:23 | LL | let _ = [0; baz::<'b>(&())]; | ^^ cannot perform const operation using `'b` @@ -98,7 +98,7 @@ LL | let _ = [0; baz::<'b>(&())]; = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations - --> $DIR/const-arg-in-const-arg.rs:35:24 + --> $DIR/const-arg-in-const-arg.rs:33:24 | LL | let _: Foo<{ foo::() }>; | ^ cannot perform const operation using `T` @@ -107,7 +107,7 @@ LL | let _: Foo<{ foo::() }>; = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations - --> $DIR/const-arg-in-const-arg.rs:36:24 + --> $DIR/const-arg-in-const-arg.rs:34:24 | LL | let _: Foo<{ bar::() }>; | ^ cannot perform const operation using `N` @@ -116,7 +116,7 @@ LL | let _: Foo<{ bar::() }>; = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations - --> $DIR/const-arg-in-const-arg.rs:38:24 + --> $DIR/const-arg-in-const-arg.rs:35:24 | LL | let _: Foo<{ faz::<'a>(&()) }>; | ^^ cannot perform const operation using `'a` @@ -125,7 +125,7 @@ LL | let _: Foo<{ faz::<'a>(&()) }>; = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations - --> $DIR/const-arg-in-const-arg.rs:40:24 + --> $DIR/const-arg-in-const-arg.rs:37:24 | LL | let _: Foo<{ baz::<'a>(&()) }>; | ^^ cannot perform const operation using `'a` @@ -134,7 +134,7 @@ LL | let _: Foo<{ baz::<'a>(&()) }>; = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations - --> $DIR/const-arg-in-const-arg.rs:41:24 + --> $DIR/const-arg-in-const-arg.rs:38:24 | LL | let _: Foo<{ faz::<'b>(&()) }>; | ^^ cannot perform const operation using `'b` @@ -143,7 +143,7 @@ LL | let _: Foo<{ faz::<'b>(&()) }>; = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations - --> $DIR/const-arg-in-const-arg.rs:43:24 + --> $DIR/const-arg-in-const-arg.rs:40:24 | LL | let _: Foo<{ baz::<'b>(&()) }>; | ^^ cannot perform const operation using `'b` @@ -152,7 +152,7 @@ LL | let _: Foo<{ baz::<'b>(&()) }>; = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations - --> $DIR/const-arg-in-const-arg.rs:44:27 + --> $DIR/const-arg-in-const-arg.rs:41:27 | LL | let _ = Foo::<{ foo::() }>; | ^ cannot perform const operation using `T` @@ -161,7 +161,7 @@ LL | let _ = Foo::<{ foo::() }>; = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations - --> $DIR/const-arg-in-const-arg.rs:45:27 + --> $DIR/const-arg-in-const-arg.rs:42:27 | LL | let _ = Foo::<{ bar::() }>; | ^ cannot perform const operation using `N` @@ -170,7 +170,7 @@ LL | let _ = Foo::<{ bar::() }>; = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations - --> $DIR/const-arg-in-const-arg.rs:47:27 + --> $DIR/const-arg-in-const-arg.rs:43:27 | LL | let _ = Foo::<{ faz::<'a>(&()) }>; | ^^ cannot perform const operation using `'a` @@ -179,7 +179,7 @@ LL | let _ = Foo::<{ faz::<'a>(&()) }>; = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations - --> $DIR/const-arg-in-const-arg.rs:49:27 + --> $DIR/const-arg-in-const-arg.rs:45:27 | LL | let _ = Foo::<{ baz::<'a>(&()) }>; | ^^ cannot perform const operation using `'a` @@ -188,7 +188,7 @@ LL | let _ = Foo::<{ baz::<'a>(&()) }>; = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations - --> $DIR/const-arg-in-const-arg.rs:50:27 + --> $DIR/const-arg-in-const-arg.rs:46:27 | LL | let _ = Foo::<{ faz::<'b>(&()) }>; | ^^ cannot perform const operation using `'b` @@ -197,7 +197,7 @@ LL | let _ = Foo::<{ faz::<'b>(&()) }>; = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations - --> $DIR/const-arg-in-const-arg.rs:52:27 + --> $DIR/const-arg-in-const-arg.rs:48:27 | LL | let _ = Foo::<{ baz::<'b>(&()) }>; | ^^ cannot perform const operation using `'b` @@ -205,19 +205,8 @@ LL | let _ = Foo::<{ baz::<'b>(&()) }>; = note: lifetime parameters may not be used in const expressions = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions -error[E0747]: unresolved item provided when a constant was expected - --> $DIR/const-arg-in-const-arg.rs:16:23 - | -LL | let _: [u8; bar::()]; - | ^ - | -help: if this generic argument was intended as a const parameter, surround it with braces - | -LL | let _: [u8; bar::<{ N }>()]; - | + + - error[E0794]: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present - --> $DIR/const-arg-in-const-arg.rs:18:23 + --> $DIR/const-arg-in-const-arg.rs:17:23 | LL | let _: [u8; faz::<'a>(&())]; | ^^ @@ -229,7 +218,7 @@ LL | const fn faz<'a>(_: &'a ()) -> usize { 13 } | ^^ error[E0794]: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present - --> $DIR/const-arg-in-const-arg.rs:21:23 + --> $DIR/const-arg-in-const-arg.rs:20:23 | LL | let _: [u8; faz::<'b>(&())]; | ^^ @@ -241,7 +230,7 @@ LL | const fn faz<'a>(_: &'a ()) -> usize { 13 } | ^^ error: constant expression depends on a generic parameter - --> $DIR/const-arg-in-const-arg.rs:25:17 + --> $DIR/const-arg-in-const-arg.rs:24:17 | LL | let _ = [0; foo::()]; | ^^^^^^^^^^ @@ -249,26 +238,15 @@ LL | let _ = [0; foo::()]; = note: this may fail depending on what value the parameter takes error: constant expression depends on a generic parameter - --> $DIR/const-arg-in-const-arg.rs:25:13 + --> $DIR/const-arg-in-const-arg.rs:24:13 | LL | let _ = [0; foo::()]; | ^^^^^^^^^^^^^^^ | = note: this may fail depending on what value the parameter takes -error[E0747]: unresolved item provided when a constant was expected - --> $DIR/const-arg-in-const-arg.rs:27:23 - | -LL | let _ = [0; bar::()]; - | ^ - | -help: if this generic argument was intended as a const parameter, surround it with braces - | -LL | let _ = [0; bar::<{ N }>()]; - | + + - error[E0794]: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present - --> $DIR/const-arg-in-const-arg.rs:29:23 + --> $DIR/const-arg-in-const-arg.rs:27:23 | LL | let _ = [0; faz::<'a>(&())]; | ^^ @@ -280,7 +258,7 @@ LL | const fn faz<'a>(_: &'a ()) -> usize { 13 } | ^^ error[E0794]: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present - --> $DIR/const-arg-in-const-arg.rs:32:23 + --> $DIR/const-arg-in-const-arg.rs:30:23 | LL | let _ = [0; faz::<'b>(&())]; | ^^ @@ -291,19 +269,8 @@ note: the late bound lifetime parameter is introduced here LL | const fn faz<'a>(_: &'a ()) -> usize { 13 } | ^^ -error[E0747]: unresolved item provided when a constant was expected - --> $DIR/const-arg-in-const-arg.rs:36:24 - | -LL | let _: Foo<{ bar::() }>; - | ^ - | -help: if this generic argument was intended as a const parameter, surround it with braces - | -LL | let _: Foo<{ bar::<{ N }>() }>; - | + + - error[E0794]: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present - --> $DIR/const-arg-in-const-arg.rs:38:24 + --> $DIR/const-arg-in-const-arg.rs:35:24 | LL | let _: Foo<{ faz::<'a>(&()) }>; | ^^ @@ -315,7 +282,7 @@ LL | const fn faz<'a>(_: &'a ()) -> usize { 13 } | ^^ error[E0794]: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present - --> $DIR/const-arg-in-const-arg.rs:41:24 + --> $DIR/const-arg-in-const-arg.rs:38:24 | LL | let _: Foo<{ faz::<'b>(&()) }>; | ^^ @@ -326,19 +293,8 @@ note: the late bound lifetime parameter is introduced here LL | const fn faz<'a>(_: &'a ()) -> usize { 13 } | ^^ -error[E0747]: unresolved item provided when a constant was expected - --> $DIR/const-arg-in-const-arg.rs:45:27 - | -LL | let _ = Foo::<{ bar::() }>; - | ^ - | -help: if this generic argument was intended as a const parameter, surround it with braces - | -LL | let _ = Foo::<{ bar::<{ N }>() }>; - | + + - error[E0794]: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present - --> $DIR/const-arg-in-const-arg.rs:47:27 + --> $DIR/const-arg-in-const-arg.rs:43:27 | LL | let _ = Foo::<{ faz::<'a>(&()) }>; | ^^ @@ -350,7 +306,7 @@ LL | const fn faz<'a>(_: &'a ()) -> usize { 13 } | ^^ error[E0794]: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present - --> $DIR/const-arg-in-const-arg.rs:50:27 + --> $DIR/const-arg-in-const-arg.rs:46:27 | LL | let _ = Foo::<{ faz::<'b>(&()) }>; | ^^ @@ -361,7 +317,6 @@ note: the late bound lifetime parameter is introduced here LL | const fn faz<'a>(_: &'a ()) -> usize { 13 } | ^^ -error: aborting due to 37 previous errors +error: aborting due to 33 previous errors -Some errors have detailed explanations: E0747, E0794. -For more information about an error, try `rustc --explain E0747`. +For more information about this error, try `rustc --explain E0794`. diff --git a/tests/ui/const-generics/const-arg-in-const-arg.rs b/tests/ui/const-generics/const-arg-in-const-arg.rs index 0e1c6552edf1e..31dfe7969894b 100644 --- a/tests/ui/const-generics/const-arg-in-const-arg.rs +++ b/tests/ui/const-generics/const-arg-in-const-arg.rs @@ -14,7 +14,6 @@ struct Foo; fn test<'a, 'b, T, const N: usize>() where &'b (): Sized { let _: [u8; foo::()]; //[min]~ ERROR generic parameters may not let _: [u8; bar::()]; //[min]~ ERROR generic parameters may not - //[min]~^ ERROR unresolved item provided when a constant was expected let _: [u8; faz::<'a>(&())]; //[min]~ ERROR generic parameters may not //[min]~^ ERROR cannot specify lifetime arguments let _: [u8; baz::<'a>(&())]; //[min]~ ERROR generic parameters may not @@ -25,7 +24,6 @@ fn test<'a, 'b, T, const N: usize>() where &'b (): Sized { let _ = [0; foo::()]; //[min]~ ERROR constant expression depends on a generic parameter //[min]~^ ERROR constant expression depends on a generic parameter let _ = [0; bar::()]; //[min]~ ERROR generic parameters may not - //[min]~^ ERROR unresolved item provided when a constant was expected let _ = [0; faz::<'a>(&())]; //[min]~ ERROR generic parameters may not //[min]~^ ERROR cannot specify lifetime arguments let _ = [0; baz::<'a>(&())]; //[min]~ ERROR generic parameters may not @@ -34,7 +32,6 @@ fn test<'a, 'b, T, const N: usize>() where &'b (): Sized { let _ = [0; baz::<'b>(&())]; //[min]~ ERROR generic parameters may not let _: Foo<{ foo::() }>; //[min]~ ERROR generic parameters may not let _: Foo<{ bar::() }>; //[min]~ ERROR generic parameters may not - //[min]~^ ERROR unresolved item provided when a constant was expected let _: Foo<{ faz::<'a>(&()) }>; //[min]~ ERROR generic parameters may not //[min]~^ ERROR cannot specify lifetime arguments let _: Foo<{ baz::<'a>(&()) }>; //[min]~ ERROR generic parameters may not @@ -43,7 +40,6 @@ fn test<'a, 'b, T, const N: usize>() where &'b (): Sized { let _: Foo<{ baz::<'b>(&()) }>; //[min]~ ERROR generic parameters may not let _ = Foo::<{ foo::() }>; //[min]~ ERROR generic parameters may not let _ = Foo::<{ bar::() }>; //[min]~ ERROR generic parameters may not - //[min]~^ ERROR unresolved item provided when a constant was expected let _ = Foo::<{ faz::<'a>(&()) }>; //[min]~ ERROR generic parameters may not //[min]~^ ERROR cannot specify lifetime arguments let _ = Foo::<{ baz::<'a>(&()) }>; //[min]~ ERROR generic parameters may not diff --git a/tests/ui/const-generics/const-argument-typo.rs b/tests/ui/const-generics/const-argument-typo.rs new file mode 100644 index 0000000000000..089126c92e162 --- /dev/null +++ b/tests/ui/const-generics/const-argument-typo.rs @@ -0,0 +1,10 @@ +// Typo of `CONST` to `CONS`. #149660 + +const CONST: usize = 0; + +fn foo() {} + +fn main() { + foo::(); + //~^ ERROR cannot find type `CONS` in this scope +} diff --git a/tests/ui/const-generics/const-argument-typo.stderr b/tests/ui/const-generics/const-argument-typo.stderr new file mode 100644 index 0000000000000..fad98a09ad9a9 --- /dev/null +++ b/tests/ui/const-generics/const-argument-typo.stderr @@ -0,0 +1,12 @@ +error[E0425]: cannot find type `CONS` in this scope + --> $DIR/const-argument-typo.rs:8:11 + | +LL | const CONST: usize = 0; + | ----------------------- similarly named constant `CONST` defined here +... +LL | foo::(); + | ^^^^ help: a constant with a similar name exists: `CONST` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0425`. diff --git a/tests/ui/const-generics/const-generic-function.rs b/tests/ui/const-generics/const-generic-function.rs index c8d2683e53f47..98834d2aa107f 100644 --- a/tests/ui/const-generics/const-generic-function.rs +++ b/tests/ui/const-generics/const-generic-function.rs @@ -14,7 +14,6 @@ const FOO: i32 = 3; fn main() { foo::(); //~ ERROR expected type, found function `baz` - //~| ERROR unresolved item provided when a constant was expected foo::(); //~ ERROR expected type, found `1` foo::(); //~ ERROR expected type, found `1` foo::(); //~ ERROR expected type, found `2` diff --git a/tests/ui/const-generics/const-generic-function.stderr b/tests/ui/const-generics/const-generic-function.stderr index 5ad3f1006c17d..0c87a291f66c6 100644 --- a/tests/ui/const-generics/const-generic-function.stderr +++ b/tests/ui/const-generics/const-generic-function.stderr @@ -1,5 +1,5 @@ error: expected type, found `1` - --> $DIR/const-generic-function.rs:18:19 + --> $DIR/const-generic-function.rs:17:19 | LL | foo::(); | ^ expected type @@ -10,7 +10,7 @@ LL | foo::<{ bar(bar(1, 1), bar(1, 1)) }>(); | + + error: expected type, found `1` - --> $DIR/const-generic-function.rs:19:15 + --> $DIR/const-generic-function.rs:18:15 | LL | foo::(); | ^ expected type @@ -21,7 +21,7 @@ LL | foo::<{ bar(1, 1) }>(); | + + error: expected type, found `2` - --> $DIR/const-generic-function.rs:20:20 + --> $DIR/const-generic-function.rs:19:20 | LL | foo::(); | ^ expected type @@ -37,18 +37,6 @@ error[E0573]: expected type, found function `baz` LL | foo::(); | ^^^^^ not a type -error[E0747]: unresolved item provided when a constant was expected - --> $DIR/const-generic-function.rs:16:11 - | -LL | foo::(); - | ^^^^^ - | -help: if this generic argument was intended as a const parameter, surround it with braces - | -LL | foo::<{ baz() }>(); - | + + - -error: aborting due to 5 previous errors +error: aborting due to 4 previous errors -Some errors have detailed explanations: E0573, E0747. -For more information about an error, try `rustc --explain E0573`. +For more information about this error, try `rustc --explain E0573`. diff --git a/tests/ui/const-generics/early/invalid-const-arguments.rs b/tests/ui/const-generics/early/invalid-const-arguments.rs index 68e6b2ac458e0..b48b3b95a7595 100644 --- a/tests/ui/const-generics/early/invalid-const-arguments.rs +++ b/tests/ui/const-generics/early/invalid-const-arguments.rs @@ -4,7 +4,6 @@ struct A; trait Foo {} impl Foo for A {} //~^ ERROR cannot find type -//~| ERROR unresolved item provided when a constant struct B; impl Foo for B {} @@ -13,4 +12,3 @@ impl Foo for B {} struct C; impl Foo for C {} //~^ ERROR cannot find type -//~| ERROR unresolved item provided when a constant diff --git a/tests/ui/const-generics/early/invalid-const-arguments.stderr b/tests/ui/const-generics/early/invalid-const-arguments.stderr index a0a6d8cc8679b..eaee4687af119 100644 --- a/tests/ui/const-generics/early/invalid-const-arguments.stderr +++ b/tests/ui/const-generics/early/invalid-const-arguments.stderr @@ -18,7 +18,7 @@ LL | impl Foo for A {} | +++ error[E0425]: cannot find type `T` in this scope - --> $DIR/invalid-const-arguments.rs:14:32 + --> $DIR/invalid-const-arguments.rs:13:32 | LL | struct A; | ---------------------- similarly named struct `A` defined here @@ -36,19 +36,8 @@ help: you might be missing a type parameter LL | impl Foo for C {} | +++ -error[E0747]: unresolved item provided when a constant was expected - --> $DIR/invalid-const-arguments.rs:5:16 - | -LL | impl Foo for A {} - | ^ - | -help: if this generic argument was intended as a const parameter, surround it with braces - | -LL | impl Foo for A<{ N }> {} - | + + - error[E0747]: type provided when a constant was expected - --> $DIR/invalid-const-arguments.rs:10:19 + --> $DIR/invalid-const-arguments.rs:9:19 | LL | impl Foo for B {} | ^ @@ -59,18 +48,7 @@ LL - impl Foo for B {} LL + impl Foo for B {} | -error[E0747]: unresolved item provided when a constant was expected - --> $DIR/invalid-const-arguments.rs:14:32 - | -LL | impl Foo for C {} - | ^ - | -help: if this generic argument was intended as a const parameter, surround it with braces - | -LL | impl Foo for C {} - | + + - -error: aborting due to 5 previous errors +error: aborting due to 3 previous errors Some errors have detailed explanations: E0425, E0747. For more information about an error, try `rustc --explain E0425`. diff --git a/tests/ui/const-generics/invalid-enum.rs b/tests/ui/const-generics/invalid-enum.rs index 56fac3e2eb6c8..85ca4f821eef3 100644 --- a/tests/ui/const-generics/invalid-enum.rs +++ b/tests/ui/const-generics/invalid-enum.rs @@ -23,15 +23,12 @@ impl Example { pub fn main() { test_1::(); //~^ ERROR: expected type, found variant - //~| ERROR: unresolved item provided when a constant was expected test_2::<_, CompileFlag::A>(0); //~^ ERROR: expected type, found variant - //~| ERROR: unresolved item provided when a constant was expected let _: Example = Example { x: 0 }; //~^ ERROR: expected type, found variant - //~| ERROR: unresolved item provided when a constant was expected let _: Example = Example { x: 0 }; //~^ ERROR: type provided when a constant was expected diff --git a/tests/ui/const-generics/invalid-enum.stderr b/tests/ui/const-generics/invalid-enum.stderr index 911052370f43c..e2304947c60d1 100644 --- a/tests/ui/const-generics/invalid-enum.stderr +++ b/tests/ui/const-generics/invalid-enum.stderr @@ -8,7 +8,7 @@ LL | test_1::(); | help: try using the variant's enum: `CompileFlag` error[E0573]: expected type, found variant `CompileFlag::A` - --> $DIR/invalid-enum.rs:28:15 + --> $DIR/invalid-enum.rs:27:15 | LL | test_2::<_, CompileFlag::A>(0); | ^^^^^^^^^^^^^^ @@ -17,7 +17,7 @@ LL | test_2::<_, CompileFlag::A>(0); | help: try using the variant's enum: `CompileFlag` error[E0573]: expected type, found variant `CompileFlag::A` - --> $DIR/invalid-enum.rs:32:18 + --> $DIR/invalid-enum.rs:30:18 | LL | let _: Example = Example { x: 0 }; | ^^^^^^^^^^^^^^ @@ -25,41 +25,8 @@ LL | let _: Example = Example { x: 0 }; | not a type | help: try using the variant's enum: `CompileFlag` -error[E0747]: unresolved item provided when a constant was expected - --> $DIR/invalid-enum.rs:24:12 - | -LL | test_1::(); - | ^^^^^^^^^^^^^^ - | -help: if this generic argument was intended as a const parameter, surround it with braces - | -LL | test_1::<{ CompileFlag::A }>(); - | + + - -error[E0747]: unresolved item provided when a constant was expected - --> $DIR/invalid-enum.rs:28:15 - | -LL | test_2::<_, CompileFlag::A>(0); - | ^^^^^^^^^^^^^^ - | -help: if this generic argument was intended as a const parameter, surround it with braces - | -LL | test_2::<_, { CompileFlag::A }>(0); - | + + - -error[E0747]: unresolved item provided when a constant was expected - --> $DIR/invalid-enum.rs:32:18 - | -LL | let _: Example = Example { x: 0 }; - | ^^^^^^^^^^^^^^ - | -help: if this generic argument was intended as a const parameter, surround it with braces - | -LL | let _: Example<{ CompileFlag::A }, _> = Example { x: 0 }; - | + + - error[E0747]: type provided when a constant was expected - --> $DIR/invalid-enum.rs:36:18 + --> $DIR/invalid-enum.rs:33:18 | LL | let _: Example = Example { x: 0 }; | ^^^^^^^^^^^^^^^^^^^ @@ -69,7 +36,7 @@ help: if this generic argument was intended as a const parameter, surround it wi LL | let _: Example<{ Example::ASSOC_FLAG }, _> = Example { x: 0 }; | + + -error: aborting due to 7 previous errors +error: aborting due to 4 previous errors Some errors have detailed explanations: E0573, E0747. For more information about an error, try `rustc --explain E0573`. diff --git a/tests/ui/missing/missing-items/missing-type-parameter2.rs b/tests/ui/missing/missing-items/missing-type-parameter2.rs index 772e60b1376c3..746a50456951a 100644 --- a/tests/ui/missing/missing-items/missing-type-parameter2.rs +++ b/tests/ui/missing/missing-items/missing-type-parameter2.rs @@ -2,11 +2,9 @@ struct X(); impl X {} //~^ ERROR cannot find type `N` in this scope -//~| ERROR unresolved item provided when a constant was expected impl X {} //~^ ERROR cannot find type `N` in this scope //~| ERROR defaults for generic parameters are not allowed here -//~| ERROR unresolved item provided when a constant was expected fn foo(_: T) where T: Send {} //~^ ERROR cannot find type `T` in this scope diff --git a/tests/ui/missing/missing-items/missing-type-parameter2.stderr b/tests/ui/missing/missing-items/missing-type-parameter2.stderr index c361ed79cc799..832977cd4dfb5 100644 --- a/tests/ui/missing/missing-items/missing-type-parameter2.stderr +++ b/tests/ui/missing/missing-items/missing-type-parameter2.stderr @@ -18,7 +18,7 @@ LL | impl X {} | +++ error[E0425]: cannot find type `N` in this scope - --> $DIR/missing-type-parameter2.rs:6:28 + --> $DIR/missing-type-parameter2.rs:5:28 | LL | impl X {} | - ^ @@ -36,7 +36,7 @@ LL | impl X {} | +++ error[E0425]: cannot find type `T` in this scope - --> $DIR/missing-type-parameter2.rs:11:20 + --> $DIR/missing-type-parameter2.rs:9:20 | LL | struct X(); | ------------------------ similarly named struct `X` defined here @@ -55,7 +55,7 @@ LL | fn foo(_: T) where T: Send {} | +++ error[E0425]: cannot find type `T` in this scope - --> $DIR/missing-type-parameter2.rs:11:11 + --> $DIR/missing-type-parameter2.rs:9:11 | LL | struct X(); | ------------------------ similarly named struct `X` defined here @@ -74,7 +74,7 @@ LL | fn foo(_: T) where T: Send {} | +++ error[E0425]: cannot find type `A` in this scope - --> $DIR/missing-type-parameter2.rs:15:24 + --> $DIR/missing-type-parameter2.rs:13:24 | LL | struct X(); | ------------------------ similarly named struct `X` defined here @@ -92,35 +92,12 @@ help: you might be missing a type parameter LL | fn bar(_: A) {} | +++ -error[E0747]: unresolved item provided when a constant was expected - --> $DIR/missing-type-parameter2.rs:3:8 - | -LL | impl X {} - | ^ - | -help: if this generic argument was intended as a const parameter, surround it with braces - | -LL | impl X<{ N }> {} - | + + - error: defaults for generic parameters are not allowed here - --> $DIR/missing-type-parameter2.rs:6:9 + --> $DIR/missing-type-parameter2.rs:5:9 | LL | impl X {} | ^^^^^^^^^^^^^^^ -error[E0747]: unresolved item provided when a constant was expected - --> $DIR/missing-type-parameter2.rs:6:28 - | -LL | impl X {} - | ^ - | -help: if this generic argument was intended as a const parameter, surround it with braces - | -LL | impl X<{ N }> {} - | + + - -error: aborting due to 8 previous errors +error: aborting due to 6 previous errors -Some errors have detailed explanations: E0425, E0747. -For more information about an error, try `rustc --explain E0425`. +For more information about this error, try `rustc --explain E0425`.