From 69b43c209c2808f3b6fe0eef857dc7585503666d Mon Sep 17 00:00:00 2001 From: Bastian Kauschke Date: Fri, 13 Nov 2020 20:23:37 +0100 Subject: [PATCH] improve error message for const ty param mismatch --- compiler/rustc_hir/src/hir.rs | 8 + compiler/rustc_typeck/src/astconv/generics.rs | 146 ++++++++---------- compiler/rustc_typeck/src/lib.rs | 1 + .../const-generics/const-param-shadowing.rs | 9 ++ .../const-param-shadowing.stderr | 14 ++ .../invalid-constant-in-args.rs | 3 +- .../invalid-constant-in-args.stderr | 2 +- src/test/ui/const-generics/invalid-enum.rs | 12 +- .../ui/const-generics/invalid-enum.stderr | 64 +++----- .../issues/issue-62878.full.stderr | 16 +- .../ui/const-generics/issues/issue-62878.rs | 3 +- .../ui/const-generics/issues/issue-76595.rs | 2 +- .../const-generics/issues/issue-76595.stderr | 4 +- ...const-expression-suggest-missing-braces.rs | 3 +- ...t-expression-suggest-missing-braces.stderr | 36 ++--- .../min_const_generics/macro-fail.rs | 12 +- .../min_const_generics/macro-fail.stderr | 56 ++----- src/test/ui/parser/issue-14303-fncall.stderr | 2 - src/test/ui/parser/issue-14303-path.stderr | 2 - src/test/ui/privacy/privacy-ns1.rs | 4 +- src/test/ui/privacy/privacy-ns1.stderr | 16 +- src/test/ui/privacy/privacy-ns2.rs | 6 +- src/test/ui/privacy/privacy-ns2.stderr | 42 ++--- .../ui/suggestions/suggest-move-types.stderr | 4 - .../ui/traits/trait-object-vs-lifetime.stderr | 2 - 25 files changed, 194 insertions(+), 275 deletions(-) create mode 100644 src/test/ui/const-generics/const-param-shadowing.rs create mode 100644 src/test/ui/const-generics/const-param-shadowing.stderr diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index 3c28b48795f56..4497c8c0eaaa8 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -282,6 +282,14 @@ impl GenericArg<'_> { GenericArg::Const(_) => "constant", } } + + pub fn short_descr(&self) -> &'static str { + match self { + GenericArg::Lifetime(_) => "lifetime", + GenericArg::Type(_) => "type", + GenericArg::Const(_) => "const", + } + } } #[derive(Debug, HashStable_Generic)] diff --git a/compiler/rustc_typeck/src/astconv/generics.rs b/compiler/rustc_typeck/src/astconv/generics.rs index 5768ed3cdca91..d8d6456e476ce 100644 --- a/compiler/rustc_typeck/src/astconv/generics.rs +++ b/compiler/rustc_typeck/src/astconv/generics.rs @@ -22,6 +22,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { sess: &Session, arg: &GenericArg<'_>, kind: &'static str, + possible_ordering_error: bool, help: Option<&str>, ) { let mut err = struct_span_err!( @@ -48,8 +49,23 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { GenericArg::Const(_) => ParamKindOrd::Const { unordered }, }; + if matches!(arg, GenericArg::Type(hir::Ty { kind: hir::TyKind::Path { .. }, .. })) + && matches!(kind_ord, ParamKindOrd::Const { .. }) + { + let suggestions = vec![ + (arg.span().shrink_to_lo(), String::from("{ ")), + (arg.span().shrink_to_hi(), String::from(" }")), + ]; + err.multipart_suggestion( + "if this generic argument was intended as a const parameter, \ + try surrounding it with braces:", + suggestions, + Applicability::MaybeIncorrect, + ); + } + // This note is only true when generic parameters are strictly ordered by their kind. - if kind_ord.cmp(&arg_ord) != core::cmp::Ordering::Equal { + if possible_ordering_error && kind_ord.cmp(&arg_ord) != core::cmp::Ordering::Equal { let (first, last) = if kind_ord < arg_ord { (kind, arg.descr()) } else { (arg.descr(), kind) }; err.note(&format!("{} arguments must be provided before {} arguments", first, last)); @@ -153,8 +169,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { // Check whether this segment takes generic arguments and the user has provided any. let (generic_args, infer_args) = args_for_def_id(def_id); - let mut args = - generic_args.iter().flat_map(|generic_args| generic_args.args.iter()).peekable(); + let args_iter = generic_args.iter().flat_map(|generic_args| generic_args.args.iter()); + let mut args = args_iter.clone().peekable(); // If we encounter a type or const when we expect a lifetime, we infer the lifetimes. // If we later encounter a lifetime, we know that the arguments were provided in the @@ -221,8 +237,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { GenericParamDefKind::Const => { ParamKindOrd::Const { unordered: tcx - .sess - .features_untracked() + .features() .const_generics, } } @@ -242,6 +257,13 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { tcx.sess, arg, kind.descr(), + !args_iter.clone().is_sorted_by_key(|arg| match arg { + GenericArg::Lifetime(_) => ParamKindOrd::Lifetime, + GenericArg::Type(_) => ParamKindOrd::Type, + GenericArg::Const(_) => ParamKindOrd::Const { + unordered: tcx.features().const_generics, + }, + }), Some(&format!( "reorder the arguments: {}: `<{}>`", param_types_present @@ -293,7 +315,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { assert_eq!(kind, "lifetime"); let provided = force_infer_lt.expect("lifetimes ought to have been inferred"); - Self::generic_arg_mismatch_err(tcx.sess, provided, kind, None); + Self::generic_arg_mismatch_err(tcx.sess, provided, kind, false, None); } break; @@ -351,6 +373,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { // that lifetimes will proceed types. So it suffices to check the number of each generic // arguments in order to validate them with respect to the generic parameters. let param_counts = def.own_counts(); + let named_type_param_count = param_counts.types - has_self as usize; let arg_counts = args.own_counts(); let infer_lifetimes = position != GenericArgPosition::Type && arg_counts.lifetimes == 0; @@ -389,11 +412,11 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { // For kinds without defaults (e.g.., lifetimes), `required == permitted`. // For other kinds (i.e., types), `permitted` may be greater than `required`. if required <= provided && provided <= permitted { - return Ok(()); + return true; } if silent { - return Err((0i32, None)); + return false; } // Unfortunately lifetime and type parameter mismatches are typically styled @@ -409,25 +432,26 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { (required, "") }; - let (spans, label) = if provided > permitted { + let (spans, labels) = if provided > permitted { // In the case when the user has provided too many arguments, // we want to point to the unexpected arguments. - let spans: Vec = args.args[offset + permitted..offset + provided] + let (spans, labels): (Vec, Vec) = args.args + [offset + permitted..offset + provided] .iter() - .map(|arg| arg.span()) - .collect(); + .map(|arg| (arg.span(), format!("unexpected {} argument", arg.short_descr()))) + .unzip(); unexpected_spans.extend(spans.clone()); - (spans, format!("unexpected {} argument", kind)) + (spans, labels) } else { ( vec![span], - format!( + vec![format!( "expected {}{} {} argument{}", quantifier, bound, kind, pluralize!(bound), - ), + )], ) }; @@ -439,12 +463,11 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { ), DiagnosticId::Error("E0107".into()), ); - for span in spans { + for (span, label) in spans.into_iter().zip(labels) { err.span_label(span, label.as_str()); } - - assert_ne!(bound, provided); - Err((bound as i32 - provided as i32, Some(err))) + err.emit(); + false }; let mut unexpected_spans = vec![]; @@ -459,75 +482,38 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { explicit_late_bound == ExplicitLateBound::Yes, ); - // FIXME(const_generics:defaults) - let mut const_count_correct = check_kind_count( - "const", - if infer_args { 0 } else { param_counts.consts }, - param_counts.consts, - arg_counts.consts, - arg_counts.lifetimes + arg_counts.types, - &mut unexpected_spans, - false, - ); + let kind_str = if param_counts.consts + arg_counts.consts == 0 { + "type" + } else if named_type_param_count + arg_counts.types == 0 { + "const" + } else { + "generic" + }; - // Note that type errors are currently be emitted *after* const errors. - let mut type_count_correct = check_kind_count( - "type", - if infer_args { 0 } else { param_counts.types - defaults.types - has_self as usize }, - param_counts.types - has_self as usize, - arg_counts.types, + let arg_count_correct = check_kind_count( + kind_str, + if infer_args { + 0 + } else { + param_counts.consts + named_type_param_count - defaults.types + }, + param_counts.consts + named_type_param_count, + arg_counts.consts + arg_counts.types, arg_counts.lifetimes, &mut unexpected_spans, false, ); - // Emit a help message if it's possible that a type could be surrounded in braces - if let Err((c_mismatch, Some(ref mut _const_err))) = const_count_correct { - if let Err((_, Some(ref mut type_err))) = type_count_correct { - let possible_matches = args.args[arg_counts.lifetimes..] - .iter() - .filter(|arg| { - matches!( - arg, - GenericArg::Type(hir::Ty { kind: hir::TyKind::Path { .. }, .. }) - ) - }) - .take(c_mismatch.max(0) as usize); - for arg in possible_matches { - let suggestions = vec![ - (arg.span().shrink_to_lo(), String::from("{ ")), - (arg.span().shrink_to_hi(), String::from(" }")), - ]; - type_err.multipart_suggestion( - "If this generic argument was intended as a const parameter, \ - try surrounding it with braces:", - suggestions, - Applicability::MaybeIncorrect, - ); - } - } - } - - let emit_correct = - |correct: Result<(), (_, Option>)>| match correct { - Ok(()) => Ok(()), - Err((_, None)) => Err(()), - Err((_, Some(mut err))) => { - err.emit(); - Err(()) - } - }; - - let arg_count_correct = emit_correct(lifetime_count_correct) - .and(emit_correct(const_count_correct)) - .and(emit_correct(type_count_correct)); - GenericArgCountResult { explicit_late_bound, - correct: arg_count_correct.map_err(|()| GenericArgCountMismatch { - reported: Some(ErrorReported), - invalid_args: unexpected_spans, - }), + correct: if lifetime_count_correct && arg_count_correct { + Ok(()) + } else { + Err(GenericArgCountMismatch { + reported: Some(ErrorReported), + invalid_args: unexpected_spans, + }) + }, } } diff --git a/compiler/rustc_typeck/src/lib.rs b/compiler/rustc_typeck/src/lib.rs index 30904091c1b3f..929c88455f041 100644 --- a/compiler/rustc_typeck/src/lib.rs +++ b/compiler/rustc_typeck/src/lib.rs @@ -61,6 +61,7 @@ This API is completely unstable and subject to change. #![feature(box_syntax)] #![feature(crate_visibility_modifier)] #![feature(in_band_lifetimes)] +#![feature(is_sorted)] #![feature(nll)] #![feature(or_patterns)] #![feature(try_blocks)] diff --git a/src/test/ui/const-generics/const-param-shadowing.rs b/src/test/ui/const-generics/const-param-shadowing.rs new file mode 100644 index 0000000000000..8440e47968e9a --- /dev/null +++ b/src/test/ui/const-generics/const-param-shadowing.rs @@ -0,0 +1,9 @@ +#![feature(min_const_generics)] + +type N = u32; +struct Foo; +fn test() -> Foo { //~ ERROR type provided when + Foo +} + +fn main() {} diff --git a/src/test/ui/const-generics/const-param-shadowing.stderr b/src/test/ui/const-generics/const-param-shadowing.stderr new file mode 100644 index 0000000000000..df17027802672 --- /dev/null +++ b/src/test/ui/const-generics/const-param-shadowing.stderr @@ -0,0 +1,14 @@ +error[E0747]: type provided when a constant was expected + --> $DIR/const-param-shadowing.rs:5:34 + | +LL | fn test() -> Foo { + | ^ + | +help: if this generic argument was intended as a const parameter, try surrounding it with braces: + | +LL | fn test() -> Foo<{ N }> { + | ^ ^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0747`. diff --git a/src/test/ui/const-generics/invalid-constant-in-args.rs b/src/test/ui/const-generics/invalid-constant-in-args.rs index 40df237ee72ed..38ad510e5d7f0 100644 --- a/src/test/ui/const-generics/invalid-constant-in-args.rs +++ b/src/test/ui/const-generics/invalid-constant-in-args.rs @@ -1,3 +1,4 @@ fn main() { - let _: Vec<&str, "a"> = Vec::new(); //~ ERROR wrong number of const arguments + let _: Vec<&str, "a"> = Vec::new(); + //~^ ERROR wrong number of generic arguments } diff --git a/src/test/ui/const-generics/invalid-constant-in-args.stderr b/src/test/ui/const-generics/invalid-constant-in-args.stderr index b9f874ff18bb3..5111815e002f1 100644 --- a/src/test/ui/const-generics/invalid-constant-in-args.stderr +++ b/src/test/ui/const-generics/invalid-constant-in-args.stderr @@ -1,4 +1,4 @@ -error[E0107]: wrong number of const arguments: expected 0, found 1 +error[E0107]: wrong number of generic arguments: expected 1, found 2 --> $DIR/invalid-constant-in-args.rs:2:22 | LL | let _: Vec<&str, "a"> = Vec::new(); diff --git a/src/test/ui/const-generics/invalid-enum.rs b/src/test/ui/const-generics/invalid-enum.rs index ceb188a0d3d34..4ca10ed8b71a2 100644 --- a/src/test/ui/const-generics/invalid-enum.rs +++ b/src/test/ui/const-generics/invalid-enum.rs @@ -20,20 +20,16 @@ impl Example { pub fn main() { test_1::(); //~^ ERROR: expected type, found variant - //~| ERROR: wrong number of const arguments - //~| ERROR: wrong number of type arguments + //~| ERROR: type provided when a constant was expected test_2::<_, CompileFlag::A>(0); //~^ ERROR: expected type, found variant - //~| ERROR: wrong number of const arguments - //~| ERROR: wrong number of type arguments + //~| ERROR: type provided when a constant was expected let _: Example = Example { x: 0 }; //~^ ERROR: expected type, found variant - //~| ERROR: wrong number of const arguments - //~| ERROR: wrong number of type arguments + //~| ERROR: type provided when a constant was expected let _: Example = Example { x: 0 }; - //~^ ERROR: wrong number of const arguments - //~| ERROR: wrong number of type arguments + //~^ ERROR: type provided when a constant was expected } diff --git a/src/test/ui/const-generics/invalid-enum.stderr b/src/test/ui/const-generics/invalid-enum.stderr index edaa0ab527dbb..7822fc072e35c 100644 --- a/src/test/ui/const-generics/invalid-enum.stderr +++ b/src/test/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:26:15 + --> $DIR/invalid-enum.rs:25: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:31:18 + --> $DIR/invalid-enum.rs:29:18 | LL | let _: Example = Example { x: 0 }; | ^^^^^^^^^^^^^^ @@ -25,75 +25,51 @@ LL | let _: Example = Example { x: 0 }; | not a type | help: try using the variant's enum: `CompileFlag` -error[E0107]: wrong number of const arguments: expected 1, found 0 - --> $DIR/invalid-enum.rs:31:10 +error[E0747]: type provided when a constant was expected + --> $DIR/invalid-enum.rs:29:18 | LL | let _: Example = Example { x: 0 }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ expected 1 const argument - -error[E0107]: wrong number of type arguments: expected at most 1, found 2 - --> $DIR/invalid-enum.rs:31:34 - | -LL | let _: Example = Example { x: 0 }; - | ^ unexpected type argument + | ^^^^^^^^^^^^^^ | -help: If this generic argument was intended as a const parameter, try surrounding it with braces: +help: if this generic argument was intended as a const parameter, try surrounding it with braces: | LL | let _: Example<{ CompileFlag::A }, _> = Example { x: 0 }; | ^ ^ -error[E0107]: wrong number of const arguments: expected 1, found 0 - --> $DIR/invalid-enum.rs:36:10 +error[E0747]: type provided when a constant was expected + --> $DIR/invalid-enum.rs:33:18 | LL | let _: Example = Example { x: 0 }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected 1 const argument - -error[E0107]: wrong number of type arguments: expected at most 1, found 2 - --> $DIR/invalid-enum.rs:36:39 - | -LL | let _: Example = Example { x: 0 }; - | ^ unexpected type argument + | ^^^^^^^^^^^^^^^^^^^ | -help: If this generic argument was intended as a const parameter, try surrounding it with braces: +help: if this generic argument was intended as a const parameter, try surrounding it with braces: | LL | let _: Example<{ Example::ASSOC_FLAG }, _> = Example { x: 0 }; | ^ ^ -error[E0107]: wrong number of const arguments: expected 1, found 0 - --> $DIR/invalid-enum.rs:21:3 - | -LL | test_1::(); - | ^^^^^^^^^^^^^^^^^^^^^^^^ expected 1 const argument - -error[E0107]: wrong number of type arguments: expected 0, found 1 +error[E0747]: type provided when a constant was expected --> $DIR/invalid-enum.rs:21:12 | LL | test_1::(); - | ^^^^^^^^^^^^^^ unexpected type argument + | ^^^^^^^^^^^^^^ | -help: If this generic argument was intended as a const parameter, try surrounding it with braces: +help: if this generic argument was intended as a const parameter, try surrounding it with braces: | LL | test_1::<{ CompileFlag::A }>(); | ^ ^ -error[E0107]: wrong number of const arguments: expected 1, found 0 - --> $DIR/invalid-enum.rs:26:3 +error[E0747]: type provided when a constant was expected + --> $DIR/invalid-enum.rs:25:15 | LL | test_2::<_, CompileFlag::A>(0); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected 1 const argument - -error[E0107]: wrong number of type arguments: expected 1, found 2 - --> $DIR/invalid-enum.rs:26:15 - | -LL | test_2::<_, CompileFlag::A>(0); - | ^^^^^^^^^^^^^^ unexpected type argument + | ^^^^^^^^^^^^^^ | -help: If this generic argument was intended as a const parameter, try surrounding it with braces: +help: if this generic argument was intended as a const parameter, try surrounding it with braces: | LL | test_2::<_, { CompileFlag::A }>(0); | ^ ^ -error: aborting due to 11 previous errors +error: aborting due to 7 previous errors -Some errors have detailed explanations: E0107, E0573. -For more information about an error, try `rustc --explain E0107`. +Some errors have detailed explanations: E0573, E0747. +For more information about an error, try `rustc --explain E0573`. diff --git a/src/test/ui/const-generics/issues/issue-62878.full.stderr b/src/test/ui/const-generics/issues/issue-62878.full.stderr index c8b9db8941098..fc70be404971e 100644 --- a/src/test/ui/const-generics/issues/issue-62878.full.stderr +++ b/src/test/ui/const-generics/issues/issue-62878.full.stderr @@ -4,17 +4,11 @@ error[E0770]: the type of const parameters must not depend on other generic para LL | fn foo() {} | ^ the type must not depend on the parameter `N` -error[E0107]: wrong number of const arguments: expected 2, found 1 - --> $DIR/issue-62878.rs:11:5 - | -LL | foo::<_, {[1]}>(); - | ^^^^^^^^^^^^^^^ expected 2 const arguments - -error[E0107]: wrong number of type arguments: expected 0, found 1 +error[E0747]: type provided when a constant was expected --> $DIR/issue-62878.rs:11:11 | LL | foo::<_, {[1]}>(); - | ^ unexpected type argument + | ^ error[E0308]: mismatched types --> $DIR/issue-62878.rs:11:15 @@ -22,7 +16,7 @@ error[E0308]: mismatched types LL | foo::<_, {[1]}>(); | ^^^ expected `usize`, found array `[{integer}; 1]` -error: aborting due to 4 previous errors +error: aborting due to 3 previous errors -Some errors have detailed explanations: E0107, E0308, E0770. -For more information about an error, try `rustc --explain E0107`. +Some errors have detailed explanations: E0308, E0747, E0770. +For more information about an error, try `rustc --explain E0308`. diff --git a/src/test/ui/const-generics/issues/issue-62878.rs b/src/test/ui/const-generics/issues/issue-62878.rs index 0487dda2fe81d..c087711e5f9ad 100644 --- a/src/test/ui/const-generics/issues/issue-62878.rs +++ b/src/test/ui/const-generics/issues/issue-62878.rs @@ -9,7 +9,6 @@ fn foo() {} fn main() { foo::<_, {[1]}>(); - //[full]~^ ERROR wrong number of const arguments - //[full]~| ERROR wrong number of type arguments + //[full]~^ ERROR type provided when a constant was expected //[full]~| ERROR mismatched types } diff --git a/src/test/ui/const-generics/issues/issue-76595.rs b/src/test/ui/const-generics/issues/issue-76595.rs index 9fdbbff66e9e9..04c019015179e 100644 --- a/src/test/ui/const-generics/issues/issue-76595.rs +++ b/src/test/ui/const-generics/issues/issue-76595.rs @@ -13,5 +13,5 @@ fn test() where Bool<{core::mem::size_of::() > 4}>: True { fn main() { test::<2>(); - //~^ ERROR wrong number of type + //~^ ERROR wrong number of generic arguments } diff --git a/src/test/ui/const-generics/issues/issue-76595.stderr b/src/test/ui/const-generics/issues/issue-76595.stderr index f258d2977186f..1e37f9dcb1925 100644 --- a/src/test/ui/const-generics/issues/issue-76595.stderr +++ b/src/test/ui/const-generics/issues/issue-76595.stderr @@ -1,8 +1,8 @@ -error[E0107]: wrong number of type arguments: expected 1, found 0 +error[E0107]: wrong number of generic arguments: expected 2, found 1 --> $DIR/issue-76595.rs:15:5 | LL | test::<2>(); - | ^^^^^^^^^ expected 1 type argument + | ^^^^^^^^^ expected 2 generic arguments error: aborting due to previous error diff --git a/src/test/ui/const-generics/min_const_generics/const-expression-suggest-missing-braces.rs b/src/test/ui/const-generics/min_const_generics/const-expression-suggest-missing-braces.rs index aea3def5aeb23..b96d5c561ff51 100644 --- a/src/test/ui/const-generics/min_const_generics/const-expression-suggest-missing-braces.rs +++ b/src/test/ui/const-generics/min_const_generics/const-expression-suggest-missing-braces.rs @@ -13,8 +13,7 @@ fn b() { foo::(); //~^ ERROR expected trait, found constant `BAR` //~| ERROR expected trait, found constant `BAR` - //~| ERROR wrong number of const arguments: expected 1, found 0 - //~| ERROR wrong number of type arguments: expected 0, found 1 + //~| ERROR type provided when a constant was expected //~| WARN trait objects without an explicit `dyn` are deprecated } fn c() { diff --git a/src/test/ui/const-generics/min_const_generics/const-expression-suggest-missing-braces.stderr b/src/test/ui/const-generics/min_const_generics/const-expression-suggest-missing-braces.stderr index 47e9dc034efff..6adcf6a3e36d8 100644 --- a/src/test/ui/const-generics/min_const_generics/const-expression-suggest-missing-braces.stderr +++ b/src/test/ui/const-generics/min_const_generics/const-expression-suggest-missing-braces.stderr @@ -10,7 +10,7 @@ LL | foo::<{ BAR + 3 }>(); | ^ ^ error: expressions must be enclosed in braces to be used as const generic arguments - --> $DIR/const-expression-suggest-missing-braces.rs:21:11 + --> $DIR/const-expression-suggest-missing-braces.rs:20:11 | LL | foo::<3 + 3>(); | ^^^^^ @@ -21,7 +21,7 @@ LL | foo::<{ 3 + 3 }>(); | ^ ^ error: expected one of `,` or `>`, found `-` - --> $DIR/const-expression-suggest-missing-braces.rs:24:15 + --> $DIR/const-expression-suggest-missing-braces.rs:23:15 | LL | foo::(); | ^ expected one of `,` or `>` @@ -32,7 +32,7 @@ LL | foo::<{ BAR - 3 }>(); | ^ ^ error: expected one of `,` or `>`, found `-` - --> $DIR/const-expression-suggest-missing-braces.rs:27:15 + --> $DIR/const-expression-suggest-missing-braces.rs:26:15 | LL | foo::(); | ^ expected one of `,` or `>` @@ -43,7 +43,7 @@ LL | foo::<{ BAR - BAR }>(); | ^ ^ error: expressions must be enclosed in braces to be used as const generic arguments - --> $DIR/const-expression-suggest-missing-braces.rs:30:11 + --> $DIR/const-expression-suggest-missing-braces.rs:29:11 | LL | foo::<100 - BAR>(); | ^^^^^^^^^ @@ -54,7 +54,7 @@ LL | foo::<{ 100 - BAR }>(); | ^ ^ error: expected one of `,` or `>`, found `(` - --> $DIR/const-expression-suggest-missing-braces.rs:33:19 + --> $DIR/const-expression-suggest-missing-braces.rs:32:19 | LL | foo::()>(); | ^ expected one of `,` or `>` @@ -65,7 +65,7 @@ LL | foo::<{ bar() }>(); | ^ ^ error: expected one of `,` or `>`, found `(` - --> $DIR/const-expression-suggest-missing-braces.rs:36:21 + --> $DIR/const-expression-suggest-missing-braces.rs:35:21 | LL | foo::()>(); | ^ expected one of `,` or `>` @@ -76,7 +76,7 @@ LL | foo::<{ bar::() }>(); | ^ ^ error: expected one of `,` or `>`, found `(` - --> $DIR/const-expression-suggest-missing-braces.rs:39:21 + --> $DIR/const-expression-suggest-missing-braces.rs:38:21 | LL | foo::() + BAR>(); | ^ expected one of `,` or `>` @@ -87,7 +87,7 @@ LL | foo::<{ bar::() + BAR }>(); | ^ ^ error: expected one of `,` or `>`, found `(` - --> $DIR/const-expression-suggest-missing-braces.rs:42:21 + --> $DIR/const-expression-suggest-missing-braces.rs:41:21 | LL | foo::() - BAR>(); | ^ expected one of `,` or `>` @@ -98,7 +98,7 @@ LL | foo::<{ bar::() - BAR }>(); | ^ ^ error: expected one of `,` or `>`, found `-` - --> $DIR/const-expression-suggest-missing-braces.rs:45:15 + --> $DIR/const-expression-suggest-missing-braces.rs:44:15 | LL | foo::()>(); | ^ expected one of `,` or `>` @@ -109,7 +109,7 @@ LL | foo::<{ BAR - bar::() }>(); | ^ ^ error: expected one of `,` or `>`, found `-` - --> $DIR/const-expression-suggest-missing-braces.rs:48:15 + --> $DIR/const-expression-suggest-missing-braces.rs:47:15 | LL | foo::()>(); | ^ expected one of `,` or `>` @@ -139,19 +139,13 @@ LL | foo::(); | = note: `#[warn(bare_trait_objects)]` on by default -error[E0107]: wrong number of const arguments: expected 1, found 0 - --> $DIR/const-expression-suggest-missing-braces.rs:13:5 - | -LL | foo::(); - | ^^^^^^^^^^^^^^^^ expected 1 const argument - -error[E0107]: wrong number of type arguments: expected 0, found 1 +error[E0747]: type provided when a constant was expected --> $DIR/const-expression-suggest-missing-braces.rs:13:11 | LL | foo::(); - | ^^^^^^^^^ unexpected type argument + | ^^^^^^^^^ -error: aborting due to 15 previous errors; 1 warning emitted +error: aborting due to 14 previous errors; 1 warning emitted -Some errors have detailed explanations: E0107, E0404. -For more information about an error, try `rustc --explain E0107`. +Some errors have detailed explanations: E0404, E0747. +For more information about an error, try `rustc --explain E0404`. diff --git a/src/test/ui/const-generics/min_const_generics/macro-fail.rs b/src/test/ui/const-generics/min_const_generics/macro-fail.rs index 7f16f2f33de1a..1bd0c46f55e2d 100644 --- a/src/test/ui/const-generics/min_const_generics/macro-fail.rs +++ b/src/test/ui/const-generics/min_const_generics/macro-fail.rs @@ -14,11 +14,9 @@ trait Marker {} impl Marker for Example {} fn make_marker() -> impl Marker { - //~^ ERROR wrong number of const - //~| ERROR wrong number of type + //~^ ERROR: type provided when a constant was expected Example:: - //~^ ERROR wrong number of const - //~| ERROR wrong number of type + //~^ ERROR: type provided when a constant was expected } fn from_marker(_: impl Marker<{ @@ -38,11 +36,9 @@ fn main() { }>; let _fail = Example::; - //~^ ERROR wrong number of const - //~| ERROR wrong number of type + //~^ ERROR: type provided when a constant was expected let _fail = Example::; - //~^ ERROR wrong number of const - //~| ERROR wrong number of type + //~^ ERROR: type provided when a constant was expected //~| ERROR unexpected end of macro invocation } diff --git a/src/test/ui/const-generics/min_const_generics/macro-fail.stderr b/src/test/ui/const-generics/min_const_generics/macro-fail.stderr index fe7a4a5c38269..a5dedf6fe2053 100644 --- a/src/test/ui/const-generics/min_const_generics/macro-fail.stderr +++ b/src/test/ui/const-generics/min_const_generics/macro-fail.stderr @@ -1,5 +1,5 @@ error: expected type, found `{` - --> $DIR/macro-fail.rs:33:27 + --> $DIR/macro-fail.rs:31:27 | LL | fn make_marker() -> impl Marker { | ---------------------- @@ -13,7 +13,7 @@ LL | ($rusty: ident) => {{ let $rusty = 3; *&$rusty }} = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) error: expected type, found `{` - --> $DIR/macro-fail.rs:33:27 + --> $DIR/macro-fail.rs:31:27 | LL | Example:: | ---------------------- @@ -46,7 +46,7 @@ LL | let _fail = Example::; = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) error: unexpected end of macro invocation - --> $DIR/macro-fail.rs:44:25 + --> $DIR/macro-fail.rs:41:25 | LL | macro_rules! gimme_a_const { | -------------------------- when calling this macro @@ -54,54 +54,30 @@ LL | macro_rules! gimme_a_const { LL | let _fail = Example::; | ^^^^^^^^^^^^^^^^ missing tokens in macro arguments -error[E0107]: wrong number of const arguments: expected 1, found 0 - --> $DIR/macro-fail.rs:16:26 - | -LL | fn make_marker() -> impl Marker { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected 1 const argument - -error[E0107]: wrong number of type arguments: expected 0, found 1 +error[E0747]: type provided when a constant was expected --> $DIR/macro-fail.rs:16:33 | LL | fn make_marker() -> impl Marker { - | ^^^^^^^^^^^^^^^^^^^^^^ unexpected type argument - -error[E0107]: wrong number of const arguments: expected 1, found 0 - --> $DIR/macro-fail.rs:19:3 - | -LL | Example:: - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected 1 const argument + | ^^^^^^^^^^^^^^^^^^^^^^ -error[E0107]: wrong number of type arguments: expected 0, found 1 - --> $DIR/macro-fail.rs:19:13 +error[E0747]: type provided when a constant was expected + --> $DIR/macro-fail.rs:18:13 | LL | Example:: - | ^^^^^^^^^^^^^^^^^^^^^^ unexpected type argument + | ^^^^^^^^^^^^^^^^^^^^^^ -error[E0107]: wrong number of const arguments: expected 1, found 0 - --> $DIR/macro-fail.rs:40:15 +error[E0747]: type provided when a constant was expected + --> $DIR/macro-fail.rs:38:25 | LL | let _fail = Example::; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected 1 const argument - -error[E0107]: wrong number of type arguments: expected 0, found 1 - --> $DIR/macro-fail.rs:40:25 - | -LL | let _fail = Example::; - | ^^^^^^^^^^^^^^^^^ unexpected type argument - -error[E0107]: wrong number of const arguments: expected 1, found 0 - --> $DIR/macro-fail.rs:44:15 - | -LL | let _fail = Example::; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected 1 const argument + | ^^^^^^^^^^^^^^^^^ -error[E0107]: wrong number of type arguments: expected 0, found 1 - --> $DIR/macro-fail.rs:44:25 +error[E0747]: type provided when a constant was expected + --> $DIR/macro-fail.rs:41:25 | LL | let _fail = Example::; - | ^^^^^^^^^^^^^^^^ unexpected type argument + | ^^^^^^^^^^^^^^^^ -error: aborting due to 12 previous errors +error: aborting due to 8 previous errors -For more information about this error, try `rustc --explain E0107`. +For more information about this error, try `rustc --explain E0747`. diff --git a/src/test/ui/parser/issue-14303-fncall.stderr b/src/test/ui/parser/issue-14303-fncall.stderr index 109542237130a..cdda0d001c7dc 100644 --- a/src/test/ui/parser/issue-14303-fncall.stderr +++ b/src/test/ui/parser/issue-14303-fncall.stderr @@ -3,8 +3,6 @@ error[E0747]: type provided when a lifetime was expected | LL | .collect::>>(); | ^ - | - = note: lifetime arguments must be provided before type arguments error: aborting due to previous error diff --git a/src/test/ui/parser/issue-14303-path.stderr b/src/test/ui/parser/issue-14303-path.stderr index c1ad2332b5bfa..841e63ecbe9d5 100644 --- a/src/test/ui/parser/issue-14303-path.stderr +++ b/src/test/ui/parser/issue-14303-path.stderr @@ -3,8 +3,6 @@ error[E0747]: type provided when a lifetime was expected | LL | fn bar<'a, 'b, 'c, T>(x: foo::X<'a, T, 'b, 'c>) {} | ^ - | - = note: lifetime arguments must be provided before type arguments error: aborting due to previous error diff --git a/src/test/ui/privacy/privacy-ns1.rs b/src/test/ui/privacy/privacy-ns1.rs index c7084bfd98049..1af5b857e9df6 100644 --- a/src/test/ui/privacy/privacy-ns1.rs +++ b/src/test/ui/privacy/privacy-ns1.rs @@ -32,8 +32,8 @@ pub mod foo2 { fn test_glob2() { use foo2::*; - let _x: Box; //~ ERROR wrong number of const arguments: expected 0, found 1 - //~^ ERROR wrong number of type arguments: expected at least 1, found 0 + let _x: Box; + //~^ ERROR constant provided when a type was expected } // neither public diff --git a/src/test/ui/privacy/privacy-ns1.stderr b/src/test/ui/privacy/privacy-ns1.stderr index ccbb5d5c90ff5..714f28941f11f 100644 --- a/src/test/ui/privacy/privacy-ns1.stderr +++ b/src/test/ui/privacy/privacy-ns1.stderr @@ -52,19 +52,13 @@ help: consider importing this trait LL | use foo1::Bar; | -error[E0107]: wrong number of const arguments: expected 0, found 1 +error[E0747]: constant provided when a type was expected --> $DIR/privacy-ns1.rs:35:17 | LL | let _x: Box; - | ^^^ unexpected const argument - -error[E0107]: wrong number of type arguments: expected at least 1, found 0 - --> $DIR/privacy-ns1.rs:35:13 - | -LL | let _x: Box; - | ^^^^^^^^ expected at least 1 type argument + | ^^^ -error: aborting due to 5 previous errors +error: aborting due to 4 previous errors -Some errors have detailed explanations: E0107, E0412, E0423, E0425. -For more information about an error, try `rustc --explain E0107`. +Some errors have detailed explanations: E0412, E0423, E0425, E0747. +For more information about an error, try `rustc --explain E0412`. diff --git a/src/test/ui/privacy/privacy-ns2.rs b/src/test/ui/privacy/privacy-ns2.rs index b770c8f8f8610..47035ef3af5a2 100644 --- a/src/test/ui/privacy/privacy-ns2.rs +++ b/src/test/ui/privacy/privacy-ns2.rs @@ -38,16 +38,14 @@ pub mod foo2 { fn test_single2() { use foo2::Bar; - let _x : Box; //~ ERROR wrong number of const arguments: expected 0, found 1 - //~^ ERROR wrong number of type arguments: expected at least 1, found 0 + let _x : Box; //~ ERROR constant provided when a type was expected let _x : Bar(); //~ ERROR expected type, found function `Bar` } fn test_list2() { use foo2::{Bar,Baz}; - let _x: Box; //~ ERROR wrong number of const arguments: expected 0, found 1 - //~^ ERROR wrong number of type arguments: expected at least 1, found 0 + let _x: Box; //~ ERROR constant provided when a type was expected } // neither public diff --git a/src/test/ui/privacy/privacy-ns2.stderr b/src/test/ui/privacy/privacy-ns2.stderr index dbb269c0ba697..c7ad8ec503654 100644 --- a/src/test/ui/privacy/privacy-ns2.stderr +++ b/src/test/ui/privacy/privacy-ns2.stderr @@ -28,7 +28,7 @@ LL | use foo2::Bar; | error[E0573]: expected type, found function `Bar` - --> $DIR/privacy-ns2.rs:43:14 + --> $DIR/privacy-ns2.rs:42:14 | LL | let _x : Bar(); | ^^^^^ not a type @@ -43,66 +43,54 @@ LL | use foo1::Bar; | error[E0603]: trait `Bar` is private - --> $DIR/privacy-ns2.rs:63:15 + --> $DIR/privacy-ns2.rs:61:15 | LL | use foo3::Bar; | ^^^ private trait | note: the trait `Bar` is defined here - --> $DIR/privacy-ns2.rs:55:5 + --> $DIR/privacy-ns2.rs:53:5 | LL | trait Bar { | ^^^^^^^^^ error[E0603]: trait `Bar` is private - --> $DIR/privacy-ns2.rs:67:15 + --> $DIR/privacy-ns2.rs:65:15 | LL | use foo3::Bar; | ^^^ private trait | note: the trait `Bar` is defined here - --> $DIR/privacy-ns2.rs:55:5 + --> $DIR/privacy-ns2.rs:53:5 | LL | trait Bar { | ^^^^^^^^^ error[E0603]: trait `Bar` is private - --> $DIR/privacy-ns2.rs:74:16 + --> $DIR/privacy-ns2.rs:72:16 | LL | use foo3::{Bar,Baz}; | ^^^ private trait | note: the trait `Bar` is defined here - --> $DIR/privacy-ns2.rs:55:5 + --> $DIR/privacy-ns2.rs:53:5 | LL | trait Bar { | ^^^^^^^^^ -error[E0107]: wrong number of const arguments: expected 0, found 1 +error[E0747]: constant provided when a type was expected --> $DIR/privacy-ns2.rs:41:18 | LL | let _x : Box; - | ^^^ unexpected const argument + | ^^^ -error[E0107]: wrong number of type arguments: expected at least 1, found 0 - --> $DIR/privacy-ns2.rs:41:14 - | -LL | let _x : Box; - | ^^^^^^^^ expected at least 1 type argument - -error[E0107]: wrong number of const arguments: expected 0, found 1 - --> $DIR/privacy-ns2.rs:49:17 - | -LL | let _x: Box; - | ^^^ unexpected const argument - -error[E0107]: wrong number of type arguments: expected at least 1, found 0 - --> $DIR/privacy-ns2.rs:49:13 +error[E0747]: constant provided when a type was expected + --> $DIR/privacy-ns2.rs:48:17 | LL | let _x: Box; - | ^^^^^^^^ expected at least 1 type argument + | ^^^ -error: aborting due to 10 previous errors +error: aborting due to 8 previous errors -Some errors have detailed explanations: E0107, E0423, E0573, E0603. -For more information about an error, try `rustc --explain E0107`. +Some errors have detailed explanations: E0423, E0573, E0603, E0747. +For more information about an error, try `rustc --explain E0423`. diff --git a/src/test/ui/suggestions/suggest-move-types.stderr b/src/test/ui/suggestions/suggest-move-types.stderr index 3c2226574ee9e..df064f22f3584 100644 --- a/src/test/ui/suggestions/suggest-move-types.stderr +++ b/src/test/ui/suggestions/suggest-move-types.stderr @@ -107,16 +107,12 @@ error[E0747]: type provided when a lifetime was expected | LL | struct Al<'a, T, M: OneWithLifetime> { | ^ - | - = note: lifetime arguments must be provided before type arguments error[E0747]: type provided when a lifetime was expected --> $DIR/suggest-move-types.rs:48:71 | LL | struct Bl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime> { | ^ - | - = note: lifetime arguments must be provided before type arguments error[E0747]: lifetime provided when a type was expected --> $DIR/suggest-move-types.rs:65:56 diff --git a/src/test/ui/traits/trait-object-vs-lifetime.stderr b/src/test/ui/traits/trait-object-vs-lifetime.stderr index ff3fc2a197c66..8958547e82709 100644 --- a/src/test/ui/traits/trait-object-vs-lifetime.stderr +++ b/src/test/ui/traits/trait-object-vs-lifetime.stderr @@ -27,8 +27,6 @@ error[E0747]: type provided when a lifetime was expected | LL | let _: S; | ^^^^^^^^^^^^^ - | - = note: lifetime arguments must be provided before type arguments error: aborting due to 5 previous errors