Skip to content

Commit 050499c

Browse files
author
Jonathan Turner
authored
Rollup merge of rust-lang#37324 - GuillaumeGomez:trait_error_message, r=jonathandturner
Improve E0277 help message Fixes rust-lang#37319. r? @jonathandturner
2 parents 855f3e7 + 1fadd86 commit 050499c

11 files changed

+41
-36
lines changed

src/librustc/traits/error_reporting.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,8 +445,10 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
445445
let mut err = struct_span_err!(self.tcx.sess, span, E0277,
446446
"the trait bound `{}` is not satisfied",
447447
trait_ref.to_predicate());
448-
err.span_label(span, &format!("trait `{}` not satisfied",
449-
trait_ref.to_predicate()));
448+
err.span_label(span, &format!("the trait `{}` is not implemented \
449+
for `{}`",
450+
trait_ref,
451+
trait_ref.self_ty()));
450452

451453
// Try to report a help message
452454

src/test/compile-fail/E0277.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ fn some_func<T: Foo>(foo: T) {
1919
fn main() {
2020
some_func(5i32);
2121
//~^ ERROR the trait bound `i32: Foo` is not satisfied
22-
//~| NOTE trait `i32: Foo` not satisfied
22+
//~| NOTE the trait `Foo` is not implemented for `i32`
2323
//~| NOTE required by `some_func`
2424
}

src/test/compile-fail/associated-types-ICE-when-projecting-out-of-err.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@ fn ice<A>(a: A) {
3232
let r = loop {};
3333
r = r + a;
3434
//~^ ERROR the trait bound `(): Add<A>` is not satisfied
35-
//~| NOTE trait `(): Add<A>` not satisfied
35+
//~| NOTE the trait `Add<A>` is not implemented for `()`
3636
}

src/test/compile-fail/cast-rfc0401.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ fn main()
9292
let _ = v as *const [u8]; //~ ERROR cannot cast
9393
let _ = fat_v as *const Foo;
9494
//~^ ERROR the trait bound `[u8]: std::marker::Sized` is not satisfied
95-
//~| NOTE trait `[u8]: std::marker::Sized` not satisfied
95+
//~| NOTE the trait `std::marker::Sized` is not implemented for `[u8]`
9696
//~| NOTE `[u8]` does not have a constant size known at compile-time
9797
//~| NOTE required for the cast to the object type `Foo`
9898
let _ = foo as *const str; //~ ERROR casting
@@ -107,7 +107,7 @@ fn main()
107107
let a : *const str = "hello";
108108
let _ = a as *const Foo;
109109
//~^ ERROR the trait bound `str: std::marker::Sized` is not satisfied
110-
//~| NOTE trait `str: std::marker::Sized` not satisfied
110+
//~| NOTE the trait `std::marker::Sized` is not implemented for `str`
111111
//~| NOTE `str` does not have a constant size known at compile-time
112112
//~| NOTE required for the cast to the object type `Foo`
113113

src/test/compile-fail/const-unsized.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,25 @@ use std::fmt::Debug;
1212

1313
const CONST_0: Debug+Sync = *(&0 as &(Debug+Sync));
1414
//~^ ERROR `std::fmt::Debug + Sync + 'static: std::marker::Sized` is not satisfied
15-
//~| NOTE `std::fmt::Debug + Sync + 'static: std::marker::Sized` not satisfied
15+
//~| NOTE the trait `std::marker::Sized` is not implemented for `std::fmt::Debug + Sync + 'static`
1616
//~| NOTE does not have a constant size known at compile-time
1717
//~| NOTE constant expressions must have a statically known size
1818

1919
const CONST_FOO: str = *"foo";
2020
//~^ ERROR `str: std::marker::Sized` is not satisfied
21-
//~| NOTE `str: std::marker::Sized` not satisfied
21+
//~| NOTE the trait `std::marker::Sized` is not implemented for `str`
2222
//~| NOTE does not have a constant size known at compile-time
2323
//~| NOTE constant expressions must have a statically known size
2424

2525
static STATIC_1: Debug+Sync = *(&1 as &(Debug+Sync));
2626
//~^ ERROR `std::fmt::Debug + Sync + 'static: std::marker::Sized` is not satisfied
27-
//~| NOTE `std::fmt::Debug + Sync + 'static: std::marker::Sized` not satisfied
27+
//~| NOTE the trait `std::marker::Sized` is not implemented for `std::fmt::Debug + Sync + 'static`
2828
//~| NOTE does not have a constant size known at compile-time
2929
//~| NOTE constant expressions must have a statically known size
3030

3131
static STATIC_BAR: str = *"bar";
3232
//~^ ERROR `str: std::marker::Sized` is not satisfied
33-
//~| NOTE `str: std::marker::Sized` not satisfied
33+
//~| NOTE the trait `std::marker::Sized` is not implemented for `str`
3434
//~| NOTE does not have a constant size known at compile-time
3535
//~| NOTE constant expressions must have a statically known size
3636

src/test/compile-fail/impl-trait/auto-trait-leak.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ fn send<T: Send>(_: T) {}
2626
fn main() {
2727
send(before());
2828
//~^ ERROR the trait bound `std::rc::Rc<std::cell::Cell<i32>>: std::marker::Send` is not satisfied
29-
//~| NOTE trait `std::rc::Rc<std::cell::Cell<i32>>: std::marker::Send` not satisfied
29+
//~| NOTE the trait `std::marker::Send` is not implemented for `std::rc::Rc<std::cell::Cell<i32>>`
3030
//~| NOTE `std::rc::Rc<std::cell::Cell<i32>>` cannot be sent between threads safely
3131
//~| NOTE required because it appears within the type `[closure
3232
//~| NOTE required because it appears within the type `impl std::ops::Fn<(i32,)>`
3333
//~| NOTE required by `send`
3434

3535
send(after());
3636
//~^ ERROR the trait bound `std::rc::Rc<std::cell::Cell<i32>>: std::marker::Send` is not satisfied
37-
//~| NOTE trait `std::rc::Rc<std::cell::Cell<i32>>: std::marker::Send` not satisfied
37+
//~| NOTE the trait `std::marker::Send` is not implemented for `std::rc::Rc<std::cell::Cell<i32>>`
3838
//~| NOTE `std::rc::Rc<std::cell::Cell<i32>>` cannot be sent between threads safely
3939
//~| NOTE required because it appears within the type `[closure
4040
//~| NOTE required because it appears within the type `impl std::ops::Fn<(i32,)>`
@@ -54,7 +54,7 @@ fn after() -> impl Fn(i32) {
5454
fn cycle1() -> impl Clone {
5555
send(cycle2().clone());
5656
//~^ ERROR the trait bound `std::rc::Rc<std::string::String>: std::marker::Send` is not satisfied
57-
//~| NOTE trait `std::rc::Rc<std::string::String>: std::marker::Send` not satisfied
57+
//~| NOTE the trait `std::marker::Send` is not implemented for `std::rc::Rc<std::string::String>`
5858
//~| NOTE `std::rc::Rc<std::string::String>` cannot be sent between threads safely
5959
//~| NOTE required because it appears within the type `impl std::clone::Clone`
6060
//~| NOTE required by `send`
@@ -65,7 +65,7 @@ fn cycle1() -> impl Clone {
6565
fn cycle2() -> impl Clone {
6666
send(cycle1().clone());
6767
//~^ ERROR the trait bound `std::rc::Rc<std::cell::Cell<i32>>: std::marker::Send` is not satisfied
68-
//~| NOTE trait `std::rc::Rc<std::cell::Cell<i32>>: std::marker::Send` not satisfied
68+
//~| NOTE the trait `std::marker::Send` is not implemented for `std::rc::Rc<std::cell::Cell<i32>>`
6969
//~| NOTE `std::rc::Rc<std::cell::Cell<i32>>` cannot be sent between threads safely
7070
//~| NOTE required because it appears within the type `impl std::clone::Clone`
7171
//~| NOTE required by `send`

src/test/compile-fail/on-unimplemented/multiple-impls.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,17 @@ impl Index<Bar<usize>> for [i32] {
4242
fn main() {
4343
Index::index(&[] as &[i32], 2u32);
4444
//~^ ERROR E0277
45-
//~| NOTE not satisfied
45+
//~| NOTE the trait `Index<u32>` is not implemented for `[i32]`
4646
//~| NOTE trait message
4747
//~| NOTE required by
4848
Index::index(&[] as &[i32], Foo(2u32));
4949
//~^ ERROR E0277
50-
//~| NOTE not satisfied
50+
//~| NOTE the trait `Index<Foo<u32>>` is not implemented for `[i32]`
5151
//~| NOTE on impl for Foo
5252
//~| NOTE required by
5353
Index::index(&[] as &[i32], Bar(2u32));
5454
//~^ ERROR E0277
55-
//~| NOTE not satisfied
55+
//~| NOTE the trait `Index<Bar<u32>>` is not implemented for `[i32]`
5656
//~| NOTE on impl for Bar
5757
//~| NOTE required by
5858
}

src/test/compile-fail/on-unimplemented/on-impl.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ impl Index<usize> for [i32] {
2929

3030
#[rustc_error]
3131
fn main() {
32-
Index::<u32>::index(&[1, 2, 3] as &[i32], 2u32); //~ ERROR E0277
33-
//~| NOTE not satisfied
34-
//~| NOTE a usize is required
35-
//~| NOTE required by
32+
Index::<u32>::index(&[1, 2, 3] as &[i32], 2u32);
33+
//~^ ERROR E0277
34+
//~| NOTE the trait `Index<u32>` is not implemented for `[i32]`
35+
//~| NOTE a usize is required
36+
//~| NOTE required by
3637
}

src/test/compile-fail/on-unimplemented/on-trait.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ pub fn main() {
3535
//~^ ERROR
3636
//~^^ NOTE a collection of type `std::option::Option<std::vec::Vec<u8>>` cannot be built from an iterator over elements of type `&u8`
3737
//~^^^ NOTE required by `collect`
38-
//~| NOTE trait `std::option::Option<std::vec::Vec<u8>>: MyFromIterator<&u8>` not satisfied
38+
//~| NOTE the trait `MyFromIterator<&u8>` is not implemented for `std::option::Option<std::vec::Vec<u8>>`
3939
let x: String = foobar(); //~ ERROR
4040
//~^ NOTE test error `std::string::String` with `u8` `_` `u32`
4141
//~^^ NOTE required by `foobar`
42-
//~| NOTE trait `std::string::String: Foo<u8, _, u32>` not satisfied
42+
//~| NOTE the trait `Foo<u8, _, u32>` is not implemented for `std::string::String`
4343
}

src/test/compile-fail/on-unimplemented/slice-index.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ use std::ops::Index;
1717
#[rustc_error]
1818
fn main() {
1919
let x = &[1, 2, 3] as &[i32];
20-
x[1i32]; //~ ERROR E0277
21-
//~| NOTE trait `[i32]: std::ops::Index<i32>` not satisfied
22-
//~| NOTE slice indices are of type `usize`
23-
x[..1i32]; //~ ERROR E0277
24-
//~| NOTE trait `[i32]: std::ops::Index<std::ops::RangeTo<i32>>` not satisfied
25-
//~| NOTE slice indices are of type `usize`
20+
x[1i32];
21+
//~^ ERROR E0277
22+
//~| NOTE the trait `std::ops::Index<i32>` is not implemented for `[i32]`
23+
//~| NOTE slice indices are of type `usize`
24+
x[..1i32];
25+
//~^ ERROR E0277
26+
//~| NOTE the trait `std::ops::Index<std::ops::RangeTo<i32>>` is not implemented for `[i32]`
27+
//~| NOTE slice indices are of type `usize`
2628
}

src/test/compile-fail/trait-suggest-where-clause.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ fn check<T: Iterator, U: ?Sized>() {
1616
// suggest a where-clause, if needed
1717
mem::size_of::<U>();
1818
//~^ ERROR `U: std::marker::Sized` is not satisfied
19-
//~| NOTE trait `U: std::marker::Sized` not satisfied
19+
//~| NOTE the trait `std::marker::Sized` is not implemented for `U`
2020
//~| HELP consider adding a `where U: std::marker::Sized` bound
2121
//~| NOTE required by `std::mem::size_of`
2222

2323
mem::size_of::<Misc<U>>();
2424
//~^ ERROR `U: std::marker::Sized` is not satisfied
25-
//~| NOTE trait `U: std::marker::Sized` not satisfied
25+
//~| NOTE the trait `std::marker::Sized` is not implemented for `U`
2626
//~| HELP consider adding a `where U: std::marker::Sized` bound
2727
//~| NOTE required because it appears within the type `Misc<U>`
2828
//~| NOTE required by `std::mem::size_of`
@@ -31,34 +31,34 @@ fn check<T: Iterator, U: ?Sized>() {
3131

3232
<u64 as From<T>>::from;
3333
//~^ ERROR `u64: std::convert::From<T>` is not satisfied
34-
//~| NOTE trait `u64: std::convert::From<T>` not satisfied
34+
//~| NOTE the trait `std::convert::From<T>` is not implemented for `u64`
3535
//~| HELP consider adding a `where u64: std::convert::From<T>` bound
3636
//~| NOTE required by `std::convert::From::from`
3737

3838
<u64 as From<<T as Iterator>::Item>>::from;
3939
//~^ ERROR `u64: std::convert::From<<T as std::iter::Iterator>::Item>` is not satisfied
40-
//~| NOTE trait `u64: std::convert::From<<T as std::iter::Iterator>::Item>` not satisfied
40+
//~| NOTE the trait `std::convert::From<<T as std::iter::Iterator>::Item>` is not implemented
4141
//~| HELP consider adding a `where u64:
4242
//~| NOTE required by `std::convert::From::from`
4343

4444
// ... but not if there are inference variables
4545

4646
<Misc<_> as From<T>>::from;
4747
//~^ ERROR `Misc<_>: std::convert::From<T>` is not satisfied
48-
//~| NOTE trait `Misc<_>: std::convert::From<T>` not satisfied
48+
//~| NOTE the trait `std::convert::From<T>` is not implemented for `Misc<_>`
4949
//~| NOTE required by `std::convert::From::from`
5050

5151
// ... and also not if the error is not related to the type
5252

5353
mem::size_of::<[T]>();
5454
//~^ ERROR `[T]: std::marker::Sized` is not satisfied
55-
//~| NOTE `[T]: std::marker::Sized` not satisfied
55+
//~| NOTE the trait `std::marker::Sized` is not implemented for `[T]`
5656
//~| NOTE `[T]` does not have a constant size
5757
//~| NOTE required by `std::mem::size_of`
5858

5959
mem::size_of::<[&U]>();
6060
//~^ ERROR `[&U]: std::marker::Sized` is not satisfied
61-
//~| NOTE `[&U]: std::marker::Sized` not satisfied
61+
//~| NOTE the trait `std::marker::Sized` is not implemented for `[&U]`
6262
//~| NOTE `[&U]` does not have a constant size
6363
//~| NOTE required by `std::mem::size_of`
6464
}

0 commit comments

Comments
 (0)