-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Unsoundness related to implied bounds for return types #57265
Comments
Only an issue on 2018 edition. Probably NLL. |
@matthewjasper Ah right I didn’t notice. This may make investigations easier. |
Variable types aren't WF-checked in NLL. We should include the output type here:
|
Indeed, that works :) Care to make a PR? I won’t be able to do it myself today. I’ve not been able to weaponize my code snippet with this fix (or with the 2015 edition); however I believe this is because currently, when you have fn call<'a, T>(x: &'a T, f: fn(&'a T) -> S<&'a T>) {
let y = f(x);
} then you consider But when we designed implied bounds with @nikomatsakis, we thought that function pointers would be seen only in a « shallow » way, i.e. we would not consider the types appearing in the function pointer as input types, so that we don’t get any implied bounds from them. Regarding the fact that we currently do have implied bounds for return types, coupled with my gist above, I think we may want to reconsider either the WF-ness of function pointers in the implied bounds setting, or the computation of implied bounds for return types (but removing it would be a breaking change). |
I've always regretted that output types are used for WF purposes, but I don't know how to fix it without breakage. Still @scalexm we should definitely revisit the definition and make sure we get this straight. We also have to think about the interaction of variance (#25860). I've been assuming that as we transition more towards chalk, we would be able to solve the soundness hole by encoding the "implied bounds" for a |
The following code compiles and is unsound:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=fc4210fcb8ba91c1ae883cd20deb2279
I believe this is due to the fact that we compute implied bounds for return types? Ironically, I did write about this some months ago, as a reminder to myself for the implementation of the implied bounds RFC:
https://gist.github.com/scalexm/cf32cea831a5d8193fa8a484099b71a2
I wasn’t aware this bug was actually existing in Rust already.
cc @nikomatsakis
The text was updated successfully, but these errors were encountered: