Skip to content

Assorted diagnostics improvements #27313

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 29, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/librustc/middle/resolve_lifetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -674,8 +674,7 @@ impl<'a> LifetimeContext<'a> {
for lifetime in lifetimes {
if special_idents.iter().any(|&i| i.name == lifetime.lifetime.name) {
span_err!(self.sess, lifetime.lifetime.span, E0262,
"illegal lifetime parameter name: `{}`",
lifetime.lifetime.name);
"invalid lifetime parameter name: `{}`", lifetime.lifetime.name);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trans/trans/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2325,7 +2325,7 @@ fn deref_once<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
_ => {
bcx.tcx().sess.span_bug(
expr.span,
&format!("deref invoked on expr of illegal type {:?}",
&format!("deref invoked on expr of invalid type {:?}",
datum.ty));
}
};
Expand Down
28 changes: 15 additions & 13 deletions src/librustc_typeck/check/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,20 +122,21 @@ impl<'tcx> CastCheck<'tcx> {
CastError::NeedViaInt |
CastError::NeedViaUsize => {
fcx.type_error_message(self.span, |actual| {
format!("illegal cast; cast through {} first: `{}` as `{}`",
match e {
CastError::NeedViaPtr => "a raw pointer",
CastError::NeedViaInt => "an integer",
CastError::NeedViaUsize => "a usize",
_ => unreachable!()
},
format!("casting `{}` as `{}` is invalid",
actual,
fcx.infcx().ty_to_string(self.cast_ty))
}, self.expr_ty, None)
}, self.expr_ty, None);
fcx.ccx.tcx.sess.fileline_help(self.span,
&format!("cast through {} first", match e {
CastError::NeedViaPtr => "a raw pointer",
CastError::NeedViaInt => "an integer",
CastError::NeedViaUsize => "a usize",
_ => unreachable!()
}));
}
CastError::CastToBool => {
span_err!(fcx.tcx().sess, self.span, E0054,
"cannot cast as `bool`, compare with zero instead");
span_err!(fcx.tcx().sess, self.span, E0054, "cannot cast as `bool`");
fcx.ccx.tcx.sess.fileline_help(self.span, "compare with zero instead");
}
CastError::CastToChar => {
fcx.type_error_message(self.span, |actual| {
Expand All @@ -151,17 +152,18 @@ impl<'tcx> CastCheck<'tcx> {
}
CastError::IllegalCast => {
fcx.type_error_message(self.span, |actual| {
format!("illegal cast: `{}` as `{}`",
format!("casting `{}` as `{}` is invalid",
actual,
fcx.infcx().ty_to_string(self.cast_ty))
}, self.expr_ty, None);
}
CastError::DifferingKinds => {
fcx.type_error_message(self.span, |actual| {
format!("illegal cast: `{}` as `{}`; vtable kinds may not match",
format!("casting `{}` as `{}` is invalid",
actual,
fcx.infcx().ty_to_string(self.cast_ty))
}, self.expr_ty, None);
fcx.ccx.tcx.sess.fileline_note(self.span, "vtable kinds may not match");
}
}
}
Expand Down Expand Up @@ -285,7 +287,7 @@ impl<'tcx> CastCheck<'tcx> {
return Ok(CastKind::PtrPtrCast);
}

// sized -> unsized? report illegal cast (don't complain about vtable kinds)
// sized -> unsized? report invalid cast (don't complain about vtable kinds)
if fcx.type_is_known_to_be_sized(m_expr.ty, self.span) {
return Err(CastError::IllegalCast);
}
Expand Down
8 changes: 3 additions & 5 deletions src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3468,7 +3468,7 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
let tcx = fcx.tcx();
if !tcx.expr_is_lval(&**lhs) {
span_err!(tcx.sess, expr.span, E0070,
"illegal left-hand side expression");
"invalid left-hand side expression");
}

let lhs_ty = fcx.expr_ty(&**lhs);
Expand Down Expand Up @@ -4273,10 +4273,8 @@ pub fn check_representable(tcx: &ty::ctxt,
// caught by case 1.
match rty.is_representable(tcx, sp) {
ty::SelfRecursive => {
span_err!(tcx.sess, sp, E0072,
"illegal recursive {} type; \
wrap the inner value in a box to make it representable",
designation);
span_err!(tcx.sess, sp, E0072, "invalid recursive {} type", designation);
tcx.sess.fileline_help(sp, "wrap the inner value in a box to make it representable");
return false
}
ty::Representable | ty::ContainsRecursive => (),
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/check/op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub fn check_binop_assign<'a,'tcx>(fcx: &FnCtxt<'a,'tcx>,

let tcx = fcx.tcx();
if !tcx.expr_is_lval(lhs_expr) {
span_err!(tcx.sess, lhs_expr.span, E0067, "illegal left-hand side expression");
span_err!(tcx.sess, lhs_expr.span, E0067, "invalid left-hand side expression");
}

fcx.require_expr_have_sized_type(lhs_expr, traits::AssignmentLhsSized);
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_typeck/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ the pointer the size of the type would need to be unbounded.
Consider the following erroneous definition of a type for a list of bytes:

```
// error, illegal recursive struct type
// error, invalid recursive struct type
struct ListNode {
head: u8,
tail: Option<ListNode>,
Expand Down Expand Up @@ -2345,7 +2345,7 @@ register_diagnostics! {
E0241,
E0242, // internal error looking up a definition
E0245, // not a trait
E0246, // illegal recursive type
E0246, // invalid recursive type
E0247, // found module name used as a type
E0248, // found value name used as a type
E0319, // trait impls for defaulted traits allowed just for structs/enums
Expand Down
16 changes: 8 additions & 8 deletions src/libsyntax/parse/lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ impl<'a> StringReader<'a> {
accum_int *= 16;
accum_int += c.to_digit(16).unwrap_or_else(|| {
self.err_span_char(self.last_pos, self.pos,
"illegal character in numeric character escape", c);
"invalid character in numeric character escape", c);

valid = false;
0
Expand All @@ -714,7 +714,7 @@ impl<'a> StringReader<'a> {
Some(_) => valid,
None => {
let last_bpos = self.last_pos;
self.err_span_(start_bpos, last_bpos, "illegal numeric character escape");
self.err_span_(start_bpos, last_bpos, "invalid numeric character escape");
false
}
}
Expand Down Expand Up @@ -846,7 +846,7 @@ impl<'a> StringReader<'a> {
"unterminated unicode escape (needed a `}`)");
} else {
self.err_span_char(self.last_pos, self.pos,
"illegal character in unicode escape", c);
"invalid character in unicode escape", c);
}
valid = false;
0
Expand All @@ -862,7 +862,7 @@ impl<'a> StringReader<'a> {
}

if valid && (char::from_u32(accum_int).is_none() || count == 0) {
self.err_span_(start_bpos, self.last_pos, "illegal unicode character escape");
self.err_span_(start_bpos, self.last_pos, "invalid unicode character escape");
valid = false;
}

Expand Down Expand Up @@ -1138,8 +1138,8 @@ impl<'a> StringReader<'a> {
let last_bpos = self.last_pos;
let curr_char = self.curr.unwrap();
self.fatal_span_char(start_bpos, last_bpos,
"only `#` is allowed in raw string delimitation; \
found illegal character",
"found invalid character; \
only `#` is allowed in raw string delimitation",
curr_char);
}
self.bump();
Expand Down Expand Up @@ -1323,8 +1323,8 @@ impl<'a> StringReader<'a> {
let last_pos = self.last_pos;
let ch = self.curr.unwrap();
self.fatal_span_char(start_bpos, last_pos,
"only `#` is allowed in raw string delimitation; \
found illegal character",
"found invalid character; \
only `#` is allowed in raw string delimitation",
ch);
}
self.bump();
Expand Down
14 changes: 7 additions & 7 deletions src/libsyntax/parse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,11 +446,11 @@ fn filtered_float_lit(data: token::InternedString, suffix: Option<&str>,
Some(suf) => {
if suf.len() >= 2 && looks_like_width_suffix(&['f'], suf) {
// if it looks like a width, lets try to be helpful.
sd.span_err(sp, &*format!("illegal width `{}` for float literal, \
valid widths are 32 and 64", &suf[1..]));
sd.span_err(sp, &*format!("invalid width `{}` for float literal", &suf[1..]));
sd.fileline_help(sp, "valid widths are 32 and 64");
} else {
sd.span_err(sp, &*format!("illegal suffix `{}` for float literal, \
valid suffixes are `f32` and `f64`", suf));
sd.span_err(sp, &*format!("invalid suffix `{}` for float literal", suf));
sd.fileline_help(sp, "valid suffixes are `f32` and `f64`");
}

ast::LitFloatUnsuffixed(data)
Expand Down Expand Up @@ -619,11 +619,11 @@ pub fn integer_lit(s: &str,
// i<digits> and u<digits> look like widths, so lets
// give an error message along those lines
if looks_like_width_suffix(&['i', 'u'], suf) {
sd.span_err(sp, &*format!("illegal width `{}` for integer literal; \
valid widths are 8, 16, 32 and 64",
sd.span_err(sp, &*format!("invalid width `{}` for integer literal",
&suf[1..]));
sd.fileline_help(sp, "valid widths are 8, 16, 32 and 64");
} else {
sd.span_err(sp, &*format!("illegal suffix `{}` for numeric literal", suf));
sd.span_err(sp, &*format!("invalid suffix `{}` for numeric literal", suf));
sd.fileline_help(sp, "the suffix must be one of the integral types \
(`u32`, `isize`, etc)");
}
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ impl<'a> Parser<'a> {
if text.is_empty() {
self.span_bug(sp, "found empty literal suffix in Some")
}
self.span_err(sp, &*format!("{} with a suffix is illegal", kind));
self.span_err(sp, &*format!("{} with a suffix is invalid", kind));
}
}
}
Expand Down Expand Up @@ -5286,7 +5286,7 @@ impl<'a> Parser<'a> {
let last_span = self.last_span;
self.span_err(
last_span,
&format!("illegal ABI: expected one of [{}], \
&format!("invalid ABI: expected one of [{}], \
found `{}`",
abi::all_names().join(", "),
s));
Expand Down
10 changes: 5 additions & 5 deletions src/test/compile-fail/bad-expr-lhs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
// except according to those terms.

fn main() {
1 = 2; //~ ERROR illegal left-hand side expression
1 += 2; //~ ERROR illegal left-hand side expression
(1, 2) = (3, 4); //~ ERROR illegal left-hand side expression
1 = 2; //~ ERROR invalid left-hand side expression
1 += 2; //~ ERROR invalid left-hand side expression
(1, 2) = (3, 4); //~ ERROR invalid left-hand side expression

let (a, b) = (1, 2);
(a, b) = (3, 4); //~ ERROR illegal left-hand side expression
(a, b) = (3, 4); //~ ERROR invalid left-hand side expression

None = Some(3); //~ ERROR illegal left-hand side expression
None = Some(3); //~ ERROR invalid left-hand side expression
}
7 changes: 5 additions & 2 deletions src/test/compile-fail/cast-as-bool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// error-pattern: cannot cast as `bool`, compare with zero instead
fn main() { let u = (5 as bool); }
fn main() {
let u = (5 as bool);
//~^ ERROR cannot cast as `bool`
//~^^ HELP compare with zero instead
}
82 changes: 58 additions & 24 deletions src/test/compile-fail/cast-rfc0401.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@

fn illegal_cast<U:?Sized,V:?Sized>(u: *const U) -> *const V
{
u as *const V //~ ERROR vtable kinds
u as *const V
//~^ ERROR casting
//~^^ NOTE vtable kinds
}

fn illegal_cast_2<U:?Sized>(u: *const U) -> *const str
{
u as *const str //~ ERROR vtable kinds
u as *const str
//~^ ERROR casting
//~^^ NOTE vtable kinds
}

trait Foo { fn foo(&self) {} }
Expand All @@ -41,32 +45,58 @@ fn main()
let _ = v as (u32,); //~ ERROR non-scalar
let _ = Some(&v) as *const u8; //~ ERROR non-scalar

let _ = v as f32; //~ ERROR through a usize first
let _ = main as f64; //~ ERROR through a usize first
let _ = &v as usize; //~ ERROR through a raw pointer first
let _ = f as *const u8; //~ ERROR through a usize first
let _ = 3 as bool; //~ ERROR compare with zero
let _ = E::A as bool; //~ ERROR compare with zero
let _ = v as f32;
//~^ ERROR casting
//~^^ HELP through a usize first
let _ = main as f64;
//~^ ERROR casting
//~^^ HELP through a usize first
let _ = &v as usize;
//~^ ERROR casting
//~^^ HELP through a raw pointer first
let _ = f as *const u8;
//~^ ERROR casting
//~^^ HELP through a usize first
let _ = 3 as bool;
//~^ ERROR cannot cast as `bool`
//~^^ HELP compare with zero
let _ = E::A as bool;
//~^ ERROR cannot cast as `bool`
//~^^ HELP compare with zero
let _ = 0x61u32 as char; //~ ERROR only `u8` can be cast

let _ = false as f32; //~ ERROR through an integer first
let _ = E::A as f32; //~ ERROR through an integer first
let _ = 'a' as f32; //~ ERROR through an integer first
let _ = false as f32;
//~^ ERROR casting
//~^^ HELP through an integer first
let _ = E::A as f32;
//~^ ERROR casting
//~^^ HELP through an integer first
let _ = 'a' as f32;
//~^ ERROR casting
//~^^ HELP through an integer first

let _ = false as *const u8; //~ ERROR through a usize first
let _ = E::A as *const u8; //~ ERROR through a usize first
let _ = 'a' as *const u8; //~ ERROR through a usize first
let _ = false as *const u8;
//~^ ERROR casting
//~^^ HELP through a usize first
let _ = E::A as *const u8;
//~^ ERROR casting
//~^^ HELP through a usize first
let _ = 'a' as *const u8;
//~^ ERROR casting
//~^^ HELP through a usize first

let _ = 42usize as *const [u8]; //~ ERROR illegal cast
let _ = v as *const [u8]; //~ ERROR illegal cast
let _ = 42usize as *const [u8]; //~ ERROR casting
let _ = v as *const [u8]; //~ ERROR casting
let _ = fat_v as *const Foo;
//~^ ERROR `core::marker::Sized` is not implemented for the type `[u8]`
let _ = foo as *const str; //~ ERROR illegal cast
let _ = foo as *mut str; //~ ERROR illegal cast
let _ = main as *mut str; //~ ERROR illegal cast
let _ = &f as *mut f32; //~ ERROR illegal cast
let _ = &f as *const f64; //~ ERROR illegal cast
let _ = fat_v as usize; //~ ERROR through a raw pointer first
let _ = foo as *const str; //~ ERROR casting
let _ = foo as *mut str; //~ ERROR casting
let _ = main as *mut str; //~ ERROR casting
let _ = &f as *mut f32; //~ ERROR casting
let _ = &f as *const f64; //~ ERROR casting
let _ = fat_v as usize;
//~^ ERROR casting
//~^^ HELP through a raw pointer first

let a : *const str = "hello";
let _ = a as *const Foo;
Expand All @@ -76,6 +106,10 @@ fn main()
let _ = main.f as *const u32; //~ ERROR attempted access of field

let cf: *const Foo = &0;
let _ = cf as *const [u8]; //~ ERROR vtable kinds
let _ = cf as *const Bar; //~ ERROR vtable kinds
let _ = cf as *const [u8];
//~^ ERROR casting
//~^^ NOTE vtable kinds
let _ = cf as *const Bar;
//~^ ERROR casting
//~^^ NOTE vtable kinds
}
4 changes: 2 additions & 2 deletions src/test/compile-fail/const-cast-different-types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
// except according to those terms.

static a: &'static str = "foo";
static b: *const u8 = a as *const u8; //~ ERROR illegal cast
static c: *const u8 = &a as *const u8; //~ ERROR illegal cast
static b: *const u8 = a as *const u8; //~ ERROR casting
static c: *const u8 = &a as *const u8; //~ ERROR casting

fn main() {
}
4 changes: 2 additions & 2 deletions src/test/compile-fail/enum-to-float-cast-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ enum F {
}

pub fn main() {
let a = E::L0 as f32; //~ ERROR illegal cast
let c = F::H1 as f32; //~ ERROR illegal cast
let a = E::L0 as f32; //~ ERROR casting
let c = F::H1 as f32; //~ ERROR casting
assert_eq!(a, -1.0f32);
assert_eq!(c, -1.0f32);
}
Loading