-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
use implied bounds from impl header when comparing trait and impl methods #105548
Conversation
... trait and impl methods.
r? @lcnr because they're the one who's most aware of the current state of the issue w/ implied bounds and unnormalized types. |
☔ The latest upstream changes (presumably #106129) made this pull request unmergeable. Please resolve the merge conflicts. |
Unless there's another reason apart from consistency for adding this, I think this should wait until we're able to add explicit implied bounds in the trait solver. I think we should block this on coinductive trait predicates. What does this PR doWhen we check that the Does this agree with our long term plan for implied boundsDefinitely yes. We pretty much want to get to a point where we add This means that any place which uses the Is this currently soundSadly not completely. It would allow for a slightly different variant of #100051. Instead of now only relying on this unchecked implied bounds when checking that the signature has weaker requirements, we also rely on them when checking the This causes the following unsound test to compile: (pretty much #100051) trait Trait {
type Type;
}
impl<T> Trait for T {
type Type = ();
}
trait Extend<'a, 'b> {
fn extend(s: &'a str) -> &'b str;
}
impl<'a, 'b> Extend<'a, 'b> for <&'b &'a () as Trait>::Type
where
for<'what, 'ever> &'what &'ever (): Trait,
{
// instead of getting the implied bound from the self type
// we get it through an explicit bound on the impl method instead.
//
// This explicit bound is accepted because it's implied by the
// impl header.
fn extend(s: &'a str) -> &'b str
where
'a: 'b
{
s
}
}
fn main() {
let y = <() as Extend<'_, '_>>::extend(&String::from("Hello World"));
println!("{}", y);
} I don't think this unsoundness will ever get triggered by accident and if someone wants to use it, they can already use the #100051. So I don't think that this is a hard blocker to landing this PR if there were practical applications. Is it usefulI don't think it's too useful. If bounds on the impl method rely on the implied bounds from the impl header to be correct, then why add these as bounds at all if they're already implied by the impl header. borrowck also doesn't use implied bounds from the impl header right now, only from its signature, so this PR would allow circumventing that issue. That would be pretty inconsistent though. Allowing borrowck to use implied bounds from impl headers would allow the above unsoundness in a more implicit way so I fear that it might actually be possible to rely on that by accident. I guess let's go with: @rust-lang/types I believe we should delay adding implied bounds to @rfcbot fcp close |
Team member @lcnr has proposed to close this. The next step is review by the rest of the tagged team members:
No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
@rfcbot fcp cancel sorry for the ping 😅 |
@lcnr proposal cancelled. |
@rfcbot fcp close |
Team member @lcnr has proposed to close this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
The final comment period, with a disposition to close, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. |
Fixes #105495.
I pulled it out of #105483.
r? @compiler-errors