Skip to content

Commit d77608b

Browse files
authored
Rollup merge of #123211 - compiler-errors:V, r=estebank
Stop calling visitors `V` Renames some visitors which currently have the unhelpful name of `V`. It's not self-documenting, and there is no situation where saving a few bytes in source code helps anyone. Stacked on top of #123202 due to conflict.
2 parents 0928a54 + bda301e commit d77608b

File tree

4 files changed

+32
-21
lines changed

4 files changed

+32
-21
lines changed

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -540,19 +540,23 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
540540
}
541541
}
542542

543+
/// Suggest `map[k] = v` => `map.insert(k, v)` and the like.
543544
fn suggest_map_index_mut_alternatives(&self, ty: Ty<'tcx>, err: &mut Diag<'tcx>, span: Span) {
544545
let Some(adt) = ty.ty_adt_def() else { return };
545546
let did = adt.did();
546547
if self.infcx.tcx.is_diagnostic_item(sym::HashMap, did)
547548
|| self.infcx.tcx.is_diagnostic_item(sym::BTreeMap, did)
548549
{
549-
struct V<'a, 'tcx> {
550+
/// Walks through the HIR, looking for the corresponding span for this error.
551+
/// When it finds it, see if it corresponds to assignment operator whose LHS
552+
/// is an index expr.
553+
struct SuggestIndexOperatorAlternativeVisitor<'a, 'tcx> {
550554
assign_span: Span,
551555
err: &'a mut Diag<'tcx>,
552556
ty: Ty<'tcx>,
553557
suggested: bool,
554558
}
555-
impl<'a, 'tcx> Visitor<'tcx> for V<'a, 'tcx> {
559+
impl<'a, 'tcx> Visitor<'tcx> for SuggestIndexOperatorAlternativeVisitor<'a, 'tcx> {
556560
fn visit_stmt(&mut self, stmt: &'tcx hir::Stmt<'tcx>) {
557561
hir::intravisit::walk_stmt(self, stmt);
558562
let expr = match stmt.kind {
@@ -645,7 +649,12 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
645649
let Some(body_id) = hir_map.maybe_body_owned_by(local_def_id) else { return };
646650
let body = self.infcx.tcx.hir().body(body_id);
647651

648-
let mut v = V { assign_span: span, err, ty, suggested: false };
652+
let mut v = SuggestIndexOperatorAlternativeVisitor {
653+
assign_span: span,
654+
err,
655+
ty,
656+
suggested: false,
657+
};
649658
v.visit_body(body);
650659
if !v.suggested {
651660
err.help(format!(

compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -418,8 +418,10 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
418418
{
419419
if let &hir::ClosureBinder::For { span: for_sp, .. } = binder {
420420
fn span_of_infer(ty: &hir::Ty<'_>) -> Option<Span> {
421-
struct V;
422-
impl<'v> Visitor<'v> for V {
421+
/// Look for `_` anywhere in the signature of a `for<> ||` closure.
422+
/// This is currently disallowed.
423+
struct FindInferInClosureWithBinder;
424+
impl<'v> Visitor<'v> for FindInferInClosureWithBinder {
423425
type Result = ControlFlow<Span>;
424426
fn visit_ty(&mut self, t: &'v hir::Ty<'v>) -> Self::Result {
425427
if matches!(t.kind, hir::TyKind::Infer) {
@@ -429,7 +431,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
429431
}
430432
}
431433
}
432-
V.visit_ty(ty).break_value()
434+
FindInferInClosureWithBinder.visit_ty(ty).break_value()
433435
}
434436

435437
let infer_in_rt_sp = match fn_decl.output {

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

+10-11
Original file line numberDiff line numberDiff line change
@@ -1916,22 +1916,21 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
19161916
pat: &'tcx hir::Pat<'tcx>,
19171917
ty: Ty<'tcx>,
19181918
) {
1919-
struct V {
1920-
pat_hir_ids: Vec<hir::HirId>,
1921-
}
1922-
1923-
impl<'tcx> Visitor<'tcx> for V {
1924-
fn visit_pat(&mut self, p: &'tcx hir::Pat<'tcx>) {
1925-
self.pat_hir_ids.push(p.hir_id);
1926-
hir::intravisit::walk_pat(self, p);
1927-
}
1928-
}
19291919
if let Err(guar) = ty.error_reported() {
1920+
struct OverwritePatternsWithError {
1921+
pat_hir_ids: Vec<hir::HirId>,
1922+
}
1923+
impl<'tcx> Visitor<'tcx> for OverwritePatternsWithError {
1924+
fn visit_pat(&mut self, p: &'tcx hir::Pat<'tcx>) {
1925+
self.pat_hir_ids.push(p.hir_id);
1926+
hir::intravisit::walk_pat(self, p);
1927+
}
1928+
}
19301929
// Override the types everywhere with `err()` to avoid knock on errors.
19311930
let err = Ty::new_error(self.tcx, guar);
19321931
self.write_ty(hir_id, err);
19331932
self.write_ty(pat.hir_id, err);
1934-
let mut visitor = V { pat_hir_ids: vec![] };
1933+
let mut visitor = OverwritePatternsWithError { pat_hir_ids: vec![] };
19351934
hir::intravisit::walk_pat(&mut visitor, pat);
19361935
// Mark all the subpatterns as `{type error}` as well. This allows errors for specific
19371936
// subpatterns to be silenced.

compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -1128,10 +1128,11 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
11281128
err: &mut Diag<'_>,
11291129
) -> bool {
11301130
let span = obligation.cause.span;
1131-
struct V {
1131+
/// Look for the (direct) sub-expr of `?`, and return it if it's a `.` method call.
1132+
struct FindMethodSubexprOfTry {
11321133
search_span: Span,
11331134
}
1134-
impl<'v> Visitor<'v> for V {
1135+
impl<'v> Visitor<'v> for FindMethodSubexprOfTry {
11351136
type Result = ControlFlow<&'v hir::Expr<'v>>;
11361137
fn visit_expr(&mut self, ex: &'v hir::Expr<'v>) -> Self::Result {
11371138
if let hir::ExprKind::Match(expr, _arms, hir::MatchSource::TryDesugar(_)) = ex.kind
@@ -1149,8 +1150,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
11491150
hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn(_, _, body_id), .. }) => body_id,
11501151
_ => return false,
11511152
};
1152-
let ControlFlow::Break(expr) =
1153-
(V { search_span: span }).visit_body(self.tcx.hir().body(*body_id))
1153+
let ControlFlow::Break(expr) = (FindMethodSubexprOfTry { search_span: span })
1154+
.visit_body(self.tcx.hir().body(*body_id))
11541155
else {
11551156
return false;
11561157
};

0 commit comments

Comments
 (0)