-
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 recursive impl trait #56074
Forbid recursive impl trait #56074
Conversation
r? @zackmdavis (rust_highfive has picked a reviewer for you, use r? to override) |
cc #47659 |
src/librustc_typeck/check/mod.rs
Outdated
span: Span, | ||
) { | ||
if let Err(partially_expanded_type) = tcx.try_expand_impl_trait_type(def_id, substs) { | ||
let mut err = tcx.sess.struct_span_err(span, "recursive opaque type"); |
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.
Maybe this deserves a dedicated E0XXX error code? (which would be defined in librustc_typeck/diagnostics.rs)
@bors try |
…try> Forbid recursive impl trait There is no type T, such that `T = [T; 2]`, but impl Trait could sometimes be to circumvented this. This patch makes it a hard error for an opaque type to resolve to such a "type". Before this can be merged it needs - [ ] A better error message - [ ] A crater run (?) to see if this any real-world code
☀️ Test successful - status-travis |
Can I have a crater run @rust-lang/infra? |
@craterbot run start=master#0b9f19dff1347e29bf4362ab5a8fab84b43023b5 end=try#db42d4dad33013eba11ef37342ad9f614e5652b8 mode=check-only |
👌 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
🚧 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
🎉 Experiment
|
Only one regression, ThatsGobbles/taggu-rust:
|
Regression is due to this change. Code in question is: impl MetaValue {
pub fn iter_over<'a>(&'a self, mis: MappingIterScheme) -> impl Iterator<Item = &'a String> {
let closure = move || {
match *self {
MetaValue::Nil => {},
MetaValue::Str(ref s) => { yield s; },
MetaValue::Seq(ref mvs) => {
for mv in mvs {
for i in Box::new(mv.iter_over(mis)) {
yield i;
}
}
},
MetaValue::Map(ref map) => {
for (mk, mv) in map {
match mis {
MappingIterScheme::Keys | MappingIterScheme::Both => {
// This outputs the value of the Nil key first, but only if a BTreeMap is used.
for s in Box::new(mk.iter_over()) {
yield s;
}
},
MappingIterScheme::Vals => {},
};
match mis {
MappingIterScheme::Vals | MappingIterScheme::Both => {
for s in Box::new(mv.iter_over(mis)) {
yield s;
}
},
MappingIterScheme::Keys => {},
};
}
},
}
};
GenConverter::gen_to_iter(closure)
}
} Replacing let iter = Box::new(mv.iter_over(mis)) as Box<dyn Iterator<Item = &'a String>>;
for s in iter { fixes this. So @rust-lang/lang, should this be a future compatibility lint (with what default level)? |
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 code is r=me-- haven't looked or thought about crater run results yet
@Centril was a decision reached on whether this should be a future compat lint? |
I don't recall a decision on that but as there was a regression you might as well do it. An issue filed against the regressed repo would also be nice. |
📌 Commit 671da3d47366a3f79162a8c0a77c3a58f567ced8 has been approved by |
⌛ Testing commit 671da3d47366a3f79162a8c0a77c3a58f567ced8 with merge 357c9c1522caf3c1ab6c2f4380090650d491db56... |
💔 Test failed - status-travis |
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 |
@matthewjasper looks like this maybe needs a |
It used to display as just `impl`
671da3d
to
450c756
Compare
@bors r=nikomatsakis |
📌 Commit 450c756996340e50a2ed2d385b6e9d2dd6c51f67 has been approved by |
This comment has been minimized.
This comment has been minimized.
There is no type T, such that `T = [T; 2]`, we should not allow this to be circumvented by impl Trait.
450c756
to
65c1f54
Compare
@bors r=nikomatsakis |
📌 Commit 65c1f54 has been approved by |
…ikomatsakis Forbid recursive impl trait There is no type T, such that `T = [T; 2]`, but impl Trait could sometimes be to circumvented this. This patch makes it a hard error for an opaque type to resolve to such a "type". Before this can be merged it needs - [x] A better error message - it's good enough for now. - [x] A crater run (?) to see if this any real-world code closes #47659
☀️ Test successful - status-appveyor, status-travis |
There is no type T, such that
T = [T; 2]
, but impl Trait could sometimesbe to circumvented this.
This patch makes it a hard error for an opaque type to resolve to such a
"type". Before this can be merged it needs
closes #47659