Skip to content

Commit 2387651

Browse files
committed
Update the "English-language" to-string function of a cmt to use
more modern terminology and update tests accordingly.
1 parent 0a32010 commit 2387651

24 files changed

+124
-87
lines changed

src/librustc/middle/mem_categorization.rs

Lines changed: 74 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ use middle::def;
7575
use middle::region;
7676
use middle::ty::{self, Ty};
7777
use util::nodemap::{NodeMap};
78-
use util::ppaux::{Repr};
78+
use util::ppaux::{Repr, UserString};
7979

8080
use syntax::ast::{MutImmutable, MutMutable};
8181
use syntax::ast;
@@ -113,10 +113,17 @@ pub struct Upvar {
113113
// different kinds of pointers:
114114
#[derive(Clone, Copy, PartialEq, Eq, Hash, Show)]
115115
pub enum PointerKind {
116+
/// `Box<T>`
116117
Unique,
118+
119+
/// `&T`
117120
BorrowedPtr(ty::BorrowKind, ty::Region),
118-
Implicit(ty::BorrowKind, ty::Region), // Implicit deref of a borrowed ptr.
119-
UnsafePtr(ast::Mutability)
121+
122+
/// `*T`
123+
UnsafePtr(ast::Mutability),
124+
125+
/// Implicit deref of the `&T` that results from an overloaded index `[]`.
126+
Implicit(ty::BorrowKind, ty::Region),
120127
}
121128

122129
// We use the term "interior" to mean "something reachable from the
@@ -1392,22 +1399,6 @@ impl<'tcx> cmt_<'tcx> {
13921399

13931400

13941401
pub fn descriptive_string(&self, tcx: &ty::ctxt) -> String {
1395-
fn upvar_to_string(upvar: &Upvar, is_copy: bool) -> String {
1396-
if upvar.is_unboxed {
1397-
let kind = match upvar.kind {
1398-
ty::FnUnboxedClosureKind => "Fn",
1399-
ty::FnMutUnboxedClosureKind => "FnMut",
1400-
ty::FnOnceUnboxedClosureKind => "FnOnce"
1401-
};
1402-
format!("captured outer variable in an `{}` closure", kind)
1403-
} else {
1404-
(match (upvar.kind, is_copy) {
1405-
(ty::FnOnceUnboxedClosureKind, true) => "captured outer variable in a proc",
1406-
_ => "captured outer variable"
1407-
}).to_string()
1408-
}
1409-
}
1410-
14111402
match self.cat {
14121403
cat_static_item => {
14131404
"static item".to_string()
@@ -1427,16 +1418,23 @@ impl<'tcx> cmt_<'tcx> {
14271418
let upvar = self.upvar();
14281419
match upvar.as_ref().map(|i| &i.cat) {
14291420
Some(&cat_upvar(ref var)) => {
1430-
upvar_to_string(var, false)
1421+
var.user_string(tcx)
14311422
}
14321423
Some(_) => unreachable!(),
14331424
None => {
14341425
match pk {
14351426
Implicit(..) => {
1436-
"dereference (dereference is implicit, due to indexing)".to_string()
1427+
format!("indexed content")
1428+
}
1429+
Unique => {
1430+
format!("`Box` content")
1431+
}
1432+
UnsafePtr(..) => {
1433+
format!("dereference of unsafe pointer")
1434+
}
1435+
BorrowedPtr(..) => {
1436+
format!("borrowed content")
14371437
}
1438-
Unique => format!("dereference of `{}`", ptr_sigil(pk)),
1439-
_ => format!("dereference of `{}`-pointer", ptr_sigil(pk))
14401438
}
14411439
}
14421440
}
@@ -1447,14 +1445,12 @@ impl<'tcx> cmt_<'tcx> {
14471445
cat_interior(_, InteriorField(PositionalField(_))) => {
14481446
"anonymous field".to_string()
14491447
}
1450-
cat_interior(_, InteriorElement(VecElement)) => {
1451-
"vec content".to_string()
1452-
}
1448+
cat_interior(_, InteriorElement(VecElement)) |
14531449
cat_interior(_, InteriorElement(OtherElement)) => {
14541450
"indexed content".to_string()
14551451
}
14561452
cat_upvar(ref var) => {
1457-
upvar_to_string(var, true)
1453+
var.user_string(tcx)
14581454
}
14591455
cat_downcast(ref cmt, _) => {
14601456
cmt.descriptive_string(tcx)
@@ -1483,7 +1479,7 @@ impl<'tcx> Repr<'tcx> for categorization<'tcx> {
14831479
format!("{:?}", *self)
14841480
}
14851481
cat_deref(ref cmt, derefs, ptr) => {
1486-
format!("{}-{}{}->", cmt.cat.repr(tcx), ptr_sigil(ptr), derefs)
1482+
format!("{}-{}{}->", cmt.cat.repr(tcx), ptr.repr(tcx), derefs)
14871483
}
14881484
cat_interior(ref cmt, interior) => {
14891485
format!("{}.{}", cmt.cat.repr(tcx), interior.repr(tcx))
@@ -1504,7 +1500,32 @@ pub fn ptr_sigil(ptr: PointerKind) -> &'static str {
15041500
Implicit(ty::MutBorrow, _) => "&mut",
15051501
BorrowedPtr(ty::UniqueImmBorrow, _) |
15061502
Implicit(ty::UniqueImmBorrow, _) => "&unique",
1507-
UnsafePtr(_) => "*"
1503+
UnsafePtr(_) => "*",
1504+
}
1505+
}
1506+
1507+
impl<'tcx> Repr<'tcx> for PointerKind {
1508+
fn repr(&self, tcx: &ty::ctxt<'tcx>) -> String {
1509+
match *self {
1510+
Unique => {
1511+
format!("Box")
1512+
}
1513+
BorrowedPtr(ty::ImmBorrow, ref r) |
1514+
Implicit(ty::ImmBorrow, ref r) => {
1515+
format!("&{}", r.repr(tcx))
1516+
}
1517+
BorrowedPtr(ty::MutBorrow, ref r) |
1518+
Implicit(ty::MutBorrow, ref r) => {
1519+
format!("&{} mut", r.repr(tcx))
1520+
}
1521+
BorrowedPtr(ty::UniqueImmBorrow, ref r) |
1522+
Implicit(ty::UniqueImmBorrow, ref r) => {
1523+
format!("&{} uniq", r.repr(tcx))
1524+
}
1525+
UnsafePtr(_) => {
1526+
format!("*")
1527+
}
1528+
}
15081529
}
15091530
}
15101531

@@ -1531,3 +1552,27 @@ fn element_kind(t: Ty) -> ElementKind {
15311552
_ => OtherElement
15321553
}
15331554
}
1555+
1556+
impl<'tcx> Repr<'tcx> for ty::UnboxedClosureKind {
1557+
fn repr(&self, _: &ty::ctxt) -> String {
1558+
format!("Upvar({:?})", self)
1559+
}
1560+
}
1561+
1562+
impl<'tcx> Repr<'tcx> for Upvar {
1563+
fn repr(&self, tcx: &ty::ctxt) -> String {
1564+
format!("Upvar({})", self.kind.repr(tcx))
1565+
}
1566+
}
1567+
1568+
impl<'tcx> UserString<'tcx> for Upvar {
1569+
fn user_string(&self, _: &ty::ctxt) -> String {
1570+
let kind = match self.kind {
1571+
ty::FnUnboxedClosureKind => "Fn",
1572+
ty::FnMutUnboxedClosureKind => "FnMut",
1573+
ty::FnOnceUnboxedClosureKind => "FnOnce",
1574+
};
1575+
format!("captured outer variable in an `{}` closure", kind)
1576+
}
1577+
}
1578+

src/librustc_borrowck/borrowck/gather_loans/move_error.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -115,29 +115,31 @@ fn report_cannot_move_out_of<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>,
115115
match move_from.cat {
116116
mc::cat_deref(_, _, mc::BorrowedPtr(..)) |
117117
mc::cat_deref(_, _, mc::Implicit(..)) |
118-
mc::cat_deref(_, _, mc::UnsafePtr(..)) |
119118
mc::cat_static_item => {
120-
bccx.span_err(
121-
move_from.span,
122-
&format!("cannot move out of {}",
123-
bccx.cmt_to_string(&*move_from))[]);
119+
bccx.span_err(move_from.span,
120+
&format!("cannot move out of {}",
121+
move_from.descriptive_string(bccx.tcx))[]);
124122
}
125123

126124
mc::cat_downcast(ref b, _) |
127125
mc::cat_interior(ref b, _) => {
128126
match b.ty.sty {
129-
ty::ty_struct(did, _)
130-
| ty::ty_enum(did, _) if ty::has_dtor(bccx.tcx, did) => {
127+
ty::ty_struct(did, _) |
128+
ty::ty_enum(did, _) if ty::has_dtor(bccx.tcx, did) => {
131129
bccx.span_err(
132130
move_from.span,
133131
&format!("cannot move out of type `{}`, \
134132
which defines the `Drop` trait",
135133
b.ty.user_string(bccx.tcx))[]);
136134
},
137-
_ => panic!("this path should not cause illegal move")
135+
_ => {
136+
bccx.span_bug(move_from.span, "this path should not cause illegal move")
137+
}
138138
}
139139
}
140-
_ => panic!("this path should not cause illegal move")
140+
_ => {
141+
bccx.span_bug(move_from.span, "this path should not cause illegal move")
142+
}
141143
}
142144
}
143145

src/librustc_borrowck/borrowck/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,10 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
681681
self.tcx.sess.span_err(s, m);
682682
}
683683

684+
pub fn span_bug(&self, s: Span, m: &str) {
685+
self.tcx.sess.span_bug(s, m);
686+
}
687+
684688
pub fn span_note(&self, s: Span, m: &str) {
685689
self.tcx.sess.span_note(s, m);
686690
}

src/librustc_typeck/check/callee.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ pub fn check_call<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
7373
autoderef(fcx,
7474
callee_expr.span,
7575
original_callee_ty,
76-
Some(callee_expr.id),
76+
Some(callee_expr),
7777
LvaluePreference::NoPreference,
7878
|adj_ty, idx| {
7979
let autoderefref = ty::AutoDerefRef { autoderefs: idx, autoref: None };

src/librustc_typeck/check/mod.rs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2263,34 +2263,20 @@ pub enum LvaluePreference {
22632263
/// Executes an autoderef loop for the type `t`. At each step, invokes `should_stop` to decide
22642264
/// whether to terminate the loop. Returns the final type and number of derefs that it performed.
22652265
///
2266-
<<<<<<< HEAD
22672266
/// Note: this method does not modify the adjustments table. The caller is responsible for
22682267
/// inserting an AutoAdjustment record into the `fcx` using one of the suitable methods.
22692268
pub fn autoderef<'a, 'tcx, T, F>(fcx: &FnCtxt<'a, 'tcx>,
22702269
sp: Span,
2271-
||||||| merged common ancestors
2272-
/// Note: this method does not modify the adjustments table. The caller is responsible for
2273-
/// inserting an AutoAdjustment record into the `fcx` using one of the suitable methods.
2274-
pub fn autoderef<'a, 'tcx, T, F>(fcx: &FnCtxt<'a, 'tcx>, sp: Span,
2275-
=======
2276-
/// Note: this method does not modify the adjustments table. The
2277-
/// caller is responsible for inserting an AutoAdjustment record into
2278-
/// the `fcx` using one of the suitable methods. However, if
2279-
/// `opt_expr` is not `None`, it *will* insert the appropriate method
2280-
/// entries for the overloaded deref call.
2281-
pub fn autoderef<'a, 'tcx, T, F>(fcx: &FnCtxt<'a, 'tcx>,
2282-
sp: Span,
2283-
>>>>>>> Add comments to autoderef() helper and refactor it to take
22842270
base_ty: Ty<'tcx>,
22852271
opt_expr: Option<&ast::Expr>,
22862272
mut lvalue_pref: LvaluePreference,
22872273
mut should_stop: F)
22882274
-> (Ty<'tcx>, uint, Option<T>)
22892275
where F: FnMut(Ty<'tcx>, uint) -> Option<T>,
22902276
{
2291-
debug!("autoderef(base_ty={}, opt_expr={}, lvalue_pref={})",
2277+
debug!("autoderef(base_ty={}, opt_expr={}, lvalue_pref={:?})",
22922278
base_ty.repr(fcx.tcx()),
2293-
opt_expr,
2279+
opt_expr.repr(fcx.tcx()),
22942280
lvalue_pref);
22952281

22962282
let mut t = base_ty;

src/test/compile-fail/binop-move-semantics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ fn illegal_dereference<T: Add<Output=()>>(mut x: T, y: T) {
3737
let m = &mut x;
3838
let n = &y;
3939

40-
*m //~ ERROR: cannot move out of dereference of `&mut`-pointer
40+
*m //~ ERROR: cannot move out of borrowed content
4141
+
42-
*n; //~ ERROR: cannot move out of dereference of `&`-pointer
42+
*n; //~ ERROR: cannot move out of borrowed content
4343
}
4444

4545
struct Foo;

src/test/compile-fail/borrowck-borrow-immut-deref-of-box-as-mut.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ impl A {
2020
pub fn main() {
2121
let a = box A;
2222
a.foo();
23-
//~^ ERROR cannot borrow immutable dereference of `Box` `*a` as mutable
23+
//~^ ERROR cannot borrow immutable `Box` content `*a` as mutable
2424
}

src/test/compile-fail/borrowck-call-is-borrow-issue-12224.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ fn test1() {
3333
}
3434

3535
fn test2<F>(f: &F) where F: FnMut() {
36-
(*f)(); //~ ERROR: cannot borrow immutable dereference of `&`-pointer `*f` as mutable
36+
(*f)(); //~ ERROR: cannot borrow immutable borrowed content `*f` as mutable
3737
}
3838

3939
fn test3<F>(f: &mut F) where F: FnMut() {
4040
(*f)();
4141
}
4242

4343
fn test4(f: &Test) {
44-
f.f.call_mut(()) //~ ERROR: cannot borrow immutable dereference of `Box` `*f.f` as mutable
44+
f.f.call_mut(()) //~ ERROR: cannot borrow immutable `Box` content `*f.f` as mutable
4545
}
4646

4747
fn test5(f: &mut Test) {

src/test/compile-fail/borrowck-move-in-irrefut-pat.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@
1111
fn with<F>(f: F) where F: FnOnce(&String) {}
1212

1313
fn arg_item(&_x: &String) {}
14-
//~^ ERROR cannot move out of dereference of `&`-pointer
14+
//~^ ERROR cannot move out of borrowed content
1515

1616
fn arg_closure() {
1717
with(|&_x| ())
18-
//~^ ERROR cannot move out of dereference of `&`-pointer
18+
//~^ ERROR cannot move out of borrowed content
1919
}
2020

2121
fn let_pat() {
2222
let &_x = &"hi".to_string();
23-
//~^ ERROR cannot move out of dereference of `&`-pointer
23+
//~^ ERROR cannot move out of borrowed content
2424
}
2525

2626
pub fn main() {}

src/test/compile-fail/borrowck-move-out-of-overloaded-auto-deref.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ use std::rc::Rc;
1212

1313
pub fn main() {
1414
let _x = Rc::new(vec!(1i, 2)).into_iter();
15-
//~^ ERROR cannot move out of dereference of `&`-pointer
15+
//~^ ERROR cannot move out of borrowed content
1616
}

src/test/compile-fail/borrowck-move-out-of-overloaded-deref.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ use std::rc::Rc;
1212

1313
pub fn main() {
1414
let _x = *Rc::new("hi".to_string());
15-
//~^ ERROR cannot move out of dereference of `&`-pointer
15+
//~^ ERROR cannot move out of borrowed content
1616
}

src/test/compile-fail/borrowck-move-out-of-vec-tail.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub fn main() {
2525
match x {
2626
[_, tail..] => {
2727
match tail {
28-
[Foo { string: a }, //~ ERROR cannot move out of dereference of `&`-pointer
28+
[Foo { string: a }, //~ ERROR cannot move out of borrowed content
2929
Foo { string: b }] => {
3030
//~^^ NOTE attempting to move value to here
3131
//~^^ NOTE and here

src/test/compile-fail/borrowck-overloaded-index-2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@ fn main() {
2828
let v = MyVec { data: vec!(box 1i, box 2, box 3) };
2929
let good = &v[0]; // Shouldn't fail here
3030
let bad = v[0];
31-
//~^ ERROR cannot move out of dereference (dereference is implicit, due to indexing)
31+
//~^ ERROR cannot move out of indexed content
3232
}

src/test/compile-fail/borrowck-overloaded-index.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,5 @@ fn main() {
6666
x: 1,
6767
};
6868
s[2] = 20;
69-
//~^ ERROR cannot assign to immutable dereference (dereference is implicit, due to indexing)
69+
//~^ ERROR cannot assign to immutable indexed content
7070
}

src/test/compile-fail/dst-index.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ impl Index<uint> for T {
4141

4242
fn main() {
4343
S[0];
44-
//~^ ERROR cannot move out of dereference
44+
//~^ ERROR cannot move out of indexed content
4545
//~^^ ERROR E0161
4646
T[0];
47-
//~^ ERROR cannot move out of dereference
47+
//~^ ERROR cannot move out of indexed content
4848
//~^^ ERROR E0161
4949
}

src/test/compile-fail/dst-rvalue.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
pub fn main() {
1616
let _x: Box<str> = box *"hello world";
1717
//~^ ERROR E0161
18-
//~^^ ERROR cannot move out of dereference
18+
//~^^ ERROR cannot move out of borrowed content
1919

2020
let array: &[int] = &[1, 2, 3];
2121
let _x: Box<[int]> = box *array;
2222
//~^ ERROR E0161
23-
//~^^ ERROR cannot move out of dereference
23+
//~^^ ERROR cannot move out of borrowed content
2424
}

0 commit comments

Comments
 (0)