Skip to content

Commit b21a6da

Browse files
committed
auto merge of #19870 : mdinger/rust/align_error, r=nick29581
#### Updated 1/12/2014 I updated the multi-line testcase to current but didn't modify the others. The spew code was broke by the `matches!` macro no longer working and I'm not interested in fixing the testcase. I additionally added one testcase below. Errors will in general look similar to below if the error is either `mismatched types` or a few other types. The rest are ignored. --- #### Extra testcase: ```rust pub trait Foo { type A; fn boo(&self) -> <Self as Foo>::A; } struct Bar; impl Foo for i32 { type A = u32; fn boo(&self) -> u32 { 42 } } fn foo1<I: Foo<A=Bar>>(x: I) { let _: Bar = x.boo(); } fn foo2<I: Foo>(x: I) { let _: Bar = x.boo(); } pub fn baz(x: &Foo<A=Bar>) { let _: Bar = x.boo(); } pub fn main() { let a = 42i32; foo1(a); baz(&a); } ``` #### Multi-line output: ```cmd $ ./rustc test3.rs test3.rs:20:18: 20:25 error: mismatched types: expected `Bar`, found `<I as Foo>::A` (expected struct `Bar`, found associated type) test3.rs:20 let _: Bar = x.boo(); ^~~~~~~ test3.rs:31:5: 31:9 error: type mismatch resolving `<i32 as Foo>::A == Bar`: expected u32, found struct `Bar` test3.rs:31 foo1(a); ^~~~ test3.rs:31:5: 31:9 note: required by `foo1` test3.rs:31 foo1(a); ^~~~ test3.rs:32:9: 32:11 error: type mismatch resolving `<i32 as Foo>::A == Bar`: expected u32, found struct `Bar` test3.rs:32 baz(&a); ^~ test3.rs:32:9: 32:11 note: required for the cast to the object type `Foo` test3.rs:32 baz(&a); ^~ error: aborting due to 3 previous errors ``` --- This is a continuation of #19203 which I apparently broke by force pushing after it was closed. I'm attempting to add multi-line errors where they are largely beneficial - to help differentiate different types in compiler messages. As before, this is still a simple fix. #### Testcase: ```rust struct S; fn test() -> Option<i32> { let s: S; s } fn test2() -> Option<i32> { Ok(7) // Should be Some(7) } impl Iterator for S { type Item = i32; fn next(&mut self) -> Result<i32, i32> { Ok(7) } } fn main(){ test(); test2(); } ``` --- #### Single-line playpen errors: ```cmd <anon>:6:5: 6:6 error: mismatched types: expected `core::option::Option<int>`, found `S` (expected enum core::option::Option, found struct S) <anon>:6 s ^ <anon>:10:5: 10:10 error: mismatched types: expected `core::option::Option<int>`, found `core::result::Result<_, _>` (expected enum core::option::Option, found enum core::result::Result) <anon>:10 Ok(7) // Should be Some(7) ^~~~~ <anon>:14:5: 14:55 error: method `next` has an incompatible type for trait: expected enum core::option::Option, found enum core::result::Result [E0053] <anon>:14 fn next(&mut self) -> Result<uint, uint> { Ok(7) } ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: aborting due to 3 previous errors playpen: application terminated with error code 101 ``` --- #### Multi-line errors: ```cmd $ ./rustc test.rs test.rs:6:5: 6:6 error: mismatched types: expected `core::option::Option<i32>`, found `S` (expected enum `core::option::Option`, found struct `S`) test.rs:6 s ^ test.rs:10:5: 10:10 error: mismatched types: expected `core::option::Option<i32>`, found `core::result::Result<_, _>` (expected enum `core::option::Option`, found enum `core::result::Result`) test.rs:10 Ok(7) // Should be Some(7) ^~~~~ test.rs:15:5: 15:53 error: method `next` has an incompatible type for trait: expected enum `core::option::Option`, found enum `core::result::Result` [E0053] test.rs:15 fn next(&mut self) -> Result<i32, i32> { Ok(7) } ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: aborting due to 3 previous errors ``` --- #### Positive notes * Vim worked fine with it: #19203 (comment) * `make check` didn't find any errors * Fixed *backtick* placement suggested by @p1start at #19203 (comment) #### Negative notes * Didn't check Emacs support but also wasn't provided a testcase... * Needs to be tested with macro errors but I don't have a good testcase yet * I would like to move the `E[0053]` earlier (see #19464 (comment)) but I don't know how * It might be better to indent the types slightly like so (but I don't know how): ```cmd test.rs:6:5: 6:6 error: mismatched types: expected `core::option::Option<int>`, found `S` (expected enum `core::option::Option`, found struct `S`) test.rs:6 s ``` * Deep whitespace indentation may be a bad idea because early wrapping will cause misalignment between lines #### Other * I thought that compiler flags or something else (environment variables maybe) might be required because of comments against it but now that seems too much of a burden for users and for too little gain. * There was concern that it will make large quantities of errors difficult to distinguish but I don't find that an issue. They both look awful and multi-line errors makes the types easier to understand. --- #### Single lined spew: ```cmd $ rustc test2.rs test2.rs:161:9: 170:10 error: method `next` has an incompatible type for trait: expected enum core::option::Option, found enum core::result::Result [E0053] test2.rs:161 fn next(&mut self) -> Result<&'a str, int> { test2.rs:162 self.curr = self.next; test2.rs:163 test2.rs:164 if let (Some(open), Some(close)) = Parens::find_parens(self.all, self.next) { test2.rs:165 self.next = if self.all.char_at(self.next) == '(' { close } test2.rs:166 else { open } ... test2.rs:164:21: 164:31 error: mismatched types: expected `core::result::Result<uint, int>`, found `core::option::Option<_>` (expected enum core::result::Result, found enum core::option::Option) test2.rs:164 if let (Some(open), Some(close)) = Parens::find_parens(self.all, self.next) { ^~~~~~~~~~ test2.rs:164:33: 164:44 error: mismatched types: expected `core::result::Result<uint, int>`, found `core::option::Option<_>` (expected enum core::result::Result, found enum core::option::Option) test2.rs:164 if let (Some(open), Some(close)) = Parens::find_parens(self.all, self.next) { ^~~~~~~~~~~ test2.rs:169:40: 169:76 error: mismatched types: expected `core::result::Result<&'a str, int>`, found `core::option::Option<&str>` (expected enum core::result::Result, found enum core::option::Option) test2.rs:169 if self.curr != self.len { Some(self.all[self.curr..self.next]) } else { None } ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ test2.rs:169:86: 169:90 error: mismatched types: expected `core::result::Result<&'a str, int>`, found `core::option::Option<_>` (expected enum core::result::Result, found enum core::option::Option) test2.rs:169 if self.curr != self.len { Some(self.all[self.curr..self.next]) } else { None } ^~~~ test2.rs:205:14: 205:18 error: mismatched types: expected `core::result::Result<uint, int>`, found `core::option::Option<uint>` (expected enum core::result::Result, found enum core::option::Option) test2.rs:205 (open, close) ^~~~ test2.rs:205:20: 205:25 error: mismatched types: expected `core::result::Result<uint, int>`, found `core::option::Option<uint>` (expected enum core::result::Result, found enum core::option::Option) test2.rs:205 (open, close) ^~~~~ test2.rs:210:21: 210:31 error: mismatched types: expected `core::result::Result<uint, int>`, found `core::option::Option<_>` (expected enum core::result::Result, found enum core::option::Option) test2.rs:210 if let (Some(open), _) = Parens::find_parens(self.all, 0) { ^~~~~~~~~~ test2.rs:210:13: 212:28 error: mismatched types: expected `core::option::Option<&'a int>`, found `core::option::Option<&str>` (expected int, found str) test2.rs:210 if let (Some(open), _) = Parens::find_parens(self.all, 0) { test2.rs:211 Some(self.all[0..open]) test2.rs:212 } else { None } test2.rs:299:48: 299:58 error: mismatched types: expected `Box<translate::Entity>`, found `collections::vec::Vec<_>` (expected box, found struct collections::vec::Vec) test2.rs:299 pub fn new() -> Entity { Entity::Group(Vec::new()) } ^~~~~~~~~~ test2.rs:359:51: 359:58 error: type `&mut Box<translate::Entity>` does not implement any method in scope named `push` test2.rs:359 Entity::Group(ref mut vec) => vec.push(e), ^~~~~~~ test2.rs:366:51: 366:85 error: type `&mut Box<translate::Entity>` does not implement any method in scope named `push` test2.rs:366 Entity::Group(ref mut vec) => vec.push(Entity::Inner(s.to_string())), ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: aborting due to 12 previous errors ``` --- #### Multi-line spew: ```cmd $ ./rustc test2.rs test2.rs:161:9: 170:10 error: method `next` has an incompatible type for trait: expected enum `core::option::Option`, found enum `core::result::Result` [E0053] test2.rs:161 fn next(&mut self) -> Result<&'a str, int> { test2.rs:162 self.curr = self.next; test2.rs:163 test2.rs:164 if let (Some(open), Some(close)) = Parens::find_parens(self.all, self.next) { test2.rs:165 self.next = if self.all.char_at(self.next) == '(' { close } test2.rs:166 else { open } ... test2.rs:164:21: 164:31 error: mismatched types: expected `core::result::Result<uint, int>`, found `core::option::Option<_>` (expected enum `core::result::Result`, found enum `core::option::Option`) test2.rs:164 if let (Some(open), Some(close)) = Parens::find_parens(self.all, self.next) { ^~~~~~~~~~ test2.rs:164:33: 164:44 error: mismatched types: expected `core::result::Result<uint, int>`, found `core::option::Option<_>` (expected enum `core::result::Result`, found enum `core::option::Option`) test2.rs:164 if let (Some(open), Some(close)) = Parens::find_parens(self.all, self.next) { ^~~~~~~~~~~ test2.rs:169:40: 169:76 error: mismatched types: expected `core::result::Result<&'a str, int>`, found `core::option::Option<&str>` (expected enum `core::result::Result`, found enum `core::option::Option`) test2.rs:169 if self.curr != self.len { Some(self.all[self.curr..self.next]) } else { None } ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ test2.rs:169:86: 169:90 error: mismatched types: expected `core::result::Result<&'a str, int>`, found `core::option::Option<_>` (expected enum `core::result::Result`, found enum `core::option::Option`) test2.rs:169 if self.curr != self.len { Some(self.all[self.curr..self.next]) } else { None } ^~~~ test2.rs:205:14: 205:18 error: mismatched types: expected `core::result::Result<uint, int>`, found `core::option::Option<uint>` (expected enum `core::result::Result`, found enum `core::option::Option`) test2.rs:205 (open, close) ^~~~ test2.rs:205:20: 205:25 error: mismatched types: expected `core::result::Result<uint, int>`, found `core::option::Option<uint>` (expected enum `core::result::Result`, found enum `core::option::Option`) test2.rs:205 (open, close) ^~~~~ test2.rs:210:21: 210:31 error: mismatched types: expected `core::result::Result<uint, int>`, found `core::option::Option<_>` (expected enum `core::result::Result`, found enum `core::option::Option`) test2.rs:210 if let (Some(open), _) = Parens::find_parens(self.all, 0) { ^~~~~~~~~~ test2.rs:210:13: 212:28 error: mismatched types: expected `core::option::Option<&'a int>`, found `core::option::Option<&str>` (expected int, found str) test2.rs:210 if let (Some(open), _) = Parens::find_parens(self.all, 0) { test2.rs:211 Some(self.all[0..open]) test2.rs:212 } else { None } test2.rs:229:57: 229:96 error: the trait `core::ops::Fn<(char,), bool>` is not implemented for the type `|char| -> bool` test2.rs:229 .map(|s| s.trim_chars(|c: char| c.is_whitespace())) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ test2.rs:238:46: 239:75 error: type `core::str::CharSplits<'_, |char| -> bool>` does not implement any method in scope named `filter_map` test2.rs:238 .filter_map(|s| if !s.is_empty() { Some(s.trim_chars('\'')) } test2.rs:239 else { None }) test2.rs:237:46: 237:91 error: the trait `core::ops::Fn<(char,), bool>` is not implemented for the type `|char| -> bool` test2.rs:237 let vec: Vec<&str> = value[].split(|c: char| matches!(c, '(' | ')' | ',')) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ test2.rs:238:65: 238:77 error: the type of this value must be known in this context test2.rs:238 .filter_map(|s| if !s.is_empty() { Some(s.trim_chars('\'')) } ^~~~~~~~~~~~ test2.rs:299:48: 299:58 error: mismatched types: expected `Box<translate::Entity>`, found `collections::vec::Vec<_>` (expected box, found struct `collections::vec::Vec`) test2.rs:299 pub fn new() -> Entity { Entity::Group(Vec::new()) } ^~~~~~~~~~ test2.rs:321:36: 322:65 error: type `core::str::CharSplits<'_, |char| -> bool>` does not implement any method in scope named `filter_map` test2.rs:321 .filter_map(|s| if !s.is_empty() { Some(s.trim_chars('\'')) } test2.rs:322 else { None }) test2.rs:320:36: 320:81 error: the trait `core::ops::Fn<(char,), bool>` is not implemented for the type `|char| -> bool` test2.rs:320 let vec: Vec<&str> = s.split(|c: char| matches!(c, '(' | ')' | ',')) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ test2.rs:321:55: 321:67 error: the type of this value must be known in this context test2.rs:321 .filter_map(|s| if !s.is_empty() { Some(s.trim_chars('\'')) } ^~~~~~~~~~~~ test2.rs:359:51: 359:58 error: type `&mut Box<translate::Entity>` does not implement any method in scope named `push` test2.rs:359 Entity::Group(ref mut vec) => vec.push(e), ^~~~~~~ test2.rs:366:51: 366:85 error: type `&mut Box<translate::Entity>` does not implement any method in scope named `push` test2.rs:366 Entity::Group(ref mut vec) => vec.push(Entity::Inner(s.to_string())), ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: aborting due to 24 previous errors ``` Closes #18946 #19464 cc @P1start @jakub- @tomjakubowski @kballard @chris-morgan
2 parents 486f60d + 7b82a93 commit b21a6da

File tree

99 files changed

+1048
-225
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+1048
-225
lines changed

src/compiletest/runtest.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -966,6 +966,16 @@ fn check_expected_errors(expected_errors: Vec<errors::ExpectedError> ,
966966
line.starts_with( prefix )
967967
}
968968

969+
// A multi-line error will have followup lines which will always
970+
// start with one of these strings.
971+
fn continuation( line: &str) -> bool {
972+
line.starts_with(" expected") ||
973+
line.starts_with(" found") ||
974+
// 1234
975+
// Should have 4 spaces: see issue 18946
976+
line.starts_with("(")
977+
}
978+
969979
// Scan and extract our error/warning messages,
970980
// which look like:
971981
// filename:line1:col1: line2:col2: *error:* msg
@@ -981,7 +991,7 @@ fn check_expected_errors(expected_errors: Vec<errors::ExpectedError> ,
981991
ee.kind,
982992
ee.msg,
983993
line);
984-
if prefix_matches(line, prefixes[i].as_slice()) &&
994+
if (prefix_matches(line, prefixes[i].as_slice()) || continuation(line)) &&
985995
line.contains(ee.kind.as_slice()) &&
986996
line.contains(ee.msg.as_slice()) {
987997
found_flags[i] = true;

src/librustc/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ extern crate fmt_macros;
3636
extern crate getopts;
3737
extern crate graphviz;
3838
extern crate libc;
39+
extern crate regex;
3940
extern crate rustc_llvm;
4041
extern crate rustc_back;
4142
extern crate serialize;

src/librustc/middle/ty.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4702,7 +4702,7 @@ pub fn ty_sort_string<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> String {
47024702
}
47034703
ty_tup(ref tys) if tys.is_empty() => ::util::ppaux::ty_to_string(cx, ty),
47044704

4705-
ty_enum(id, _) => format!("enum {}", item_path_str(cx, id)),
4705+
ty_enum(id, _) => format!("enum `{}`", item_path_str(cx, id)),
47064706
ty_uniq(_) => "box".to_string(),
47074707
ty_vec(_, Some(n)) => format!("array of {} elements", n),
47084708
ty_vec(_, None) => "slice".to_string(),
@@ -4714,7 +4714,7 @@ pub fn ty_sort_string<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> String {
47144714
format!("trait {}", item_path_str(cx, inner.principal_def_id()))
47154715
}
47164716
ty_struct(id, _) => {
4717-
format!("struct {}", item_path_str(cx, id))
4717+
format!("struct `{}`", item_path_str(cx, id))
47184718
}
47194719
ty_unboxed_closure(..) => "closure".to_string(),
47204720
ty_tup(_) => "tuple".to_string(),

src/librustc/session/mod.rs

+54-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ use metadata::filesearch;
1515
use session::search_paths::PathKind;
1616
use util::nodemap::NodeMap;
1717

18+
use regex::Regex;
19+
1820
use syntax::ast::NodeId;
1921
use syntax::codemap::Span;
2022
use syntax::diagnostic::{self, Emitter};
@@ -71,7 +73,58 @@ impl Session {
7173
self.diagnostic().handler().fatal(msg)
7274
}
7375
pub fn span_err(&self, sp: Span, msg: &str) {
74-
self.diagnostic().span_err(sp, msg)
76+
// Conditions for enabling multi-line errors:
77+
if !msg.contains("mismatched types") &&
78+
!msg.contains("type mismatch resolving") &&
79+
!msg.contains("if and else have incompatible types") &&
80+
!msg.contains("if may be missing an else clause") &&
81+
!msg.contains("match arms have incompatible types") &&
82+
!msg.contains("structure constructor specifies a structure of type") {
83+
return self.diagnostic().span_err(sp, msg);
84+
}
85+
86+
let first = Regex::new(r"[( ]expected").unwrap();
87+
let second = Regex::new(r" found").unwrap();
88+
let third = Regex::new(
89+
r"\((values differ|lifetime|cyclic type of infinite size)").unwrap();
90+
91+
let mut new_msg = String::new();
92+
let mut head = 0u;
93+
94+
// Insert `\n` before expected and found.
95+
for (pos1, pos2) in first.find_iter(msg).zip(
96+
second.find_iter(msg)) {
97+
new_msg = new_msg +
98+
// A `(` may be preceded by a space and it should be trimmed
99+
msg[head..pos1.0].trim_right() + // prefix
100+
"\n" + // insert before first
101+
&msg[pos1.0..pos1.1] + // insert what first matched
102+
&msg[pos1.1..pos2.0] + // between matches
103+
"\n " + // insert before second
104+
// 123
105+
// `expected` is 3 char longer than `found`. To align the types, `found` gets
106+
// 3 spaces prepended.
107+
&msg[pos2.0..pos2.1]; // insert what second matched
108+
109+
head = pos2.1;
110+
}
111+
112+
let mut tail = &msg[head..];
113+
// Insert `\n` before any remaining messages which match.
114+
for pos in third.find_iter(tail).take(1) {
115+
// The end of the message may just be wrapped in `()` without `expected`/`found`.
116+
// Push this also to a new line and add the final tail after.
117+
new_msg = new_msg +
118+
// `(` is usually preceded by a space and should be trimmed.
119+
tail[..pos.0].trim_right() + // prefix
120+
"\n" + // insert before paren
121+
&tail[pos.0..]; // append the tail
122+
123+
tail = "";
124+
}
125+
126+
new_msg.push_str(tail);
127+
self.diagnostic().span_err(sp, &new_msg[])
75128
}
76129
pub fn span_err_with_code(&self, sp: Span, msg: &str, code: &str) {
77130
self.diagnostic().span_err_with_code(sp, msg, code)

src/test/compile-fail/array-not-vector.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,18 @@
99
// except according to those terms.
1010

1111
fn main() {
12-
let _x: isize = [1is, 2, 3]; //~ ERROR expected isize, found array of 3 elements
12+
let _x: isize = [1is, 2, 3];
13+
//~^ ERROR mismatched types
14+
//~| expected `isize`
15+
//~| found `[isize; 3]`
16+
//~| expected isize
17+
//~| found array of 3 elements
1318

1419
let x: &[isize] = &[1, 2, 3];
15-
let _y: &isize = x; //~ ERROR expected isize, found slice
20+
let _y: &isize = x;
21+
//~^ ERROR mismatched types
22+
//~| expected `&isize`
23+
//~| found `&[isize]`
24+
//~| expected isize
25+
//~| found slice
1626
}

src/test/compile-fail/associated-types-eq-3.rs

+14-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,12 @@ fn foo1<I: Foo<A=Bar>>(x: I) {
3030
}
3131

3232
fn foo2<I: Foo>(x: I) {
33-
let _: Bar = x.boo(); //~ERROR mismatched types
33+
let _: Bar = x.boo();
34+
//~^ ERROR mismatched types
35+
//~| expected `Bar`
36+
//~| found `<I as Foo>::A`
37+
//~| expected struct `Bar`
38+
//~| found associated type
3439
}
3540

3641

@@ -41,6 +46,12 @@ pub fn baz(x: &Foo<A=Bar>) {
4146

4247
pub fn main() {
4348
let a = 42is;
44-
foo1(a); //~ERROR expected usize, found struct Bar
45-
baz(&a); //~ERROR expected usize, found struct Bar
49+
foo1(a);
50+
//~^ ERROR type mismatch resolving
51+
//~| expected usize
52+
//~| found struct `Bar`
53+
baz(&a);
54+
//~^ ERROR type mismatch resolving
55+
//~| expected usize
56+
//~| found struct `Bar`
4657
}

src/test/compile-fail/associated-types-path-2.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ pub fn f2<T: Foo>(a: T) -> T::A {
2525

2626
pub fn f1_int_int() {
2727
f1(2is, 4is);
28-
//~^ ERROR expected usize, found isize
28+
//~^ ERROR type mismatch resolving
29+
//~| expected usize
30+
//~| found isize
2931
}
3032

3133
pub fn f1_int_uint() {
@@ -46,7 +48,11 @@ pub fn f1_uint_int() {
4648

4749
pub fn f2_int() {
4850
let _: isize = f2(2is);
49-
//~^ ERROR expected `isize`, found `usize`
51+
//~^ ERROR mismatched types
52+
//~| expected `isize`
53+
//~| found `usize`
54+
//~| expected isize
55+
//~| found usize
5056
}
5157

5258
pub fn main() { }

src/test/compile-fail/bad-const-type.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// error-pattern:expected `collections::string::String`, found `isize`
12-
1311
static i: String = 10is;
12+
//~^ ERROR mismatched types
13+
//~| expected `collections::string::String`
14+
//~| found `isize`
15+
//~| expected struct `collections::string::String`
16+
//~| found isize
1417
fn main() { println!("{}", i); }

src/test/compile-fail/block-must-not-have-result-do.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// error-pattern:mismatched types: expected `()`, found `bool`
12-
1311
fn main() {
1412
loop {
15-
true
13+
true //~ ERROR mismatched types
14+
//~| expected ()
15+
//~| found bool
16+
//~| expected ()
17+
//~| found bool
1618
}
1719
}

src/test/compile-fail/block-must-not-have-result-res.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// error-pattern:mismatched types: expected `()`, found `bool`
12-
1311
struct r;
1412

1513
impl Drop for r {
1614
fn drop(&mut self) {
17-
true
15+
true //~ ERROR mismatched types
16+
//~| expected ()
17+
//~| found bool
18+
//~| expected ()
19+
//~| found bool
1820
}
1921
}
2022

src/test/compile-fail/block-must-not-have-result-while.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// error-pattern:mismatched types: expected `()`, found `bool`
12-
1311
fn main() {
1412
while true {
15-
true
13+
true //~ ERROR mismatched types
14+
//~| expected `()`
15+
//~| found `bool`
16+
//~| expected ()
17+
//~| found bool
1618
}
1719
}

src/test/compile-fail/coercion-slice.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,10 @@
1111
// Tests that we forbid coercion from `[T; n]` to `&[T]`
1212

1313
fn main() {
14-
let _: &[isize] = [0is]; //~ERROR: mismatched types: expected `&[isize]`, found `[isize; 1]`
14+
let _: &[isize] = [0is];
15+
//~^ ERROR mismatched types
16+
//~| expected `&[isize]`
17+
//~| found `[isize; 1]`
18+
//~| expected &-ptr
19+
//~| found array of 1 elements
1520
}

src/test/compile-fail/const-cast-different-types.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,17 @@
1010

1111
static a: &'static str = "foo";
1212
static b: *const u8 = a as *const u8;
13-
//~^ ERROR mismatched types: expected `*const u8`, found `&'static str`
13+
//~^ ERROR mismatched types
14+
//~| expected *const u8
15+
//~| found &'static str
16+
//~| expected u8
17+
//~| found str
1418
static c: *const u8 = &a as *const u8;
15-
//~^ ERROR mismatched types: expected `*const u8`, found `&&'static str`
19+
//~^ ERROR mismatched types
20+
//~| expected *const u8
21+
//~| found &&'static str
22+
//~| expected u8
23+
//~| found &-ptr
1624

1725
fn main() {
1826
}

src/test/compile-fail/cross-borrow-trait.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ impl Trait for Foo {}
1919

2020
pub fn main() {
2121
let x: Box<Trait> = box Foo;
22-
let _y: &Trait = x; //~ ERROR mismatched types: expected `&Trait`, found `Box<Trait>`
22+
let _y: &Trait = x; //~ ERROR mismatched types
23+
//~| expected `&Trait`
24+
//~| found `Box<Trait>`
25+
//~| expected &-ptr
26+
//~| found box
2327
}
2428

src/test/compile-fail/destructure-trait-ref.rs

+18-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,22 @@ fn main() {
3737
let box x = box 1is as Box<T>; //~ ERROR type `Box<T>` cannot be dereferenced
3838

3939
// n > m
40-
let &&x = &1is as &T; //~ ERROR found &-ptr
41-
let &&&x = &(&1is as &T); //~ ERROR found &-ptr
42-
let box box x = box 1is as Box<T>; //~ ERROR found box
40+
let &&x = &1is as &T;
41+
//~^ ERROR mismatched types
42+
//~| expected `T`
43+
//~| found `&_`
44+
//~| expected trait T
45+
//~| found &-ptr
46+
let &&&x = &(&1is as &T);
47+
//~^ ERROR mismatched types
48+
//~| expected `T`
49+
//~| found `&_`
50+
//~| expected trait T
51+
//~| found &-ptr
52+
let box box x = box 1is as Box<T>;
53+
//~^ ERROR mismatched types
54+
//~| expected `T`
55+
//~| found `Box<_>`
56+
//~| expected trait T
57+
//~| found box
4358
}

src/test/compile-fail/dst-bad-assign.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ pub fn main() {
4444
// Assignment.
4545
let f5: &mut Fat<ToBar> = &mut Fat { f1: 5, f2: "some str", ptr: Bar1 {f :42} };
4646
let z: Box<ToBar> = box Bar1 {f: 36};
47-
f5.ptr = Bar1 {f: 36}; //~ ERROR mismatched types: expected `ToBar`, found `Bar1`
48-
//~^ ERROR the trait `core::marker::Sized` is not implemented for the type `ToBar`
47+
f5.ptr = Bar1 {f: 36};
48+
//~^ ERROR mismatched types
49+
//~| expected `ToBar`
50+
//~| found `Bar1`
51+
//~| expected trait ToBar
52+
//~| found struct `Bar1`
53+
//~| ERROR the trait `core::marker::Sized` is not implemented for the type `ToBar`
4954
}

src/test/compile-fail/dst-bad-coerce1.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ pub fn main() {
2222
let f1 = Fat { ptr: [1, 2, 3] };
2323
let f2: &Fat<[isize; 3]> = &f1;
2424
let f3: &Fat<[usize]> = f2;
25-
//~^ ERROR mismatched types: expected `&Fat<[usize]>`, found `&Fat<[isize; 3]>`
25+
//~^ ERROR mismatched types
26+
//~| expected `&Fat<[usize]>`
27+
//~| found `&Fat<[isize; 3]>`
28+
//~| expected usize
29+
//~| found isize
2630

2731
// With a trait.
2832
let f1 = Fat { ptr: Foo };

src/test/compile-fail/dst-bad-coerce4.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,9 @@ pub fn main() {
1818
// With a vec of isizes.
1919
let f1: &Fat<[isize]> = &Fat { ptr: [1, 2, 3] };
2020
let f2: &Fat<[isize; 3]> = f1;
21-
//~^ ERROR mismatched types: expected `&Fat<[isize; 3]>`, found `&Fat<[isize]>`
21+
//~^ ERROR mismatched types
22+
//~| expected `&Fat<[isize; 3]>`
23+
//~| found `&Fat<[isize]>`
24+
//~| expected array of 3 elements
25+
//~| found slice
2226
}

src/test/compile-fail/explicit-self-lifetime-mismatch.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,14 @@ struct Foo<'a,'b> {
1515

1616
impl<'a,'b> Foo<'a,'b> {
1717
fn bar(self: Foo<'b,'a>) {}
18-
//~^ ERROR mismatched types: expected `Foo<'a, 'b>`, found `Foo<'b, 'a>`
19-
//~^^ ERROR mismatched types: expected `Foo<'a, 'b>`, found `Foo<'b, 'a>`
18+
//~^ ERROR mismatched types
19+
//~| expected `Foo<'a, 'b>`
20+
//~| found `Foo<'b, 'a>`
21+
//~| lifetime mismatch
22+
//~| ERROR mismatched types
23+
//~| expected `Foo<'a, 'b>`
24+
//~| found `Foo<'b, 'a>`
25+
//~| lifetime mismatch
2026
}
2127

2228
fn main() {}

0 commit comments

Comments
 (0)