Only emit one error per unsized binding, instead of one per usage
Fix #56607.
This commit is contained in:
parent
3d86b8acda
commit
2f79681fb9
3 changed files with 22 additions and 29 deletions
|
@ -428,6 +428,25 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if let ObligationCauseCode::FunctionArgumentObligation {
|
||||||
|
arg_hir_id,
|
||||||
|
..
|
||||||
|
} = obligation.cause.code()
|
||||||
|
&& let Some(Node::Expr(arg)) = self.tcx.hir().find(*arg_hir_id)
|
||||||
|
&& let arg = arg.peel_borrows()
|
||||||
|
&& let hir::ExprKind::Path(hir::QPath::Resolved(
|
||||||
|
None,
|
||||||
|
hir::Path { res: hir::def::Res::Local(hir_id), .. },
|
||||||
|
)) = arg.kind
|
||||||
|
&& let Some(Node::Pat(pat)) = self.tcx.hir().find(*hir_id)
|
||||||
|
&& let Some(preds) = self.reported_trait_errors.borrow().get(&pat.span)
|
||||||
|
&& preds.contains(&obligation.predicate)
|
||||||
|
&& self.tcx.sess.has_errors().is_some()
|
||||||
|
{
|
||||||
|
// Silence redundant errors on binding acccess that are already
|
||||||
|
// reported on the binding definition (#56607).
|
||||||
|
return;
|
||||||
|
}
|
||||||
let trait_ref = trait_predicate.to_poly_trait_ref();
|
let trait_ref = trait_predicate.to_poly_trait_ref();
|
||||||
|
|
||||||
let (post_message, pre_message, type_def) = self
|
let (post_message, pre_message, type_def) = self
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
fn main() {
|
fn main() {
|
||||||
let x = *""; //~ ERROR E0277
|
let x = *""; //~ ERROR E0277
|
||||||
println!("{}", x); //~ ERROR E0277
|
println!("{}", x);
|
||||||
println!("{}", x); //~ ERROR E0277
|
println!("{}", x);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,32 +8,6 @@ LL | let x = *"";
|
||||||
= note: all local variables must have a statically known size
|
= note: all local variables must have a statically known size
|
||||||
= help: unsized locals are gated as an unstable feature
|
= help: unsized locals are gated as an unstable feature
|
||||||
|
|
||||||
error[E0277]: the size for values of type `str` cannot be known at compilation time
|
error: aborting due to previous error
|
||||||
--> $DIR/unsized-binding.rs:3:20
|
|
||||||
|
|
|
||||||
LL | println!("{}", x);
|
|
||||||
| -- ^ doesn't have a size known at compile-time
|
|
||||||
| |
|
|
||||||
| required by a bound introduced by this call
|
|
||||||
|
|
|
||||||
= help: the trait `Sized` is not implemented for `str`
|
|
||||||
note: required by a bound in `core::fmt::rt::Argument::<'a>::new_display`
|
|
||||||
--> $SRC_DIR/core/src/fmt/rt.rs:LL:COL
|
|
||||||
= note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
|
|
||||||
|
|
||||||
error[E0277]: the size for values of type `str` cannot be known at compilation time
|
|
||||||
--> $DIR/unsized-binding.rs:4:20
|
|
||||||
|
|
|
||||||
LL | println!("{}", x);
|
|
||||||
| -- ^ doesn't have a size known at compile-time
|
|
||||||
| |
|
|
||||||
| required by a bound introduced by this call
|
|
||||||
|
|
|
||||||
= help: the trait `Sized` is not implemented for `str`
|
|
||||||
note: required by a bound in `core::fmt::rt::Argument::<'a>::new_display`
|
|
||||||
--> $SRC_DIR/core/src/fmt/rt.rs:LL:COL
|
|
||||||
= note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
|
|
||||||
|
|
||||||
error: aborting due to 3 previous errors
|
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0277`.
|
For more information about this error, try `rustc --explain E0277`.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue