Trim output of E0277 in some cases

Remove default note for "trait is not implemented" in favor of the
more colorful diff output from the previous commit. Removes
duplicated output.
This commit is contained in:
Esteban Küber 2024-10-24 22:38:50 +00:00
parent b7fc1a7431
commit 7b9105dd88
16 changed files with 18 additions and 34 deletions

View File

@ -6,8 +6,8 @@ use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::unord::UnordSet;
use rustc_errors::codes::*;
use rustc_errors::{
Applicability, Diag, ErrorGuaranteed, MultiSpan, StashKey, StringPart, Suggestions, pluralize,
struct_span_code_err,
Applicability, Diag, ErrorGuaranteed, Level, MultiSpan, StashKey, StringPart, Suggestions,
pluralize, struct_span_code_err,
};
use rustc_hir::def::Namespace;
use rustc_hir::def_id::{DefId, LOCAL_CRATE, LocalDefId};
@ -1833,6 +1833,22 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
return false;
}
if let [child, ..] = &err.children[..]
&& child.level == Level::Help
&& let Some(line) = child.messages.get(0)
&& let Some(line) = line.0.as_str()
&& line.starts_with("the trait")
&& line.contains("is not implemented for")
{
// HACK(estebank): we remove the pre-existing
// "the trait `X` is not implemented for" note, which only happens if there
// was a custom label. We do this because we want that note to always be the
// first, and making this logic run earlier will get tricky. For now, we
// instead keep the logic the same and modify the already constructed error
// to avoid the wording duplication.
err.children.remove(0);
}
let traits = self.cmp_traits(
obligation_trait_ref.def_id,
&obligation_trait_ref.args[1..],

View File

@ -4,7 +4,6 @@ error[E0277]: the type `[{integer}]` cannot be indexed by `i32`
LL | x[0i32];
| ^^^^ slice indices are of type `usize` or ranges of `usize`
|
= help: the trait `SliceIndex<[{integer}]>` is not implemented for `i32`
= help: the trait `SliceIndex<[{integer}]>` is not implemented for `i32`
but it is implemented for `usize`
= help: for that trait implementation, expected `usize`, found `i32`

View File

@ -4,7 +4,6 @@ error[E0277]: the type `[{integer}]` cannot be indexed by `u8`
LL | [0][0u8];
| ^^^ slice indices are of type `usize` or ranges of `usize`
|
= help: the trait `SliceIndex<[{integer}]>` is not implemented for `u8`
= help: the trait `SliceIndex<[{integer}]>` is not implemented for `u8`
but it is implemented for `usize`
= help: for that trait implementation, expected `usize`, found `u8`

View File

@ -4,7 +4,6 @@ error[E0277]: the type `[isize]` cannot be indexed by `u8`
LL | v[3u8];
| ^^^ slice indices are of type `usize` or ranges of `usize`
|
= help: the trait `SliceIndex<[isize]>` is not implemented for `u8`
= help: the trait `SliceIndex<[isize]>` is not implemented for `u8`
but it is implemented for `usize`
= help: for that trait implementation, expected `usize`, found `u8`
@ -16,7 +15,6 @@ error[E0277]: the type `[isize]` cannot be indexed by `i8`
LL | v[3i8];
| ^^^ slice indices are of type `usize` or ranges of `usize`
|
= help: the trait `SliceIndex<[isize]>` is not implemented for `i8`
= help: the trait `SliceIndex<[isize]>` is not implemented for `i8`
but it is implemented for `usize`
= help: for that trait implementation, expected `usize`, found `i8`
@ -28,7 +26,6 @@ error[E0277]: the type `[isize]` cannot be indexed by `u32`
LL | v[3u32];
| ^^^^ slice indices are of type `usize` or ranges of `usize`
|
= help: the trait `SliceIndex<[isize]>` is not implemented for `u32`
= help: the trait `SliceIndex<[isize]>` is not implemented for `u32`
but it is implemented for `usize`
= help: for that trait implementation, expected `usize`, found `u32`
@ -40,7 +37,6 @@ error[E0277]: the type `[isize]` cannot be indexed by `i32`
LL | v[3i32];
| ^^^^ slice indices are of type `usize` or ranges of `usize`
|
= help: the trait `SliceIndex<[isize]>` is not implemented for `i32`
= help: the trait `SliceIndex<[isize]>` is not implemented for `i32`
but it is implemented for `usize`
= help: for that trait implementation, expected `usize`, found `i32`
@ -52,7 +48,6 @@ error[E0277]: the type `[u8]` cannot be indexed by `u8`
LL | s.as_bytes()[3u8];
| ^^^ slice indices are of type `usize` or ranges of `usize`
|
= help: the trait `SliceIndex<[u8]>` is not implemented for `u8`
= help: the trait `SliceIndex<[u8]>` is not implemented for `u8`
but it is implemented for `usize`
= help: for that trait implementation, expected `usize`, found `u8`
@ -64,7 +59,6 @@ error[E0277]: the type `[u8]` cannot be indexed by `i8`
LL | s.as_bytes()[3i8];
| ^^^ slice indices are of type `usize` or ranges of `usize`
|
= help: the trait `SliceIndex<[u8]>` is not implemented for `i8`
= help: the trait `SliceIndex<[u8]>` is not implemented for `i8`
but it is implemented for `usize`
= help: for that trait implementation, expected `usize`, found `i8`
@ -76,7 +70,6 @@ error[E0277]: the type `[u8]` cannot be indexed by `u32`
LL | s.as_bytes()[3u32];
| ^^^^ slice indices are of type `usize` or ranges of `usize`
|
= help: the trait `SliceIndex<[u8]>` is not implemented for `u32`
= help: the trait `SliceIndex<[u8]>` is not implemented for `u32`
but it is implemented for `usize`
= help: for that trait implementation, expected `usize`, found `u32`
@ -88,7 +81,6 @@ error[E0277]: the type `[u8]` cannot be indexed by `i32`
LL | s.as_bytes()[3i32];
| ^^^^ slice indices are of type `usize` or ranges of `usize`
|
= help: the trait `SliceIndex<[u8]>` is not implemented for `i32`
= help: the trait `SliceIndex<[u8]>` is not implemented for `i32`
but it is implemented for `usize`
= help: for that trait implementation, expected `usize`, found `i32`

View File

@ -17,7 +17,6 @@ error[E0277]: a value of type `Vec<(u32, _, _)>` cannot be built from an iterato
LL | let sr2: Vec<(u32, _, _)> = sr.iter().map(|(faction, th_sender, th_receiver)| {}).collect();
| ^^^^^^^ value of type `Vec<(u32, _, _)>` cannot be built from `std::iter::Iterator<Item=()>`
|
= help: the trait `FromIterator<()>` is not implemented for `Vec<(u32, _, _)>`
= help: the trait `FromIterator<()>` is not implemented for `Vec<(u32, _, _)>`
but trait `FromIterator<(u32, _, _)>` is implemented for it
= help: for that trait implementation, expected `(u32, _, _)`, found `()`

View File

@ -4,7 +4,6 @@ error[E0277]: a value of type `Vec<f64>` cannot be built from an iterator over e
LL | let x2: Vec<f64> = x1.into_iter().collect();
| ^^^^^^^ value of type `Vec<f64>` cannot be built from `std::iter::Iterator<Item=&f64>`
|
= help: the trait `FromIterator<&f64>` is not implemented for `Vec<f64>`
= help: the trait `FromIterator<&_>` is not implemented for `Vec<f64>`
but trait `FromIterator<_>` is implemented for it
= help: for that trait implementation, expected `f64`, found `&f64`
@ -26,7 +25,6 @@ LL | let x3 = x1.into_iter().collect::<Vec<f64>>();
| |
| required by a bound introduced by this call
|
= help: the trait `FromIterator<&f64>` is not implemented for `Vec<f64>`
= help: the trait `FromIterator<&_>` is not implemented for `Vec<f64>`
but trait `FromIterator<_>` is implemented for it
= help: for that trait implementation, expected `f64`, found `&f64`

View File

@ -6,7 +6,6 @@ LL | let i = i.map(|x| x.clone());
LL | i.collect()
| ^^^^^^^ value of type `Vec<X>` cannot be built from `std::iter::Iterator<Item=&X>`
|
= help: the trait `FromIterator<&X>` is not implemented for `Vec<X>`
= help: the trait `FromIterator<&_>` is not implemented for `Vec<X>`
but trait `FromIterator<_>` is implemented for it
= help: for that trait implementation, expected `X`, found `&X`
@ -124,7 +123,6 @@ error[E0277]: a value of type `Vec<i32>` cannot be built from an iterator over e
LL | let g: Vec<i32> = f.collect();
| ^^^^^^^ value of type `Vec<i32>` cannot be built from `std::iter::Iterator<Item=()>`
|
= help: the trait `FromIterator<()>` is not implemented for `Vec<i32>`
= help: the trait `FromIterator<()>` is not implemented for `Vec<i32>`
but trait `FromIterator<i32>` is implemented for it
= help: for that trait implementation, expected `i32`, found `()`

View File

@ -6,7 +6,6 @@ LL | let i = i.map(|x| x.clone());
LL | i.collect()
| ^^^^^^^ value of type `Vec<X>` cannot be built from `std::iter::Iterator<Item=&X>`
|
= help: the trait `FromIterator<&X>` is not implemented for `Vec<X>`
= help: the trait `FromIterator<&_>` is not implemented for `Vec<X>`
but trait `FromIterator<_>` is implemented for it
= help: for that trait implementation, expected `X`, found `&X`
@ -181,7 +180,6 @@ error[E0277]: a value of type `Vec<i32>` cannot be built from an iterator over e
LL | let g: Vec<i32> = f.collect();
| ^^^^^^^ value of type `Vec<i32>` cannot be built from `std::iter::Iterator<Item=()>`
|
= help: the trait `FromIterator<()>` is not implemented for `Vec<i32>`
= help: the trait `FromIterator<()>` is not implemented for `Vec<i32>`
but trait `FromIterator<i32>` is implemented for it
= help: for that trait implementation, expected `i32`, found `()`

View File

@ -6,7 +6,6 @@ LL | Foo::<usize>::foo((1i32, 1i32, 1i32));
| |
| required by a bound introduced by this call
|
= help: the trait `Foo<usize>` is not implemented for `(i32, i32, i32)`
= help: the trait `Foo<usize>` is not implemented for `(i32, i32, i32)`
but trait `Foo<i32>` is implemented for it
= help: for that trait implementation, expected `i32`, found `usize`

View File

@ -6,7 +6,6 @@ LL | Index::<u32>::index(&[1, 2, 3] as &[i32], 2u32);
| |
| required by a bound introduced by this call
|
= help: the trait `Index<u32>` is not implemented for `[i32]`
= help: the trait `Index<u32>` is not implemented for `[i32]`
but trait `Index<usize>` is implemented for it
= help: for that trait implementation, expected `usize`, found `u32`
@ -17,7 +16,6 @@ error[E0277]: the trait bound `[i32]: Index<u32>` is not satisfied
LL | Index::<u32>::index(&[1, 2, 3] as &[i32], 2u32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ a usize is required to index into a slice
|
= help: the trait `Index<u32>` is not implemented for `[i32]`
= help: the trait `Index<u32>` is not implemented for `[i32]`
but trait `Index<usize>` is implemented for it
= help: for that trait implementation, expected `usize`, found `u32`

View File

@ -4,7 +4,6 @@ error[E0277]: the type `[i32]` cannot be indexed by `i32`
LL | x[1i32];
| ^^^^ slice indices are of type `usize` or ranges of `usize`
|
= help: the trait `SliceIndex<[i32]>` is not implemented for `i32`
= help: the trait `SliceIndex<[i32]>` is not implemented for `i32`
but it is implemented for `usize`
= help: for that trait implementation, expected `usize`, found `i32`

View File

@ -4,7 +4,6 @@ error[E0277]: the type `str` cannot be indexed by `{integer}`
LL | let _: u8 = s[4];
| ^ string indices are ranges of `usize`
|
= help: the trait `SliceIndex<str>` is not implemented for `{integer}`
= note: you can use `.chars().nth()` or `.bytes().nth()`
for more information, see chapter 8 in The Book: <https://doc.rust-lang.org/book/ch08-02-strings.html#indexing-into-strings>
= help: the trait `SliceIndex<str>` is not implemented for `{integer}`
@ -20,7 +19,6 @@ LL | let _ = s.get(4);
| |
| required by a bound introduced by this call
|
= help: the trait `SliceIndex<str>` is not implemented for `{integer}`
= note: you can use `.chars().nth()` or `.bytes().nth()`
for more information, see chapter 8 in The Book: <https://doc.rust-lang.org/book/ch08-02-strings.html#indexing-into-strings>
= help: the trait `SliceIndex<str>` is not implemented for `{integer}`
@ -37,7 +35,6 @@ LL | let _ = s.get_unchecked(4);
| |
| required by a bound introduced by this call
|
= help: the trait `SliceIndex<str>` is not implemented for `{integer}`
= note: you can use `.chars().nth()` or `.bytes().nth()`
for more information, see chapter 8 in The Book: <https://doc.rust-lang.org/book/ch08-02-strings.html#indexing-into-strings>
= help: the trait `SliceIndex<str>` is not implemented for `{integer}`

View File

@ -30,7 +30,6 @@ error[E0277]: the type `str` cannot be indexed by `usize`
LL | s[1usize] = bot();
| ^^^^^^ string indices are ranges of `usize`
|
= help: the trait `SliceIndex<str>` is not implemented for `usize`
= help: the trait `SliceIndex<str>` is not implemented for `usize`
but trait `SliceIndex<[_]>` is implemented for it
= help: for that trait implementation, expected `[_]`, found `str`
@ -44,7 +43,6 @@ LL | s.get_mut(1);
| |
| required by a bound introduced by this call
|
= help: the trait `SliceIndex<str>` is not implemented for `{integer}`
= note: you can use `.chars().nth()` or `.bytes().nth()`
for more information, see chapter 8 in The Book: <https://doc.rust-lang.org/book/ch08-02-strings.html#indexing-into-strings>
= help: the trait `SliceIndex<str>` is not implemented for `{integer}`
@ -61,7 +59,6 @@ LL | s.get_unchecked_mut(1);
| |
| required by a bound introduced by this call
|
= help: the trait `SliceIndex<str>` is not implemented for `{integer}`
= note: you can use `.chars().nth()` or `.bytes().nth()`
for more information, see chapter 8 in The Book: <https://doc.rust-lang.org/book/ch08-02-strings.html#indexing-into-strings>
= help: the trait `SliceIndex<str>` is not implemented for `{integer}`

View File

@ -4,7 +4,6 @@ error[E0277]: the type `[{integer}]` cannot be indexed by `&usize`
LL | let one_item_please: i32 = [1, 2, 3][i];
| ^ slice indices are of type `usize` or ranges of `usize`
|
= help: the trait `SliceIndex<[{integer}]>` is not implemented for `&usize`
= help: the trait `SliceIndex<[{integer}]>` is not implemented for `&_`
but it is implemented for `_`
= help: for that trait implementation, expected `usize`, found `&usize`

View File

@ -66,7 +66,6 @@ LL | fn result_to_control_flow() -> ControlFlow<String> {
LL | ControlFlow::Continue(Err("hello")?)
| ^ this `?` produces `Result<Infallible, &str>`, which is incompatible with `ControlFlow<String>`
|
= help: the trait `FromResidual<Result<Infallible, &str>>` is not implemented for `ControlFlow<String>`
= help: the trait `FromResidual<Result<Infallible, &str>>` is not implemented for `ControlFlow<String>`
but trait `FromResidual<ControlFlow<String, Infallible>>` is implemented for it
= help: for that trait implementation, expected `ControlFlow<String, Infallible>`, found `Result<Infallible, &str>`
@ -79,7 +78,6 @@ LL | fn option_to_control_flow() -> ControlFlow<u64> {
LL | Some(3)?;
| ^ this `?` produces `Option<Infallible>`, which is incompatible with `ControlFlow<u64>`
|
= help: the trait `FromResidual<Option<Infallible>>` is not implemented for `ControlFlow<u64>`
= help: the trait `FromResidual<Option<Infallible>>` is not implemented for `ControlFlow<u64>`
but trait `FromResidual<ControlFlow<u64, Infallible>>` is implemented for it
= help: for that trait implementation, expected `ControlFlow<u64, Infallible>`, found `Option<Infallible>`
@ -92,7 +90,6 @@ LL | fn control_flow_to_control_flow() -> ControlFlow<i64> {
LL | ControlFlow::Break(4_u8)?;
| ^ this `?` produces `ControlFlow<u8, Infallible>`, which is incompatible with `ControlFlow<i64>`
|
= help: the trait `FromResidual<ControlFlow<u8, Infallible>>` is not implemented for `ControlFlow<i64>`
= note: unlike `Result`, there's no `From`-conversion performed for `ControlFlow`
= help: the trait `FromResidual<ControlFlow<u8, _>>` is not implemented for `ControlFlow<i64>`
but trait `FromResidual<ControlFlow<i64, _>>` is implemented for it

View File

@ -6,7 +6,6 @@ LL | fn bar() -> Bar {
LL | 42_i32
| ------ return type was inferred to be `i32` here
|
= help: the trait `PartialEq<Foo>` is not implemented for `i32`
= help: the trait `PartialEq<Foo>` is not implemented for `i32`
but trait `PartialEq<i32>` is implemented for it