mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-19 02:57:33 +00:00
improve error message
This commit is contained in:
parent
8a461d940c
commit
728d20f7cc
@ -371,13 +371,13 @@ assert_eq!(6, answer);
|
|||||||
This gives us these long, related errors:
|
This gives us these long, related errors:
|
||||||
|
|
||||||
```text
|
```text
|
||||||
error: the predicate `core::ops::Fn(i32) -> i32 : core::marker::Sized` is not satisfied [E0277]
|
error: the trait bound `core::ops::Fn(i32) -> i32 : core::marker::Sized` is not satisfied [E0277]
|
||||||
fn factory() -> (Fn(i32) -> i32) {
|
fn factory() -> (Fn(i32) -> i32) {
|
||||||
^~~~~~~~~~~~~~~~
|
^~~~~~~~~~~~~~~~
|
||||||
note: `core::ops::Fn(i32) -> i32` does not have a constant size known at compile-time
|
note: `core::ops::Fn(i32) -> i32` does not have a constant size known at compile-time
|
||||||
fn factory() -> (Fn(i32) -> i32) {
|
fn factory() -> (Fn(i32) -> i32) {
|
||||||
^~~~~~~~~~~~~~~~
|
^~~~~~~~~~~~~~~~
|
||||||
error: the predicate `core::ops::Fn(i32) -> i32 : core::marker::Sized` is not satisfied [E0277]
|
error: the trait bound `core::ops::Fn(i32) -> i32 : core::marker::Sized` is not satisfied [E0277]
|
||||||
let f = factory();
|
let f = factory();
|
||||||
^
|
^
|
||||||
note: `core::ops::Fn(i32) -> i32` does not have a constant size known at compile-time
|
note: `core::ops::Fn(i32) -> i32` does not have a constant size known at compile-time
|
||||||
|
@ -231,7 +231,7 @@ fn main() {
|
|||||||
This won't work, however, and will give us the error:
|
This won't work, however, and will give us the error:
|
||||||
|
|
||||||
```text
|
```text
|
||||||
13:9: 13:22 error: the predicate `alloc::rc::Rc<collections::vec::Vec<i32>> : core::marker::Send`
|
13:9: 13:22 error: the trait bound `alloc::rc::Rc<collections::vec::Vec<i32>> : core::marker::Send`
|
||||||
is not satisfied
|
is not satisfied
|
||||||
...
|
...
|
||||||
13:9: 13:22 note: `alloc::rc::Rc<collections::vec::Vec<i32>>`
|
13:9: 13:22 note: `alloc::rc::Rc<collections::vec::Vec<i32>>`
|
||||||
|
@ -154,7 +154,7 @@ print_area(5);
|
|||||||
We get a compile-time error:
|
We get a compile-time error:
|
||||||
|
|
||||||
```text
|
```text
|
||||||
error: the predicate `_ : HasArea` is not satisfied [E0277]
|
error: the trait bound `_ : HasArea` is not satisfied [E0277]
|
||||||
```
|
```
|
||||||
|
|
||||||
## Trait bounds on generic structs
|
## Trait bounds on generic structs
|
||||||
@ -496,7 +496,7 @@ impl FooBar for Baz {
|
|||||||
If we forget to implement `Foo`, Rust will tell us:
|
If we forget to implement `Foo`, Rust will tell us:
|
||||||
|
|
||||||
```text
|
```text
|
||||||
error: the predicate `main::Baz : main::Foo` is not satisfied [E0277]
|
error: the trait bound `main::Baz : main::Foo` is not satisfied [E0277]
|
||||||
```
|
```
|
||||||
|
|
||||||
# Deriving
|
# Deriving
|
||||||
|
@ -56,7 +56,7 @@ v[j];
|
|||||||
Indexing with a non-`usize` type gives an error that looks like this:
|
Indexing with a non-`usize` type gives an error that looks like this:
|
||||||
|
|
||||||
```text
|
```text
|
||||||
error: the predicate `collections::vec::Vec<_> : core::ops::Index<i32>`
|
error: the trait bound `collections::vec::Vec<_> : core::ops::Index<i32>`
|
||||||
is not satisfied [E0277]
|
is not satisfied [E0277]
|
||||||
v[j];
|
v[j];
|
||||||
^~~~
|
^~~~
|
||||||
|
@ -64,7 +64,7 @@ fn main() {
|
|||||||
```
|
```
|
||||||
|
|
||||||
```text
|
```text
|
||||||
<anon>:10:5: 10:8 error: the predicate `&mut i32 : Trait` is not satisfied [E0277]
|
<anon>:10:5: 10:8 error: the trait bound `&mut i32 : Trait` is not satisfied [E0277]
|
||||||
<anon>:10 foo(t);
|
<anon>:10 foo(t);
|
||||||
^~~
|
^~~
|
||||||
```
|
```
|
||||||
|
@ -1006,7 +1006,7 @@ fn some_func<T: Foo>(foo: T) {
|
|||||||
fn main() {
|
fn main() {
|
||||||
// we now call the method with the i32 type, which doesn't implement
|
// we now call the method with the i32 type, which doesn't implement
|
||||||
// the Foo trait
|
// the Foo trait
|
||||||
some_func(5i32); // error: the predicate `i32 : Foo` is not satisfied
|
some_func(5i32); // error: the trait bound `i32 : Foo` is not satisfied
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -361,7 +361,7 @@ pub fn report_selection_error<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
|
|||||||
let trait_ref = trait_predicate.to_poly_trait_ref();
|
let trait_ref = trait_predicate.to_poly_trait_ref();
|
||||||
let mut err = struct_span_err!(
|
let mut err = struct_span_err!(
|
||||||
infcx.tcx.sess, obligation.cause.span, E0277,
|
infcx.tcx.sess, obligation.cause.span, E0277,
|
||||||
"the predicate `{}` is not satisfied",
|
"the trait bound `{}` is not satisfied",
|
||||||
trait_ref.to_predicate());
|
trait_ref.to_predicate());
|
||||||
|
|
||||||
// Try to report a good error message.
|
// Try to report a good error message.
|
||||||
|
@ -15,7 +15,7 @@ trait Get {
|
|||||||
|
|
||||||
trait Other {
|
trait Other {
|
||||||
fn uhoh<U:Get>(&self, foo: U, bar: <Self as Get>::Value) {}
|
fn uhoh<U:Get>(&self, foo: U, bar: <Self as Get>::Value) {}
|
||||||
//~^ ERROR the predicate `Self : Get` is not satisfied
|
//~^ ERROR the trait bound `Self : Get` is not satisfied
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
@ -18,7 +18,7 @@ trait Foo<T> {
|
|||||||
|
|
||||||
fn f<T:Foo<isize>>(t: &T) {
|
fn f<T:Foo<isize>>(t: &T) {
|
||||||
let u: <T as Foo<usize>>::Bar = t.get_bar();
|
let u: <T as Foo<usize>>::Bar = t.get_bar();
|
||||||
//~^ ERROR the predicate `T : Foo<usize>` is not satisfied
|
//~^ ERROR the trait bound `T : Foo<usize>` is not satisfied
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() { }
|
fn main() { }
|
||||||
|
@ -19,7 +19,7 @@ struct Struct {
|
|||||||
|
|
||||||
impl Struct {
|
impl Struct {
|
||||||
fn uhoh<T>(foo: <T as Get>::Value) {}
|
fn uhoh<T>(foo: <T as Get>::Value) {}
|
||||||
//~^ ERROR the predicate `T : Get` is not satisfied
|
//~^ ERROR the trait bound `T : Get` is not satisfied
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
@ -25,7 +25,7 @@ trait Get {
|
|||||||
|
|
||||||
trait Other {
|
trait Other {
|
||||||
fn uhoh<U:Get>(&self, foo: U, bar: <Self as Get>::Value) {}
|
fn uhoh<U:Get>(&self, foo: U, bar: <Self as Get>::Value) {}
|
||||||
//~^ ERROR the predicate `Self : Get` is not satisfied
|
//~^ ERROR the trait bound `Self : Get` is not satisfied
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() { }
|
fn main() { }
|
||||||
|
@ -25,12 +25,12 @@ trait Get {
|
|||||||
|
|
||||||
trait Other {
|
trait Other {
|
||||||
fn uhoh<U:Get>(&self, foo: U, bar: <Self as Get>::Value) {}
|
fn uhoh<U:Get>(&self, foo: U, bar: <Self as Get>::Value) {}
|
||||||
//~^ ERROR the predicate `Self : Get` is not satisfied
|
//~^ ERROR the trait bound `Self : Get` is not satisfied
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T:Get> Other for T {
|
impl<T:Get> Other for T {
|
||||||
fn uhoh<U:Get>(&self, foo: U, bar: <(T, U) as Get>::Value) {}
|
fn uhoh<U:Get>(&self, foo: U, bar: <(T, U) as Get>::Value) {}
|
||||||
//~^ ERROR the predicate `(T, U) : Get` is not satisfied
|
//~^ ERROR the trait bound `(T, U) : Get` is not satisfied
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() { }
|
fn main() { }
|
||||||
|
@ -91,7 +91,7 @@ fn main()
|
|||||||
let _ = 42usize as *const [u8]; //~ ERROR casting
|
let _ = 42usize as *const [u8]; //~ ERROR casting
|
||||||
let _ = v as *const [u8]; //~ ERROR cannot cast
|
let _ = v as *const [u8]; //~ ERROR cannot cast
|
||||||
let _ = fat_v as *const Foo;
|
let _ = fat_v as *const Foo;
|
||||||
//~^ ERROR the predicate `[u8] : std::marker::Sized` is not satisfied
|
//~^ ERROR the trait bound `[u8] : std::marker::Sized` is not satisfied
|
||||||
//~^^ HELP run `rustc --explain E0277` to see a detailed explanation
|
//~^^ HELP run `rustc --explain E0277` to see a detailed explanation
|
||||||
//~^^^ NOTE `[u8]` does not have a constant size known at compile-time
|
//~^^^ NOTE `[u8]` does not have a constant size known at compile-time
|
||||||
//~^^^^ NOTE required for the cast to the object type `Foo`
|
//~^^^^ NOTE required for the cast to the object type `Foo`
|
||||||
@ -106,7 +106,7 @@ fn main()
|
|||||||
|
|
||||||
let a : *const str = "hello";
|
let a : *const str = "hello";
|
||||||
let _ = a as *const Foo;
|
let _ = a as *const Foo;
|
||||||
//~^ ERROR the predicate `str : std::marker::Sized` is not satisfied
|
//~^ ERROR the trait bound `str : std::marker::Sized` is not satisfied
|
||||||
//~^^ HELP run `rustc --explain E0277` to see a detailed explanation
|
//~^^ HELP run `rustc --explain E0277` to see a detailed explanation
|
||||||
//~^^^ NOTE `str` does not have a constant size known at compile-time
|
//~^^^ NOTE `str` does not have a constant size known at compile-time
|
||||||
//~^^^^ NOTE required for the cast to the object type `Foo`
|
//~^^^^ NOTE required for the cast to the object type `Foo`
|
||||||
|
@ -23,7 +23,7 @@ trait Bar<X> { }
|
|||||||
|
|
||||||
// We don't always check where clauses for sanity, but in this case
|
// We don't always check where clauses for sanity, but in this case
|
||||||
// wfcheck does report an error here:
|
// wfcheck does report an error here:
|
||||||
fn vacuous<A>() //~ ERROR the predicate `i32 : Bar<u32>` is not satisfied
|
fn vacuous<A>() //~ ERROR the trait bound `i32 : Bar<u32>` is not satisfied
|
||||||
where i32: Foo<u32, A>
|
where i32: Foo<u32, A>
|
||||||
{
|
{
|
||||||
// ... the original intention was to check that we don't use that
|
// ... the original intention was to check that we don't use that
|
||||||
|
@ -32,7 +32,7 @@ fn main() {
|
|||||||
let f1 = Bar;
|
let f1 = Bar;
|
||||||
|
|
||||||
f1.foo(1usize);
|
f1.foo(1usize);
|
||||||
//~^ error: the predicate `Bar : Foo<usize>` is not satisfied
|
//~^ error: the trait bound `Bar : Foo<usize>` is not satisfied
|
||||||
//~| help: the following implementations were found:
|
//~| help: the following implementations were found:
|
||||||
//~| help: <Bar as Foo<i32>>
|
//~| help: <Bar as Foo<i32>>
|
||||||
//~| help: <Bar as Foo<u8>>
|
//~| help: <Bar as Foo<u8>>
|
||||||
|
@ -36,7 +36,7 @@ fn main() {
|
|||||||
let f1 = Bar;
|
let f1 = Bar;
|
||||||
|
|
||||||
f1.foo(1usize);
|
f1.foo(1usize);
|
||||||
//~^ error: the predicate `Bar : Foo<usize>` is not satisfied
|
//~^ error: the trait bound `Bar : Foo<usize>` is not satisfied
|
||||||
//~| help: the following implementations were found:
|
//~| help: the following implementations were found:
|
||||||
//~| help: <Bar as Foo<i8>>
|
//~| help: <Bar as Foo<i8>>
|
||||||
//~| help: <Bar as Foo<i16>>
|
//~| help: <Bar as Foo<i16>>
|
||||||
|
@ -25,7 +25,7 @@ pub trait Foo {
|
|||||||
|
|
||||||
impl<T> Foo for T {
|
impl<T> Foo for T {
|
||||||
type Bar = MySet<T>;
|
type Bar = MySet<T>;
|
||||||
//~^ ERROR the predicate `T : MyHash` is not satisfied
|
//~^ ERROR the trait bound `T : MyHash` is not satisfied
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rustc_error]
|
#[rustc_error]
|
||||||
|
@ -21,7 +21,7 @@ impl<T> Foo<T> {
|
|||||||
|
|
||||||
fn fails_copy(self) {
|
fn fails_copy(self) {
|
||||||
require_copy(self.x);
|
require_copy(self.x);
|
||||||
//~^ ERROR the predicate `T : std::marker::Copy` is not satisfied
|
//~^ ERROR the trait bound `T : std::marker::Copy` is not satisfied
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ impl<T> Foo<T> for Bar<T> {
|
|||||||
|
|
||||||
fn fails_copy(self) {
|
fn fails_copy(self) {
|
||||||
require_copy(self.x);
|
require_copy(self.x);
|
||||||
//~^ ERROR the predicate `T : std::marker::Copy` is not satisfied
|
//~^ ERROR the trait bound `T : std::marker::Copy` is not satisfied
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,5 +28,5 @@ impl Bar<X> for isize {
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
1.method::<X>();
|
1.method::<X>();
|
||||||
//~^ ERROR the predicate `X : Foo<X>` is not satisfied
|
//~^ ERROR the trait bound `X : Foo<X>` is not satisfied
|
||||||
}
|
}
|
||||||
|
@ -15,5 +15,5 @@ struct Struct;
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
drop(equal(&Struct, &Struct))
|
drop(equal(&Struct, &Struct))
|
||||||
//~^ ERROR the predicate `Struct : std::cmp::Eq` is not satisfied
|
//~^ ERROR the trait bound `Struct : std::cmp::Eq` is not satisfied
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user