Skip to content
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

Merged
merged 12 commits into from
Oct 12, 2017

Conversation

zilbuz
Copy link
Contributor

@zilbuz zilbuz commented Oct 2, 2017

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

@rust-highfive
Copy link
Collaborator

r? @pnkfelix

(rust_highfive has picked a reviewer for you, use r? to override)

@zilbuz
Copy link
Contributor Author

zilbuz commented Oct 2, 2017

I'd like some feedback on this PR. I can't think of any example that trigger the messages marked debug!() in my diff of borrow_check.rs. Can someone give me some example ?

@pnkfelix
Copy link
Member

pnkfelix commented Oct 2, 2017

@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"),
    }
}

@aidanhs aidanhs added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 5, 2017
zilbuz added 12 commits October 6, 2017 17:44
… AST borrowck

- Print fields with `.name` rather than `.<num>`
- Autoderef values if followed by a field or an index
…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.
@zilbuz zilbuz changed the title [WIP] MIR borrowck: print lvalues in error messages in the same way that the AST borrowck MIR borrowck: print lvalues in error messages in the same way that the AST borrowck Oct 6, 2017
@zilbuz
Copy link
Contributor Author

zilbuz commented Oct 6, 2017

r? @pnkfelix

The only commit untested is e32e81c. I couldn't find a way to access a field through a subslice. I'd have to be able to do something like [1..3].x or xn @ [F { x }..] in a match maybe...

// Static and field from struct
unsafe {
let _x = sfoo.x();
sfoo.x; //[mir]~ ERROR cannot use `sfoo.x` because it was mutably borrowed (Mir)
Copy link
Member

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.)

Copy link
Member

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)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Filed as #45129

@pnkfelix
Copy link
Member

pnkfelix commented Oct 9, 2017

@bors r+

thanks for all the work here @zilbuz !

@bors
Copy link
Contributor

bors commented Oct 9, 2017

📌 Commit e32e81c has been approved by pnkfelix

@bors
Copy link
Contributor

bors commented Oct 10, 2017

⌛ Testing commit e32e81c with merge fd85391dbaf891fda53943b00e97cd609d3186c2...

@bors
Copy link
Contributor

bors commented Oct 10, 2017

💔 Test failed - status-travis

@kennytm
Copy link
Member

kennytm commented Oct 11, 2017

@bors retry

@bors
Copy link
Contributor

bors commented Oct 12, 2017

⌛ Testing commit e32e81c with merge d274114...

bors added a commit that referenced this pull request Oct 12, 2017
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
@bors
Copy link
Contributor

bors commented Oct 12, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: pnkfelix
Pushing d274114 to master...

@bors bors merged commit e32e81c into rust-lang:master Oct 12, 2017
@zilbuz zilbuz deleted the issue-44974 branch March 1, 2018 13:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants