diff options
| author | Basile Desloges <basile.desloges@gmail.com> | 2017-10-06 17:21:06 +0200 |
|---|---|---|
| committer | Basile Desloges <basile.desloges@gmail.com> | 2017-10-06 17:44:50 +0200 |
| commit | 0241ea45b2e71e53921627bc09219653f2629c0e (patch) | |
| tree | 3c4b0aad7afd427e3e827cd673b696f073201904 | |
| parent | ef2f42d04a4c83dd5b50cd672b8a1b0791e00f98 (diff) | |
| download | rust-0241ea45b2e71e53921627bc09219653f2629c0e.tar.gz rust-0241ea45b2e71e53921627bc09219653f2629c0e.zip | |
mir-borrowck: Replace all constant index and sublices output with `[..]` to match the AST borrowck output
| -rw-r--r-- | src/librustc_mir/borrow_check.rs | 17 | ||||
| -rw-r--r-- | src/test/compile-fail/borrowck/borrowck-describe-lvalue.rs | 43 |
2 files changed, 44 insertions, 16 deletions
diff --git a/src/librustc_mir/borrow_check.rs b/src/librustc_mir/borrow_check.rs index 85ecb9d6e36..d57bac7c85a 100644 --- a/src/librustc_mir/borrow_check.rs +++ b/src/librustc_mir/borrow_check.rs @@ -1090,20 +1090,13 @@ impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx> autoderef = true; ("", format!(""), Some(index)) }, - ProjectionElem::ConstantIndex { offset, from_end: false, .. } => { + ProjectionElem::ConstantIndex { .. } | ProjectionElem::Subslice { .. } => { autoderef = true; - ("", format!("[{}]", offset), None) + // Since it isn't possible to borrow an element on a particular index and + // then use another while the borrow is held, don't output indices details + // to avoid confusing the end-user + ("", format!("[..]"), None) }, - ProjectionElem::ConstantIndex { offset, from_end: true, .. } => { - autoderef = true; - ("", format!("[-{}]", offset), None) - }, - ProjectionElem::Subslice { from, to: 0 } => - ("", format!("[{}:]", from), None), - ProjectionElem::Subslice { from: 0, to } => - ("", format!("[:-{}]", to), None), - ProjectionElem::Subslice { from, to } => - ("", format!("[{}:-{}]", from, to), None), }; buf.push_str(prefix); self.append_lvalue_to_string(&proj.base, buf, Some(autoderef)); diff --git a/src/test/compile-fail/borrowck/borrowck-describe-lvalue.rs b/src/test/compile-fail/borrowck/borrowck-describe-lvalue.rs index 9d1b2b64d85..088b678efb5 100644 --- a/src/test/compile-fail/borrowck/borrowck-describe-lvalue.rs +++ b/src/test/compile-fail/borrowck/borrowck-describe-lvalue.rs @@ -8,9 +8,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// ignore-tidy-linelength // revisions: ast mir //[mir]compile-flags: -Z emit-end-regions -Z borrowck-mir +#![feature(slice_patterns)] #![feature(advanced_slice_patterns)] pub struct Foo { @@ -173,29 +175,62 @@ fn main() { &[x, _, .., _, _] => println!("{}", x), //[ast]~^ ERROR cannot use `v[..]` because it was mutably borrowed //[mir]~^^ ERROR cannot use `v[..]` because it was mutably borrowed (Ast) - //[mir]~| ERROR cannot use `v[0]` because it was mutably borrowed (Mir) + //[mir]~| ERROR cannot use `v[..]` because it was mutably borrowed (Mir) _ => panic!("other case"), } match v { &[_, x, .., _, _] => println!("{}", x), //[ast]~^ ERROR cannot use `v[..]` because it was mutably borrowed //[mir]~^^ ERROR cannot use `v[..]` because it was mutably borrowed (Ast) - //[mir]~| ERROR cannot use `v[1]` because it was mutably borrowed (Mir) + //[mir]~| ERROR cannot use `v[..]` because it was mutably borrowed (Mir) _ => panic!("other case"), } match v { &[_, _, .., x, _] => println!("{}", x), //[ast]~^ ERROR cannot use `v[..]` because it was mutably borrowed //[mir]~^^ ERROR cannot use `v[..]` because it was mutably borrowed (Ast) - //[mir]~| ERROR cannot use `v[-2]` because it was mutably borrowed (Mir) + //[mir]~| ERROR cannot use `v[..]` because it was mutably borrowed (Mir) _ => panic!("other case"), } match v { &[_, _, .., _, x] => println!("{}", x), //[ast]~^ ERROR cannot use `v[..]` because it was mutably borrowed //[mir]~^^ ERROR cannot use `v[..]` because it was mutably borrowed (Ast) - //[mir]~| ERROR cannot use `v[-1]` because it was mutably borrowed (Mir) + //[mir]~| ERROR cannot use `v[..]` because it was mutably borrowed (Mir) _ => panic!("other case"), } } + // Subslices + { + let mut v = &[1, 2, 3, 4, 5]; + let _v = &mut v; + match v { + &[x..] => println!("{:?}", x), + //[ast]~^ ERROR cannot use `v[..]` because it was mutably borrowed + //[mir]~^^ ERROR cannot use `v[..]` because it was mutably borrowed (Ast) + //[mir]~| ERROR cannot use `v[..]` because it was mutably borrowed (Mir) + _ => panic!("other case"), + } + match v { + &[_, x..] => println!("{:?}", x), + //[ast]~^ ERROR cannot use `v[..]` because it was mutably borrowed + //[mir]~^^ ERROR cannot use `v[..]` because it was mutably borrowed (Ast) + //[mir]~| ERROR cannot use `v[..]` because it was mutably borrowed (Mir) + _ => panic!("other case"), + } + match v { + &[x.., _] => println!("{:?}", x), + //[ast]~^ ERROR cannot use `v[..]` because it was mutably borrowed + //[mir]~^^ ERROR cannot use `v[..]` because it was mutably borrowed (Ast) + //[mir]~| ERROR cannot use `v[..]` because it was mutably borrowed (Mir) + _ => panic!("other case"), + } + match v { + &[_, x.., _] => println!("{:?}", x), + //[ast]~^ ERROR cannot use `v[..]` because it was mutably borrowed + //[mir]~^^ ERROR cannot use `v[..]` because it was mutably borrowed (Ast) + //[mir]~| ERROR cannot use `v[..]` because it was mutably borrowed (Mir) + _ => panic!("other case"), + } + } } |
