-
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
Ensure the types of methods are well-formed #28669
Conversation
☔ The latest upstream changes (presumably #28629) made this pull request unmergeable. Please resolve the merge conflicts. |
Minimal example for the rustc regression: pub trait Lift<'tcx> {
type Lifted /* adding :'tcx solves this */;
}
pub fn lift<'tcx,T:?Sized+Lift<'tcx>>(value: &T) -> T::Lifted {
loop {}
}
pub fn my_lift_to_tcx<'tcx, T: Lift<'tcx>>(this: &T)
{
let mut result = Vec::new(); // adding a type annotation here solves this
result.push(lift(this));
} |
The warning is
I think the reference lifetime somehow becomes underconstrained. |
8352807
to
98fe9eb
Compare
|
||
// check that static methods don't get to assume `Self` is well-formed | ||
|
||
// TODO: I (arielb1) isn't sure whether this is a bug or feature. |
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.
Note tidy error: /home/travis/build/rust-lang/rust/src/test/compile-fail/wf-static-method.rs:13: TODO is deprecated; use FIXME
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 question was meant to you - I should have asked it more explicitly.
98fe9eb
to
1c3645e
Compare
Running on crater |
Toolchains built, testing crates. |
regression summary
I think these are both acceptable |
sgtm Let's at least give the authors of these two crates a head's up. cc @zonyitoo @aepsil0n this soundness fix will break some of your stuff. |
@brson Thanks! I will update the |
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// check that static methods don't get to assume `Self` is well-formed |
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.
So I've been meaning to get back to you on this test. I'm not quite sure what this is testing... it seems like the Self
type, if WF, would imply that 'b: 'a, but the various tests are erroring because 'a: 'b doesn't hold. Is this testing what you think it is?
Also, within an impl block, part of RFC 1214 was that we DO get to assume that the Self (and other input types) to the trait are well-formed, which is why we check that the trait ref is WF when we project. This was used to reduce the overhead on associated type values, but I imagine it should apply to static fns 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.
I got the order wrong. I also added a test on the caller side.
By RFC1214: Before calling a fn, we check that its argument and return types are WF. This check takes place after all higher-ranked lifetimes have been instantiated. Checking the argument types ensures that the implied bounds due to argument types are correct. Checking the return type ensures that the resulting type of the call is WF. The previous code only checked the trait-ref, which was not enough in several cases. As this is a soundness fix, it is a [breaking-change]. Fixes rust-lang#28609
looks like some mix of rust-lang#18653 and `projection_must_outlive`, but that needs to be investigated further (crater run?)
d6924fe
to
db22da0
Compare
also, ensure that callers are checked.
db22da0
to
2f23e17
Compare
@arielb1 already gave me a heads up. Will fix as soon as I find the time. |
@bors r+ |
📌 Commit 2f23e17 has been approved by |
By RFC1214: > Before calling a fn, we check that its argument and return types are WF. The previous code only checked the trait-ref, which was not enough in several cases. As this is a soundness fix, it is a [breaking-change]. Some new annotations are needed, which I think are because of #18653 and the imperfection of `projection_must_outlive` (that can probably be worked around by moving the wf obligation later). Fixes #28609 r? @nikomatsakis
@arielb1 Is there an issue tracking the pinyin regression (https://tools.taskcluster.net/task-inspector/#UFk2m1UJRweSxQNABRB84w/0)? It appears to be real (although I'm not sure it's relevant). |
Filed #28853 to track the pinyin regression. |
…felix This rather crucial requirement was not checked. In most cases, that didn't cause any trouble because the argument types are required to outlive the call and are subtypes of a subformula of the callee type. However, binary ops are taken by ref only indirectly, without it being marked in the argument types, which led to the argument types not being constrained anywhere causing spurious errors (as these are basically unconstrainable, I don't think this change can break code). Of course, the old way was also incorrent with contravariance, but that is still unsound for other reasons. This also improves rustc::front to get RUST_LOG to *somewhat* work. Fixes rust-lang#28999. That issue is one of the several regression introduced by rust-lang#28669. r? @pnkfelix
By RFC1214:
The previous code only checked the trait-ref, which was not enough
in several cases.
As this is a soundness fix, it is a [breaking-change]. Some new annotations are needed, which I think are because of #18653 and the imperfection of
projection_must_outlive
(that can probably be worked around by moving the wf obligation later).Fixes #28609
r? @nikomatsakis