-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
refactor the BorrowckErrors trait to take fn(self) #48783
Copy link
Copy link
Closed
Labels
A-NLLArea: Non-lexical lifetimes (NLL)Area: Non-lexical lifetimes (NLL)C-cleanupCategory: PRs that clean code up or issues documenting cleanup.Category: 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.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.
Metadata
Metadata
Assignees
Labels
A-NLLArea: Non-lexical lifetimes (NLL)Area: Non-lexical lifetimes (NLL)C-cleanupCategory: PRs that clean code up or issues documenting cleanup.Category: 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.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.
Type
Fields
Give feedbackNo fields configured for issues without a type.
The [
BorrowckErrorstrait] 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
TyCtxttype: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 finalselfwinds 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&mutself method. In particular, if you do something like this:this will borrow
&self.tcxfor as long aserris in use, preventing us from invoking other&mut selfmethods.For now, we worked around this problem by storing the
tcxinto 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
DiagnosticBuildervalues carry the lifetime of the incoming&selfreference. 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
TyCtxtlike:And we would have to modify the other impl like so: