Skip to content

Commit 7d984ef

Browse files
committed
split "has incompatible type for trait" errors into multiple lines
closes #21332
1 parent a27fed7 commit 7d984ef

8 files changed

+44
-9
lines changed

Diff for: src/librustc/session/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,8 @@ fn split_msg_into_multilines(msg: &str) -> Option<String> {
301301
!msg.contains("if and else have incompatible types") &&
302302
!msg.contains("if may be missing an else clause") &&
303303
!msg.contains("match arms have incompatible types") &&
304-
!msg.contains("structure constructor specifies a structure of type") {
304+
!msg.contains("structure constructor specifies a structure of type") &&
305+
!msg.contains("has an incompatible type for trait") {
305306
return None
306307
}
307308
let first = msg.match_indices("expected").filter(|s| {

Diff for: src/test/compile-fail/associated-const-impl-wrong-type.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ struct SignedBar;
1818

1919
impl Foo for SignedBar {
2020
const BAR: i32 = -1;
21-
//~^ ERROR E0326
21+
//~^ ERROR implemented const `BAR` has an incompatible type for trait
22+
//~| expected u32,
23+
//~| found i32 [E0326]
2224
}
2325

2426
fn main() {}

Diff for: src/test/compile-fail/issue-15094.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ struct Debuger<T> {
1919
impl<T: fmt::Debug> ops::FnOnce<(),> for Debuger<T> {
2020
type Output = ();
2121
fn call_once(self, _args: ()) {
22-
//~^ ERROR `call_once` has an incompatible type for trait: expected "rust-call" fn, found "Rust" fn
22+
//~^ ERROR `call_once` has an incompatible type for trait
23+
//~| expected "rust-call" fn,
24+
//~| found "Rust" fn
2325
println!("{:?}", self.x);
2426
}
2527
}

Diff for: src/test/compile-fail/issue-20225.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,22 @@ struct Foo;
1414

1515
impl<'a, T> Fn<(&'a T,)> for Foo {
1616
extern "rust-call" fn call(&self, (_,): (T,)) {}
17-
//~^ ERROR: has an incompatible type for trait: expected &-ptr
17+
//~^ ERROR: has an incompatible type for trait
18+
//~| expected &-ptr
1819
}
1920

2021
impl<'a, T> FnMut<(&'a T,)> for Foo {
2122
extern "rust-call" fn call_mut(&mut self, (_,): (T,)) {}
22-
//~^ ERROR: has an incompatible type for trait: expected &-ptr
23+
//~^ ERROR: has an incompatible type for trait
24+
//~| expected &-ptr
2325
}
2426

2527
impl<'a, T> FnOnce<(&'a T,)> for Foo {
2628
type Output = ();
2729

2830
extern "rust-call" fn call_once(self, (_,): (T,)) {}
29-
//~^ ERROR: has an incompatible type for trait: expected &-ptr
31+
//~^ ERROR: has an incompatible type for trait
32+
//~| expected &-ptr
3033
}
3134

3235
fn main() {}

Diff for: src/test/compile-fail/issue-21332.rs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
struct S;
12+
13+
impl Iterator for S {
14+
type Item = i32;
15+
fn next(&mut self) -> Result<i32, i32> { Ok(7) }
16+
//~^ ERROR method `next` has an incompatible type for trait
17+
//~| expected enum `core::option::Option`
18+
//~| found enum `core::result::Result` [E0053]
19+
}
20+
21+
fn main() {}

Diff for: src/test/compile-fail/issue-24356.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ fn main() {
3030
impl Deref for Thing {
3131
//~^ ERROR not all trait items implemented, missing: `Target` [E0046]
3232
fn deref(&self) -> i8 { self.0 }
33-
//~^ ERROR method `deref` has an incompatible type for trait: expected &-ptr, found i8 [E0053]
33+
//~^ ERROR method `deref` has an incompatible type for trait
34+
//~| expected &-ptr
35+
//~| found i8 [E0053]
3436
}
3537

3638
let thing = Thing(72);

Diff for: src/test/compile-fail/trait-impl-method-mismatch.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ trait Mumbo {
1616
impl Mumbo for usize {
1717
// Cannot have a larger effect than the trait:
1818
unsafe fn jumbo(&self, x: &usize) { *self + *x; }
19-
//~^ ERROR expected normal fn, found unsafe fn
19+
//~^ ERROR method `jumbo` has an incompatible type for trait
20+
//~| expected normal fn,
21+
//~| found unsafe fn
2022
}
2123

2224
fn main() {}

Diff for: src/test/compile-fail/unsafe-trait-impl.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ trait Foo {
1616

1717
impl Foo for u32 {
1818
fn len(&self) -> u32 { *self }
19-
//~^ ERROR incompatible type for trait: expected unsafe fn, found normal fn
19+
//~^ ERROR method `len` has an incompatible type for trait
20+
//~| expected unsafe fn,
21+
//~| found normal fn
2022
}
2123

2224
fn main() { }

0 commit comments

Comments
 (0)