-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Check that impl method args are WF given implied-bounds from trait method #105483
Check that impl method args are WF given implied-bounds from trait method #105483
Conversation
tcx, | ||
cause.clone(), | ||
param_env, | ||
ty::Binder::dummy(ty::PredicateKind::WellFormed(arg.into())), |
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 only question I guess I have is whether or not we need to also check that the unnormalized impl arg is also WF...
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.
Yes, almost certainly we do.
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.
Done :)
this possibly needs a crater run... @bors try |
⌛ Trying commit 66da457c472cca69d31a1b8abbbdd37592c63741 with merge 1055f710142b5b63c86f756e7b7fd3415974d1e8... |
66da457
to
503ac38
Compare
@bors try |
⌛ Trying commit 503ac38db52ff3f72240e32fe5614909b28c6a4b with merge d4af306fdd6ab261dfeb0aa57301d08b31b2dd92... |
☀️ Try build successful - checks-actions |
@craterbot check |
👌 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
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.
awaiting crater, FCP, and the change to only check WF(unnormalized_ty)
, r=me
🚧 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
@@ -0,0 +1,18 @@ | |||
use std::cell::RefCell; |
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.
Another test should be added for checking unnormalized types. Remarkably, such test can still be relevant even if we require equivalence between impl_fty
and trait_fty
, instead of the subtyping we currently do.
Here is a one derived from #105295 (comment):
trait Project {
type Ty;
}
impl Project for &'_ &'_ () {
type Ty = ();
}
trait Trait {
fn get<'s>(s: &'s str, _: ()) -> &'static str;
}
impl Trait for () {
fn get<'s>(s: &'s str, _: <&'static &'s () as Project>::Ty) -> &'static str {
s
}
}
fn main() {
let val = <() as Trait>::get(&String::from("blah blah blah"), ());
println!("{}", val);
}
🎉 Experiment
|
503ac38
to
8c1df5a
Compare
I'm gonna retry crater with @aliemjay's suggestion of assuming the impl's types are WF. Though here's an example failure that still fails (from biogarden): struct Sequence;
impl<Idx> std::ops::Index<Idx> for Sequence
where
Idx: std::slice::SliceIndex<[u8]>,
{
type Output = Idx::Output;
fn index(&self, index: Idx) -> &Self::Output {
todo!()
}
}
impl<'a,Idx> std::ops::Index<Idx> for &'a Sequence
where
Idx: std::slice::SliceIndex<[u8]>,
{
type Output = Idx::Output;
fn index(&self, index: Idx) -> &'a Self::Output {
todo!()
}
} I haven't sat down to think about how this could be weaponized, but I'm pretty sure the compiler is right rejecting this. Haven't looked at the rest of the failures, but I'll probably have a better idea after this next crater run is finished. |
@bors try |
⌛ Trying commit 8c1df5a873dd63146cf7df01b9c4e374fbd6aa14 with merge bb2bccfb91f43c4b6f3320bbbfc96310078e139a... |
Are there any recently (in the last two years?) updated crates affected by this? Can we do a future incompat lint with reasonable effort? |
@oli-obk, yes, it can be made into a lint first by forking the inference context. I'll put that into a separate PR -- since it's a deny-by-default lint, I'm not sure if that needs an FCP? |
GitHub repos can be un-archived, and even if that's not possible for some reason, it should still be possible to update the copy on crates.io. |
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
⌛ Trying commit 45d1e92 with merge d3e5f0ca41a62a336b366dad05ad6232129ba294... |
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (d3e5f0ca41a62a336b366dad05ad6232129ba294): comparison URL. Overall result: ❌✅ regressions and improvements - ACTION NEEDEDBenchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf. Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @bors rollup=never Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)This benchmark run did not return any relevant results for this metric. CyclesResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
|
Add `IMPLIED_BOUNDS_ENTAILMENT` lint Implements a lint (rust-lang#105572) version of the hard-error introduced in rust-lang#105483. Context is in that PR. r? `@lcnr` cc `@oli-obk` who had asked for this to be a lint first Not sure if this needs to be an FCP, since it's a lint for now.
@rfcbot cancel |
@compiler-errors proposal cancelled. |
Closing this since it's landing as a lint first, will open a new PR to promote it to an error eventually. |
Fixes #105295
Check out my explanation of the issue here: #105295 (comment).
Basically, this PR registers some additional well-formed bounds to ensure that the argument implied bounds of an impl method are not stronger than those coming from the trait method.
r? types
This arguably could live in wfcheck, but it'd be somewhat of a pain to move it there since we need the hybrid param-env we construct above in
compare_predicate_entailment
. Also, this really isn't a well-formedness check of the impl method -- this really is a form of (implied bounds) predicate entailment comparison...