10000 Only emit one error per unsized binding, instead of one per usage by estebank · Pull Request #113183 · rust-lang/rust · GitHub
[go: up one dir, main page]

Skip to content

Only emit one error per unsized binding, instead of one per usage #113183

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 27, 2023
Merged
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
Move predicate error early check to its own method
  • Loading branch information
estebank committed Oct 9, 2023
commit 568b316ce3ec25aaaecf8e63a7b3a1301f016d4c
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ pub trait TypeErrCtxtExt<'tcx> {
error: &SelectionError<'tcx>,
);

fn fn_arg_obligation(&self, obligation: &PredicateObligation<'tcx>) -> bool;

fn report_const_param_not_wf(
&self,
ty: Ty<'tcx>,
Expand Down Expand Up @@ -434,20 +436,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
{
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)
{
if self.fn_arg_obligation(&obligation) {
// Silence redundant errors on binding acccess that are already
// reported on the binding definition (#56607).
return;
Expand Down Expand Up @@ -948,6 +937,26 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
err.emit();
}

fn fn_arg_obligation(&self, obligation: &PredicateObligation<'tcx>) -> bool {
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)
{
return true;
}
false
}

fn report_const_param_not_wf(
&self,
ty: Ty<'tcx>,
Expand Down
0