-
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
add notes to report_conflicting_borrow MIR borrowck #44882
Conversation
r? @arielb1 (rust_highfive has picked a reviewer for you, use r? to override) |
src/librustc_mir/borrow_check.rs
Outdated
|
||
let issued_span = self.retrieve_borrow_span(issued_borrow); | ||
|
||
let issued_end_loan_span = if let Lvalue::Local(local) = issued_borrow.lvalue { |
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.
That's not how you do it. You should look up the span of the StatementKind::EndRegion
for the borrow region, which should be easily available by looking at the MIR.
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.
I've spent some time trying to do this, but StatementKind::EndRegion
contains region::Scope
, and I cannot get span from it.
impl Scope {
pub fn span(&self, tcx: TyCtxt, scope_tree: &ScopeTree)
Where should I get ScopeTree? I found MIR build already do this and resided to use it result.
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.
@mikhail-m1 I think the idea is that the EndRegion
itself is a Statement
, and every Statement
carries a SourceInfo
which in turn carries a Span
.
new_loan.span, &nl, &new_loan_msg, old_loan.span, &old_loan_msg, | ||
previous_end_span, Origin::Ast), | ||
(ty::UniqueImmBorrow, ty::UniqueImmBorrow) => | ||
self.bccx.cannot_uniquely_borrow_by_two_closures( |
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.
I'm not sure how "unique" became related to closures. I mean, unique implies closure but not vice-versa (closures can also borrow immutably). But that's pre-existing.
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.
generally LGTM, but you should get the region-end span the right way - I think you should create a Region -> span-of-endregion map by indexing the MIR, and look the region up in that.
src/librustc_mir/borrow_check.rs
Outdated
// FIXME: obviously falsifiable. Generalize for non-eq lvalues later. | ||
assert_eq!(loan1_lvalue, loan2_lvalue); | ||
assert_eq!(lvalue, &issued_borrow.lvalue); |
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.
Could you add a message to this assertions, e.g.:
assert_eq!(lvalue, &issued_borrow.lvalue, "complex conflicts are not supported");
statement: &mir::Statement<'tcx>, | ||
location: Location) { | ||
if let mir::StatementKind::EndRegion(region_scope) = statement.kind { | ||
error!("statement {:?} {:?}", statement, statement.source_info.span); |
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.
Is this supposed to be in here? Or was this instrumentation you put in but was supposed to be removed before merging?
location: Location) { | ||
if let mir::StatementKind::EndRegion(region_scope) = statement.kind { | ||
error!("statement {:?} {:?}", statement, statement.source_info.span); | ||
if let Some(span) = self.region_span_map.insert(ReScope(region_scope), statement.source_info.span) { |
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.
I think the tidy pass is complaining about this line being too long. (We have a hard 100-character limit on line length.)
@bors r+ |
📌 Commit a9eb8e7 has been approved by |
src/librustc_mir/borrow_check.rs
Outdated
@@ -396,26 +396,31 @@ impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx> | |||
ReadKind::Copy => | |||
this.report_use_while_mutably_borrowed( | |||
context, lvalue_span, borrow), | |||
ReadKind::Borrow(bk) => | |||
ReadKind::Borrow(bk) =>{ |
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.
nit: coding style in project is to put a single space between the =>
and the {
in a match arm
src/librustc_mir/borrow_check.rs
Outdated
context, lvalue_span, | ||
(lvalue_span.0, bk), (&borrow.lvalue, borrow.kind)), | ||
context, lvalue_span, bk, &borrow, end_issued_loan_span) | ||
}, |
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.
nit: coding style in project is to leave out the trailing comma when a match arm's code is delimited by curly braces
src/librustc_mir/borrow_check.rs
Outdated
this.report_conflicting_borrow( | ||
context, lvalue_span, | ||
(lvalue_span.0, bk), (&borrow.lvalue, borrow.kind)), | ||
context, lvalue_span, bk, &borrow, end_issued_loan_span)}, |
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.
nit: coding style in project is to both omit the trailing comma here (see earlier comment) and also put a line break before the ending }
@bors r+ |
📌 Commit c0ca0f9 has been approved by |
⌛ Testing commit c0ca0f906116b46cbeb341b8097174d60ca175da with merge 8c59b0f38daa077d520d78ff37629e103c37e9ea... |
💔 Test failed - status-travis |
looks like some bug with powerpc64 build |
☔ The latest upstream changes (presumably #44999) made this pull request unmergeable. Please resolve the merge conflicts. |
e052df4
to
24489e3
Compare
@bors r+ |
📌 Commit c68b10f has been approved by |
add notes to report_conflicting_borrow MIR borrowck part of #44596
☀️ Test successful - status-appveyor, status-travis |
part of #44596