-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #75611 - JulianKnodt:cg_enum_err, r=lcnr
Add help note when using type in place of const This adds a small help note when it might be possible that wrapping a parameter in braces might resolve the issue of having a type where a const was expected. Currently, I am displaying the `HirId`, and I'm not particularly sure where to get the currently displayed path(?). r? `@lcnr`
- Loading branch information
Showing
3 changed files
with
197 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#![feature(const_generics)] | ||
#![allow(incomplete_features)] | ||
|
||
#[derive(PartialEq, Eq)] | ||
enum CompileFlag { | ||
A, | ||
B, | ||
} | ||
|
||
pub fn test_1<const CF: CompileFlag>() {} | ||
pub fn test_2<T, const CF: CompileFlag>(x: T) {} | ||
pub struct Example<const CF: CompileFlag, T=u32>{ | ||
x: T, | ||
} | ||
|
||
impl<const CF: CompileFlag, T> Example<CF, T> { | ||
const ASSOC_FLAG: CompileFlag = CompileFlag::A; | ||
} | ||
|
||
pub fn main() { | ||
test_1::<CompileFlag::A>(); | ||
//~^ ERROR: expected type, found variant | ||
//~| ERROR: wrong number of const arguments | ||
//~| ERROR: wrong number of type arguments | ||
|
||
test_2::<_, CompileFlag::A>(0); | ||
//~^ ERROR: expected type, found variant | ||
//~| ERROR: wrong number of const arguments | ||
//~| ERROR: wrong number of type arguments | ||
|
||
let _: Example<CompileFlag::A, _> = Example { x: 0 }; | ||
//~^ ERROR: expected type, found variant | ||
//~| ERROR: wrong number of const arguments | ||
//~| ERROR: wrong number of type arguments | ||
|
||
let _: Example<Example::ASSOC_FLAG, _> = Example { x: 0 }; | ||
//~^ ERROR: wrong number of const arguments | ||
//~| ERROR: wrong number of type arguments | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
error[E0573]: expected type, found variant `CompileFlag::A` | ||
--> $DIR/invalid-enum.rs:21:12 | ||
| | ||
LL | test_1::<CompileFlag::A>(); | ||
| ^^^^^^^^^^^^^^ | ||
| | | ||
| not a type | ||
| help: try using the variant's enum: `CompileFlag` | ||
|
||
error[E0573]: expected type, found variant `CompileFlag::A` | ||
--> $DIR/invalid-enum.rs:26:15 | ||
| | ||
LL | test_2::<_, CompileFlag::A>(0); | ||
| ^^^^^^^^^^^^^^ | ||
| | | ||
| not a type | ||
| help: try using the variant's enum: `CompileFlag` | ||
|
||
error[E0573]: expected type, found variant `CompileFlag::A` | ||
--> $DIR/invalid-enum.rs:31:18 | ||
| | ||
LL | let _: Example<CompileFlag::A, _> = 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 | ||
| | ||
LL | let _: Example<CompileFlag::A, _> = 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:10 | ||
| | ||
LL | let _: Example<CompileFlag::A, _> = Example { x: 0 }; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ expected at most 1 type argument | ||
| | ||
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 | ||
| | ||
LL | let _: Example<Example::ASSOC_FLAG, _> = 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:10 | ||
| | ||
LL | let _: Example<Example::ASSOC_FLAG, _> = Example { x: 0 }; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected at most 1 type argument | ||
| | ||
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::<CompileFlag::A>(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^ expected 1 const argument | ||
|
||
error[E0107]: wrong number of type arguments: expected 0, found 1 | ||
--> $DIR/invalid-enum.rs:21:12 | ||
| | ||
LL | test_1::<CompileFlag::A>(); | ||
| ^^^^^^^^^^^^^^ unexpected type argument | ||
| | ||
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 | ||
| | ||
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: | ||
| | ||
LL | test_2::<_, { CompileFlag::A }>(0); | ||
| ^ ^ | ||
|
||
error: aborting due to 11 previous errors | ||
|
||
Some errors have detailed explanations: E0107, E0573. | ||
For more information about an error, try `rustc --explain E0107`. |