Update the "English-language" to-string function of a cmt
to use
more modern terminology and update tests accordingly.
This commit is contained in:
parent
0a32010e43
commit
2387651f7d
24 changed files with 124 additions and 87 deletions
|
@ -75,7 +75,7 @@ use middle::def;
|
|||
use middle::region;
|
||||
use middle::ty::{self, Ty};
|
||||
use util::nodemap::{NodeMap};
|
||||
use util::ppaux::{Repr};
|
||||
use util::ppaux::{Repr, UserString};
|
||||
|
||||
use syntax::ast::{MutImmutable, MutMutable};
|
||||
use syntax::ast;
|
||||
|
@ -113,10 +113,17 @@ pub struct Upvar {
|
|||
// different kinds of pointers:
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, Show)]
|
||||
pub enum PointerKind {
|
||||
/// `Box<T>`
|
||||
Unique,
|
||||
|
||||
/// `&T`
|
||||
BorrowedPtr(ty::BorrowKind, ty::Region),
|
||||
Implicit(ty::BorrowKind, ty::Region), // Implicit deref of a borrowed ptr.
|
||||
UnsafePtr(ast::Mutability)
|
||||
|
||||
/// `*T`
|
||||
UnsafePtr(ast::Mutability),
|
||||
|
||||
/// Implicit deref of the `&T` that results from an overloaded index `[]`.
|
||||
Implicit(ty::BorrowKind, ty::Region),
|
||||
}
|
||||
|
||||
// We use the term "interior" to mean "something reachable from the
|
||||
|
@ -1392,22 +1399,6 @@ impl<'tcx> cmt_<'tcx> {
|
|||
|
||||
|
||||
pub fn descriptive_string(&self, tcx: &ty::ctxt) -> String {
|
||||
fn upvar_to_string(upvar: &Upvar, is_copy: bool) -> String {
|
||||
if upvar.is_unboxed {
|
||||
let kind = match upvar.kind {
|
||||
ty::FnUnboxedClosureKind => "Fn",
|
||||
ty::FnMutUnboxedClosureKind => "FnMut",
|
||||
ty::FnOnceUnboxedClosureKind => "FnOnce"
|
||||
};
|
||||
format!("captured outer variable in an `{}` closure", kind)
|
||||
} else {
|
||||
(match (upvar.kind, is_copy) {
|
||||
(ty::FnOnceUnboxedClosureKind, true) => "captured outer variable in a proc",
|
||||
_ => "captured outer variable"
|
||||
}).to_string()
|
||||
}
|
||||
}
|
||||
|
||||
match self.cat {
|
||||
cat_static_item => {
|
||||
"static item".to_string()
|
||||
|
@ -1427,16 +1418,23 @@ impl<'tcx> cmt_<'tcx> {
|
|||
let upvar = self.upvar();
|
||||
match upvar.as_ref().map(|i| &i.cat) {
|
||||
Some(&cat_upvar(ref var)) => {
|
||||
upvar_to_string(var, false)
|
||||
var.user_string(tcx)
|
||||
}
|
||||
Some(_) => unreachable!(),
|
||||
None => {
|
||||
match pk {
|
||||
Implicit(..) => {
|
||||
"dereference (dereference is implicit, due to indexing)".to_string()
|
||||
format!("indexed content")
|
||||
}
|
||||
Unique => {
|
||||
format!("`Box` content")
|
||||
}
|
||||
UnsafePtr(..) => {
|
||||
format!("dereference of unsafe pointer")
|
||||
}
|
||||
BorrowedPtr(..) => {
|
||||
format!("borrowed content")
|
||||
}
|
||||
Unique => format!("dereference of `{}`", ptr_sigil(pk)),
|
||||
_ => format!("dereference of `{}`-pointer", ptr_sigil(pk))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1447,14 +1445,12 @@ impl<'tcx> cmt_<'tcx> {
|
|||
cat_interior(_, InteriorField(PositionalField(_))) => {
|
||||
"anonymous field".to_string()
|
||||
}
|
||||
cat_interior(_, InteriorElement(VecElement)) => {
|
||||
"vec content".to_string()
|
||||
}
|
||||
cat_interior(_, InteriorElement(VecElement)) |
|
||||
cat_interior(_, InteriorElement(OtherElement)) => {
|
||||
"indexed content".to_string()
|
||||
}
|
||||
cat_upvar(ref var) => {
|
||||
upvar_to_string(var, true)
|
||||
var.user_string(tcx)
|
||||
}
|
||||
cat_downcast(ref cmt, _) => {
|
||||
cmt.descriptive_string(tcx)
|
||||
|
@ -1483,7 +1479,7 @@ impl<'tcx> Repr<'tcx> for categorization<'tcx> {
|
|||
format!("{:?}", *self)
|
||||
}
|
||||
cat_deref(ref cmt, derefs, ptr) => {
|
||||
format!("{}-{}{}->", cmt.cat.repr(tcx), ptr_sigil(ptr), derefs)
|
||||
format!("{}-{}{}->", cmt.cat.repr(tcx), ptr.repr(tcx), derefs)
|
||||
}
|
||||
cat_interior(ref cmt, interior) => {
|
||||
format!("{}.{}", cmt.cat.repr(tcx), interior.repr(tcx))
|
||||
|
@ -1504,7 +1500,32 @@ pub fn ptr_sigil(ptr: PointerKind) -> &'static str {
|
|||
Implicit(ty::MutBorrow, _) => "&mut",
|
||||
BorrowedPtr(ty::UniqueImmBorrow, _) |
|
||||
Implicit(ty::UniqueImmBorrow, _) => "&unique",
|
||||
UnsafePtr(_) => "*"
|
||||
UnsafePtr(_) => "*",
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Repr<'tcx> for PointerKind {
|
||||
fn repr(&self, tcx: &ty::ctxt<'tcx>) -> String {
|
||||
match *self {
|
||||
Unique => {
|
||||
format!("Box")
|
||||
}
|
||||
BorrowedPtr(ty::ImmBorrow, ref r) |
|
||||
Implicit(ty::ImmBorrow, ref r) => {
|
||||
format!("&{}", r.repr(tcx))
|
||||
}
|
||||
BorrowedPtr(ty::MutBorrow, ref r) |
|
||||
Implicit(ty::MutBorrow, ref r) => {
|
||||
format!("&{} mut", r.repr(tcx))
|
||||
}
|
||||
BorrowedPtr(ty::UniqueImmBorrow, ref r) |
|
||||
Implicit(ty::UniqueImmBorrow, ref r) => {
|
||||
format!("&{} uniq", r.repr(tcx))
|
||||
}
|
||||
UnsafePtr(_) => {
|
||||
format!("*")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1531,3 +1552,27 @@ fn element_kind(t: Ty) -> ElementKind {
|
|||
_ => OtherElement
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Repr<'tcx> for ty::UnboxedClosureKind {
|
||||
fn repr(&self, _: &ty::ctxt) -> String {
|
||||
format!("Upvar({:?})", self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Repr<'tcx> for Upvar {
|
||||
fn repr(&self, tcx: &ty::ctxt) -> String {
|
||||
format!("Upvar({})", self.kind.repr(tcx))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> UserString<'tcx> for Upvar {
|
||||
fn user_string(&self, _: &ty::ctxt) -> String {
|
||||
let kind = match self.kind {
|
||||
ty::FnUnboxedClosureKind => "Fn",
|
||||
ty::FnMutUnboxedClosureKind => "FnMut",
|
||||
ty::FnOnceUnboxedClosureKind => "FnOnce",
|
||||
};
|
||||
format!("captured outer variable in an `{}` closure", kind)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -115,29 +115,31 @@ fn report_cannot_move_out_of<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>,
|
|||
match move_from.cat {
|
||||
mc::cat_deref(_, _, mc::BorrowedPtr(..)) |
|
||||
mc::cat_deref(_, _, mc::Implicit(..)) |
|
||||
mc::cat_deref(_, _, mc::UnsafePtr(..)) |
|
||||
mc::cat_static_item => {
|
||||
bccx.span_err(
|
||||
move_from.span,
|
||||
&format!("cannot move out of {}",
|
||||
bccx.cmt_to_string(&*move_from))[]);
|
||||
bccx.span_err(move_from.span,
|
||||
&format!("cannot move out of {}",
|
||||
move_from.descriptive_string(bccx.tcx))[]);
|
||||
}
|
||||
|
||||
mc::cat_downcast(ref b, _) |
|
||||
mc::cat_interior(ref b, _) => {
|
||||
match b.ty.sty {
|
||||
ty::ty_struct(did, _)
|
||||
| ty::ty_enum(did, _) if ty::has_dtor(bccx.tcx, did) => {
|
||||
ty::ty_struct(did, _) |
|
||||
ty::ty_enum(did, _) if ty::has_dtor(bccx.tcx, did) => {
|
||||
bccx.span_err(
|
||||
move_from.span,
|
||||
&format!("cannot move out of type `{}`, \
|
||||
which defines the `Drop` trait",
|
||||
b.ty.user_string(bccx.tcx))[]);
|
||||
},
|
||||
_ => panic!("this path should not cause illegal move")
|
||||
_ => {
|
||||
bccx.span_bug(move_from.span, "this path should not cause illegal move")
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => panic!("this path should not cause illegal move")
|
||||
_ => {
|
||||
bccx.span_bug(move_from.span, "this path should not cause illegal move")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -681,6 +681,10 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
|
|||
self.tcx.sess.span_err(s, m);
|
||||
}
|
||||
|
||||
pub fn span_bug(&self, s: Span, m: &str) {
|
||||
self.tcx.sess.span_bug(s, m);
|
||||
}
|
||||
|
||||
pub fn span_note(&self, s: Span, m: &str) {
|
||||
self.tcx.sess.span_note(s, m);
|
||||
}
|
||||
|
|
|
@ -73,7 +73,7 @@ pub fn check_call<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
|||
autoderef(fcx,
|
||||
callee_expr.span,
|
||||
original_callee_ty,
|
||||
Some(callee_expr.id),
|
||||
Some(callee_expr),
|
||||
LvaluePreference::NoPreference,
|
||||
|adj_ty, idx| {
|
||||
let autoderefref = ty::AutoDerefRef { autoderefs: idx, autoref: None };
|
||||
|
|
|
@ -2263,24 +2263,10 @@ pub enum LvaluePreference {
|
|||
/// Executes an autoderef loop for the type `t`. At each step, invokes `should_stop` to decide
|
||||
/// whether to terminate the loop. Returns the final type and number of derefs that it performed.
|
||||
///
|
||||
<<<<<<< HEAD
|
||||
/// Note: this method does not modify the adjustments table. The caller is responsible for
|
||||
/// inserting an AutoAdjustment record into the `fcx` using one of the suitable methods.
|
||||
pub fn autoderef<'a, 'tcx, T, F>(fcx: &FnCtxt<'a, 'tcx>,
|
||||
sp: Span,
|
||||
||||||| merged common ancestors
|
||||
/// Note: this method does not modify the adjustments table. The caller is responsible for
|
||||
/// inserting an AutoAdjustment record into the `fcx` using one of the suitable methods.
|
||||
pub fn autoderef<'a, 'tcx, T, F>(fcx: &FnCtxt<'a, 'tcx>, sp: Span,
|
||||
=======
|
||||
/// Note: this method does not modify the adjustments table. The
|
||||
/// caller is responsible for inserting an AutoAdjustment record into
|
||||
/// the `fcx` using one of the suitable methods. However, if
|
||||
/// `opt_expr` is not `None`, it *will* insert the appropriate method
|
||||
/// entries for the overloaded deref call.
|
||||
pub fn autoderef<'a, 'tcx, T, F>(fcx: &FnCtxt<'a, 'tcx>,
|
||||
sp: Span,
|
||||
>>>>>>> Add comments to autoderef() helper and refactor it to take
|
||||
base_ty: Ty<'tcx>,
|
||||
opt_expr: Option<&ast::Expr>,
|
||||
mut lvalue_pref: LvaluePreference,
|
||||
|
@ -2288,9 +2274,9 @@ pub fn autoderef<'a, 'tcx, T, F>(fcx: &FnCtxt<'a, 'tcx>,
|
|||
-> (Ty<'tcx>, uint, Option<T>)
|
||||
where F: FnMut(Ty<'tcx>, uint) -> Option<T>,
|
||||
{
|
||||
debug!("autoderef(base_ty={}, opt_expr={}, lvalue_pref={})",
|
||||
debug!("autoderef(base_ty={}, opt_expr={}, lvalue_pref={:?})",
|
||||
base_ty.repr(fcx.tcx()),
|
||||
opt_expr,
|
||||
opt_expr.repr(fcx.tcx()),
|
||||
lvalue_pref);
|
||||
|
||||
let mut t = base_ty;
|
||||
|
|
|
@ -37,9 +37,9 @@ fn illegal_dereference<T: Add<Output=()>>(mut x: T, y: T) {
|
|||
let m = &mut x;
|
||||
let n = &y;
|
||||
|
||||
*m //~ ERROR: cannot move out of dereference of `&mut`-pointer
|
||||
*m //~ ERROR: cannot move out of borrowed content
|
||||
+
|
||||
*n; //~ ERROR: cannot move out of dereference of `&`-pointer
|
||||
*n; //~ ERROR: cannot move out of borrowed content
|
||||
}
|
||||
|
||||
struct Foo;
|
||||
|
|
|
@ -20,5 +20,5 @@ impl A {
|
|||
pub fn main() {
|
||||
let a = box A;
|
||||
a.foo();
|
||||
//~^ ERROR cannot borrow immutable dereference of `Box` `*a` as mutable
|
||||
//~^ ERROR cannot borrow immutable `Box` content `*a` as mutable
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ fn test1() {
|
|||
}
|
||||
|
||||
fn test2<F>(f: &F) where F: FnMut() {
|
||||
(*f)(); //~ ERROR: cannot borrow immutable dereference of `&`-pointer `*f` as mutable
|
||||
(*f)(); //~ ERROR: cannot borrow immutable borrowed content `*f` as mutable
|
||||
}
|
||||
|
||||
fn test3<F>(f: &mut F) where F: FnMut() {
|
||||
|
@ -41,7 +41,7 @@ fn test3<F>(f: &mut F) where F: FnMut() {
|
|||
}
|
||||
|
||||
fn test4(f: &Test) {
|
||||
f.f.call_mut(()) //~ ERROR: cannot borrow immutable dereference of `Box` `*f.f` as mutable
|
||||
f.f.call_mut(()) //~ ERROR: cannot borrow immutable `Box` content `*f.f` as mutable
|
||||
}
|
||||
|
||||
fn test5(f: &mut Test) {
|
||||
|
|
|
@ -11,16 +11,16 @@
|
|||
fn with<F>(f: F) where F: FnOnce(&String) {}
|
||||
|
||||
fn arg_item(&_x: &String) {}
|
||||
//~^ ERROR cannot move out of dereference of `&`-pointer
|
||||
//~^ ERROR cannot move out of borrowed content
|
||||
|
||||
fn arg_closure() {
|
||||
with(|&_x| ())
|
||||
//~^ ERROR cannot move out of dereference of `&`-pointer
|
||||
//~^ ERROR cannot move out of borrowed content
|
||||
}
|
||||
|
||||
fn let_pat() {
|
||||
let &_x = &"hi".to_string();
|
||||
//~^ ERROR cannot move out of dereference of `&`-pointer
|
||||
//~^ ERROR cannot move out of borrowed content
|
||||
}
|
||||
|
||||
pub fn main() {}
|
||||
|
|
|
@ -12,5 +12,5 @@ use std::rc::Rc;
|
|||
|
||||
pub fn main() {
|
||||
let _x = Rc::new(vec!(1i, 2)).into_iter();
|
||||
//~^ ERROR cannot move out of dereference of `&`-pointer
|
||||
//~^ ERROR cannot move out of borrowed content
|
||||
}
|
||||
|
|
|
@ -12,5 +12,5 @@ use std::rc::Rc;
|
|||
|
||||
pub fn main() {
|
||||
let _x = *Rc::new("hi".to_string());
|
||||
//~^ ERROR cannot move out of dereference of `&`-pointer
|
||||
//~^ ERROR cannot move out of borrowed content
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ pub fn main() {
|
|||
match x {
|
||||
[_, tail..] => {
|
||||
match tail {
|
||||
[Foo { string: a }, //~ ERROR cannot move out of dereference of `&`-pointer
|
||||
[Foo { string: a }, //~ ERROR cannot move out of borrowed content
|
||||
Foo { string: b }] => {
|
||||
//~^^ NOTE attempting to move value to here
|
||||
//~^^ NOTE and here
|
||||
|
|
|
@ -28,5 +28,5 @@ fn main() {
|
|||
let v = MyVec { data: vec!(box 1i, box 2, box 3) };
|
||||
let good = &v[0]; // Shouldn't fail here
|
||||
let bad = v[0];
|
||||
//~^ ERROR cannot move out of dereference (dereference is implicit, due to indexing)
|
||||
//~^ ERROR cannot move out of indexed content
|
||||
}
|
||||
|
|
|
@ -66,5 +66,5 @@ fn main() {
|
|||
x: 1,
|
||||
};
|
||||
s[2] = 20;
|
||||
//~^ ERROR cannot assign to immutable dereference (dereference is implicit, due to indexing)
|
||||
//~^ ERROR cannot assign to immutable indexed content
|
||||
}
|
||||
|
|
|
@ -41,9 +41,9 @@ impl Index<uint> for T {
|
|||
|
||||
fn main() {
|
||||
S[0];
|
||||
//~^ ERROR cannot move out of dereference
|
||||
//~^ ERROR cannot move out of indexed content
|
||||
//~^^ ERROR E0161
|
||||
T[0];
|
||||
//~^ ERROR cannot move out of dereference
|
||||
//~^ ERROR cannot move out of indexed content
|
||||
//~^^ ERROR E0161
|
||||
}
|
||||
|
|
|
@ -15,10 +15,10 @@
|
|||
pub fn main() {
|
||||
let _x: Box<str> = box *"hello world";
|
||||
//~^ ERROR E0161
|
||||
//~^^ ERROR cannot move out of dereference
|
||||
//~^^ ERROR cannot move out of borrowed content
|
||||
|
||||
let array: &[int] = &[1, 2, 3];
|
||||
let _x: Box<[int]> = box *array;
|
||||
//~^ ERROR E0161
|
||||
//~^^ ERROR cannot move out of dereference
|
||||
//~^^ ERROR cannot move out of borrowed content
|
||||
}
|
||||
|
|
|
@ -12,11 +12,11 @@ fn match_vecs<'a, T>(l1: &'a [T], l2: &'a [T]) {
|
|||
match (l1, l2) {
|
||||
([], []) => println!("both empty"),
|
||||
([], [hd, tl..]) | ([hd, tl..], []) => println!("one empty"),
|
||||
//~^ ERROR: cannot move out of dereference
|
||||
//~^^ ERROR: cannot move out of dereference
|
||||
//~^ ERROR: cannot move out of borrowed content
|
||||
//~^^ ERROR: cannot move out of borrowed content
|
||||
([hd1, tl1..], [hd2, tl2..]) => println!("both nonempty"),
|
||||
//~^ ERROR: cannot move out of dereference
|
||||
//~^^ ERROR: cannot move out of dereference
|
||||
//~^ ERROR: cannot move out of borrowed content
|
||||
//~^^ ERROR: cannot move out of borrowed content
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,6 @@
|
|||
|
||||
fn main() {
|
||||
(|&:| box *[0us].as_slice())();
|
||||
//~^ ERROR cannot move out of dereference
|
||||
//~^ ERROR cannot move out of borrowed content
|
||||
//~^^ ERROR cannot move a value of type [usize]
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ trait parse {
|
|||
|
||||
impl parse for parser {
|
||||
fn parse(&self) -> Vec<int> {
|
||||
self.tokens //~ ERROR cannot move out of dereference of `&`-pointer
|
||||
self.tokens //~ ERROR cannot move out of borrowed content
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -23,5 +23,5 @@ fn main() {
|
|||
Foo::bar(&x); //~ERROR cannot borrow `x`
|
||||
|
||||
let x = Foo;
|
||||
Foo::baz(&x); //~ERROR cannot borrow immutable dereference of `&`-pointer as mutable
|
||||
Foo::baz(&x); //~ERROR cannot borrow immutable borrowed content as mutable
|
||||
}
|
||||
|
|
|
@ -14,5 +14,5 @@ fn main() {
|
|||
let x: &[int] = &[1, 2, 3, 4, 5];
|
||||
// Can't mutably slice an immutable slice
|
||||
let slice: &mut [int] = &mut [0, 1];
|
||||
let _ = &mut x[2..4]; //~ERROR cannot borrow immutable dereference of `&`-pointer `*x` as mutabl
|
||||
let _ = &mut x[2..4]; //~ERROR cannot borrow immutable borrowed content `*x` as mutable
|
||||
}
|
||||
|
|
|
@ -13,5 +13,5 @@
|
|||
fn main() {
|
||||
let x: &[int] = &[1, 2, 3, 4, 5];
|
||||
// Immutable slices are not mutable.
|
||||
let y: &mut[_] = &x[2..4]; //~ ERROR cannot borrow immutable dereference of `&`-pointer as mutab
|
||||
let y: &mut[_] = &x[2..4]; //~ ERROR cannot borrow immutable borrowed content as mutable
|
||||
}
|
||||
|
|
|
@ -16,11 +16,11 @@ use std::ptr;
|
|||
|
||||
fn main() {
|
||||
let x = ATOMIC_BOOL_INIT;
|
||||
let x = *&x; //~ ERROR: cannot move out of dereference
|
||||
let x = *&x; //~ ERROR: cannot move out of borrowed content
|
||||
let x = ATOMIC_INT_INIT;
|
||||
let x = *&x; //~ ERROR: cannot move out of dereference
|
||||
let x = *&x; //~ ERROR: cannot move out of borrowed content
|
||||
let x = ATOMIC_UINT_INIT;
|
||||
let x = *&x; //~ ERROR: cannot move out of dereference
|
||||
let x = *&x; //~ ERROR: cannot move out of borrowed content
|
||||
let x: AtomicPtr<uint> = AtomicPtr::new(ptr::null_mut());
|
||||
let x = *&x; //~ ERROR: cannot move out of dereference
|
||||
let x = *&x; //~ ERROR: cannot move out of borrowed content
|
||||
}
|
||||
|
|
|
@ -31,9 +31,9 @@ fn illegal_dereference<T: Not<Output=T>>(mut x: T, y: T) {
|
|||
let m = &mut x;
|
||||
let n = &y;
|
||||
|
||||
!*m; //~ ERROR: cannot move out of dereference of `&mut`-pointer
|
||||
!*m; //~ ERROR: cannot move out of borrowed content
|
||||
|
||||
!*n; //~ ERROR: cannot move out of dereference of `&`-pointer
|
||||
!*n; //~ ERROR: cannot move out of borrowed content
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
Loading…
Add table
Reference in a new issue