Skip to content

Commit

Permalink
Add note regarding argument ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
varkor committed Feb 22, 2020
1 parent e372ad4 commit bead79e
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 11 deletions.
8 changes: 5 additions & 3 deletions src/librustc_typeck/astconv.rs
Expand Up @@ -464,15 +464,17 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
/// Report an error that a generic argument did not match the generic parameter that was
/// expected.
fn generic_arg_mismatch_err(sess: &Session, arg: &GenericArg<'_>, kind: &'static str) {
struct_span_err!(
let mut err = struct_span_err!(
sess,
arg.span(),
E0747,
"{} provided when a {} was expected",
arg.descr(),
kind,
)
.emit();
);
// This note will be true as long as generic parameters are strictly ordered by their kind.
err.note(&format!("{} arguments must be provided before {} arguments", kind, arg.descr()));
err.emit();
}

/// Creates the relevant generic argument substitutions
Expand Down
Expand Up @@ -11,6 +11,8 @@ error[E0747]: constant provided when a type was expected
|
LL | fn foo<const N: usize>() -> Array<N, ()> {
| ^
|
= note: type arguments must be provided before constant arguments

error: aborting due to previous error

Expand Down
Expand Up @@ -10,13 +10,5 @@ error: type parameters must be declared prior to const parameters
LL | fn foo<const X: (), T>(_: &T) {
| --------------^- help: reorder the parameters: lifetimes, then types, then consts: `<T, const X: ()>`

warning: the feature `const_generics` is incomplete and may cause the compiler to crash
--> $DIR/const-param-before-other-params.rs:1:12
|
LL | #![feature(const_generics)]
| ^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default

error: aborting due to 2 previous errors

2 changes: 2 additions & 0 deletions src/test/ui/parser/issue-14303-fncall.stderr
Expand Up @@ -3,6 +3,8 @@ error[E0747]: type provided when a lifetime was expected
|
LL | .collect::<Vec<S<_, 'a>>>();
| ^
|
= note: lifetime arguments must be provided before type arguments

error: aborting due to previous error

Expand Down
2 changes: 2 additions & 0 deletions src/test/ui/parser/issue-14303-path.stderr
Expand Up @@ -3,6 +3,8 @@ 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

Expand Down
8 changes: 8 additions & 0 deletions src/test/ui/suggestions/suggest-move-types.stderr
Expand Up @@ -79,24 +79,32 @@ error[E0747]: type provided when a lifetime was expected
|
LL | struct Al<'a, T, M: OneWithLifetime<A=(), T, 'a>> {
| ^
|
= 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<A=(), B=(), C=(), T, U, V, 'a, 'b, 'c>> {
| ^
|
= note: lifetime arguments must be provided before type arguments

error[E0747]: lifetime provided when a type was expected
--> $DIR/suggest-move-types.rs:64:56
|
LL | struct Cl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime<T, 'a, A=(), B=(), C=(), U, 'b, V, 'c>> {
| ^^
|
= note: type arguments must be provided before lifetime arguments

error[E0747]: lifetime provided when a type was expected
--> $DIR/suggest-move-types.rs:80:56
|
LL | struct Dl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime<T, 'a, A=(), B=(), U, 'b, C=(), V, 'c>> {
| ^^
|
= note: type arguments must be provided before lifetime arguments

error: aborting due to 12 previous errors

Expand Down
2 changes: 2 additions & 0 deletions src/test/ui/traits/trait-object-vs-lifetime.stderr
Expand Up @@ -27,6 +27,8 @@ error[E0747]: type provided when a lifetime was expected
|
LL | let _: S<dyn 'static +, 'static>;
| ^^^^^^^^^^^^^
|
= note: lifetime arguments must be provided before type arguments

error: aborting due to 5 previous errors

Expand Down

0 comments on commit bead79e

Please sign in to comment.