Fix E0284 to not use incorrect wording

Fix #71584, fix #69683.
This commit is contained in:
Esteban Küber 2020-05-06 15:26:03 -07:00
parent 339f574809
commit a7b03ad4ed
9 changed files with 81 additions and 26 deletions

View File

@ -1492,12 +1492,26 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
ty::Predicate::Projection(ref data) => {
let trait_ref = data.to_poly_trait_ref(self.tcx);
let self_ty = trait_ref.self_ty();
let ty = data.skip_binder().ty;
if predicate.references_error() {
return;
}
let mut err = self.need_type_info_err(body_id, span, self_ty, ErrorCode::E0284);
err.note(&format!("cannot satisfy `{}`", predicate));
err
if self_ty.needs_infer() && ty.needs_infer() {
// We do this for the `foo.collect()?` case to produce a suggestion.
let mut err = self.need_type_info_err(body_id, span, self_ty, ErrorCode::E0284);
err.note(&format!("cannot satisfy `{}`", predicate));
err
} else {
let mut err = struct_span_err!(
self.tcx.sess,
span,
E0284,
"type annotations needed: cannot satisfy `{}`",
predicate,
);
err.span_label(span, &format!("cannot satisfy `{}`", predicate));
err
}
}
_ => {

View File

@ -1,22 +1,18 @@
error[E0284]: type annotations needed
error[E0284]: type annotations needed: cannot satisfy `<Self as std::iter::Iterator>::Item == i32`
--> $DIR/associated-types-overridden-binding.rs:4:12
|
LL | trait Foo: Iterator<Item = i32> {}
| ---------- required by this bound in `Foo`
LL | trait Bar: Foo<Item = u32> {}
| ^^^^^^^^^^^^^^^ cannot infer type for type parameter `Self`
|
= note: cannot satisfy `<Self as std::iter::Iterator>::Item == i32`
| ^^^^^^^^^^^^^^^ cannot satisfy `<Self as std::iter::Iterator>::Item == i32`
error[E0284]: type annotations needed
error[E0284]: type annotations needed: cannot satisfy `<Self as std::iter::Iterator>::Item == i32`
--> $DIR/associated-types-overridden-binding.rs:7:21
|
LL | trait I32Iterator = Iterator<Item = i32>;
| ---------- required by this bound in `I32Iterator`
LL | trait U32Iterator = I32Iterator<Item = u32>;
| ^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for type parameter `Self`
|
= note: cannot satisfy `<Self as std::iter::Iterator>::Item == i32`
| ^^^^^^^^^^^^^^^^^^^^^^^ cannot satisfy `<Self as std::iter::Iterator>::Item == i32`
error: aborting due to 2 previous errors

View File

@ -1,10 +1,8 @@
error[E0284]: type annotations needed
error[E0284]: type annotations needed: cannot satisfy `<_ as StreamHasher>::S == <H as StreamHasher>::S`
--> $DIR/issue-12028.rs:27:14
|
LL | self.input_stream(&mut stream);
| ^^^^^^^^^^^^ cannot infer type for type parameter `H` declared on the trait `StreamHash`
|
= note: cannot satisfy `<_ as StreamHasher>::S == <H as StreamHasher>::S`
| ^^^^^^^^^^^^ cannot satisfy `<_ as StreamHasher>::S == <H as StreamHasher>::S`
error: aborting due to previous error

View File

@ -26,5 +26,5 @@ impl Test<u64> for u64 {
fn main() {
let xs: Vec<u64> = vec![1, 2, 3];
println!("{}", 23u64.test(xs.iter().sum())); //~ ERROR: type annotations needed [E0284]
println!("{}", 23u64.test(xs.iter().sum())); //~ ERROR: type annotations needed
}

View File

@ -1,16 +1,8 @@
error[E0284]: type annotations needed
error[E0284]: type annotations needed: cannot satisfy `<u64 as Test<_>>::Output == _`
--> $DIR/issue-69455.rs:29:26
|
LL | type Output;
| ------------ `<Self as Test<Rhs>>::Output` defined here
...
LL | println!("{}", 23u64.test(xs.iter().sum()));
| ------^^^^-----------------
| | |
| | cannot infer type for type `u64`
| this method call resolves to `<Self as Test<Rhs>>::Output`
|
= note: cannot satisfy `<u64 as Test<_>>::Output == _`
| ^^^^ cannot satisfy `<u64 as Test<_>>::Output == _`
error: aborting due to previous error

View File

@ -0,0 +1,32 @@
pub trait Element<S> {
type Array;
}
impl<T> Element<()> for T {
type Array = T;
}
impl<T: Element<S>, S> Element<[S; 3]> for T {
type Array = [T::Array; 3];
}
trait Foo<I>
where
u8: Element<I>,
{
fn foo(self, x: <u8 as Element<I>>::Array);
}
impl<I> Foo<I> for u16
where
u8: Element<I>,
{
fn foo(self, _: <u8 as Element<I>>::Array) {}
}
fn main() {
let b: [u8; 3] = [0u8; 3];
0u16.foo(b); //~ ERROR type annotations needed
//<u16 as Foo<[(); 3]>>::foo(0u16, b);
}

View File

@ -0,0 +1,9 @@
error[E0284]: type annotations needed: cannot satisfy `<u8 as Element<_>>::Array == [u8; 3]`
--> $DIR/issue-69683.rs:30:10
|
LL | 0u16.foo(b);
| ^^^ cannot satisfy `<u8 as Element<_>>::Array == [u8; 3]`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0284`.

View File

@ -0,0 +1,5 @@
fn main() {
let n: u32 = 1;
let mut d: u64 = 2;
d = d % n.into(); //~ ERROR type annotations needed
}

View File

@ -0,0 +1,9 @@
error[E0284]: type annotations needed: cannot satisfy `<u64 as std::ops::Rem<_>>::Output == u64`
--> $DIR/issue-71584.rs:4:11
|
LL | d = d % n.into();
| ^ cannot satisfy `<u64 as std::ops::Rem<_>>::Output == u64`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0284`.