Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A slightly clearer diagnostic when misusing const #79697

Merged
merged 2 commits into from
Dec 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_parse/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ 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
};

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() {}
Original file line number Diff line number Diff line change
@@ -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
|
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/issues/issue-20616-3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 `,`
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/issues/issue-20616-3.stderr
Original file line number Diff line number Diff line change
@@ -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

2 changes: 1 addition & 1 deletion src/test/ui/issues/issue-20616-4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, ()>;
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/issues/issue-20616-4.stderr
Original file line number Diff line number Diff line change
@@ -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

2 changes: 1 addition & 1 deletion src/test/ui/issues/issue-20616-5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 `,`
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/issues/issue-20616-5.stderr
Original file line number Diff line number Diff line change
@@ -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

2 changes: 1 addition & 1 deletion src/test/ui/issues/issue-20616-6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 `,`
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/issues/issue-20616-6.stderr
Original file line number Diff line number Diff line change
@@ -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

2 changes: 1 addition & 1 deletion src/test/ui/issues/issue-20616-7.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 `,`
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/issues/issue-20616-7.stderr
Original file line number Diff line number Diff line change
@@ -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

2 changes: 1 addition & 1 deletion src/test/ui/parser/removed-syntax-uniq-mut-ty.rs
Original file line number Diff line number Diff line change
@@ -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`
4 changes: 2 additions & 2 deletions src/test/ui/parser/removed-syntax-uniq-mut-ty.stderr
Original file line number Diff line number Diff line change
@@ -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