Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #7331.
Motivating example:
When we typecheck
FromVec::fromVec
, we getfn(&'self [u8]) -> T
whereT
is bounded byFromVec<'self>
. Usually we would replace the argument's'self
with a new region variable which could match anything. However, if we allow that here then we lose an important constraint between the argument and the return typeT
, namely that the'self
inFromVec<'self>
needs to be the same as the argument's'self
.In this patch, I handle this case by replacing the argument's
'self
with the free region that has already been constructed for'self
in the enclosing scope.Note that I remove the region param from static trait methods (line 360 of collect.rs). The main motivation for that change is to provide a more sensible error message on something like
FromVec::fromVec::<'self>(self.v)
, which would otherwise confusingly yield the error message "this trait has a lifetime parameter but no lifetime was specified". Moreover, although it could be argued that these methods technically still are region-parameterized, the actual plugged-in region is always the same thing---a free region associated with'self
; I think it's prudent to syntactically prevent anyone from trying to plug anything else in.