-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
forbid dyn Trait
in patterns
#71038
forbid dyn Trait
in patterns
#71038
Conversation
21185be
to
b373917
Compare
IMO this PR's title/description should focus on pattern-matching. r? @pnkfelix |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
if !ty_is_partial_eq { | ||
// span_fatal avoids ICE from resolution of non-existent method (rare case). | ||
self.tcx().sess.span_fatal(self.span, &make_msg()); | ||
self.tcx().sess.span_fatal(self.span, &msg); |
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
is true
for &dyn PartialEq<u32>
. It is fixed for all other traits though.
This fails correctly
const F: &'static dyn Send = &7u32;
fn main() {
let a: &dyn Send = &7u32;
match a {
F => panic!(),
//~^ ERROR trait object cannot be used in patterns
_ => {}
}
}
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.
It is fixed for all other traits though.
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:
// FIXME(oli-obk): this is reachable for `const FOO: &&&u32 = &&&42;` being used |
@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).
460b8c4
to
1c4fc95
Compare
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
1c4fc95
to
4549ef5
Compare
@pnkfelix this is ready for review |
impl A for B {} | ||
|
||
fn test<const T: &'static dyn A>() { | ||
//~^ ERROR the types of const generic parameters must derive `PartialEq` and `Eq` |
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.
The PR seems fine and I'm planning to r+ it, but I wanted to ask about this part:
Do you see the error here as being the absence of PartialEq
and Eq
, as indicated by the diagnostic? Or is it that any use of dyn A
will be broken here?
I personally suspect that, unless we expose a StructuralMatch
marker trait (at which point maybe one would be able to do trait A: StructuralMatch {}
), the user error here is in the use of dyn A
, and therefore the diagnostic message in this case is misleading.
But I'm willing to deal with that in a followup patch.
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.
Not sure tbh, I think that we should allow something like trait A: StructuralMatch {}
in the future.
cc @eddyb i guess
@bors r+ rollup |
📌 Commit 4549ef5 has been approved by |
…pnkfelix forbid `dyn Trait` in patterns Do not allow `&dyn Trait` as a generic const parameters. This also changes dyn trait in pattern from ICE to error. closes rust-lang#63322 closes rust-lang#70972 r? @eddyb
failed in rollup @bors r- |
4549ef5
to
ecf574f
Compare
fixed |
☔ The latest upstream changes (presumably #67343) made this pull request unmergeable. Please resolve the merge conflicts. |
ecf574f
to
2f5c0f5
Compare
@pnkfelix This should be ready for merge afaict. |
@bors r+ |
📌 Commit 2f5c0f5 has been approved by |
Rollup of 5 pull requests Successful merges: - rust-lang#71038 (forbid `dyn Trait` in patterns) - rust-lang#71697 (Added MIR constant propagation of Scalars into function call arguments) - rust-lang#71773 (doc: misc rustdoc things) - rust-lang#71810 (Do not try to find binop method on RHS `TyErr`) - rust-lang#71877 (Use f64 in f64 examples) Failed merges: r? @ghost
Do not allow
&dyn Trait
as a generic const parameters.This also changes dyn trait in pattern from ICE to error.
closes #63322
closes #70972
r? @eddyb