-
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
Combine lifetime parameters when instantiating default methods #13503
Conversation
// ICE due to the lifetime parameter of `bar`. | ||
} | ||
|
||
fn main() { |
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.
main needs to be pub
for check-fast tests to run this code
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.
check-fast
was removed as of #13288.
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.
Damn, I missed that! Thanks @luqmana
This test does fail, though not with the error message I was expecting:
|
@edwardw let me re-read the code again and make sure I'm remembering what it is for properly. I may be confused. |
@edwardw I think I was confused. This is one of the very few cases in which it makes sense to substitute to a bound region. Hence, I think your patch is correct. I expect the test case failure I was seeing is just #12856. Though, now that I think of it, I'm a bit surprised that you didn't hit it in your example. That may be another bug. |
I see. I also revised the patch a little bit. Please review. |
So, I think the patch is correct as written, but i'm still not happy about it, because it is repeating the knowledge about the index adjustment. This is of course what we do for types but that's not a great thing. To make this more DRY, one option is to add the (adjusted) index into the RegionParameterDef -- that's certainly an improvement, but it still leaves knowledge distributed between the code in A better approach is to have a routine that can compute the correct index from "first principles". This probably requires @pnkfelix's changes from #13261. The idea would be to walk up from the definition to examine the context in which it occurs. This same routine could then be used by both I guess though that even if we do this, the result is still not totally DRY, since there is code that computes the combined substitution which currently concatenates vectors. So maybe it's not worth the effort to make the change I propose. I'd like to just remove this notion of concatenating vectors altogether in favor of something more obvious and less annoying, and that'd be the REAL right fix. |
When instantiating trait default methods for certain implementation, `typeck` correctly combined type parameters from trait bound with those from method bound, but didn't do so for lifetime parameters. Applies the same logic to lifetime parameters. Closes rust-lang#13204
Interesting challenge. I reckon the purpose of a monotonic index in So, pub struct substs {
pub self_ty: Option<ty::t>,
pub tps: DefIdMap<t>, // instead of Vec<t>
pub regions: RegionSubsts,
}
pub enum RegionSubsts {
ErasedRegions,
NonerasedRegions(NodeMap<Region>) // instead of OwnedSlice<Region>
} may work without vector concatenation at all. A little bit daunting to touch such a core data structure. |
When instantiating trait default methods for certain implementation, `typeck` correctly combined type parameters from trait bound with those from method bound, but didn't do so for lifetime parameters. Applies the same logic to lifetime parameters. Closes #13204
…=Alexendoo Check for needless raw strings in `format_args!()` template as well changelog: [`needless_raw_strings`, `needless_raw_string_hashes`]: check `format_args!()` template as well Fix rust-lang#13503
When instantiating trait default methods for certain implementation,
typeck
correctly combined type parameters from trait bound with thosefrom method bound, but didn't do so for lifetime parameters. Applies
the same logic to lifetime parameters.
Closes #13204