-
Notifications
You must be signed in to change notification settings - Fork 13.3k
forbid dyn Trait
in patterns
#71038
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
Merged
Merged
forbid dyn Trait
in patterns
#71038
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
15 changes: 15 additions & 0 deletions
15
src/test/ui/const-generics/issues/issue-63322-forbid-dyn.rs
This file contains hidden or 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,15 @@ | ||
#![feature(const_generics)] | ||
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash | ||
|
||
trait A {} | ||
struct B; | ||
impl A for B {} | ||
|
||
fn test<const T: &'static dyn A>() { | ||
//~^ ERROR must be annotated with `#[derive(PartialEq, Eq)]` to be used | ||
unimplemented!() | ||
} | ||
|
||
fn main() { | ||
test::<{ &B }>(); | ||
} |
17 changes: 17 additions & 0 deletions
17
src/test/ui/const-generics/issues/issue-63322-forbid-dyn.stderr
This file contains hidden or 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,17 @@ | ||
warning: the feature `const_generics` is incomplete and may cause the compiler to crash | ||
--> $DIR/issue-63322-forbid-dyn.rs:1:12 | ||
| | ||
LL | #![feature(const_generics)] | ||
| ^^^^^^^^^^^^^^ | ||
| | ||
= note: `#[warn(incomplete_features)]` on by default | ||
|
||
error[E0741]: `&'static (dyn A + 'static)` must be annotated with `#[derive(PartialEq, Eq)]` to be used as the type of a const parameter | ||
--> $DIR/issue-63322-forbid-dyn.rs:8:18 | ||
| | ||
LL | fn test<const T: &'static dyn A>() { | ||
| ^^^^^^^^^^^^^^ `&'static (dyn A + 'static)` doesn't derive both `PartialEq` and `Eq` | ||
|
||
error: aborting due to previous error; 1 warning emitted | ||
|
||
For more information about this error, try `rustc --explain E0741`. |
This file contains hidden or 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,10 @@ | ||
const F: &'static dyn Send = &7u32; | ||
|
||
fn main() { | ||
let a: &dyn Send = &7u32; | ||
match a { | ||
F => panic!(), | ||
//~^ ERROR trait objects cannot be used in patterns | ||
_ => {} | ||
} | ||
} |
This file contains hidden or 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,8 @@ | ||
error: trait objects cannot be used in patterns | ||
--> $DIR/issue-70972-dyn-trait.rs:6:9 | ||
| | ||
LL | F => panic!(), | ||
| ^ | ||
|
||
error: aborting due to previous error | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't this stop your ICE as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nope.
ty_is_partial_eq
istrue
for&dyn PartialEq<u32>
. It is fixed for all other traits though.This fails correctly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see. I think it's fine to leave
dyn PartialEq
an ICE (and we can do an ICE test, I think we have another one already). At least that's what this comment makes me think:rust/src/librustc_mir_build/hair/pattern/_match.rs
Line 317 in 32fb4dc
@oli-obk has a PR that should allow fixing this more directly: #70743
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed the test to
dyn Send
and rebased.Don't know how to test for an ICE, we could just open an issue for
dyn PartialEq
after this is merged (which is then added to glacier).