You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
nikomatsakis opened this issue
Mar 6, 2018
· 3 comments
Labels
A-NLLArea: Non-lexical lifetimes (NLL)C-cleanupCategory: PRs that clean code up or issues documenting cleanup.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.
This type is actually an alias for an &-reference, so that means that the final self winds up passing a double reference. This is not bad in and of itself, but @spastorino encountered in #48682 that the current setup causes conflicts around the tcx when using an &mut self method. In particular, if you do something like this:
let err = self.tcx.cannot_use_while_mutably_borrowed(...);
..
this will borrow &self.tcx for as long as err is in use, preventing us from invoking other &mut self methods.
For now, we worked around this problem by storing the tcx into a local variable:
let tcx = self.tcx;
But if the methods were defined instead as fn(self), then it would have worked fine the original way.
Making this transformation would involve a few changes though. First off, right now the returned DiagnosticBuilder values carry the lifetime of the incoming &self reference. We would want to change that to the lifetime of the TyCtxt, so we would need to modify the trait to carry a lifetime parameter:
/// This trait is expected to be implemented on a reference./// The `'r` is the lifetime of that reference.traitBorrowckErrors<'cx>{
...
fncannot_use_when_mutably_borrowed(self,// changed to selfspan:Span,
...
) -> DiagnosticBuilder<'cx>{
...// as before}
...
}
A-NLLArea: Non-lexical lifetimes (NLL)C-cleanupCategory: PRs that clean code up or issues documenting cleanup.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.
The [
BorrowckErrors
trait] is used to report errors from both HIR and MIR-based borrowck:rust/src/librustc_mir/util/borrowck_errors.rs
Line 55 in c933440
It contains various methods currently defined to take
&self
:rust/src/librustc_mir/util/borrowck_errors.rs
Lines 77 to 84 in c933440
However, it is implemented on the
TyCtxt
type:rust/src/librustc_mir/util/borrowck_errors.rs
Line 494 in c933440
This type is actually an alias for an
&
-reference, so that means that the finalself
winds up passing a double reference. This is not bad in and of itself, but @spastorino encountered in #48682 that the current setup causes conflicts around the tcx when using an&mut
self method. In particular, if you do something like this:this will borrow
&self.tcx
for as long aserr
is in use, preventing us from invoking other&mut self
methods.For now, we worked around this problem by storing the
tcx
into a local variable:But if the methods were defined instead as
fn(self)
, then it would have worked fine the original way.Making this transformation would involve a few changes though. First off, right now the returned
DiagnosticBuilder
values carry the lifetime of the incoming&self
reference. We would want to change that to the lifetime of theTyCtxt
, so we would need to modify the trait to carry a lifetime parameter:Then it would be implememented for
TyCtxt
like:And we would have to modify the other impl like so:
The text was updated successfully, but these errors were encountered: