Auto merge of #79697 - rylev:clearer-const-diagnostic, r=oli-obk

A slightly clearer diagnostic when misusing const

Fixes #79598

This produces the following diagnostic:
"expected one of `>`, a const expression, lifetime, or type, found keyword `const`"

Instead of the previous, more confusing:
"expected one of `>`, const, lifetime, or type, found keyword `const`"

This might not be completely clear as some users might not understand what a const expression is, but I do believe this is an improvement.
This commit is contained in:
bors 2020-12-05 22:47:37 +00:00
commit bb0d481b5a
15 changed files with 25 additions and 25 deletions

View File

@ -264,7 +264,7 @@ impl TokenType {
TokenType::Ident => "identifier".to_string(),
TokenType::Path => "path".to_string(),
TokenType::Type => "type".to_string(),
TokenType::Const => "const".to_string(),
TokenType::Const => "a const expression".to_string(),
}
}
}

View File

@ -7,7 +7,7 @@ trait X {
const _: () = {
fn f1<'a>(arg : Box<dyn X< : 32 >>) {}
//~^ ERROR: expected one of `>`, const, lifetime, or type, found `:`
//~^ ERROR: expected one of `>`, a const expression, lifetime, or type, found `:`
//~| ERROR: expected parameter name, found `>`
//~| ERROR: expected one of `!`, `)`, `+`, `,`, or `::`, found `>`
//~| ERROR: constant provided when a type was expected
@ -15,7 +15,7 @@ const _: () = {
const _: () = {
fn f1<'a>(arg : Box<dyn X< = 32 >>) {}
//~^ ERROR: expected one of `>`, const, lifetime, or type, found `=`
//~^ ERROR: expected one of `>`, a const expression, lifetime, or type, found `=`
};
fn main() {}

View File

@ -1,8 +1,8 @@
error: expected one of `>`, const, lifetime, or type, found `:`
error: expected one of `>`, a const expression, lifetime, or type, found `:`
--> $DIR/trait-path-missing-gen_arg.rs:9:30
|
LL | fn f1<'a>(arg : Box<dyn X< : 32 >>) {}
| ^ expected one of `>`, const, lifetime, or type
| ^ expected one of `>`, a const expression, lifetime, or type
|
help: expressions must be enclosed in braces to be used as const generic arguments
|
@ -24,11 +24,11 @@ LL | fn f1<'a>(arg : Box<dyn X< : 32 >>) {}
| expected one of `!`, `)`, `+`, `,`, or `::`
| help: missing `,`
error: expected one of `>`, const, lifetime, or type, found `=`
error: expected one of `>`, a const expression, lifetime, or type, found `=`
--> $DIR/trait-path-missing-gen_arg.rs:17:30
|
LL | fn f1<'a>(arg : Box<dyn X< = 32 >>) {}
| ^ expected one of `>`, const, lifetime, or type
| ^ expected one of `>`, a const expression, lifetime, or type
warning: the feature `generic_associated_types` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/trait-path-missing-gen_arg.rs:1:12

View File

@ -11,7 +11,7 @@ type Type_1_<'a, T> = &'a T;
type Type_3<T> = Box<T,,>;
//~^ error: expected one of `>`, const, lifetime, or type, found `,`
//~^ error: expected one of `>`, a const expression, lifetime, or type, found `,`
//type Type_4<T> = Type_1_<'static,, T>; // error: expected type, found `,`

View File

@ -1,8 +1,8 @@
error: expected one of `>`, const, lifetime, or type, found `,`
error: expected one of `>`, a const expression, lifetime, or type, found `,`
--> $DIR/issue-20616-3.rs:13:24
|
LL | type Type_3<T> = Box<T,,>;
| ^ expected one of `>`, const, lifetime, or type
| ^ expected one of `>`, a const expression, lifetime, or type
error: aborting due to previous error

View File

@ -14,7 +14,7 @@ type Type_1_<'a, T> = &'a T;
type Type_4<T> = Type_1_<'static,, T>;
//~^ error: expected one of `>`, const, lifetime, or type, found `,`
//~^ error: expected one of `>`, a const expression, lifetime, or type, found `,`
type Type_5_<'a> = Type_1_<'a, ()>;

View File

@ -1,8 +1,8 @@
error: expected one of `>`, const, lifetime, or type, found `,`
error: expected one of `>`, a const expression, lifetime, or type, found `,`
--> $DIR/issue-20616-4.rs:16:34
|
LL | type Type_4<T> = Type_1_<'static,, T>;
| ^ expected one of `>`, const, lifetime, or type
| ^ expected one of `>`, a const expression, lifetime, or type
error: aborting due to previous error

View File

@ -20,7 +20,7 @@ type Type_5_<'a> = Type_1_<'a, ()>;
type Type_5<'a> = Type_1_<'a, (),,>;
//~^ error: expected one of `>`, const, lifetime, or type, found `,`
//~^ error: expected one of `>`, a const expression, lifetime, or type, found `,`
//type Type_6 = Type_5_<'a,,>; // error: expected type, found `,`

View File

@ -1,8 +1,8 @@
error: expected one of `>`, const, lifetime, or type, found `,`
error: expected one of `>`, a const expression, lifetime, or type, found `,`
--> $DIR/issue-20616-5.rs:22:34
|
LL | type Type_5<'a> = Type_1_<'a, (),,>;
| ^ expected one of `>`, const, lifetime, or type
| ^ expected one of `>`, a const expression, lifetime, or type
error: aborting due to previous error

View File

@ -23,7 +23,7 @@ type Type_5_<'a> = Type_1_<'a, ()>;
type Type_6 = Type_5_<'a,,>;
//~^ error: expected one of `>`, const, lifetime, or type, found `,`
//~^ error: expected one of `>`, a const expression, lifetime, or type, found `,`
//type Type_7 = Box<(),,>; // error: expected type, found `,`

View File

@ -1,8 +1,8 @@
error: expected one of `>`, const, lifetime, or type, found `,`
error: expected one of `>`, a const expression, lifetime, or type, found `,`
--> $DIR/issue-20616-6.rs:25:26
|
LL | type Type_6 = Type_5_<'a,,>;
| ^ expected one of `>`, const, lifetime, or type
| ^ expected one of `>`, a const expression, lifetime, or type
error: aborting due to previous error

View File

@ -26,7 +26,7 @@ type Type_5_<'a> = Type_1_<'a, ()>;
type Type_7 = Box<(),,>;
//~^ error: expected one of `>`, const, lifetime, or type, found `,`
//~^ error: expected one of `>`, a const expression, lifetime, or type, found `,`
//type Type_8<'a,,> = &'a (); // error: expected ident, found `,`

View File

@ -1,8 +1,8 @@
error: expected one of `>`, const, lifetime, or type, found `,`
error: expected one of `>`, a const expression, lifetime, or type, found `,`
--> $DIR/issue-20616-7.rs:28:22
|
LL | type Type_7 = Box<(),,>;
| ^ expected one of `>`, const, lifetime, or type
| ^ expected one of `>`, a const expression, lifetime, or type
error: aborting due to previous error

View File

@ -1,2 +1,2 @@
type mut_box = Box<mut isize>;
//~^ ERROR expected one of `>`, const, lifetime, or type, found keyword `mut`
//~^ ERROR expected one of `>`, a const expression, lifetime, or type, found keyword `mut`

View File

@ -1,8 +1,8 @@
error: expected one of `>`, const, lifetime, or type, found keyword `mut`
error: expected one of `>`, a const expression, lifetime, or type, found keyword `mut`
--> $DIR/removed-syntax-uniq-mut-ty.rs:1:20
|
LL | type mut_box = Box<mut isize>;
| ^^^ expected one of `>`, const, lifetime, or type
| ^^^ expected one of `>`, a const expression, lifetime, or type
error: aborting due to previous error