mir-borrowck: Replace all constant index and sublices output with [..] to match the AST borrowck output

This commit is contained in:
Basile Desloges 2017-10-06 17:21:06 +02:00
parent ef2f42d04a
commit 0241ea45b2
2 changed files with 44 additions and 16 deletions

View File

@ -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));

View File

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