Skip to content
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

Rollup of 9 pull requests #35430

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
2f5294e
Fixes #35304
mikhail-m1 Aug 5, 2016
e7e5cfe
Merge branch 'master' of https://github.com/rust-lang/rust
mikhail-m1 Aug 5, 2016
424e772
Add error code check in librustc_const_eval/diagnostics.rs
GuillaumeGomez Aug 5, 2016
5bab0e6
Update E0206 message to new format
KiChjang Aug 5, 2016
065c685
Update E0223 to the new format
KiChjang Aug 6, 2016
c9e9d42
Update compiler error 0027 to use new error format.
silenuss Aug 6, 2016
1d25e2e
Update compiler error 0029 to use new error format.
silenuss Aug 6, 2016
f4dd1f9
Updated error message E0252
Aug 5, 2016
eb469d6
Updated E0225 to new format.
razielgn Aug 6, 2016
4e2dd8d
Add new error code tests
GuillaumeGomez Aug 5, 2016
24ddca0
Update error message for E0243 and E0244
Aug 6, 2016
fbd7c55
Rollup merge of #35362 - medzin:E0252, r=GuillaumeGomez
Aug 6, 2016
edd8e04
Rollup merge of #35393 - GuillaumeGomez:err_codes2, r=jonathandturner
Aug 6, 2016
5e84fc4
Rollup merge of #35394 - mikhail-m1:master, r=jonathandturner
Aug 6, 2016
ae59b96
Rollup merge of #35402 - KiChjang:e0206-new-msg, r=GuillaumeGomez
Aug 6, 2016
2fd369f
Rollup merge of #35410 - silenuss:e0027-formatting, r=jonathandturner
Aug 6, 2016
388e7d6
Rollup merge of #35411 - KiChjang:e0223-new-format, r=jonathandturner
Aug 6, 2016
32de7ca
Rollup merge of #35413 - silenuss:e0029-formatting, r=jonathandturner
Aug 6, 2016
14163fa
Rollup merge of #35419 - Keats:err-243, r=jonathandturner
Aug 6, 2016
11022b4
Rollup merge of #35421 - razielgn:updated-e0225-to-new-format, r=jona…
Aug 6, 2016
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
48 changes: 26 additions & 22 deletions src/librustc_const_eval/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ one is too specific or the ordering is incorrect.

For example, the following `match` block has too many arms:

```compile_fail
match foo {
```compile_fail,E0001
match Some(0) {
Some(bar) => {/* ... */}
None => {/* ... */}
_ => {/* ... */} // All possible cases have already been handled
Expand Down Expand Up @@ -108,7 +108,7 @@ one or more possible inputs to a match expression. Guaranteed matches are
required in order to assign values to match expressions, or alternatively,
determine the flow of execution. Erroneous code example:

```compile_fail
```compile_fail,E0004
enum Terminator {
HastaLaVistaBaby,
TalkToMyHand,
Expand Down Expand Up @@ -153,7 +153,7 @@ E0005: r##"
Patterns used to bind names must be irrefutable, that is, they must guarantee
that a name will be extracted in all cases. Erroneous code example:

```compile_fail
```compile_fail,E0005
let x = Some(1);
let Some(y) = x;
// error: refutable pattern in local binding: `None` not covered
Expand Down Expand Up @@ -187,7 +187,7 @@ like the following is invalid as it requires the entire `Option<String>` to be
moved into a variable called `op_string` while simultaneously requiring the
inner `String` to be moved into a variable called `s`.

```compile_fail
```compile_fail,E0007
let x = Some("s".to_string());

match x {
Expand All @@ -205,7 +205,7 @@ name is bound by move in a pattern, it should also be moved to wherever it is
referenced in the pattern guard code. Doing so however would prevent the name
from being available in the body of the match arm. Consider the following:

```compile_fail
```compile_fail,E0008
match Some("hi".to_string()) {
Some(s) if s.len() == 0 => {}, // use s.
_ => {},
Expand All @@ -229,7 +229,7 @@ match Some("hi".to_string()) {
Though this example seems innocuous and easy to solve, the problem becomes clear
when it encounters functions which consume the value:

```compile_fail
```compile_fail,E0008
struct A{}

impl A {
Expand Down Expand Up @@ -283,7 +283,7 @@ This limitation may be removed in a future version of Rust.

Erroneous code example:

```compile_fail
```compile_fail,E0009
struct X { x: (), }

let x = Some((X { x: () }, X { x: () }));
Expand Down Expand Up @@ -351,25 +351,25 @@ An if-let pattern attempts to match the pattern, and enters the body if the
match was successful. If the match is irrefutable (when it cannot fail to
match), use a regular `let`-binding instead. For instance:

```compile_fail
```compile_fail,E0162
struct Irrefutable(i32);
let irr = Irrefutable(0);

// This fails to compile because the match is irrefutable.
if let Irrefutable(x) = irr {
// This body will always be executed.
foo(x);
// ...
}
```

Try this instead:

```ignore
```
struct Irrefutable(i32);
let irr = Irrefutable(0);

let Irrefutable(x) = irr;
foo(x);
println!("{}", x);
```
"##,

Expand All @@ -378,7 +378,7 @@ A while-let pattern attempts to match the pattern, and enters the body if the
match was successful. If the match is irrefutable (when it cannot fail to
match), use a regular `let`-binding inside a `loop` instead. For instance:

```compile_fail
```compile_fail,E0165
struct Irrefutable(i32);
let irr = Irrefutable(0);

Expand Down Expand Up @@ -455,7 +455,7 @@ that a name will be extracted in all cases. Instead of pattern matching the
loop variable, consider using a `match` or `if let` inside the loop body. For
instance:

```compile_fail
```compile_fail,E0297
let xs : Vec<Option<i32>> = vec!(Some(1), None);

// This fails because `None` is not covered.
Expand Down Expand Up @@ -497,7 +497,7 @@ on which the match depends in such a way, that the match would not be
exhaustive. For instance, the following would not match any arm if mutable
borrows were allowed:

```compile_fail
```compile_fail,E0301
match Some(()) {
None => { },
option if option.take().is_none() => {
Expand All @@ -515,10 +515,10 @@ on which the match depends in such a way, that the match would not be
exhaustive. For instance, the following would not match any arm if assignments
were allowed:

```compile_fail
```compile_fail,E0302
match Some(()) {
None => { },
option if { option = None; false } { },
option if { option = None; false } => { },
Some(_) => { } // When the previous match failed, the option became `None`.
}
```
Expand All @@ -529,14 +529,18 @@ In certain cases it is possible for sub-bindings to violate memory safety.
Updates to the borrow checker in a future version of Rust may remove this
restriction, but for now patterns must be rewritten without sub-bindings.

```ignore
// Before.
Before:

```compile_fail,E0303
match Some("hi".to_string()) {
ref op_string_ref @ Some(s) => {},
None => {},
}
```

After:

// After.
```
match Some("hi".to_string()) {
Some(ref s) => {
let op_string_ref = &Some(s);
Expand All @@ -556,7 +560,7 @@ This error indicates that the compiler was unable to sensibly evaluate an
constant expression that had to be evaluated. Attempting to divide by 0
or causing integer overflow are two ways to induce this error. For example:

```compile_fail
```compile_fail,E0080
enum Enum {
X = (1 << 500),
Y = (1 / 0)
Expand All @@ -575,7 +579,7 @@ E0306: r##"
In an array literal `[x; N]`, `N` is the number of elements in the array. This
must be an unsigned integer. Erroneous code example:

```compile_fail
```compile_fail,E0306
let x = [0i32; true]; // error: expected positive integer for repeat count,
// found boolean
```
Expand Down
6 changes: 5 additions & 1 deletion src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3375,7 +3375,11 @@ impl<'a> Resolver<'a> {
(true, _) | (_, true) => struct_span_err!(self.session, span, E0260, "{}", msg),
_ => match (old_binding.is_import(), binding.is_import()) {
(false, false) => struct_span_err!(self.session, span, E0428, "{}", msg),
(true, true) => struct_span_err!(self.session, span, E0252, "{}", msg),
(true, true) => {
let mut e = struct_span_err!(self.session, span, E0252, "{}", msg);
e.span_label(span, &format!("already imported"));
e
},
_ => {
let mut e = struct_span_err!(self.session, span, E0255, "{}", msg);
e.span_label(span, &format!("`{}` was already imported", name));
Expand Down
46 changes: 29 additions & 17 deletions src/librustc_typeck/astconv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1215,10 +1215,12 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
type_str: &str,
trait_str: &str,
name: &str) {
span_err!(self.tcx().sess, span, E0223,
"ambiguous associated type; specify the type using the syntax \
`<{} as {}>::{}`",
type_str, trait_str, name);
struct_span_err!(self.tcx().sess, span, E0223, "ambiguous associated type")
.span_label(span, &format!("ambiguous associated type"))
.note(&format!("specify the type using the syntax `<{} as {}>::{}`",
type_str, trait_str, name))
.emit();

}

// Search for a bound on a type parameter which includes the associated item
Expand Down Expand Up @@ -2095,8 +2097,11 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {

if !trait_bounds.is_empty() {
let b = &trait_bounds[0];
span_err!(self.tcx().sess, b.trait_ref.path.span, E0225,
"only the builtin traits can be used as closure or object bounds");
let span = b.trait_ref.path.span;
struct_span_err!(self.tcx().sess, span, E0225,
"only the builtin traits can be used as closure or object bounds")
.span_label(span, &format!("non-builtin trait used as bounds"))
.emit();
}

let region_bound =
Expand Down Expand Up @@ -2255,20 +2260,27 @@ fn check_type_argument_count(tcx: TyCtxt, span: Span, supplied: usize,
} else {
"expected"
};
span_err!(tcx.sess, span, E0243,
"wrong number of type arguments: {} {}, found {}",
expected, required, supplied);
struct_span_err!(tcx.sess, span, E0243, "wrong number of type arguments")
.span_label(
span,
&format!("{} {} type arguments, found {}", expected, required, supplied)
)
.emit();
} else if supplied > accepted {
let expected = if required < accepted {
"expected at most"
let expected = if required == 0 {
"expected no".to_string()
} else if required < accepted {
format!("expected at most {}", accepted)
} else {
"expected"
format!("expected {}", accepted)
};
span_err!(tcx.sess, span, E0244,
"wrong number of type arguments: {} {}, found {}",
expected,
accepted,
supplied);

struct_span_err!(tcx.sess, span, E0244, "wrong number of type arguments")
.span_label(
span,
&format!("{} type arguments, found {}", expected, supplied)
)
.emit();
}
}

Expand Down
21 changes: 11 additions & 10 deletions src/librustc_typeck/check/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
end.span
};

// Note: spacing here is intentional, we want a space before "start" and "end".
span_err!(tcx.sess, span, E0029,
"only char and numeric types are allowed in range patterns\n \
start type: {}\n end type: {}",
self.ty_to_string(lhs_ty),
self.ty_to_string(rhs_ty)
);
struct_span_err!(tcx.sess, span, E0029,
"only char and numeric types are allowed in range patterns")
.span_label(span, &format!("ranges require char or numeric types"))
.note(&format!("start type: {}", self.ty_to_string(lhs_ty)))
.note(&format!("end type: {}", self.ty_to_string(rhs_ty)))
.emit();
return;
}

Expand Down Expand Up @@ -700,9 +699,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
for field in variant.fields
.iter()
.filter(|field| !used_fields.contains_key(&field.name)) {
span_err!(tcx.sess, span, E0027,
"pattern does not mention field `{}`",
field.name);
struct_span_err!(tcx.sess, span, E0027,
"pattern does not mention field `{}`",
field.name)
.span_label(span, &format!("missing field `{}`", field.name))
.emit();
}
}
}
Expand Down
15 changes: 11 additions & 4 deletions src/librustc_typeck/coherence/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,17 @@ impl<'a, 'gcx, 'tcx> CoherenceChecker<'a, 'gcx, 'tcx> {
name)
}
Err(CopyImplementationError::NotAnAdt) => {
span_err!(tcx.sess, span, E0206,
"the trait `Copy` may not be implemented \
for this type; type is not a structure or \
enumeration")
let item = tcx.map.expect_item(impl_node_id);
let span = if let ItemImpl(_, _, _, _, ref ty, _) = item.node {
ty.span
} else {
span
};

struct_span_err!(tcx.sess, span, E0206,
"the trait `Copy` may not be implemented for this type")
.span_label(span, &format!("type is not a structure or enumeration"))
.emit();
}
Err(CopyImplementationError::HasDestructor) => {
span_err!(tcx.sess, span, E0184,
Expand Down
7 changes: 4 additions & 3 deletions src/librustc_typeck/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -770,9 +770,10 @@ fn convert_item(ccx: &CrateCtxt, it: &hir::Item) {
let mut err = struct_span_err!(tcx.sess, impl_item.span, E0201,
"duplicate definitions with name `{}`:",
impl_item.name);
span_note!(&mut err, *entry.get(),
"previous definition of `{}` here",
impl_item.name);
err.span_label(*entry.get(),
&format!("previous definition of `{}` here",
impl_item.name));
err.span_label(impl_item.span, &format!("duplicate definition"));
err.emit();
}
Vacant(entry) => {
Expand Down
4 changes: 3 additions & 1 deletion src/test/compile-fail/E0027.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ fn main() {
let d = Dog { name: "Rusty".to_string(), age: 8 };

match d {
Dog { age: x } => {} //~ ERROR E0027
Dog { age: x } => {}
//~^ ERROR pattern does not mention field `name`
//~| NOTE missing field `name`
}
}
6 changes: 5 additions & 1 deletion src/test/compile-fail/E0029.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ fn main() {
let s = "hoho";

match s {
"hello" ... "world" => {} //~ ERROR E0029
"hello" ... "world" => {}
//~^ ERROR only char and numeric types are allowed in range patterns
//~| NOTE ranges require char or numeric types
//~| NOTE start type: &'static str
//~| NOTE end type: &'static str
_ => {}
}
}
10 changes: 7 additions & 3 deletions src/test/compile-fail/E0206.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@

type Foo = i32;

impl Copy for Foo { } //~ ERROR E0206
//~^ ERROR E0117
impl Copy for Foo { }
//~^ ERROR the trait `Copy` may not be implemented for this type
//~| NOTE type is not a structure or enumeration
//~| ERROR E0117

#[derive(Copy, Clone)]
struct Bar;

impl Copy for &'static Bar { } //~ ERROR E0206
impl Copy for &'static Bar { }
//~^ ERROR the trait `Copy` may not be implemented for this type
//~| NOTE type is not a structure or enumeration

fn main() {
}
5 changes: 4 additions & 1 deletion src/test/compile-fail/E0223.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@
trait MyTrait { type X; }

fn main() {
let foo: MyTrait::X; //~ ERROR E0223
let foo: MyTrait::X;
//~^ ERROR ambiguous associated type
//~| NOTE ambiguous associated type
//~| NOTE specify the type using the syntax `<Type as MyTrait>::X`
}
4 changes: 3 additions & 1 deletion src/test/compile-fail/E0225.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@
// except according to those terms.

fn main() {
let _: Box<std::io::Read + std::io::Write>; //~ ERROR E0225
let _: Box<std::io::Read + std::io::Write>;
//~^ ERROR only the builtin traits can be used as closure or object bounds [E0225]
//~| NOTE non-builtin trait used as bounds
}
Loading