1
Fork 0

Deduplicate errors that come from places like normalization, sized

This commit is contained in:
Michael Goulet 2022-08-17 02:22:06 +00:00
parent 24559ce2fe
commit c0c6603c79
7 changed files with 53 additions and 152 deletions

View file

@ -15,6 +15,7 @@ use crate::check::{
use crate::structured_errors::StructuredDiagnostic; use crate::structured_errors::StructuredDiagnostic;
use rustc_ast as ast; use rustc_ast as ast;
use rustc_data_structures::fx::FxHashSet;
use rustc_errors::{pluralize, Applicability, Diagnostic, DiagnosticId, MultiSpan}; use rustc_errors::{pluralize, Applicability, Diagnostic, DiagnosticId, MultiSpan};
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def::{CtorOf, DefKind, Res}; use rustc_hir::def::{CtorOf, DefKind, Res};
@ -1612,24 +1613,52 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
&self, &self,
errors: &mut Vec<traits::FulfillmentError<'tcx>>, errors: &mut Vec<traits::FulfillmentError<'tcx>>,
) { ) {
let mut remap_cause = FxHashSet::default();
let mut not_adjusted = vec![];
for error in errors { for error in errors {
self.adjust_fulfillment_error_for_expr_obligation(error); let before_span = error.obligation.cause.span;
if self.adjust_fulfillment_error_for_expr_obligation(error) {
remap_cause.insert((
before_span,
error.obligation.predicate,
error.obligation.cause.clone(),
));
remap_cause.insert((
before_span,
error.obligation.predicate.without_const(self.tcx),
error.obligation.cause.clone(),
));
} else {
not_adjusted.push(error);
}
}
for error in not_adjusted {
for (span, predicate, cause) in &remap_cause {
if *predicate == error.obligation.predicate
&& span.contains(error.obligation.cause.span)
{
error.obligation.cause = cause.clone();
continue;
}
}
} }
} }
fn adjust_fulfillment_error_for_expr_obligation( fn adjust_fulfillment_error_for_expr_obligation(
&self, &self,
error: &mut traits::FulfillmentError<'tcx>, error: &mut traits::FulfillmentError<'tcx>,
) { ) -> bool {
let (traits::ExprItemObligation(def_id, hir_id, idx) | traits::ExprBindingObligation(def_id, _, hir_id, idx)) let (traits::ExprItemObligation(def_id, hir_id, idx) | traits::ExprBindingObligation(def_id, _, hir_id, idx))
= *error.obligation.cause.code().peel_derives() else { return; }; = *error.obligation.cause.code().peel_derives() else { return false; };
// Skip over mentioning async lang item // Skip over mentioning async lang item
if Some(def_id) == self.tcx.lang_items().from_generator_fn() if Some(def_id) == self.tcx.lang_items().from_generator_fn()
&& error.obligation.cause.span.desugaring_kind() && error.obligation.cause.span.desugaring_kind()
== Some(rustc_span::DesugaringKind::Async) == Some(rustc_span::DesugaringKind::Async)
{ {
return; return false;
} }
// Skip over closure arg mismatch, which has a better heuristic // Skip over closure arg mismatch, which has a better heuristic
// to determine what span to point at. // to determine what span to point at.
@ -1638,11 +1667,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
) = error.code ) = error.code
&& let ty::Closure(..) | ty::Generator(..) = expected.skip_binder().self_ty().kind() && let ty::Closure(..) | ty::Generator(..) = expected.skip_binder().self_ty().kind()
{ {
return; return false;
} }
let Some(unsubstituted_pred) = let Some(unsubstituted_pred) =
self.tcx.predicates_of(def_id).instantiate_identity(self.tcx).predicates.into_iter().nth(idx) else { return; }; self.tcx.predicates_of(def_id).instantiate_identity(self.tcx).predicates.into_iter().nth(idx)
else { return false; };
let generics = self.tcx.generics_of(def_id); let generics = self.tcx.generics_of(def_id);
let predicate_substs = match unsubstituted_pred.kind().skip_binder() { let predicate_substs = match unsubstituted_pred.kind().skip_binder() {
@ -1709,19 +1739,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
{ {
if let Some(param_to_point_at) = param_to_point_at if let Some(param_to_point_at) = param_to_point_at
&& self.point_at_args_if_possible(error, def_id, param_to_point_at, *call_hir_id, callee.span, args) { && self.point_at_args_if_possible(error, def_id, param_to_point_at, *call_hir_id, callee.span, args) {
return; return true;
} }
if let Some(fallback_param_to_point_at) = fallback_param_to_point_at if let Some(fallback_param_to_point_at) = fallback_param_to_point_at
&& self.point_at_args_if_possible(error, def_id, fallback_param_to_point_at, *call_hir_id, callee.span, args) && self.point_at_args_if_possible(error, def_id, fallback_param_to_point_at, *call_hir_id, callee.span, args)
{ {
return; return true;
} }
if let Some(self_param_to_point_at) = self_param_to_point_at if let Some(self_param_to_point_at) = self_param_to_point_at
&& self.point_at_args_if_possible(error, def_id, self_param_to_point_at, *call_hir_id, callee.span, args) && self.point_at_args_if_possible(error, def_id, self_param_to_point_at, *call_hir_id, callee.span, args)
{ {
return; return true;
} }
if let hir::QPath::Resolved(_, path) = qpath if let hir::QPath::Resolved(_, path) = qpath
@ -1729,14 +1759,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
&& let Some(segment) = path.segments.last() && let Some(segment) = path.segments.last()
&& self.point_at_generics_if_possible(error, def_id, param_to_point_at, segment) && self.point_at_generics_if_possible(error, def_id, param_to_point_at, segment)
{ {
return; return true;
} }
if let hir::QPath::TypeRelative(_, segment) = qpath if let hir::QPath::TypeRelative(_, segment) = qpath
&& let Some(param_to_point_at) = param_to_point_at && let Some(param_to_point_at) = param_to_point_at
&& self.point_at_generics_if_possible(error, def_id, param_to_point_at, segment) && self.point_at_generics_if_possible(error, def_id, param_to_point_at, segment)
{ {
return; return true;
} }
} }
} }
@ -1744,25 +1774,25 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if let Some(param_to_point_at) = param_to_point_at if let Some(param_to_point_at) = param_to_point_at
&& self.point_at_args_if_possible(error, def_id, param_to_point_at, hir_id, segment.ident.span, args) && self.point_at_args_if_possible(error, def_id, param_to_point_at, hir_id, segment.ident.span, args)
{ {
return; return true;
} }
if let Some(fallback_param_to_point_at) = fallback_param_to_point_at if let Some(fallback_param_to_point_at) = fallback_param_to_point_at
&& self.point_at_args_if_possible(error, def_id, fallback_param_to_point_at, hir_id, segment.ident.span, args) && self.point_at_args_if_possible(error, def_id, fallback_param_to_point_at, hir_id, segment.ident.span, args)
{ {
return; return true;
} }
if let Some(self_param_to_point_at) = self_param_to_point_at if let Some(self_param_to_point_at) = self_param_to_point_at
&& self.point_at_args_if_possible(error, def_id, self_param_to_point_at, hir_id, segment.ident.span, args) && self.point_at_args_if_possible(error, def_id, self_param_to_point_at, hir_id, segment.ident.span, args)
{ {
return; return true;
} }
if let Some(param_to_point_at) = param_to_point_at if let Some(param_to_point_at) = param_to_point_at
&& self.point_at_generics_if_possible(error, def_id, param_to_point_at, segment) && self.point_at_generics_if_possible(error, def_id, param_to_point_at, segment)
{ {
return; return true;
} }
} }
hir::Node::Expr(hir::Expr { kind: hir::ExprKind::Struct(..), .. }) => { hir::Node::Expr(hir::Expr { kind: hir::ExprKind::Struct(..), .. }) => {
@ -1770,6 +1800,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
_ => {} _ => {}
} }
false
} }
fn find_ambiguous_parameter_in<T: TypeVisitable<'tcx>>( fn find_ambiguous_parameter_in<T: TypeVisitable<'tcx>>(

View file

@ -8,14 +8,6 @@ LL | let _ = Iterator::next(&mut ());
| |
= help: the trait `Iterator` is not implemented for `()` = help: the trait `Iterator` is not implemented for `()`
error[E0277]: `()` is not an iterator
--> $DIR/issue-28098.rs:2:13
|
LL | let _ = Iterator::next(&mut ());
| ^^^^^^^^^^^^^^ `()` is not an iterator
|
= help: the trait `Iterator` is not implemented for `()`
error[E0277]: `bool` is not an iterator error[E0277]: `bool` is not an iterator
--> $DIR/issue-28098.rs:5:14 --> $DIR/issue-28098.rs:5:14
| |
@ -35,14 +27,6 @@ LL | let _ = Iterator::next(&mut ());
| |
= help: the trait `Iterator` is not implemented for `()` = help: the trait `Iterator` is not implemented for `()`
error[E0277]: `()` is not an iterator
--> $DIR/issue-28098.rs:8:13
|
LL | let _ = Iterator::next(&mut ());
| ^^^^^^^^^^^^^^ `()` is not an iterator
|
= help: the trait `Iterator` is not implemented for `()`
error[E0277]: `()` is not an iterator error[E0277]: `()` is not an iterator
--> $DIR/issue-28098.rs:17:28 --> $DIR/issue-28098.rs:17:28
| |
@ -53,14 +37,6 @@ LL | let _ = Iterator::next(&mut ());
| |
= help: the trait `Iterator` is not implemented for `()` = help: the trait `Iterator` is not implemented for `()`
error[E0277]: `()` is not an iterator
--> $DIR/issue-28098.rs:17:13
|
LL | let _ = Iterator::next(&mut ());
| ^^^^^^^^^^^^^^ `()` is not an iterator
|
= help: the trait `Iterator` is not implemented for `()`
error[E0277]: `()` is not an iterator error[E0277]: `()` is not an iterator
--> $DIR/issue-28098.rs:20:28 --> $DIR/issue-28098.rs:20:28
| |
@ -71,14 +47,6 @@ LL | let _ = Iterator::next(&mut ());
| |
= help: the trait `Iterator` is not implemented for `()` = help: the trait `Iterator` is not implemented for `()`
error[E0277]: `()` is not an iterator
--> $DIR/issue-28098.rs:20:13
|
LL | let _ = Iterator::next(&mut ());
| ^^^^^^^^^^^^^^ `()` is not an iterator
|
= help: the trait `Iterator` is not implemented for `()`
error[E0277]: `bool` is not an iterator error[E0277]: `bool` is not an iterator
--> $DIR/issue-28098.rs:23:14 --> $DIR/issue-28098.rs:23:14
| |
@ -88,6 +56,6 @@ LL | for _ in false {}
= help: the trait `Iterator` is not implemented for `bool` = help: the trait `Iterator` is not implemented for `bool`
= note: required for `bool` to implement `IntoIterator` = note: required for `bool` to implement `IntoIterator`
error: aborting due to 10 previous errors error: aborting due to 6 previous errors
For more information about this error, try `rustc --explain E0277`. For more information about this error, try `rustc --explain E0277`.

View file

@ -11,17 +11,6 @@ LL | Index::index(&[] as &[i32], 2u32);
<[i32] as Index<Bar<usize>>> <[i32] as Index<Bar<usize>>>
<[i32] as Index<Foo<usize>>> <[i32] as Index<Foo<usize>>>
error[E0277]: the trait bound `[i32]: Index<u32>` is not satisfied
--> $DIR/multiple-impls.rs:33:5
|
LL | Index::index(&[] as &[i32], 2u32);
| ^^^^^^^^^^^^ trait message
|
= help: the trait `Index<u32>` is not implemented for `[i32]`
= help: the following other types implement trait `Index<Idx>`:
<[i32] as Index<Bar<usize>>>
<[i32] as Index<Foo<usize>>>
error[E0277]: the trait bound `[i32]: Index<Foo<u32>>` is not satisfied error[E0277]: the trait bound `[i32]: Index<Foo<u32>>` is not satisfied
--> $DIR/multiple-impls.rs:35:33 --> $DIR/multiple-impls.rs:35:33
| |
@ -35,17 +24,6 @@ LL | Index::index(&[] as &[i32], Foo(2u32));
<[i32] as Index<Bar<usize>>> <[i32] as Index<Bar<usize>>>
<[i32] as Index<Foo<usize>>> <[i32] as Index<Foo<usize>>>
error[E0277]: the trait bound `[i32]: Index<Foo<u32>>` is not satisfied
--> $DIR/multiple-impls.rs:35:5
|
LL | Index::index(&[] as &[i32], Foo(2u32));
| ^^^^^^^^^^^^ on impl for Foo
|
= help: the trait `Index<Foo<u32>>` is not implemented for `[i32]`
= help: the following other types implement trait `Index<Idx>`:
<[i32] as Index<Bar<usize>>>
<[i32] as Index<Foo<usize>>>
error[E0277]: the trait bound `[i32]: Index<Bar<u32>>` is not satisfied error[E0277]: the trait bound `[i32]: Index<Bar<u32>>` is not satisfied
--> $DIR/multiple-impls.rs:37:33 --> $DIR/multiple-impls.rs:37:33
| |
@ -59,17 +37,6 @@ LL | Index::index(&[] as &[i32], Bar(2u32));
<[i32] as Index<Bar<usize>>> <[i32] as Index<Bar<usize>>>
<[i32] as Index<Foo<usize>>> <[i32] as Index<Foo<usize>>>
error[E0277]: the trait bound `[i32]: Index<Bar<u32>>` is not satisfied error: aborting due to 3 previous errors
--> $DIR/multiple-impls.rs:37:5
|
LL | Index::index(&[] as &[i32], Bar(2u32));
| ^^^^^^^^^^^^ on impl for Bar
|
= help: the trait `Index<Bar<u32>>` is not implemented for `[i32]`
= help: the following other types implement trait `Index<Idx>`:
<[i32] as Index<Bar<usize>>>
<[i32] as Index<Foo<usize>>>
error: aborting due to 6 previous errors
For more information about this error, try `rustc --explain E0277`. For more information about this error, try `rustc --explain E0277`.

View file

@ -9,15 +9,6 @@ LL | Index::<u32>::index(&[1, 2, 3] as &[i32], 2u32);
= help: the trait `Index<u32>` is not implemented for `[i32]` = help: the trait `Index<u32>` is not implemented for `[i32]`
= help: the trait `Index<usize>` is implemented for `[i32]` = help: the trait `Index<usize>` is implemented for `[i32]`
error[E0277]: the trait bound `[i32]: Index<u32>` is not satisfied error: aborting due to previous error
--> $DIR/on-impl.rs:22:5
|
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<usize>` is implemented for `[i32]`
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0277`. For more information about this error, try `rustc --explain E0277`.

View file

@ -28,17 +28,6 @@ note: required by a bound in `core::str::<impl str>::get`
LL | pub const fn get<I: ~const SliceIndex<str>>(&self, i: I) -> Option<&I::Output> { LL | pub const fn get<I: ~const SliceIndex<str>>(&self, i: I) -> Option<&I::Output> {
| ^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `core::str::<impl str>::get` | ^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `core::str::<impl str>::get`
error[E0277]: the type `str` cannot be indexed by `{integer}`
--> $DIR/str-idx.rs:4:15
|
LL | let _ = s.get(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<[T]>` is implemented for `usize`
error[E0277]: the type `str` cannot be indexed by `{integer}` error[E0277]: the type `str` cannot be indexed by `{integer}`
--> $DIR/str-idx.rs:5:29 --> $DIR/str-idx.rs:5:29
| |
@ -57,17 +46,6 @@ note: required by a bound in `core::str::<impl str>::get_unchecked`
LL | pub const unsafe fn get_unchecked<I: ~const SliceIndex<str>>(&self, i: I) -> &I::Output { LL | pub const unsafe fn get_unchecked<I: ~const SliceIndex<str>>(&self, i: I) -> &I::Output {
| ^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `core::str::<impl str>::get_unchecked` | ^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `core::str::<impl str>::get_unchecked`
error[E0277]: the type `str` cannot be indexed by `{integer}`
--> $DIR/str-idx.rs:5:15
|
LL | let _ = s.get_unchecked(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<[T]>` is implemented for `usize`
error[E0277]: the type `str` cannot be indexed by `char` error[E0277]: the type `str` cannot be indexed by `char`
--> $DIR/str-idx.rs:6:19 --> $DIR/str-idx.rs:6:19
| |
@ -77,6 +55,6 @@ LL | let _: u8 = s['c'];
= help: the trait `SliceIndex<str>` is not implemented for `char` = help: the trait `SliceIndex<str>` is not implemented for `char`
= note: required for `str` to implement `Index<char>` = note: required for `str` to implement `Index<char>`
error: aborting due to 6 previous errors error: aborting due to 4 previous errors
For more information about this error, try `rustc --explain E0277`. For more information about this error, try `rustc --explain E0277`.

View file

@ -52,17 +52,6 @@ note: required by a bound in `core::str::<impl str>::get_mut`
LL | pub const fn get_mut<I: ~const SliceIndex<str>>(&mut self, i: I) -> Option<&mut I::Output> { LL | pub const fn get_mut<I: ~const SliceIndex<str>>(&mut self, i: I) -> Option<&mut I::Output> {
| ^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `core::str::<impl str>::get_mut` | ^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `core::str::<impl str>::get_mut`
error[E0277]: the type `str` cannot be indexed by `{integer}`
--> $DIR/str-mut-idx.rs:9:7
|
LL | s.get_mut(1);
| ^^^^^^^ 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<[T]>` is implemented for `usize`
error[E0277]: the type `str` cannot be indexed by `{integer}` error[E0277]: the type `str` cannot be indexed by `{integer}`
--> $DIR/str-mut-idx.rs:11:25 --> $DIR/str-mut-idx.rs:11:25
| |
@ -81,17 +70,6 @@ note: required by a bound in `core::str::<impl str>::get_unchecked_mut`
LL | pub const unsafe fn get_unchecked_mut<I: ~const SliceIndex<str>>( LL | pub const unsafe fn get_unchecked_mut<I: ~const SliceIndex<str>>(
| ^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `core::str::<impl str>::get_unchecked_mut` | ^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `core::str::<impl str>::get_unchecked_mut`
error[E0277]: the type `str` cannot be indexed by `{integer}`
--> $DIR/str-mut-idx.rs:11:7
|
LL | s.get_unchecked_mut(1);
| ^^^^^^^^^^^^^^^^^ 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<[T]>` is implemented for `usize`
error[E0277]: the type `str` cannot be indexed by `char` error[E0277]: the type `str` cannot be indexed by `char`
--> $DIR/str-mut-idx.rs:13:7 --> $DIR/str-mut-idx.rs:13:7
| |
@ -101,6 +79,6 @@ LL | s['c'];
= help: the trait `SliceIndex<str>` is not implemented for `char` = help: the trait `SliceIndex<str>` is not implemented for `char`
= note: required for `str` to implement `Index<char>` = note: required for `str` to implement `Index<char>`
error: aborting due to 8 previous errors error: aborting due to 6 previous errors
For more information about this error, try `rustc --explain E0277`. For more information about this error, try `rustc --explain E0277`.

View file

@ -13,19 +13,6 @@ note: required by a bound in `BufWriter::<W>::new`
LL | impl<W: Write> BufWriter<W> { LL | impl<W: Write> BufWriter<W> {
| ^^^^^ required by this bound in `BufWriter::<W>::new` | ^^^^^ required by this bound in `BufWriter::<W>::new`
error[E0277]: the trait bound `&dyn std::io::Write: std::io::Write` is not satisfied
--> $DIR/mut-borrow-needed-by-trait.rs:17:14
|
LL | let fp = BufWriter::new(fp);
| ^^^^^^^^^ the trait `std::io::Write` is not implemented for `&dyn std::io::Write`
|
= note: `std::io::Write` is implemented for `&mut dyn std::io::Write`, but not for `&dyn std::io::Write`
note: required by a bound in `BufWriter`
--> $SRC_DIR/std/src/io/buffered/bufwriter.rs:LL:COL
|
LL | pub struct BufWriter<W: Write> {
| ^^^^^ required by this bound in `BufWriter`
error[E0277]: the trait bound `&dyn std::io::Write: std::io::Write` is not satisfied error[E0277]: the trait bound `&dyn std::io::Write: std::io::Write` is not satisfied
--> $DIR/mut-borrow-needed-by-trait.rs:17:14 --> $DIR/mut-borrow-needed-by-trait.rs:17:14
| |
@ -55,7 +42,7 @@ LL | pub struct BufWriter<W: Write> {
which is required by `BufWriter<&dyn std::io::Write>: std::io::Write` which is required by `BufWriter<&dyn std::io::Write>: std::io::Write`
= note: this error originates in the macro `writeln` (in Nightly builds, run with -Z macro-backtrace for more info) = note: this error originates in the macro `writeln` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 4 previous errors error: aborting due to 3 previous errors
Some errors have detailed explanations: E0277, E0599. Some errors have detailed explanations: E0277, E0599.
For more information about an error, try `rustc --explain E0277`. For more information about an error, try `rustc --explain E0277`.