-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
MIR borrowck: print lvalues in error messages in the same way that the AST borrowck #44985
Conversation
r? @pnkfelix (rust_highfive has picked a reviewer for you, use r? to override) |
I'd like some feedback on this PR. I can't think of any example that trigger the messages marked |
@zilbuz I'm about to hit the sack, but if you use the following input code, I think you should see some examples of some of the cases you are wondering about: #![feature(slice_patterns)]
fn main() {
#[derive(Debug)]
enum E<X> { A(X), B { x: X } }
#[derive(Debug)]
struct S<'a, X: 'a, Y>{ x: &'a [X], y: (Y, Y), };
let e = E::A(3);
match e {
E::A(ref ax) => println!("e.ax: {:?}", ax),
E::B { x: ref bx } => println!("e.bx: {:?}", bx),
}
let s = S { x: &[1, 2, 3,], y: (999, 998) };
match s {
S {
x: &[ref x0, ref xn..],
y: (ref y0, ref y1)
} => {
println!("s.x0: {:?} s.xn: {:?}", x0, xn);
println!("s.y0: {:?}, s.y1: {:?}", y0, y1);
}
_ => panic!("other case"),
}
} |
… AST borrowck - Print fields with `.name` rather than `.<num>` - Autoderef values if followed by a field or an index
…type that is neither Adt nor tuple
…reported lvalue for constant index Previously the constant index was reported as `[x of y]` or `[-x of y]` where `x` was the offset and `y` the minimum length of the slice. The minus sign wasn't in the right case since for `&[_, x, .., _, _]`, the error reported was `[-1 of 4]`, and for `&[_, _, .., x, _]`, the error reported was `[2 of 4]`. This commit fixes the sign so that the indexes 1 and -2 are reported, and remove the ` of y` part of the message to make it more succinct.
….]` to match the AST borrowck output
…variable hasn't a name
// Static and field from struct | ||
unsafe { | ||
let _x = sfoo.x(); | ||
sfoo.x; //[mir]~ ERROR cannot use `sfoo.x` because it was mutably borrowed (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.
oh interesting...
(I think this represents a bug in MIR-borrowck. But fixing that is orthogonal to this PR in any case.)
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.
(likewise for all the other cases below that are paths based off of static variables)
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.
Filed as #45129
📌 Commit e32e81c has been approved by |
⌛ Testing commit e32e81c with merge fd85391dbaf891fda53943b00e97cd609d3186c2... |
💔 Test failed - status-travis |
@bors retry
|
MIR borrowck: print lvalues in error messages in the same way that the AST borrowck Fix #44974 - Print fields with `.name` rather than `.<num>` - Autoderef values if followed by a field or an index - Output `[..]` when borrowing inside a slice
☀️ Test successful - status-appveyor, status-travis |
Fix #44974
.name
rather than.<num>
[..]
when borrowing inside a slice