Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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.
  • Loading branch information
estebank committed Nov 2, 2024
commit 7b9105dd8865ef10ef8d5f2f7bc3da180aec9dd2
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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..],
Expand Down
1 change: 0 additions & 1 deletion tests/ui/indexing/index-help.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
1 change: 0 additions & 1 deletion tests/ui/indexing/indexing-requires-a-uint.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
8 changes: 0 additions & 8 deletions tests/ui/integral-indexing.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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`
Expand All @@ -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`
Expand All @@ -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`
Expand All @@ -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`
Expand All @@ -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`
Expand All @@ -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`
Expand All @@ -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`
Expand Down
1 change: 0 additions & 1 deletion tests/ui/issues/issue-34334.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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 `()`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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`
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/iterators/invalid-iterator-chain-fixable.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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 `()`
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/iterators/invalid-iterator-chain.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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 `()`
Expand Down
1 change: 0 additions & 1 deletion tests/ui/on-unimplemented/impl-substs.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/on-unimplemented/on-impl.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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`
Expand Down
1 change: 0 additions & 1 deletion tests/ui/on-unimplemented/slice-index.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
3 changes: 0 additions & 3 deletions tests/ui/str/str-idx.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
Expand All @@ -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}`
Expand All @@ -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}`
Expand Down
3 changes: 0 additions & 3 deletions tests/ui/str/str-mut-idx.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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}`
Expand All @@ -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}`
Expand Down
1 change: 0 additions & 1 deletion tests/ui/suggestions/suggest-dereferencing-index.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
3 changes: 0 additions & 3 deletions tests/ui/try-trait/bad-interconversion.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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>`
Expand All @@ -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>`
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down