Skip to content

Commit 175ecfe

Browse files
author
Jonathan Turner
committed
Improve a few errors and fix #33366
1 parent 3e9747a commit 175ecfe

File tree

11 files changed

+68
-58
lines changed

11 files changed

+68
-58
lines changed

src/librustc/infer/error_reporting.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ use std::cell::{Cell, RefCell};
9090
use std::char::from_u32;
9191
use std::fmt;
9292
use syntax::ast;
93-
use syntax::errors::DiagnosticBuilder;
93+
use syntax::errors::{DiagnosticBuilder, check_old_skool};
9494
use syntax::codemap::{self, Pos, Span};
9595
use syntax::parse::token;
9696
use syntax::ptr::P;
@@ -481,7 +481,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
481481
"{}",
482482
trace.origin);
483483

484-
if !is_simple_error {
484+
if !is_simple_error || check_old_skool() {
485485
err.note_expected_found(&"type", &expected, &found);
486486
}
487487

src/librustc_borrowck/borrowck/check_loans.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,7 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
872872
&format!("borrow of `{}` occurs here",
873873
self.bccx.loan_path_to_string(loan_path)))
874874
.span_label(span,
875-
&format!("assignment to `{}` occurs here",
875+
&format!("assignment to borrowed `{}` occurs here",
876876
self.bccx.loan_path_to_string(loan_path)))
877877
.emit();
878878
}

src/librustc_borrowck/borrowck/gather_loans/move_error.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ fn report_cannot_move_out_of<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>,
126126
move_from.descriptive_string(bccx.tcx));
127127
err.span_label(
128128
move_from.span,
129-
&format!("move occurs here")
129+
&format!("cannot move out of {}", move_from.descriptive_string(bccx.tcx))
130130
);
131131
err
132132
}
@@ -138,7 +138,7 @@ fn report_cannot_move_out_of<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>,
138138
"cannot move out of type `{}`, \
139139
a non-copy fixed-size array",
140140
b.ty);
141-
err.span_label(move_from.span, &format!("can not move out of here"));
141+
err.span_label(move_from.span, &format!("cannot move out of here"));
142142
err
143143
} else {
144144
span_bug!(move_from.span, "this path should not cause illegal move");
@@ -154,7 +154,7 @@ fn report_cannot_move_out_of<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>,
154154
"cannot move out of type `{}`, \
155155
which defines the `Drop` trait",
156156
b.ty);
157-
err.span_label(move_from.span, &format!("can not move out of here"));
157+
err.span_label(move_from.span, &format!("cannot move out of here"));
158158
err
159159
},
160160
_ => {
@@ -175,16 +175,12 @@ fn note_move_destination(mut err: DiagnosticBuilder,
175175
if is_first_note {
176176
err.span_label(
177177
move_to_span,
178-
&format!("attempting to move value to here"));
179-
err.help(
180-
&format!("to prevent the move, \
181-
use `ref {0}` or `ref mut {0}` to capture value by \
182-
reference",
178+
&format!("hint: to prevent move, use `ref {0}` or `ref mut {0}`",
183179
pat_name));
184180
err
185181
} else {
186-
err.span_note(move_to_span,
187-
&format!("and here (use `ref {0}` or `ref mut {0}`)",
182+
err.span_label(move_to_span,
183+
&format!("...and here (use `ref {0}` or `ref mut {0}`)",
188184
pat_name));
189185
err
190186
}

src/libsyntax/errors/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -699,13 +699,13 @@ pub fn expect<T, M>(diag: &Handler, opt: Option<T>, msg: M) -> T where
699699
///
700700
/// FIXME(#33240)
701701
#[cfg(not(test))]
702-
fn check_old_skool() -> bool {
702+
pub fn check_old_skool() -> bool {
703703
use std::env;
704704
env::var("RUST_NEW_ERROR_FORMAT").is_err()
705705
}
706706

707707
/// For unit tests, use the new format.
708708
#[cfg(test)]
709-
fn check_old_skool() -> bool {
709+
pub fn check_old_skool() -> bool {
710710
false
711711
}

src/test/compile-fail/borrowck/borrowck-move-error-with-note.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ enum Foo {
1919
fn blah() {
2020
let f = &Foo::Foo1(box 1, box 2);
2121
match *f { //~ ERROR cannot move out of
22-
//~| move occurs here
23-
Foo::Foo1(num1, //~ NOTE attempting to move value to here
22+
//~| cannot move out
23+
Foo::Foo1(num1, //~ NOTE to prevent move
2424
num2) => (), //~ NOTE and here
2525
Foo::Foo2(num) => (), //~ NOTE and here
2626
Foo::Foo3 => ()
@@ -38,8 +38,8 @@ impl Drop for S {
3838
fn move_in_match() {
3939
match (S {f: "foo".to_string(), g: "bar".to_string()}) {
4040
S { //~ ERROR cannot move out of type `S`, which defines the `Drop` trait
41-
//~| can not move out of here
42-
f: _s, //~ NOTE attempting to move value to here
41+
//~| cannot move out of here
42+
f: _s, //~ NOTE to prevent move
4343
g: _t //~ NOTE and here
4444
} => {}
4545
}
@@ -55,8 +55,8 @@ fn free<T>(_: T) {}
5555
fn blah2() {
5656
let a = &A { a: box 1 };
5757
match a.a { //~ ERROR cannot move out of
58-
//~| move occurs here
59-
n => { //~ NOTE attempting to move value to here
58+
//~| cannot move out
59+
n => { //~ NOTE to prevent move
6060
free(n)
6161
}
6262
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ pub fn main() {
2929
match tail {
3030
[Foo { string: a },
3131
//~^ ERROR cannot move out of borrowed content
32-
//~| move occurs here
33-
//~| attempting to move value to here
32+
//~| cannot move out
33+
//~| to prevent move
3434
Foo { string: b }] => {
3535
//~^ NOTE and here
3636
}

src/test/compile-fail/borrowck/borrowck-vec-pattern-nesting.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fn a() {
1919
[box ref _a, _, _] => {
2020
//~^ borrow of `vec[..]` occurs here
2121
vec[0] = box 4; //~ ERROR cannot assign
22-
//~^ assignment to `vec[..]` occurs here
22+
//~^ assignment to borrowed `vec[..]` occurs here
2323
}
2424
}
2525
}
@@ -31,7 +31,7 @@ fn b() {
3131
[_b..] => {
3232
//~^ borrow of `vec[..]` occurs here
3333
vec[0] = box 4; //~ ERROR cannot assign
34-
//~^ assignment to `vec[..]` occurs here
34+
//~^ assignment to borrowed `vec[..]` occurs here
3535
}
3636
}
3737
}
@@ -41,8 +41,8 @@ fn c() {
4141
let vec: &mut [Box<isize>] = &mut vec;
4242
match vec {
4343
[_a, //~ ERROR cannot move out
44-
//~| move occurs here
45-
//~| attempting to move value to here
44+
//~| cannot move out
45+
//~| to prevent move
4646
_b..] => {
4747
// Note: `_a` is *moved* here, but `b` is borrowing,
4848
// hence illegal.
@@ -53,38 +53,38 @@ fn c() {
5353
_ => {}
5454
}
5555
let a = vec[0]; //~ ERROR cannot move out
56-
//~^ NOTE attempting to move value to here
57-
//~| can not move out of here
56+
//~^ NOTE to prevent move
57+
//~| cannot move out of here
5858
}
5959

6060
fn d() {
6161
let mut vec = vec!(box 1, box 2, box 3);
6262
let vec: &mut [Box<isize>] = &mut vec;
6363
match vec {
6464
[_a.., //~ ERROR cannot move out
65-
//~^ move occurs here
66-
_b] => {} //~ NOTE attempting to move value to here
65+
//~^ cannot move out
66+
_b] => {} //~ NOTE to prevent move
6767
_ => {}
6868
}
6969
let a = vec[0]; //~ ERROR cannot move out
70-
//~^ NOTE attempting to move value to here
71-
//~| can not move out of here
70+
//~^ NOTE to prevent move
71+
//~| cannot move out of here
7272
}
7373

7474
fn e() {
7575
let mut vec = vec!(box 1, box 2, box 3);
7676
let vec: &mut [Box<isize>] = &mut vec;
7777
match vec {
7878
[_a, _b, _c] => {} //~ ERROR cannot move out
79-
//~| move occurs here
80-
//~| NOTE attempting to move value to here
79+
//~| cannot move out
80+
//~| NOTE to prevent move
8181
//~| NOTE and here
8282
//~| NOTE and here
8383
_ => {}
8484
}
8585
let a = vec[0]; //~ ERROR cannot move out
86-
//~^ NOTE attempting to move value to here
87-
//~| can not move out of here
86+
//~^ NOTE to prevent move
87+
//~| cannot move out of here
8888
}
8989

9090
fn main() {}

src/test/compile-fail/issue-26480.rs

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ macro_rules! write {
2626
$arr.len() * size_of($arr[0]));
2727
//~^ ERROR mismatched types
2828
//~| expected u64, found usize
29+
//~| expected type
30+
//~| found type
2931
}
3032
}}
3133
}
@@ -38,6 +40,8 @@ fn main() {
3840
let hello = ['H', 'e', 'y'];
3941
write!(hello);
4042
//~^ NOTE in this expansion of write!
43+
//~| NOTE in this expansion of write!
44+
//~| NOTE in this expansion of write!
4145

4246
cast!(2);
4347
//~^ NOTE in this expansion of cast!

src/test/compile-fail/moves-based-on-type-block-bad.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@ fn main() {
3232
loop {
3333
f(&s, |hellothere| {
3434
match hellothere.x { //~ ERROR cannot move out
35-
//~| move occurs here
35+
//~| cannot move out of borrowed content
3636
box E::Foo(_) => {}
37-
box E::Bar(x) => println!("{}", x.to_string()), //~ NOTE attempting to move value to here
37+
box E::Bar(x) => println!("{}", x.to_string()),
38+
//~^ NOTE to prevent move
3839
box E::Baz => {}
3940
}
4041
})

src/tools/compiletest/src/json.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use errors::{Error, ErrorKind};
1212
use rustc_serialize::json;
1313
use std::str::FromStr;
1414
use std::path::Path;
15-
use runtest::{fatal_proc_rec, ProcRes};
15+
use runtest::{ProcRes};
1616

1717
// These structs are a subset of the ones found in
1818
// `syntax::errors::json`.
@@ -73,9 +73,9 @@ fn parse_line(file_name: &str, line: &str, output: &str, proc_res: &ProcRes) ->
7373
expected_errors
7474
}
7575
Err(error) => {
76-
fatal_proc_rec(None, &format!(
76+
proc_res.fatal(Some(&format!(
7777
"failed to decode compiler output as json: `{}`\noutput: {}\nline: {}",
78-
error, line, output), proc_res);
78+
error, line, output)));
7979
}
8080
}
8181
} else {

src/tools/compiletest/src/runtest.rs

+25-16
Original file line numberDiff line numberDiff line change
@@ -1528,23 +1528,9 @@ actual:\n\
15281528
self.error(err); panic!();
15291529
}
15301530

1531-
pub fn fatal_proc_rec(&self, err: &str, proc_res: &ProcRes) -> ! {
1531+
fn fatal_proc_rec(&self, err: &str, proc_res: &ProcRes) -> ! {
15321532
self.error(err);
1533-
print!("\
1534-
status: {}\n\
1535-
command: {}\n\
1536-
stdout:\n\
1537-
------------------------------------------\n\
1538-
{}\n\
1539-
------------------------------------------\n\
1540-
stderr:\n\
1541-
------------------------------------------\n\
1542-
{}\n\
1543-
------------------------------------------\n\
1544-
\n",
1545-
proc_res.status, proc_res.cmdline, proc_res.stdout,
1546-
proc_res.stderr);
1547-
panic!();
1533+
proc_res.fatal(None);
15481534
}
15491535

15501536
fn _arm_exec_compiled_test(&self, env: Vec<(String, String)>) -> ProcRes {
@@ -2209,6 +2195,29 @@ enum Status {
22092195
Normal(ExitStatus),
22102196
}
22112197

2198+
impl ProcRes {
2199+
pub fn fatal(&self, err: Option<&str>) -> ! {
2200+
if let Some(e) = err {
2201+
println!("\nerror: {}", e);
2202+
}
2203+
print!("\
2204+
status: {}\n\
2205+
command: {}\n\
2206+
stdout:\n\
2207+
------------------------------------------\n\
2208+
{}\n\
2209+
------------------------------------------\n\
2210+
stderr:\n\
2211+
------------------------------------------\n\
2212+
{}\n\
2213+
------------------------------------------\n\
2214+
\n",
2215+
self.status, self.cmdline, self.stdout,
2216+
self.stderr);
2217+
panic!();
2218+
}
2219+
}
2220+
22122221
impl Status {
22132222
fn code(&self) -> Option<i32> {
22142223
match *self {

0 commit comments

Comments
 (0)