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 ff0a5a8df0faf..1ab0272894a26 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/generics.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/generics.rs @@ -3,7 +3,7 @@ use rustc_errors::codes::*; use rustc_errors::{Applicability, Diag, ErrorGuaranteed, MultiSpan, struct_span_code_err}; use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::DefId; -use rustc_hir::{self as hir, GenericArg}; +use rustc_hir::{self as hir, GenericArg, QPath, TyKind}; use rustc_middle::ty::{ self, GenericArgsRef, GenericParamDef, GenericParamDefKind, IsSuggestable, Ty, }; @@ -41,6 +41,16 @@ fn generic_arg_mismatch_err( param.kind.descr(), ); + if let GenericArg::Type(ty, ..) = arg + && let TyKind::Path(qpath) = &ty.kind + && let QPath::Resolved(_, path) = qpath + { + let res = path.res; + if matches!(res, Res::Err) { + return err.delay_as_bug(); + } + } + let add_braces_suggestion = |arg: &GenericArg<'_>, err: &mut Diag<'_>| { let suggestions = vec![ (arg.span().shrink_to_lo(), String::from("{ ")), diff --git a/compiler/rustc_resolve/src/build_reduced_graph.rs b/compiler/rustc_resolve/src/build_reduced_graph.rs index a280acc0d51df..67c3a6150c2f8 100644 --- a/compiler/rustc_resolve/src/build_reduced_graph.rs +++ b/compiler/rustc_resolve/src/build_reduced_graph.rs @@ -898,7 +898,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> { } // These items live in both the type and value namespaces. - ItemKind::Struct(ident, _, ref vdata) => { + ItemKind::Struct(ident, ref generics, ref vdata) => { self.build_reduced_graph_for_struct_variant( vdata.fields(), ident, @@ -947,6 +947,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> { .struct_constructors .insert(local_def_id, (ctor_res, ctor_vis.to_def_id(), ret_fields)); } + self.r.struct_generics.insert(local_def_id, generics.clone()); } ItemKind::Union(ident, _, ref vdata) => { diff --git a/compiler/rustc_resolve/src/errors.rs b/compiler/rustc_resolve/src/errors.rs index 54427535c5f6e..afe3825cd734d 100644 --- a/compiler/rustc_resolve/src/errors.rs +++ b/compiler/rustc_resolve/src/errors.rs @@ -882,6 +882,19 @@ pub(crate) struct UnexpectedResChangeTyToConstParamSugg { pub applicability: Applicability, } +#[derive(Subdiagnostic)] +#[suggestion( + "you might have meant to write a const parameter here", + code = "{snippet}", + applicability = "machine-applicable", + style = "verbose" +)] +pub(crate) struct UnexpectedMissingConstParameter { + #[primary_span] + pub span: Span, + pub snippet: String, +} + #[derive(Subdiagnostic)] #[multipart_suggestion( "you might have meant to write a const parameter here", diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index 6e9d4a38d987c..7d801c00a0d9f 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -4426,7 +4426,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { let Finalize { node_id, path_span, .. } = finalize; let report_errors = |this: &mut Self, res: Option| { if this.should_report_errs() { - let (err, candidates) = this.smart_resolve_report_errors( + let (mut err, candidates) = this.smart_resolve_report_errors( path, None, path_span, @@ -4437,7 +4437,8 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { let def_id = this.parent_scope.module.nearest_parent_mod(); let instead = res.is_some(); - let suggestion = if let Some((start, end)) = this.diag_metadata.in_range + let (suggestion, const_err) = if let Some((start, end)) = + this.diag_metadata.in_range && path[0].ident.span.lo() == end.span.lo() && !matches!(start.kind, ExprKind::Lit(_)) { @@ -4449,12 +4450,15 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { span = span.with_lo(span.lo() + BytePos(1)); sugg = ""; } - Some(( - span, - "you might have meant to write `.` instead of `..`", - sugg.to_string(), - Applicability::MaybeIncorrect, - )) + ( + Some(( + span, + "you might have meant to write `.` instead of `..`", + sugg.to_string(), + Applicability::MaybeIncorrect, + )), + None, + ) } else if res.is_none() && let PathSource::Type | PathSource::Expr(_) @@ -4462,9 +4466,14 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { { this.suggest_adding_generic_parameter(path, source) } else { - None + (None, None) }; + if let Some(const_err) = const_err { + err.cancel(); + err = const_err; + } + let ue = UseError { err, candidates, diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index 95a6b25d54e6b..8ac1a598122ee 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -6,8 +6,9 @@ use std::ops::Deref; use rustc_ast::visit::{FnCtxt, FnKind, LifetimeCtxt, Visitor, walk_ty}; use rustc_ast::{ - self as ast, AssocItemKind, DUMMY_NODE_ID, Expr, ExprKind, GenericParam, GenericParamKind, - Item, ItemKind, MethodCall, NodeId, Path, PathSegment, Ty, TyKind, + self as ast, AngleBracketedArg, AssocItemKind, DUMMY_NODE_ID, Expr, ExprKind, GenericArg, + GenericArgs, GenericParam, GenericParamKind, Item, ItemKind, MethodCall, NodeId, Path, + PathSegment, Ty, TyKind, }; use rustc_ast_pretty::pprust::{path_to_string, where_bound_predicate_to_string}; use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet}; @@ -37,8 +38,8 @@ use crate::late::{ }; use crate::ty::fast_reject::SimplifiedType; use crate::{ - Module, ModuleKind, ModuleOrUniformRoot, ParentScope, PathResult, PathSource, Resolver, - ScopeSet, Segment, errors, path_names_to_string, + Finalize, Module, ModuleKind, ModuleOrUniformRoot, ParentScope, PathResult, PathSource, + Resolver, ScopeSet, Segment, errors, path_names_to_string, }; type Res = def::Res; @@ -3277,11 +3278,116 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> { } } + /// This function is mainly for detecting and suggesting const parameter errors in impls. + /// For example: + /// use std::fmt::{Display}; + /// struct A; + /// impl Display for A { <- missing const parameter N + /// } + pub(crate) fn detect_and_suggest_const_parameter_error( + &mut self, + path: &[Segment], + source: PathSource<'_, 'ast, 'ra>, + ) -> Option> { + if let Some(item) = self.diag_metadata.current_item + && let ItemKind::Impl(impl_) = &item.kind + { + let self_ty = &impl_.self_ty; + + // Represents parameter to the struct whether A `N` or `P` + let [current_parameter] = path else { + return None; // or emit error + }; + + let target_ident = current_parameter.ident; + + // Find the parent of the above parameter, i.e the struct `A` in the `impl` + // + let mut visitor = ParentPathVisitor::new(self_ty, target_ident); + if let Some(target_id) = current_parameter.id { + // find the index of the parameter in the `A` + visitor.find_arg_index(target_id); + } + + if let Some(parent_segment) = visitor.parent { + // now try to resolve the parent struct `A` in `impl` + // to get the struct `A` as declared in struct A; + let ns = source.namespace(); + + let segment = Segment::from(parent_segment); + let segments = [segment]; + let finalize = Finalize::new(parent_segment.id, parent_segment.ident.span); + + match self.resolve_qpath_anywhere( + &None, + &segments, + ns, + source.defer_to_typeck(), + finalize, + source, + ) { + Ok(Some(resolve)) => { + // the resolved gives DefId of struct `A` so we look up its generics + // in the resolver + if let Some(resolve) = resolve.full_res() + && let Res::Def(_, def_id) = resolve + && def_id.is_local() + && let Some(local_def_id) = def_id.as_local() + && let Some(generics) = self.r.struct_generics.get(&local_def_id) + && let Some(idx) = visitor.target_index + { + let target_param = &generics.params[idx]; + + if let GenericParamKind::Const { ty, .. } = &target_param.kind + && let TyKind::Path(_, path) = &ty.kind + { + let full_type = path + .segments + .iter() + .map(|seg| seg.ident.to_string()) + .collect::>() + .join("::"); + + let mut err = self.r.dcx().struct_span_err( + target_ident.span, + format!("cannot find const `{}` in this scope", target_ident), + ); + + err.code(E0425); + + err.span_label(target_ident.span, "not found in this scope"); + + err.span_label( + target_param.span(), + format!("const parameter `{}` is defined here", target_ident), + ); + + err.subdiagnostic(errors::UnexpectedMissingConstParameter { + span: impl_.generics.span, + snippet: format!( + "", + target_ident.to_string(), + full_type + ), + }); + + return Some(err); + } + } + } + _ => {} + } + } + } + return None; + } + pub(crate) fn suggest_adding_generic_parameter( - &self, + &mut self, path: &[Segment], - source: PathSource<'_, '_, '_>, - ) -> Option<(Span, &'static str, String, Applicability)> { + source: PathSource<'_, 'ast, 'ra>, + ) -> (Option<(Span, &'static str, String, Applicability)>, Option>) { + tracing::info!("path: from suggest_adding_generic_parameter {:#?}", path); let (ident, span) = match path { [segment] if !segment.has_generic_args @@ -3290,13 +3396,13 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> { { (segment.ident.to_string(), segment.ident.span) } - _ => return None, + _ => return (None, None), }; let mut iter = ident.chars().map(|c| c.is_uppercase()); let single_uppercase_char = matches!(iter.next(), Some(true)) && matches!(iter.next(), None); if !self.diag_metadata.currently_processing_generic_args && !single_uppercase_char { - return None; + return (None, None); } match (self.diag_metadata.current_item, single_uppercase_char, self.diag_metadata.currently_processing_generic_args) { (Some(Item { kind: ItemKind::Fn(fn_), .. }), _, _) if fn_.ident.name == sym::main => { @@ -3326,18 +3432,21 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> { // | ^- help: you might be missing a type parameter: `, A` // | | // | not found in this scope - return None; + return (None, None); } let (msg, sugg) = match source { PathSource::Type | PathSource::PreciseCapturingArg(TypeNS) => { + if let Some(err) = self.detect_and_suggest_const_parameter_error(path, source) { + return (None, Some(err)); + } ("you might be missing a type parameter", ident) } PathSource::Expr(_) | PathSource::PreciseCapturingArg(ValueNS) => ( "you might be missing a const parameter", format!("const {ident}: /* Type */"), ), - _ => return None, + _ => return (None, None), }; let (span, sugg) = if let [.., param] = &generics.params[..] { let span = if let [.., bound] = ¶m.bounds[..] { @@ -3355,18 +3464,18 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> { }; // Do not suggest if this is coming from macro expansion. if span.can_be_used_for_suggestions() { - return Some(( + return (Some(( span.shrink_to_hi(), msg, sugg, Applicability::MaybeIncorrect, - )); + )), None); } } } _ => {} } - None + (None, None) } /// Given the target `label`, search the `rib_index`th label rib for similarly named labels, @@ -4349,3 +4458,75 @@ pub(super) fn signal_label_shadowing(sess: &Session, orig: Span, shadower: Ident .with_span_label(shadower, format!("label `{name}` already in scope")) .emit(); } + +struct ParentPathVisitor<'a> { + target: Ident, + parent: Option<&'a PathSegment>, + stack: Vec<&'a Ty>, + target_index: Option, +} + +impl<'a> ParentPathVisitor<'a> { + fn new(self_ty: &'a Ty, target: Ident) -> Self { + let mut v = + ParentPathVisitor { target, parent: None, stack: Vec::new(), target_index: None }; + + v.visit_ty(self_ty); + v + } + + fn find_arg_index(&mut self, target_id: NodeId) { + let Some(parent) = self.parent else { + return; + }; + + let Some(args) = parent.args.as_ref() else { + return; + }; + + let GenericArgs::AngleBracketed(angle) = args.as_ref() else { + return; + }; + + self.target_index = angle.args.iter().enumerate().find_map(|(idx, arg)| { + if let AngleBracketedArg::Arg(GenericArg::Type(ty)) = arg + && let TyKind::Path(_, path) = &ty.kind + && let [segment] = path.segments.as_slice() + { + tracing::info!("she e reich here ty = {:#?}", ty); + (segment.id == target_id).then_some(idx) + } else { + None + } + }); + } +} + +impl<'a> Visitor<'a> for ParentPathVisitor<'a> { + fn visit_ty(&mut self, ty: &'a Ty) { + if self.parent.is_some() { + return; + } + + // push current type + self.stack.push(ty); + + if let TyKind::Path(_, path) = &ty.kind { + // is this just `N`? + if path.segments.len() == 1 && path.segments[0].ident == self.target { + // parent is previous element in stack + if self.stack.len() >= 2 { + let parent_ty = self.stack[self.stack.len() - 2]; + + if let TyKind::Path(_, parent_path) = &parent_ty.kind { + self.parent = parent_path.segments.first(); + } + } + } + } + + walk_ty(self, ty); + + self.stack.pop(); + } +} diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index 6b3b5e2ec45f0..2cc9ac01f338b 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -43,7 +43,7 @@ use rustc_arena::{DroplessArena, TypedArena}; use rustc_ast::node_id::NodeMap; use rustc_ast::{ self as ast, AngleBracketedArg, CRATE_NODE_ID, Crate, Expr, ExprKind, GenericArg, GenericArgs, - NodeId, Path, attr, + Generics, NodeId, Path, attr, }; use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet, default}; use rustc_data_structures::intern::Interned; @@ -1320,6 +1320,10 @@ pub struct Resolver<'ra, 'tcx> { /// Also includes of list of each fields visibility struct_constructors: LocalDefIdMap<(Res, Visibility, Vec>)> = Default::default(), + /// for all the struct + /// it's not used during normal resolution, only for better error reporting. + struct_generics: LocalDefIdMap = Default::default(), + lint_buffer: LintBuffer, next_node_id: NodeId = CRATE_NODE_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..15688147e3d21 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,7 @@ fn bar() {} fn foo() { bar::<::ASSOC>(); //~^ ERROR: expected associated type, found associated constant `Trait::ASSOC` - //~| ERROR: unresolved item provided when a constant was expected + //~| ERROR: type annotations needed } 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..8ff98400d96e0 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,19 @@ 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 +error[E0284]: type annotations needed + --> $DIR/assoc_const_as_type_argument.rs:8:5 | LL | bar::<::ASSOC>(); - | ^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer the value of the const parameter `N` declared on the function `bar` | -help: if this generic argument was intended as a const parameter, surround it with braces +note: required by a const generic parameter in `bar` + --> $DIR/assoc_const_as_type_argument.rs:5:8 | -LL | bar::<{ ::ASSOC }>(); - | + + +LL | fn bar() {} + | ^^^^^^^^^^^^^^ required by this const generic parameter in `bar` error: aborting due to 2 previous errors -Some errors have detailed explanations: E0575, E0747. -For more information about an error, try `rustc --explain E0575`. +Some errors have detailed explanations: E0284, E0575. +For more information about an error, try `rustc --explain E0284`. 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..f7de9b8f036ff 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 @@ -205,16 +205,17 @@ 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 +error[E0284]: type annotations needed + --> $DIR/const-arg-in-const-arg.rs:16:17 | LL | let _: [u8; bar::()]; - | ^ + | ^^^^^^^^ cannot infer the value of the const parameter `N` declared on the function `bar` | -help: if this generic argument was intended as a const parameter, surround it with braces +note: required by a const generic parameter in `bar` + --> $DIR/const-arg-in-const-arg.rs:9:14 | -LL | let _: [u8; bar::<{ N }>()]; - | + + +LL | const fn bar() -> usize { N } + | ^^^^^^^^^^^^^^ required by this const generic parameter in `bar` error[E0794]: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present --> $DIR/const-arg-in-const-arg.rs:18:23 @@ -256,16 +257,17 @@ 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 +error[E0284]: type annotations needed + --> $DIR/const-arg-in-const-arg.rs:27:17 | LL | let _ = [0; bar::()]; - | ^ + | ^^^^^^^^ cannot infer the value of the const parameter `N` declared on the function `bar` | -help: if this generic argument was intended as a const parameter, surround it with braces +note: required by a const generic parameter in `bar` + --> $DIR/const-arg-in-const-arg.rs:9:14 | -LL | let _ = [0; bar::<{ N }>()]; - | + + +LL | const fn bar() -> usize { N } + | ^^^^^^^^^^^^^^ required by this const generic parameter in `bar` error[E0794]: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present --> $DIR/const-arg-in-const-arg.rs:29:23 @@ -291,16 +293,17 @@ 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 +error[E0284]: type annotations needed + --> $DIR/const-arg-in-const-arg.rs:36:18 | LL | let _: Foo<{ bar::() }>; - | ^ + | ^^^^^^^^ cannot infer the value of the const parameter `N` declared on the function `bar` | -help: if this generic argument was intended as a const parameter, surround it with braces +note: required by a const generic parameter in `bar` + --> $DIR/const-arg-in-const-arg.rs:9:14 | -LL | let _: Foo<{ bar::<{ N }>() }>; - | + + +LL | const fn bar() -> usize { N } + | ^^^^^^^^^^^^^^ required by this const generic parameter in `bar` error[E0794]: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present --> $DIR/const-arg-in-const-arg.rs:38:24 @@ -326,16 +329,17 @@ 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 +error[E0284]: type annotations needed + --> $DIR/const-arg-in-const-arg.rs:45:21 | LL | let _ = Foo::<{ bar::() }>; - | ^ + | ^^^^^^^^ cannot infer the value of the const parameter `N` declared on the function `bar` | -help: if this generic argument was intended as a const parameter, surround it with braces +note: required by a const generic parameter in `bar` + --> $DIR/const-arg-in-const-arg.rs:9:14 | -LL | let _ = Foo::<{ bar::<{ N }>() }>; - | + + +LL | const fn bar() -> usize { N } + | ^^^^^^^^^^^^^^ required by this const generic parameter in `bar` error[E0794]: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present --> $DIR/const-arg-in-const-arg.rs:47:27 @@ -363,5 +367,5 @@ LL | const fn faz<'a>(_: &'a ()) -> usize { 13 } error: aborting due to 37 previous errors -Some errors have detailed explanations: E0747, E0794. -For more information about an error, try `rustc --explain E0747`. +Some errors have detailed explanations: E0284, E0794. +For more information about an error, try `rustc --explain E0284`. 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..0d896efcd6114 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,7 @@ 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 + //[min]~^ ERROR type annotations needed 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 +25,7 @@ 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 + //[min]~^ ERROR type annotations needed 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 +34,7 @@ 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 + //[min]~^ ERROR type annotations needed 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 +43,7 @@ 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 + //[min]~^ ERROR type annotations needed 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-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..b8903b9a34d60 100644 --- a/tests/ui/const-generics/early/invalid-const-arguments.rs +++ b/tests/ui/const-generics/early/invalid-const-arguments.rs @@ -3,8 +3,7 @@ struct A; trait Foo {} impl Foo for A {} -//~^ ERROR cannot find type -//~| ERROR unresolved item provided when a constant +//~^ ERROR cannot find const `N` in this scope struct B; impl Foo for B {} @@ -12,5 +11,4 @@ impl Foo for B {} struct C; impl Foo for C {} -//~^ ERROR cannot find type -//~| ERROR unresolved item provided when a constant +//~^ ERROR cannot find const `T` in this scope diff --git a/tests/ui/const-generics/early/invalid-const-arguments.stderr b/tests/ui/const-generics/early/invalid-const-arguments.stderr index a0a6d8cc8679b..002c091d61fe9 100644 --- a/tests/ui/const-generics/early/invalid-const-arguments.stderr +++ b/tests/ui/const-generics/early/invalid-const-arguments.stderr @@ -1,54 +1,33 @@ -error[E0425]: cannot find type `N` in this scope +error[E0425]: cannot find const `N` in this scope --> $DIR/invalid-const-arguments.rs:5:16 | LL | struct A; - | ---------------------- similarly named struct `A` defined here + | ----------- const parameter `N` is defined here LL | trait Foo {} LL | impl Foo for A {} - | ^ + | ^ not found in this scope | -help: a struct with a similar name exists +help: you might have meant to write a const parameter here | -LL - impl Foo for A {} -LL + impl Foo for A {} - | -help: you might be missing a type parameter - | -LL | impl Foo for A {} - | +++ +LL | impl Foo for A {} + | +++++++++++++ -error[E0425]: cannot find type `T` in this scope - --> $DIR/invalid-const-arguments.rs:14:32 +error[E0425]: cannot find const `T` in this scope + --> $DIR/invalid-const-arguments.rs:13:32 | -LL | struct A; - | ---------------------- similarly named struct `A` defined here -... +LL | struct C; + | ----------- const parameter `T` is defined here LL | impl Foo for C {} - | ^ + | ^ not found in this scope | -help: a struct with a similar name exists +help: you might have meant to write a const parameter here | LL - impl Foo for C {} -LL + impl Foo for C {} - | -help: you might be missing a type parameter +LL + impl Foo for C {} | -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 +38,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/delegation/generics/generics-gen-args-errors.rs b/tests/ui/delegation/generics/generics-gen-args-errors.rs index 3edcc70420145..30a37f87b8463 100644 --- a/tests/ui/delegation/generics/generics-gen-args-errors.rs +++ b/tests/ui/delegation/generics/generics-gen-args-errors.rs @@ -29,13 +29,11 @@ mod test_1 { //~^ ERROR: cannot find type `asd` in this scope //~| ERROR: cannot find type `asd` in this scope //~| ERROR: cannot find type `asd` in this scope - //~| ERROR: unresolved item provided when a constant was expected reuse foo:: as xd; //~^ ERROR can't use generic parameters from outer item //~| ERROR can't use generic parameters from outer item //~| ERROR can't use generic parameters from outer item - //~| ERROR: unresolved item provided when a constant was expected } } diff --git a/tests/ui/delegation/generics/generics-gen-args-errors.stderr b/tests/ui/delegation/generics/generics-gen-args-errors.stderr index 78aefbc6604cc..5e5aff5beaaea 100644 --- a/tests/ui/delegation/generics/generics-gen-args-errors.stderr +++ b/tests/ui/delegation/generics/generics-gen-args-errors.stderr @@ -1,5 +1,5 @@ error[E0401]: can't use generic parameters from outer item - --> $DIR/generics-gen-args-errors.rs:34:21 + --> $DIR/generics-gen-args-errors.rs:33:21 | LL | fn check() { | - type parameter from outer item @@ -12,7 +12,7 @@ LL | reuse foo:: as xd; = note: nested items are independent from their parent item for everything except for privacy and name resolution error[E0401]: can't use generic parameters from outer item - --> $DIR/generics-gen-args-errors.rs:34:24 + --> $DIR/generics-gen-args-errors.rs:33:24 | LL | fn check() { | - type parameter from outer item @@ -25,7 +25,7 @@ LL | reuse foo:: as xd; = note: nested items are independent from their parent item for everything except for privacy and name resolution error[E0401]: can't use generic parameters from outer item - --> $DIR/generics-gen-args-errors.rs:34:27 + --> $DIR/generics-gen-args-errors.rs:33:27 | LL | fn check() { | - type parameter from outer item @@ -38,7 +38,7 @@ LL | reuse foo:: as xd; = note: nested items are independent from their parent item for everything except for privacy and name resolution error[E0261]: use of undeclared lifetime name `'asdasd` - --> $DIR/generics-gen-args-errors.rs:51:29 + --> $DIR/generics-gen-args-errors.rs:49:29 | LL | reuse foo::<'static, _, 'asdasd, 'static, 'static, 'static, _> as bar3; | ^^^^^^^ undeclared lifetime @@ -49,7 +49,7 @@ LL | reuse foo'asdasd, ::<'static, _, 'asdasd, 'static, 'static, 'static, _> | ++++++++ error[E0261]: use of undeclared lifetime name `'a` - --> $DIR/generics-gen-args-errors.rs:66:50 + --> $DIR/generics-gen-args-errors.rs:64:50 | LL | reuse foo::<"asdasd", asd, "askdn", 'static, 'a> as bar7; | ^^ undeclared lifetime @@ -60,7 +60,7 @@ LL | reuse foo'a, ::<"asdasd", asd, "askdn", 'static, 'a> as bar7; | +++ error[E0106]: missing lifetime specifiers - --> $DIR/generics-gen-args-errors.rs:111:19 + --> $DIR/generics-gen-args-errors.rs:109:19 | LL | reuse Trait::::foo::<1, 2, 3, _, 6> as bar7; | ^^^^^ expected 3 lifetime parameters @@ -114,84 +114,73 @@ LL | fn check() { | +++++ error[E0425]: cannot find type `asdasd` in this scope - --> $DIR/generics-gen-args-errors.rs:55:39 + --> $DIR/generics-gen-args-errors.rs:53:39 | LL | reuse foo:: as bar4; | ^^^^^^ not found in this scope error[E0425]: cannot find type `asd` in this scope - --> $DIR/generics-gen-args-errors.rs:62:22 + --> $DIR/generics-gen-args-errors.rs:60:22 | LL | reuse foo::<1, 2,asd,String, { let x = 0; }> as bar6; | ^^^ not found in this scope error[E0425]: cannot find type `asd` in this scope - --> $DIR/generics-gen-args-errors.rs:66:27 + --> $DIR/generics-gen-args-errors.rs:64:27 | LL | reuse foo::<"asdasd", asd, "askdn", 'static, 'a> as bar7; | ^^^ not found in this scope error[E0425]: cannot find type `asd` in this scope - --> $DIR/generics-gen-args-errors.rs:80:19 + --> $DIR/generics-gen-args-errors.rs:78:19 | LL | reuse Trait::::foo as bar1; | ^^^ not found in this scope error[E0425]: cannot find type `asd` in this scope - --> $DIR/generics-gen-args-errors.rs:80:24 + --> $DIR/generics-gen-args-errors.rs:78:24 | LL | reuse Trait::::foo as bar1; | ^^^ not found in this scope error[E0425]: cannot find type `asd` in this scope - --> $DIR/generics-gen-args-errors.rs:80:29 + --> $DIR/generics-gen-args-errors.rs:78:29 | LL | reuse Trait::::foo as bar1; | ^^^ not found in this scope error[E0425]: cannot find type `asd` in this scope - --> $DIR/generics-gen-args-errors.rs:80:34 + --> $DIR/generics-gen-args-errors.rs:78:34 | LL | reuse Trait::::foo as bar1; | ^^^ not found in this scope error[E0425]: cannot find type `asd` in this scope - --> $DIR/generics-gen-args-errors.rs:80:39 + --> $DIR/generics-gen-args-errors.rs:78:39 | LL | reuse Trait::::foo as bar1; | ^^^ not found in this scope error[E0425]: cannot find type `asdasa` in this scope - --> $DIR/generics-gen-args-errors.rs:80:44 + --> $DIR/generics-gen-args-errors.rs:78:44 | LL | reuse Trait::::foo as bar1; | ^^^^^^ not found in this scope error[E0425]: cannot find type `DDDD` in this scope - --> $DIR/generics-gen-args-errors.rs:105:34 + --> $DIR/generics-gen-args-errors.rs:103:34 | LL | reuse Trait::<1, 2, 'static, DDDD>::foo::<1, 2, 3, 4, 5, 6> as bar6; | ^^^^ not found in this scope -error[E0747]: unresolved item provided when a constant was expected - --> $DIR/generics-gen-args-errors.rs:34:27 - | -LL | reuse foo:: as xd; - | ^ - | -help: if this generic argument was intended as a const parameter, surround it with braces - | -LL | reuse foo:: as xd; - | + + - error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/generics-gen-args-errors.rs:45:11 + --> $DIR/generics-gen-args-errors.rs:43:11 | LL | reuse foo::<> as bar1; | ^^^ not allowed in type signatures error[E0107]: function takes 3 generic arguments but 2 generic arguments were supplied - --> $DIR/generics-gen-args-errors.rs:48:11 + --> $DIR/generics-gen-args-errors.rs:46:11 | LL | reuse foo:: as bar2; | ^^^ ------ ------ supplied 2 generic arguments @@ -199,7 +188,7 @@ LL | reuse foo:: as bar2; | expected 3 generic arguments | note: function defined here, with 3 generic parameters: `T`, `U`, `N` - --> $DIR/generics-gen-args-errors.rs:43:8 + --> $DIR/generics-gen-args-errors.rs:41:8 | LL | fn foo<'a: 'a, 'b: 'b, T: Clone, U: Clone, const N: usize>() {} | ^^^ - - -------------- @@ -209,7 +198,7 @@ LL | reuse foo:: as bar2; | +++ error[E0107]: function takes 2 lifetime arguments but 5 lifetime arguments were supplied - --> $DIR/generics-gen-args-errors.rs:51:11 + --> $DIR/generics-gen-args-errors.rs:49:11 | LL | reuse foo::<'static, _, 'asdasd, 'static, 'static, 'static, _> as bar3; | ^^^ --------------------------- help: remove the lifetime arguments @@ -217,19 +206,19 @@ LL | reuse foo::<'static, _, 'asdasd, 'static, 'static, 'static, _> as bar3; | expected 2 lifetime arguments | note: function defined here, with 2 lifetime parameters: `'a`, `'b` - --> $DIR/generics-gen-args-errors.rs:43:8 + --> $DIR/generics-gen-args-errors.rs:41:8 | LL | fn foo<'a: 'a, 'b: 'b, T: Clone, U: Clone, const N: usize>() {} | ^^^ -- -- error[E0107]: function takes 3 generic arguments but 2 generic arguments were supplied - --> $DIR/generics-gen-args-errors.rs:51:11 + --> $DIR/generics-gen-args-errors.rs:49:11 | LL | reuse foo::<'static, _, 'asdasd, 'static, 'static, 'static, _> as bar3; | ^^^ expected 3 generic arguments ------- - supplied 2 generic arguments | note: function defined here, with 3 generic parameters: `T`, `U`, `N` - --> $DIR/generics-gen-args-errors.rs:43:8 + --> $DIR/generics-gen-args-errors.rs:41:8 | LL | fn foo<'a: 'a, 'b: 'b, T: Clone, U: Clone, const N: usize>() {} | ^^^ - - -------------- @@ -239,7 +228,7 @@ LL | reuse foo::<'static, _, 'asdasd, 'static, 'static, 'static, _, N> as ba | +++ error[E0107]: function takes 2 lifetime arguments but 1 lifetime argument was supplied - --> $DIR/generics-gen-args-errors.rs:55:11 + --> $DIR/generics-gen-args-errors.rs:53:11 | LL | reuse foo:: as bar4; | ^^^ ------ supplied 1 lifetime argument @@ -247,7 +236,7 @@ LL | reuse foo:: as bar4; | expected 2 lifetime arguments | note: function defined here, with 2 lifetime parameters: `'a`, `'b` - --> $DIR/generics-gen-args-errors.rs:43:8 + --> $DIR/generics-gen-args-errors.rs:41:8 | LL | fn foo<'a: 'a, 'b: 'b, T: Clone, U: Clone, const N: usize>() {} | ^^^ -- -- @@ -257,7 +246,7 @@ LL | reuse foo:: as bar4; | +++++++++ error[E0107]: function takes 3 generic arguments but 6 generic arguments were supplied - --> $DIR/generics-gen-args-errors.rs:59:11 + --> $DIR/generics-gen-args-errors.rs:57:11 | LL | reuse foo::<1, 2, _, 4, 5, _> as bar5; | ^^^ --------- help: remove the unnecessary generic arguments @@ -265,13 +254,13 @@ LL | reuse foo::<1, 2, _, 4, 5, _> as bar5; | expected 3 generic arguments | note: function defined here, with 3 generic parameters: `T`, `U`, `N` - --> $DIR/generics-gen-args-errors.rs:43:8 + --> $DIR/generics-gen-args-errors.rs:41:8 | LL | fn foo<'a: 'a, 'b: 'b, T: Clone, U: Clone, const N: usize>() {} | ^^^ - - -------------- error[E0107]: function takes 3 generic arguments but 5 generic arguments were supplied - --> $DIR/generics-gen-args-errors.rs:62:11 + --> $DIR/generics-gen-args-errors.rs:60:11 | LL | reuse foo::<1, 2,asd,String, { let x = 0; }> as bar6; | ^^^ ----------------------- help: remove the unnecessary generic arguments @@ -279,31 +268,31 @@ LL | reuse foo::<1, 2,asd,String, { let x = 0; }> as bar6; | expected 3 generic arguments | note: function defined here, with 3 generic parameters: `T`, `U`, `N` - --> $DIR/generics-gen-args-errors.rs:43:8 + --> $DIR/generics-gen-args-errors.rs:41:8 | LL | fn foo<'a: 'a, 'b: 'b, T: Clone, U: Clone, const N: usize>() {} | ^^^ - - -------------- error[E0747]: constant provided when a type was expected - --> $DIR/generics-gen-args-errors.rs:66:17 + --> $DIR/generics-gen-args-errors.rs:64:17 | LL | reuse foo::<"asdasd", asd, "askdn", 'static, 'a> as bar7; | ^^^^^^^^ error[E0747]: constant provided when a type was expected - --> $DIR/generics-gen-args-errors.rs:71:17 + --> $DIR/generics-gen-args-errors.rs:69:17 | LL | reuse foo::<{}, {}, {}> as bar8; | ^^ error[E0107]: trait takes 3 lifetime arguments but 0 lifetime arguments were supplied - --> $DIR/generics-gen-args-errors.rs:80:11 + --> $DIR/generics-gen-args-errors.rs:78:11 | LL | reuse Trait::::foo as bar1; | ^^^^^ expected 3 lifetime arguments | note: trait defined here, with 3 lifetime parameters: `'b`, `'c`, `'a` - --> $DIR/generics-gen-args-errors.rs:76:11 + --> $DIR/generics-gen-args-errors.rs:74:11 | LL | trait Trait<'b, 'c, 'a, T, const N: usize>: Sized { | ^^^^^ -- -- -- @@ -313,7 +302,7 @@ LL | reuse Trait::<'b, 'c, 'a, asd, asd, asd, asd, asd, asdasa>::foo as bar1 | +++++++++++ error[E0107]: trait takes 2 generic arguments but 6 generic arguments were supplied - --> $DIR/generics-gen-args-errors.rs:80:11 + --> $DIR/generics-gen-args-errors.rs:78:11 | LL | reuse Trait::::foo as bar1; | ^^^^^ ----------------------- help: remove the unnecessary generic arguments @@ -321,13 +310,13 @@ LL | reuse Trait::::foo as bar1; | expected 2 generic arguments | note: trait defined here, with 2 generic parameters: `T`, `N` - --> $DIR/generics-gen-args-errors.rs:76:11 + --> $DIR/generics-gen-args-errors.rs:74:11 | LL | trait Trait<'b, 'c, 'a, T, const N: usize>: Sized { | ^^^^^ - -------------- error[E0107]: trait takes 3 lifetime arguments but 2 lifetime arguments were supplied - --> $DIR/generics-gen-args-errors.rs:90:11 + --> $DIR/generics-gen-args-errors.rs:88:11 | LL | reuse Trait::<'static, 'static>::foo as bar2; | ^^^^^ ------- ------- supplied 2 lifetime arguments @@ -335,7 +324,7 @@ LL | reuse Trait::<'static, 'static>::foo as bar2; | expected 3 lifetime arguments | note: trait defined here, with 3 lifetime parameters: `'b`, `'c`, `'a` - --> $DIR/generics-gen-args-errors.rs:76:11 + --> $DIR/generics-gen-args-errors.rs:74:11 | LL | trait Trait<'b, 'c, 'a, T, const N: usize>: Sized { | ^^^^^ -- -- -- @@ -345,19 +334,19 @@ LL | reuse Trait::<'static, 'static, 'static>::foo as bar2; | +++++++++ error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/generics-gen-args-errors.rs:90:11 + --> $DIR/generics-gen-args-errors.rs:88:11 | LL | reuse Trait::<'static, 'static>::foo as bar2; | ^^^^^ not allowed in type signatures error[E0107]: trait takes 3 lifetime arguments but 0 lifetime arguments were supplied - --> $DIR/generics-gen-args-errors.rs:93:11 + --> $DIR/generics-gen-args-errors.rs:91:11 | LL | reuse Trait::<1, 2, 3, 4, 5>::foo as bar3; | ^^^^^ expected 3 lifetime arguments | note: trait defined here, with 3 lifetime parameters: `'b`, `'c`, `'a` - --> $DIR/generics-gen-args-errors.rs:76:11 + --> $DIR/generics-gen-args-errors.rs:74:11 | LL | trait Trait<'b, 'c, 'a, T, const N: usize>: Sized { | ^^^^^ -- -- -- @@ -367,7 +356,7 @@ LL | reuse Trait::<'b, 'c, 'a, 1, 2, 3, 4, 5>::foo as bar3; | +++++++++++ error[E0107]: trait takes 2 generic arguments but 5 generic arguments were supplied - --> $DIR/generics-gen-args-errors.rs:93:11 + --> $DIR/generics-gen-args-errors.rs:91:11 | LL | reuse Trait::<1, 2, 3, 4, 5>::foo as bar3; | ^^^^^ --------- help: remove the unnecessary generic arguments @@ -375,19 +364,19 @@ LL | reuse Trait::<1, 2, 3, 4, 5>::foo as bar3; | expected 2 generic arguments | note: trait defined here, with 2 generic parameters: `T`, `N` - --> $DIR/generics-gen-args-errors.rs:76:11 + --> $DIR/generics-gen-args-errors.rs:74:11 | LL | trait Trait<'b, 'c, 'a, T, const N: usize>: Sized { | ^^^^^ - -------------- error[E0107]: trait takes 3 lifetime arguments but 0 lifetime arguments were supplied - --> $DIR/generics-gen-args-errors.rs:97:11 + --> $DIR/generics-gen-args-errors.rs:95:11 | LL | reuse Trait::<1, 2, true>::foo as bar4; | ^^^^^ expected 3 lifetime arguments | note: trait defined here, with 3 lifetime parameters: `'b`, `'c`, `'a` - --> $DIR/generics-gen-args-errors.rs:76:11 + --> $DIR/generics-gen-args-errors.rs:74:11 | LL | trait Trait<'b, 'c, 'a, T, const N: usize>: Sized { | ^^^^^ -- -- -- @@ -397,7 +386,7 @@ LL | reuse Trait::<'b, 'c, 'a, 1, 2, true>::foo as bar4; | +++++++++++ error[E0107]: trait takes 2 generic arguments but 3 generic arguments were supplied - --> $DIR/generics-gen-args-errors.rs:97:11 + --> $DIR/generics-gen-args-errors.rs:95:11 | LL | reuse Trait::<1, 2, true>::foo as bar4; | ^^^^^ ------ help: remove the unnecessary generic argument @@ -405,13 +394,13 @@ LL | reuse Trait::<1, 2, true>::foo as bar4; | expected 2 generic arguments | note: trait defined here, with 2 generic parameters: `T`, `N` - --> $DIR/generics-gen-args-errors.rs:76:11 + --> $DIR/generics-gen-args-errors.rs:74:11 | LL | trait Trait<'b, 'c, 'a, T, const N: usize>: Sized { | ^^^^^ - -------------- error[E0107]: trait takes 3 lifetime arguments but 1 lifetime argument was supplied - --> $DIR/generics-gen-args-errors.rs:101:11 + --> $DIR/generics-gen-args-errors.rs:99:11 | LL | reuse Trait::<'static>::foo as bar5; | ^^^^^ ------- supplied 1 lifetime argument @@ -419,7 +408,7 @@ LL | reuse Trait::<'static>::foo as bar5; | expected 3 lifetime arguments | note: trait defined here, with 3 lifetime parameters: `'b`, `'c`, `'a` - --> $DIR/generics-gen-args-errors.rs:76:11 + --> $DIR/generics-gen-args-errors.rs:74:11 | LL | trait Trait<'b, 'c, 'a, T, const N: usize>: Sized { | ^^^^^ -- -- -- @@ -429,13 +418,13 @@ LL | reuse Trait::<'static, 'static, 'static>::foo as bar5; | ++++++++++++++++++ error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/generics-gen-args-errors.rs:101:11 + --> $DIR/generics-gen-args-errors.rs:99:11 | LL | reuse Trait::<'static>::foo as bar5; | ^^^^^ not allowed in type signatures error[E0107]: trait takes 3 lifetime arguments but 1 lifetime argument was supplied - --> $DIR/generics-gen-args-errors.rs:105:11 + --> $DIR/generics-gen-args-errors.rs:103:11 | LL | reuse Trait::<1, 2, 'static, DDDD>::foo::<1, 2, 3, 4, 5, 6> as bar6; | ^^^^^ - supplied 1 lifetime argument @@ -443,7 +432,7 @@ LL | reuse Trait::<1, 2, 'static, DDDD>::foo::<1, 2, 3, 4, 5, 6> as bar6; | expected 3 lifetime arguments | note: trait defined here, with 3 lifetime parameters: `'b`, `'c`, `'a` - --> $DIR/generics-gen-args-errors.rs:76:11 + --> $DIR/generics-gen-args-errors.rs:74:11 | LL | trait Trait<'b, 'c, 'a, T, const N: usize>: Sized { | ^^^^^ -- -- -- @@ -453,7 +442,7 @@ LL | reuse Trait::<1, 'static, 'static, 2, 'static, DDDD>::foo::<1, 2, 3, 4, | ++++++++++++++++++ error[E0107]: trait takes 2 generic arguments but 3 generic arguments were supplied - --> $DIR/generics-gen-args-errors.rs:105:11 + --> $DIR/generics-gen-args-errors.rs:103:11 | LL | reuse Trait::<1, 2, 'static, DDDD>::foo::<1, 2, 3, 4, 5, 6> as bar6; | ^^^^^ --------------- help: remove the unnecessary generic argument @@ -461,13 +450,13 @@ LL | reuse Trait::<1, 2, 'static, DDDD>::foo::<1, 2, 3, 4, 5, 6> as bar6; | expected 2 generic arguments | note: trait defined here, with 2 generic parameters: `T`, `N` - --> $DIR/generics-gen-args-errors.rs:76:11 + --> $DIR/generics-gen-args-errors.rs:74:11 | LL | trait Trait<'b, 'c, 'a, T, const N: usize>: Sized { | ^^^^^ - -------------- error[E0107]: method takes 2 generic arguments but 6 generic arguments were supplied - --> $DIR/generics-gen-args-errors.rs:105:41 + --> $DIR/generics-gen-args-errors.rs:103:41 | LL | reuse Trait::<1, 2, 'static, DDDD>::foo::<1, 2, 3, 4, 5, 6> as bar6; | ^^^ ------------ help: remove the unnecessary generic arguments @@ -475,13 +464,13 @@ LL | reuse Trait::<1, 2, 'static, DDDD>::foo::<1, 2, 3, 4, 5, 6> as bar6; | expected 2 generic arguments | note: method defined here, with 2 generic parameters: `U`, `M` - --> $DIR/generics-gen-args-errors.rs:77:12 + --> $DIR/generics-gen-args-errors.rs:75:12 | LL | fn foo<'d: 'd, U, const M: bool>(self) {} | ^^^ - ------------- error[E0107]: trait takes 3 lifetime arguments but 1 lifetime argument was supplied - --> $DIR/generics-gen-args-errors.rs:111:11 + --> $DIR/generics-gen-args-errors.rs:109:11 | LL | reuse Trait::::foo::<1, 2, 3, _, 6> as bar7; | ^^^^^ ----- supplied 1 lifetime argument @@ -489,7 +478,7 @@ LL | reuse Trait::::foo::<1, 2, 3, _, | expected 3 lifetime arguments | note: trait defined here, with 3 lifetime parameters: `'b`, `'c`, `'a` - --> $DIR/generics-gen-args-errors.rs:76:11 + --> $DIR/generics-gen-args-errors.rs:74:11 | LL | trait Trait<'b, 'c, 'a, T, const N: usize>: Sized { | ^^^^^ -- -- -- @@ -499,7 +488,7 @@ LL | reuse Trait::: | ++++++++++++++++++ error[E0107]: trait takes 2 generic arguments but 5 generic arguments were supplied - --> $DIR/generics-gen-args-errors.rs:111:11 + --> $DIR/generics-gen-args-errors.rs:109:11 | LL | reuse Trait::::foo::<1, 2, 3, _, 6> as bar7; | ^^^^^ --- help: remove the unnecessary generic argument @@ -507,13 +496,13 @@ LL | reuse Trait::::foo::<1, 2, 3, _, | expected 2 generic arguments | note: trait defined here, with 2 generic parameters: `T`, `N` - --> $DIR/generics-gen-args-errors.rs:76:11 + --> $DIR/generics-gen-args-errors.rs:74:11 | LL | trait Trait<'b, 'c, 'a, T, const N: usize>: Sized { | ^^^^^ - -------------- error[E0107]: method takes 2 generic arguments but 5 generic arguments were supplied - --> $DIR/generics-gen-args-errors.rs:111:59 + --> $DIR/generics-gen-args-errors.rs:109:59 | LL | reuse Trait::::foo::<1, 2, 3, _, 6> as bar7; | ^^^ --------- help: remove the unnecessary generic arguments @@ -521,7 +510,7 @@ LL | reuse Trait::::foo::<1, 2, 3, _, | expected 2 generic arguments | note: method defined here, with 2 generic parameters: `U`, `M` - --> $DIR/generics-gen-args-errors.rs:77:12 + --> $DIR/generics-gen-args-errors.rs:75:12 | LL | fn foo<'d: 'd, U, const M: bool>(self) {} | ^^^ - ------------- @@ -580,18 +569,7 @@ LL | fn foo<'a: 'a, 'b: 'b, T: Clone, U: Clone, const N: usize>() {} LL | reuse foo as bar; | ^^^ -error[E0747]: unresolved item provided when a constant was expected - --> $DIR/generics-gen-args-errors.rs:28:25 - | -LL | bar::(); - | ^^^ - | -help: if this generic argument was intended as a const parameter, surround it with braces - | -LL | bar::(); - | + + - -error: aborting due to 51 previous errors +error: aborting due to 49 previous errors Some errors have detailed explanations: E0106, E0107, E0121, E0261, E0401, E0423, E0425, E0747. For more information about an error, try `rustc --explain E0106`. diff --git a/tests/ui/missing/missing-items/missing-type-parameter2.rs b/tests/ui/missing/missing-items/missing-type-parameter2.rs index 772e60b1376c3..84f32feaf0672 100644 --- a/tests/ui/missing/missing-items/missing-type-parameter2.rs +++ b/tests/ui/missing/missing-items/missing-type-parameter2.rs @@ -1,12 +1,10 @@ struct X(); impl X {} -//~^ ERROR cannot find type `N` in this scope -//~| ERROR unresolved item provided when a constant was expected +//~^ ERROR cannot find const `N` in this scope impl X {} -//~^ ERROR cannot find type `N` in this scope +//~^ ERROR cannot find const `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..3ce844d5a2eba 100644 --- a/tests/ui/missing/missing-items/missing-type-parameter2.stderr +++ b/tests/ui/missing/missing-items/missing-type-parameter2.stderr @@ -1,42 +1,34 @@ -error[E0425]: cannot find type `N` in this scope +error[E0425]: cannot find const `N` in this scope --> $DIR/missing-type-parameter2.rs:3:8 | LL | struct X(); - | ------------------------ similarly named struct `X` defined here + | ----------- const parameter `N` is defined here LL | LL | impl X {} - | ^ - | -help: a struct with a similar name exists + | ^ not found in this scope | -LL - impl X {} -LL + impl X {} - | -help: you might be missing a type parameter +help: you might have meant to write a const parameter here | -LL | impl X {} - | +++ +LL | impl X {} + | +++++++++++++ -error[E0425]: cannot find type `N` in this scope - --> $DIR/missing-type-parameter2.rs:6:28 +error[E0425]: cannot find const `N` in this scope + --> $DIR/missing-type-parameter2.rs:5:28 | +LL | struct X(); + | ----------- const parameter `N` is defined here +... LL | impl X {} - | - ^ - | | - | similarly named type parameter `T` defined here + | ^ not found in this scope | -help: a type parameter with a similar name exists +help: you might have meant to write a const parameter here | LL - impl X {} -LL + impl X {} +LL + impl X {} | -help: you might be missing a type parameter - | -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 +47,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 +66,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 +84,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`.