Improve a few errors and fix #33366
This commit is contained in:
parent
3e9747af49
commit
175ecfefd5
11 changed files with 68 additions and 58 deletions
|
|
@ -90,7 +90,7 @@ use std::cell::{Cell, RefCell};
|
|||
use std::char::from_u32;
|
||||
use std::fmt;
|
||||
use syntax::ast;
|
||||
use syntax::errors::DiagnosticBuilder;
|
||||
use syntax::errors::{DiagnosticBuilder, check_old_skool};
|
||||
use syntax::codemap::{self, Pos, Span};
|
||||
use syntax::parse::token;
|
||||
use syntax::ptr::P;
|
||||
|
|
@ -481,7 +481,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
|||
"{}",
|
||||
trace.origin);
|
||||
|
||||
if !is_simple_error {
|
||||
if !is_simple_error || check_old_skool() {
|
||||
err.note_expected_found(&"type", &expected, &found);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -872,7 +872,7 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
|
|||
&format!("borrow of `{}` occurs here",
|
||||
self.bccx.loan_path_to_string(loan_path)))
|
||||
.span_label(span,
|
||||
&format!("assignment to `{}` occurs here",
|
||||
&format!("assignment to borrowed `{}` occurs here",
|
||||
self.bccx.loan_path_to_string(loan_path)))
|
||||
.emit();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -126,7 +126,7 @@ fn report_cannot_move_out_of<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>,
|
|||
move_from.descriptive_string(bccx.tcx));
|
||||
err.span_label(
|
||||
move_from.span,
|
||||
&format!("move occurs here")
|
||||
&format!("cannot move out of {}", move_from.descriptive_string(bccx.tcx))
|
||||
);
|
||||
err
|
||||
}
|
||||
|
|
@ -138,7 +138,7 @@ fn report_cannot_move_out_of<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>,
|
|||
"cannot move out of type `{}`, \
|
||||
a non-copy fixed-size array",
|
||||
b.ty);
|
||||
err.span_label(move_from.span, &format!("can not move out of here"));
|
||||
err.span_label(move_from.span, &format!("cannot move out of here"));
|
||||
err
|
||||
} else {
|
||||
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>,
|
|||
"cannot move out of type `{}`, \
|
||||
which defines the `Drop` trait",
|
||||
b.ty);
|
||||
err.span_label(move_from.span, &format!("can not move out of here"));
|
||||
err.span_label(move_from.span, &format!("cannot move out of here"));
|
||||
err
|
||||
},
|
||||
_ => {
|
||||
|
|
@ -175,16 +175,12 @@ fn note_move_destination(mut err: DiagnosticBuilder,
|
|||
if is_first_note {
|
||||
err.span_label(
|
||||
move_to_span,
|
||||
&format!("attempting to move value to here"));
|
||||
err.help(
|
||||
&format!("to prevent the move, \
|
||||
use `ref {0}` or `ref mut {0}` to capture value by \
|
||||
reference",
|
||||
&format!("hint: to prevent move, use `ref {0}` or `ref mut {0}`",
|
||||
pat_name));
|
||||
err
|
||||
} else {
|
||||
err.span_note(move_to_span,
|
||||
&format!("and here (use `ref {0}` or `ref mut {0}`)",
|
||||
err.span_label(move_to_span,
|
||||
&format!("...and here (use `ref {0}` or `ref mut {0}`)",
|
||||
pat_name));
|
||||
err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -699,13 +699,13 @@ pub fn expect<T, M>(diag: &Handler, opt: Option<T>, msg: M) -> T where
|
|||
///
|
||||
/// FIXME(#33240)
|
||||
#[cfg(not(test))]
|
||||
fn check_old_skool() -> bool {
|
||||
pub fn check_old_skool() -> bool {
|
||||
use std::env;
|
||||
env::var("RUST_NEW_ERROR_FORMAT").is_err()
|
||||
}
|
||||
|
||||
/// For unit tests, use the new format.
|
||||
#[cfg(test)]
|
||||
fn check_old_skool() -> bool {
|
||||
pub fn check_old_skool() -> bool {
|
||||
false
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,8 +19,8 @@ enum Foo {
|
|||
fn blah() {
|
||||
let f = &Foo::Foo1(box 1, box 2);
|
||||
match *f { //~ ERROR cannot move out of
|
||||
//~| move occurs here
|
||||
Foo::Foo1(num1, //~ NOTE attempting to move value to here
|
||||
//~| cannot move out
|
||||
Foo::Foo1(num1, //~ NOTE to prevent move
|
||||
num2) => (), //~ NOTE and here
|
||||
Foo::Foo2(num) => (), //~ NOTE and here
|
||||
Foo::Foo3 => ()
|
||||
|
|
@ -38,8 +38,8 @@ impl Drop for S {
|
|||
fn move_in_match() {
|
||||
match (S {f: "foo".to_string(), g: "bar".to_string()}) {
|
||||
S { //~ ERROR cannot move out of type `S`, which defines the `Drop` trait
|
||||
//~| can not move out of here
|
||||
f: _s, //~ NOTE attempting to move value to here
|
||||
//~| cannot move out of here
|
||||
f: _s, //~ NOTE to prevent move
|
||||
g: _t //~ NOTE and here
|
||||
} => {}
|
||||
}
|
||||
|
|
@ -55,8 +55,8 @@ fn free<T>(_: T) {}
|
|||
fn blah2() {
|
||||
let a = &A { a: box 1 };
|
||||
match a.a { //~ ERROR cannot move out of
|
||||
//~| move occurs here
|
||||
n => { //~ NOTE attempting to move value to here
|
||||
//~| cannot move out
|
||||
n => { //~ NOTE to prevent move
|
||||
free(n)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,8 +29,8 @@ pub fn main() {
|
|||
match tail {
|
||||
[Foo { string: a },
|
||||
//~^ ERROR cannot move out of borrowed content
|
||||
//~| move occurs here
|
||||
//~| attempting to move value to here
|
||||
//~| cannot move out
|
||||
//~| to prevent move
|
||||
Foo { string: b }] => {
|
||||
//~^ NOTE and here
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ fn a() {
|
|||
[box ref _a, _, _] => {
|
||||
//~^ borrow of `vec[..]` occurs here
|
||||
vec[0] = box 4; //~ ERROR cannot assign
|
||||
//~^ assignment to `vec[..]` occurs here
|
||||
//~^ assignment to borrowed `vec[..]` occurs here
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -31,7 +31,7 @@ fn b() {
|
|||
[_b..] => {
|
||||
//~^ borrow of `vec[..]` occurs here
|
||||
vec[0] = box 4; //~ ERROR cannot assign
|
||||
//~^ assignment to `vec[..]` occurs here
|
||||
//~^ assignment to borrowed `vec[..]` occurs here
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -41,8 +41,8 @@ fn c() {
|
|||
let vec: &mut [Box<isize>] = &mut vec;
|
||||
match vec {
|
||||
[_a, //~ ERROR cannot move out
|
||||
//~| move occurs here
|
||||
//~| attempting to move value to here
|
||||
//~| cannot move out
|
||||
//~| to prevent move
|
||||
_b..] => {
|
||||
// Note: `_a` is *moved* here, but `b` is borrowing,
|
||||
// hence illegal.
|
||||
|
|
@ -53,8 +53,8 @@ fn c() {
|
|||
_ => {}
|
||||
}
|
||||
let a = vec[0]; //~ ERROR cannot move out
|
||||
//~^ NOTE attempting to move value to here
|
||||
//~| can not move out of here
|
||||
//~^ NOTE to prevent move
|
||||
//~| cannot move out of here
|
||||
}
|
||||
|
||||
fn d() {
|
||||
|
|
@ -62,13 +62,13 @@ fn d() {
|
|||
let vec: &mut [Box<isize>] = &mut vec;
|
||||
match vec {
|
||||
[_a.., //~ ERROR cannot move out
|
||||
//~^ move occurs here
|
||||
_b] => {} //~ NOTE attempting to move value to here
|
||||
//~^ cannot move out
|
||||
_b] => {} //~ NOTE to prevent move
|
||||
_ => {}
|
||||
}
|
||||
let a = vec[0]; //~ ERROR cannot move out
|
||||
//~^ NOTE attempting to move value to here
|
||||
//~| can not move out of here
|
||||
//~^ NOTE to prevent move
|
||||
//~| cannot move out of here
|
||||
}
|
||||
|
||||
fn e() {
|
||||
|
|
@ -76,15 +76,15 @@ fn e() {
|
|||
let vec: &mut [Box<isize>] = &mut vec;
|
||||
match vec {
|
||||
[_a, _b, _c] => {} //~ ERROR cannot move out
|
||||
//~| move occurs here
|
||||
//~| NOTE attempting to move value to here
|
||||
//~| cannot move out
|
||||
//~| NOTE to prevent move
|
||||
//~| NOTE and here
|
||||
//~| NOTE and here
|
||||
_ => {}
|
||||
}
|
||||
let a = vec[0]; //~ ERROR cannot move out
|
||||
//~^ NOTE attempting to move value to here
|
||||
//~| can not move out of here
|
||||
//~^ NOTE to prevent move
|
||||
//~| cannot move out of here
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -26,6 +26,8 @@ macro_rules! write {
|
|||
$arr.len() * size_of($arr[0]));
|
||||
//~^ ERROR mismatched types
|
||||
//~| expected u64, found usize
|
||||
//~| expected type
|
||||
//~| found type
|
||||
}
|
||||
}}
|
||||
}
|
||||
|
|
@ -38,6 +40,8 @@ fn main() {
|
|||
let hello = ['H', 'e', 'y'];
|
||||
write!(hello);
|
||||
//~^ NOTE in this expansion of write!
|
||||
//~| NOTE in this expansion of write!
|
||||
//~| NOTE in this expansion of write!
|
||||
|
||||
cast!(2);
|
||||
//~^ NOTE in this expansion of cast!
|
||||
|
|
|
|||
|
|
@ -32,9 +32,10 @@ fn main() {
|
|||
loop {
|
||||
f(&s, |hellothere| {
|
||||
match hellothere.x { //~ ERROR cannot move out
|
||||
//~| move occurs here
|
||||
//~| cannot move out of borrowed content
|
||||
box E::Foo(_) => {}
|
||||
box E::Bar(x) => println!("{}", x.to_string()), //~ NOTE attempting to move value to here
|
||||
box E::Bar(x) => println!("{}", x.to_string()),
|
||||
//~^ NOTE to prevent move
|
||||
box E::Baz => {}
|
||||
}
|
||||
})
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ use errors::{Error, ErrorKind};
|
|||
use rustc_serialize::json;
|
||||
use std::str::FromStr;
|
||||
use std::path::Path;
|
||||
use runtest::{fatal_proc_rec, ProcRes};
|
||||
use runtest::{ProcRes};
|
||||
|
||||
// These structs are a subset of the ones found in
|
||||
// `syntax::errors::json`.
|
||||
|
|
@ -73,9 +73,9 @@ fn parse_line(file_name: &str, line: &str, output: &str, proc_res: &ProcRes) ->
|
|||
expected_errors
|
||||
}
|
||||
Err(error) => {
|
||||
fatal_proc_rec(None, &format!(
|
||||
proc_res.fatal(Some(&format!(
|
||||
"failed to decode compiler output as json: `{}`\noutput: {}\nline: {}",
|
||||
error, line, output), proc_res);
|
||||
error, line, output)));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -1528,23 +1528,9 @@ actual:\n\
|
|||
self.error(err); panic!();
|
||||
}
|
||||
|
||||
pub fn fatal_proc_rec(&self, err: &str, proc_res: &ProcRes) -> ! {
|
||||
fn fatal_proc_rec(&self, err: &str, proc_res: &ProcRes) -> ! {
|
||||
self.error(err);
|
||||
print!("\
|
||||
status: {}\n\
|
||||
command: {}\n\
|
||||
stdout:\n\
|
||||
------------------------------------------\n\
|
||||
{}\n\
|
||||
------------------------------------------\n\
|
||||
stderr:\n\
|
||||
------------------------------------------\n\
|
||||
{}\n\
|
||||
------------------------------------------\n\
|
||||
\n",
|
||||
proc_res.status, proc_res.cmdline, proc_res.stdout,
|
||||
proc_res.stderr);
|
||||
panic!();
|
||||
proc_res.fatal(None);
|
||||
}
|
||||
|
||||
fn _arm_exec_compiled_test(&self, env: Vec<(String, String)>) -> ProcRes {
|
||||
|
|
@ -2209,6 +2195,29 @@ enum Status {
|
|||
Normal(ExitStatus),
|
||||
}
|
||||
|
||||
impl ProcRes {
|
||||
pub fn fatal(&self, err: Option<&str>) -> ! {
|
||||
if let Some(e) = err {
|
||||
println!("\nerror: {}", e);
|
||||
}
|
||||
print!("\
|
||||
status: {}\n\
|
||||
command: {}\n\
|
||||
stdout:\n\
|
||||
------------------------------------------\n\
|
||||
{}\n\
|
||||
------------------------------------------\n\
|
||||
stderr:\n\
|
||||
------------------------------------------\n\
|
||||
{}\n\
|
||||
------------------------------------------\n\
|
||||
\n",
|
||||
self.status, self.cmdline, self.stdout,
|
||||
self.stderr);
|
||||
panic!();
|
||||
}
|
||||
}
|
||||
|
||||
impl Status {
|
||||
fn code(&self) -> Option<i32> {
|
||||
match *self {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue