forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#82055 - JulianKnodt:ty_where_const, r=estebank
Add diagnostics for specific cases for const/type mismatch err For now, this adds at least more information so better diagnostics can be emitted for const mismatch errors. I'm not sure what exactly we want to emit, so I've left notes there temporarily, also to see if this is the right approach r? ``@lcnr`` cc: ``@estebank``
- Loading branch information
Showing
6 changed files
with
134 additions
and
29 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
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,18 @@ | ||
#![crate_type="lib"] | ||
#![feature(min_const_generics)] | ||
#![allow(incomplete_features)] | ||
|
||
struct A<const N: u8>; | ||
trait Foo {} | ||
impl Foo for A<N> {} | ||
//~^ ERROR cannot find type | ||
//~| unresolved item provided when a constant | ||
|
||
struct B<const N: u8>; | ||
impl<N> Foo for B<N> {} | ||
//~^ ERROR type provided when a constant | ||
|
||
struct C<const C: u8, const N: u8>; | ||
impl<const N: u8> Foo for C<N, T> {} | ||
//~^ ERROR cannot find type | ||
//~| unresolved item provided when a constant |
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,52 @@ | ||
error[E0412]: cannot find type `N` in this scope | ||
--> $DIR/diagnostics.rs:7:16 | ||
| | ||
LL | struct A<const N: u8>; | ||
| ---------------------- similarly named struct `A` defined here | ||
LL | trait Foo {} | ||
LL | impl Foo for A<N> {} | ||
| ^ help: a struct with a similar name exists: `A` | ||
|
||
error[E0412]: cannot find type `T` in this scope | ||
--> $DIR/diagnostics.rs:16:32 | ||
| | ||
LL | struct A<const N: u8>; | ||
| ---------------------- similarly named struct `A` defined here | ||
... | ||
LL | impl<const N: u8> Foo for C<N, T> {} | ||
| ^ help: a struct with a similar name exists: `A` | ||
|
||
error[E0747]: unresolved item provided when a constant was expected | ||
--> $DIR/diagnostics.rs:7:16 | ||
| | ||
LL | impl Foo for A<N> {} | ||
| ^ | ||
| | ||
help: if this generic argument was intended as a const parameter, surround it with braces | ||
| | ||
LL | impl Foo for A<{ N }> {} | ||
| ^ ^ | ||
|
||
error[E0747]: type provided when a constant was expected | ||
--> $DIR/diagnostics.rs:12:19 | ||
| | ||
LL | impl<N> Foo for B<N> {} | ||
| - ^ | ||
| | | ||
| help: consider changing this type paramater to a `const`-generic: `const N: u8` | ||
|
||
error[E0747]: unresolved item provided when a constant was expected | ||
--> $DIR/diagnostics.rs:16:32 | ||
| | ||
LL | impl<const N: u8> Foo for C<N, T> {} | ||
| ^ | ||
| | ||
help: if this generic argument was intended as a const parameter, surround it with braces | ||
| | ||
LL | impl<const N: u8> Foo for C<N, { T }> {} | ||
| ^ ^ | ||
|
||
error: aborting due to 5 previous errors | ||
|
||
Some errors have detailed explanations: E0412, E0747. | ||
For more information about an error, try `rustc --explain E0412`. |
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