Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a46dda2

Browse files
committedFeb 29, 2024
Rename DiagnosticMetadata as DiagMetadata.
1 parent cea352e commit a46dda2

File tree

2 files changed

+86
-92
lines changed

2 files changed

+86
-92
lines changed
 

‎compiler/rustc_resolve/src/late.rs

Lines changed: 60 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ impl MaybeExported<'_> {
581581
}
582582

583583
#[derive(Default)]
584-
struct DiagnosticMetadata<'ast> {
584+
struct DiagMetadata<'ast> {
585585
/// The current trait's associated items' ident, used for diagnostic suggestions.
586586
current_trait_assoc_items: Option<&'ast [P<AssocItem>]>,
587587

@@ -674,7 +674,7 @@ struct LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
674674
current_trait_ref: Option<(Module<'a>, TraitRef)>,
675675

676676
/// Fields used to add information to diagnostic errors.
677-
diagnostic_metadata: Box<DiagnosticMetadata<'ast>>,
677+
diag_metadata: Box<DiagMetadata<'ast>>,
678678

679679
/// State used to know whether to ignore resolution errors for function bodies.
680680
///
@@ -694,12 +694,12 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
694694
// as they do not correspond to actual code.
695695
}
696696
fn visit_item(&mut self, item: &'ast Item) {
697-
let prev = replace(&mut self.diagnostic_metadata.current_item, Some(item));
697+
let prev = replace(&mut self.diag_metadata.current_item, Some(item));
698698
// Always report errors in items we just entered.
699699
let old_ignore = replace(&mut self.in_func_body, false);
700700
self.with_lifetime_rib(LifetimeRibKind::Item, |this| this.resolve_item(item));
701701
self.in_func_body = old_ignore;
702-
self.diagnostic_metadata.current_item = prev;
702+
self.diag_metadata.current_item = prev;
703703
}
704704
fn visit_arm(&mut self, arm: &'ast Arm) {
705705
self.resolve_arm(arm);
@@ -716,10 +716,10 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
716716
self.resolve_expr(expr, None);
717717
}
718718
fn visit_pat(&mut self, p: &'ast Pat) {
719-
let prev = self.diagnostic_metadata.current_pat;
720-
self.diagnostic_metadata.current_pat = Some(p);
719+
let prev = self.diag_metadata.current_pat;
720+
self.diag_metadata.current_pat = Some(p);
721721
visit::walk_pat(self, p);
722-
self.diagnostic_metadata.current_pat = prev;
722+
self.diag_metadata.current_pat = prev;
723723
}
724724
fn visit_local(&mut self, local: &'ast Local) {
725725
let local_spans = match local.pat.kind {
@@ -731,13 +731,13 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
731731
local.kind.init().map(|init| init.span),
732732
)),
733733
};
734-
let original = replace(&mut self.diagnostic_metadata.current_let_binding, local_spans);
734+
let original = replace(&mut self.diag_metadata.current_let_binding, local_spans);
735735
self.resolve_local(local);
736-
self.diagnostic_metadata.current_let_binding = original;
736+
self.diag_metadata.current_let_binding = original;
737737
}
738738
fn visit_ty(&mut self, ty: &'ast Ty) {
739-
let prev = self.diagnostic_metadata.current_trait_object;
740-
let prev_ty = self.diagnostic_metadata.current_type_path;
739+
let prev = self.diag_metadata.current_trait_object;
740+
let prev_ty = self.diag_metadata.current_type_path;
741741
match &ty.kind {
742742
TyKind::Ref(None, _) => {
743743
// Elided lifetime in reference: we resolve as if there was some lifetime `'_` with
@@ -748,7 +748,7 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
748748
visit::walk_ty(self, ty);
749749
}
750750
TyKind::Path(qself, path) => {
751-
self.diagnostic_metadata.current_type_path = Some(ty);
751+
self.diag_metadata.current_type_path = Some(ty);
752752
self.smart_resolve_path(ty.id, qself, path, PathSource::Type);
753753

754754
// Check whether we should interpret this as a bare trait object.
@@ -795,7 +795,7 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
795795
self.lifetime_elision_candidates = candidates;
796796
}
797797
TyKind::TraitObject(bounds, ..) => {
798-
self.diagnostic_metadata.current_trait_object = Some(&bounds[..]);
798+
self.diag_metadata.current_trait_object = Some(&bounds[..]);
799799
visit::walk_ty(self, ty)
800800
}
801801
TyKind::BareFn(bare_fn) => {
@@ -842,8 +842,8 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
842842
}
843843
_ => visit::walk_ty(self, ty),
844844
}
845-
self.diagnostic_metadata.current_trait_object = prev;
846-
self.diagnostic_metadata.current_type_path = prev_ty;
845+
self.diag_metadata.current_trait_object = prev;
846+
self.diag_metadata.current_type_path = prev_ty;
847847
}
848848
fn visit_poly_trait_ref(&mut self, tref: &'ast PolyTraitRef) {
849849
let span = tref.span.shrink_to_lo().to(tref.trait_ref.path.span.shrink_to_lo());
@@ -906,7 +906,7 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
906906
}
907907
}
908908
fn visit_fn(&mut self, fn_kind: FnKind<'ast>, sp: Span, fn_id: NodeId) {
909-
let previous_value = self.diagnostic_metadata.current_function;
909+
let previous_value = self.diag_metadata.current_function;
910910
match fn_kind {
911911
// Bail if the function is foreign, and thus cannot validly have
912912
// a body, or if there's no body for some other reason.
@@ -939,7 +939,7 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
939939
return;
940940
}
941941
FnKind::Fn(..) => {
942-
self.diagnostic_metadata.current_function = Some((fn_kind, sp));
942+
self.diag_metadata.current_function = Some((fn_kind, sp));
943943
}
944944
// Do not update `current_function` for closures: it suggests `self` parameters.
945945
FnKind::Closure(..) => {}
@@ -1040,17 +1040,14 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
10401040
}
10411041
})
10421042
});
1043-
self.diagnostic_metadata.current_function = previous_value;
1043+
self.diag_metadata.current_function = previous_value;
10441044
}
10451045
fn visit_lifetime(&mut self, lifetime: &'ast Lifetime, use_ctxt: visit::LifetimeCtxt) {
10461046
self.resolve_lifetime(lifetime, use_ctxt)
10471047
}
10481048

10491049
fn visit_generics(&mut self, generics: &'ast Generics) {
1050-
self.visit_generic_params(
1051-
&generics.params,
1052-
self.diagnostic_metadata.current_self_item.is_some(),
1053-
);
1050+
self.visit_generic_params(&generics.params, self.diag_metadata.current_self_item.is_some());
10541051
for p in &generics.where_clause.predicates {
10551052
self.visit_where_predicate(p);
10561053
}
@@ -1062,15 +1059,15 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
10621059
ClosureBinder::For { generic_params, .. } => {
10631060
self.visit_generic_params(
10641061
generic_params,
1065-
self.diagnostic_metadata.current_self_item.is_some(),
1062+
self.diag_metadata.current_self_item.is_some(),
10661063
);
10671064
}
10681065
}
10691066
}
10701067

10711068
fn visit_generic_arg(&mut self, arg: &'ast GenericArg) {
10721069
debug!("visit_generic_arg({:?})", arg);
1073-
let prev = replace(&mut self.diagnostic_metadata.currently_processing_generic_args, true);
1070+
let prev = replace(&mut self.diag_metadata.currently_processing_generic_args, true);
10741071
match arg {
10751072
GenericArg::Type(ref ty) => {
10761073
// We parse const arguments as path types as we cannot distinguish them during
@@ -1101,7 +1098,7 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
11011098
},
11021099
);
11031100

1104-
self.diagnostic_metadata.currently_processing_generic_args = prev;
1101+
self.diag_metadata.currently_processing_generic_args = prev;
11051102
return;
11061103
}
11071104
}
@@ -1114,7 +1111,7 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
11141111
self.resolve_anon_const(ct, AnonConstKind::ConstArg(IsRepeatExpr::No))
11151112
}
11161113
}
1117-
self.diagnostic_metadata.currently_processing_generic_args = prev;
1114+
self.diag_metadata.currently_processing_generic_args = prev;
11181115
}
11191116

11201117
fn visit_assoc_constraint(&mut self, constraint: &'ast AssocConstraint) {
@@ -1192,8 +1189,7 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
11921189

11931190
fn visit_where_predicate(&mut self, p: &'ast WherePredicate) {
11941191
debug!("visit_where_predicate {:?}", p);
1195-
let previous_value =
1196-
replace(&mut self.diagnostic_metadata.current_where_predicate, Some(p));
1192+
let previous_value = replace(&mut self.diag_metadata.current_where_predicate, Some(p));
11971193
self.with_lifetime_rib(LifetimeRibKind::AnonymousReportError, |this| {
11981194
if let WherePredicate::BoundPredicate(WhereBoundPredicate {
11991195
ref bounded_ty,
@@ -1224,7 +1220,7 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
12241220
visit::walk_where_predicate(this, p);
12251221
}
12261222
});
1227-
self.diagnostic_metadata.current_where_predicate = previous_value;
1223+
self.diag_metadata.current_where_predicate = previous_value;
12281224
}
12291225

12301226
fn visit_inline_asm(&mut self, asm: &'ast InlineAsm) {
@@ -1297,7 +1293,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
12971293
lifetime_ribs: Vec::new(),
12981294
lifetime_elision_candidates: None,
12991295
current_trait_ref: None,
1300-
diagnostic_metadata: Default::default(),
1296+
diag_metadata: Default::default(),
13011297
// errors at module scope should always be reported
13021298
in_func_body: false,
13031299
lifetime_uses: Default::default(),
@@ -1707,7 +1703,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
17071703
return;
17081704
}
17091705
LifetimeRibKind::ElisionFailure => {
1710-
self.diagnostic_metadata.current_elision_failures.push(missing_lifetime);
1706+
self.diag_metadata.current_elision_failures.push(missing_lifetime);
17111707
self.record_lifetime_res(lifetime.id, LifetimeRes::Error, elision_candidate);
17121708
return;
17131709
}
@@ -1911,7 +1907,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
19111907
break;
19121908
}
19131909
LifetimeRibKind::ElisionFailure => {
1914-
self.diagnostic_metadata.current_elision_failures.push(missing_lifetime);
1910+
self.diag_metadata.current_elision_failures.push(missing_lifetime);
19151911
for id in node_ids {
19161912
self.record_lifetime_res(
19171913
id,
@@ -2003,7 +1999,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
20031999
let elision_lifetime = self.resolve_fn_params(has_self, inputs);
20042000
debug!(?elision_lifetime);
20052001

2006-
let outer_failures = take(&mut self.diagnostic_metadata.current_elision_failures);
2002+
let outer_failures = take(&mut self.diag_metadata.current_elision_failures);
20072003
let output_rib = if let Ok(res) = elision_lifetime.as_ref() {
20082004
self.r.lifetime_elision_allowed.insert(fn_id);
20092005
LifetimeRibKind::Elided(*res)
@@ -2012,7 +2008,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
20122008
};
20132009
self.with_lifetime_rib(output_rib, |this| visit::walk_fn_ret_ty(this, output_ty));
20142010
let elision_failures =
2015-
replace(&mut self.diagnostic_metadata.current_elision_failures, outer_failures);
2011+
replace(&mut self.diag_metadata.current_elision_failures, outer_failures);
20162012
if !elision_failures.is_empty() {
20172013
let Err(failure_info) = elision_lifetime else { bug!() };
20182014
self.report_missing_lifetime_specifiers(elision_failures, Some(failure_info));
@@ -2187,7 +2183,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
21872183
}
21882184

21892185
let impl_self = self
2190-
.diagnostic_metadata
2186+
.diag_metadata
21912187
.current_self_type
21922188
.as_ref()
21932189
.and_then(|ty| {
@@ -2385,7 +2381,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
23852381
items: ref impl_items,
23862382
..
23872383
}) => {
2388-
self.diagnostic_metadata.current_impl_items = Some(impl_items);
2384+
self.diag_metadata.current_impl_items = Some(impl_items);
23892385
self.resolve_implementation(
23902386
&item.attrs,
23912387
generics,
@@ -2394,7 +2390,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
23942390
item.id,
23952391
impl_items,
23962392
);
2397-
self.diagnostic_metadata.current_impl_items = None;
2393+
self.diag_metadata.current_impl_items = None;
23982394
}
23992395

24002396
ItemKind::Trait(box Trait { ref generics, ref bounds, ref items, .. }) => {
@@ -2744,24 +2740,23 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
27442740
fn with_current_self_type<T>(&mut self, self_type: &Ty, f: impl FnOnce(&mut Self) -> T) -> T {
27452741
// Handle nested impls (inside fn bodies)
27462742
let previous_value =
2747-
replace(&mut self.diagnostic_metadata.current_self_type, Some(self_type.clone()));
2743+
replace(&mut self.diag_metadata.current_self_type, Some(self_type.clone()));
27482744
let result = f(self);
2749-
self.diagnostic_metadata.current_self_type = previous_value;
2745+
self.diag_metadata.current_self_type = previous_value;
27502746
result
27512747
}
27522748

27532749
fn with_current_self_item<T>(&mut self, self_item: &Item, f: impl FnOnce(&mut Self) -> T) -> T {
2754-
let previous_value =
2755-
replace(&mut self.diagnostic_metadata.current_self_item, Some(self_item.id));
2750+
let previous_value = replace(&mut self.diag_metadata.current_self_item, Some(self_item.id));
27562751
let result = f(self);
2757-
self.diagnostic_metadata.current_self_item = previous_value;
2752+
self.diag_metadata.current_self_item = previous_value;
27582753
result
27592754
}
27602755

27612756
/// When evaluating a `trait` use its associated types' idents for suggestions in E0412.
27622757
fn resolve_trait_items(&mut self, trait_items: &'ast [P<AssocItem>]) {
27632758
let trait_assoc_items =
2764-
replace(&mut self.diagnostic_metadata.current_trait_assoc_items, Some(trait_items));
2759+
replace(&mut self.diag_metadata.current_trait_assoc_items, Some(trait_items));
27652760

27662761
let walk_assoc_item =
27672762
|this: &mut Self, generics: &Generics, kind, item: &'ast AssocItem| {
@@ -2818,7 +2813,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
28182813
};
28192814
}
28202815

2821-
self.diagnostic_metadata.current_trait_assoc_items = trait_assoc_items;
2816+
self.diag_metadata.current_trait_assoc_items = trait_assoc_items;
28222817
}
28232818

28242819
/// This is called to resolve a trait reference from an `impl` (i.e., `impl Trait for Foo`).
@@ -2832,7 +2827,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
28322827
let mut new_id = None;
28332828
if let Some(trait_ref) = opt_trait_ref {
28342829
let path: Vec<_> = Segment::from_path(&trait_ref.path);
2835-
self.diagnostic_metadata.currently_processing_impl_trait =
2830+
self.diag_metadata.currently_processing_impl_trait =
28362831
Some((trait_ref.clone(), self_type.clone()));
28372832
let res = self.smart_resolve_path_fragment(
28382833
&None,
@@ -2841,7 +2836,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
28412836
Finalize::new(trait_ref.ref_id, trait_ref.path.span),
28422837
RecordPartialRes::Yes,
28432838
);
2844-
self.diagnostic_metadata.currently_processing_impl_trait = None;
2839+
self.diag_metadata.currently_processing_impl_trait = None;
28452840
if let Some(def_id) = res.expect_full_res().opt_def_id() {
28462841
new_id = Some(def_id);
28472842
new_val = Some((self.r.expect_module(def_id), trait_ref.clone()));
@@ -3737,7 +3732,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
37373732

37383733
let def_id = this.parent_scope.module.nearest_parent_mod();
37393734
let instead = res.is_some();
3740-
let suggestion = if let Some((start, end)) = this.diagnostic_metadata.in_range
3735+
let suggestion = if let Some((start, end)) = this.diag_metadata.in_range
37413736
&& path[0].ident.span.lo() == end.span.lo()
37423737
{
37433738
let mut sugg = ".";
@@ -3890,7 +3885,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
38903885
) {
38913886
Ok(Some(partial_res)) if let Some(res) = partial_res.full_res() => {
38923887
// if we also have an associated type that matches the ident, stash a suggestion
3893-
if let Some(items) = self.diagnostic_metadata.current_trait_assoc_items
3888+
if let Some(items) = self.diag_metadata.current_trait_assoc_items
38943889
&& let [Segment { ident, .. }] = path
38953890
&& items.iter().any(|item| {
38963891
item.ident == *ident && matches!(item.kind, AssocItemKind::Type(_))
@@ -4187,7 +4182,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
41874182
fn with_resolved_label(&mut self, label: Option<Label>, id: NodeId, f: impl FnOnce(&mut Self)) {
41884183
if let Some(label) = label {
41894184
if label.ident.as_str().as_bytes()[1] != b'_' {
4190-
self.diagnostic_metadata.unused_labels.insert(id, label.ident.span);
4185+
self.diag_metadata.unused_labels.insert(id, label.ident.span);
41914186
}
41924187

41934188
if let Ok((_, orig_span)) = self.resolve_label(label.ident) {
@@ -4224,12 +4219,12 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
42244219
self.ribs[ValueNS].push(Rib::new(RibKind::Normal));
42254220
}
42264221

4227-
let prev = self.diagnostic_metadata.current_block_could_be_bare_struct_literal.take();
4222+
let prev = self.diag_metadata.current_block_could_be_bare_struct_literal.take();
42284223
if let (true, [Stmt { kind: StmtKind::Expr(expr), .. }]) =
42294224
(block.could_be_bare_literal, &block.stmts[..])
42304225
&& let ExprKind::Type(..) = expr.kind
42314226
{
4232-
self.diagnostic_metadata.current_block_could_be_bare_struct_literal = Some(block.span);
4227+
self.diag_metadata.current_block_could_be_bare_struct_literal = Some(block.span);
42334228
}
42344229
// Descend into the block.
42354230
for stmt in &block.stmts {
@@ -4244,7 +4239,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
42444239

42454240
self.visit_stmt(stmt);
42464241
}
4247-
self.diagnostic_metadata.current_block_could_be_bare_struct_literal = prev;
4242+
self.diag_metadata.current_block_could_be_bare_struct_literal = prev;
42484243

42494244
// Move back up.
42504245
self.parent_scope.module = orig_module;
@@ -4351,7 +4346,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
43514346
Ok((node_id, _)) => {
43524347
// Since this res is a label, it is never read.
43534348
self.r.label_res_map.insert(expr.id, node_id);
4354-
self.diagnostic_metadata.unused_labels.remove(&node_id);
4349+
self.diag_metadata.unused_labels.remove(&node_id);
43554350
}
43564351
Err(error) => {
43574352
self.report_error(label.ident.span, error);
@@ -4375,9 +4370,9 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
43754370

43764371
ExprKind::If(ref cond, ref then, ref opt_else) => {
43774372
self.with_rib(ValueNS, RibKind::Normal, |this| {
4378-
let old = this.diagnostic_metadata.in_if_condition.replace(cond);
4373+
let old = this.diag_metadata.in_if_condition.replace(cond);
43794374
this.visit_expr(cond);
4380-
this.diagnostic_metadata.in_if_condition = old;
4375+
this.diag_metadata.in_if_condition = old;
43814376
this.visit_block(then);
43824377
});
43834378
if let Some(expr) = opt_else {
@@ -4392,9 +4387,9 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
43924387
ExprKind::While(ref cond, ref block, label) => {
43934388
self.with_resolved_label(label, expr.id, |this| {
43944389
this.with_rib(ValueNS, RibKind::Normal, |this| {
4395-
let old = this.diagnostic_metadata.in_if_condition.replace(cond);
4390+
let old = this.diag_metadata.in_if_condition.replace(cond);
43964391
this.visit_expr(cond);
4397-
this.diagnostic_metadata.in_if_condition = old;
4392+
this.diag_metadata.in_if_condition = old;
43984393
this.visit_block(block);
43994394
})
44004395
});
@@ -4474,20 +4469,20 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
44744469
self.visit_expr(idx);
44754470
}
44764471
ExprKind::Assign(ref lhs, ref rhs, _) => {
4477-
if !self.diagnostic_metadata.is_assign_rhs {
4478-
self.diagnostic_metadata.in_assignment = Some(expr);
4472+
if !self.diag_metadata.is_assign_rhs {
4473+
self.diag_metadata.in_assignment = Some(expr);
44794474
}
44804475
self.visit_expr(lhs);
4481-
self.diagnostic_metadata.is_assign_rhs = true;
4482-
self.diagnostic_metadata.in_assignment = None;
4476+
self.diag_metadata.is_assign_rhs = true;
4477+
self.diag_metadata.in_assignment = None;
44834478
self.visit_expr(rhs);
4484-
self.diagnostic_metadata.is_assign_rhs = false;
4479+
self.diag_metadata.is_assign_rhs = false;
44854480
}
44864481
ExprKind::Range(Some(ref start), Some(ref end), RangeLimits::HalfOpen) => {
4487-
self.diagnostic_metadata.in_range = Some((start, end));
4482+
self.diag_metadata.in_range = Some((start, end));
44884483
self.resolve_expr(start, Some(expr));
44894484
self.resolve_expr(end, Some(expr));
4490-
self.diagnostic_metadata.in_range = None;
4485+
self.diag_metadata.in_range = None;
44914486
}
44924487
_ => {
44934488
visit::walk_expr(self, expr);
@@ -4735,7 +4730,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
47354730
let mut late_resolution_visitor = LateResolutionVisitor::new(self);
47364731
late_resolution_visitor.resolve_doc_links(&krate.attrs, MaybeExported::Ok(CRATE_NODE_ID));
47374732
visit::walk_crate(&mut late_resolution_visitor, krate);
4738-
for (id, span) in late_resolution_visitor.diagnostic_metadata.unused_labels.iter() {
4733+
for (id, span) in late_resolution_visitor.diag_metadata.unused_labels.iter() {
47394734
self.lint_buffer.buffer_lint(lint::builtin::UNUSED_LABELS, *id, *span, "unused label");
47404735
}
47414736
}

‎compiler/rustc_resolve/src/late/diagnostics.rs

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -224,13 +224,13 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
224224
let item_ident = path.last().unwrap().ident;
225225
let item_span = item_ident.span;
226226
let (mod_prefix, mod_str, module, suggestion) = if path.len() == 1 {
227-
debug!(?self.diagnostic_metadata.current_impl_items);
228-
debug!(?self.diagnostic_metadata.current_function);
227+
debug!(?self.diag_metadata.current_impl_items);
228+
debug!(?self.diag_metadata.current_function);
229229
let suggestion = if self.current_trait_ref.is_none()
230-
&& let Some((fn_kind, _)) = self.diagnostic_metadata.current_function
230+
&& let Some((fn_kind, _)) = self.diag_metadata.current_function
231231
&& let Some(FnCtxt::Assoc(_)) = fn_kind.ctxt()
232232
&& let FnKind::Fn(_, _, sig, ..) = fn_kind
233-
&& let Some(items) = self.diagnostic_metadata.current_impl_items
233+
&& let Some(items) = self.diag_metadata.current_impl_items
234234
&& let Some(item) = items.iter().find(|i| {
235235
i.ident.name == item_str.name
236236
// Don't suggest if the item is in Fn signature arguments (#112590).
@@ -501,7 +501,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
501501
err: &mut Diag<'_>,
502502
base_error: &BaseError,
503503
) {
504-
let Some(ty) = self.diagnostic_metadata.current_type_path else {
504+
let Some(ty) = self.diag_metadata.current_type_path else {
505505
return;
506506
};
507507
let TyKind::Path(_, path) = &ty.kind else {
@@ -555,7 +555,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
555555
);
556556
if !self.self_value_is_available(path[0].ident.span) {
557557
if let Some((FnKind::Fn(_, _, sig, ..), fn_span)) =
558-
&self.diagnostic_metadata.current_function
558+
&self.diag_metadata.current_function
559559
{
560560
let (span, sugg) = if let Some(param) = sig.decl.inputs.get(0) {
561561
(param.span.shrink_to_lo(), "&self, ")
@@ -805,7 +805,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
805805
) = (source, res, is_macro)
806806
{
807807
if let Some(bounds @ [first_bound, .., last_bound]) =
808-
self.diagnostic_metadata.current_trait_object
808+
self.diag_metadata.current_trait_object
809809
{
810810
fallback = true;
811811
let spans: Vec<Span> = bounds
@@ -880,7 +880,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
880880
let typo_sugg = typo_sugg.to_opt_suggestion();
881881
if !self.r.add_typo_suggestion(err, typo_sugg, ident_span) {
882882
fallback = true;
883-
match self.diagnostic_metadata.current_let_binding {
883+
match self.diag_metadata.current_let_binding {
884884
Some((pat_sp, Some(ty_sp), None))
885885
if ty_sp.contains(base_error.span) && base_error.could_be_expr =>
886886
{
@@ -962,7 +962,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
962962
Applicability::MaybeIncorrect,
963963
);
964964
// Do not lint against unused label when we suggest them.
965-
self.diagnostic_metadata.unused_labels.remove(node_id);
965+
self.diag_metadata.unused_labels.remove(node_id);
966966
}
967967
}
968968
}
@@ -993,7 +993,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
993993
}
994994
err.code(E0411);
995995
err.span_label(span, "`Self` is only available in impls, traits, and type definitions");
996-
if let Some(item_kind) = self.diagnostic_metadata.current_item {
996+
if let Some(item_kind) = self.diag_metadata.current_item {
997997
if !item_kind.ident.span.is_dummy() {
998998
err.span_label(
999999
item_kind.ident.span,
@@ -1031,7 +1031,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
10311031
},
10321032
);
10331033
let is_assoc_fn = self.self_type_is_available();
1034-
if let Some((fn_kind, span)) = &self.diagnostic_metadata.current_function {
1034+
if let Some((fn_kind, span)) = &self.diag_metadata.current_function {
10351035
// The current function has a `self` parameter, but we were unable to resolve
10361036
// a reference to `self`. This can only happen if the `self` identifier we
10371037
// are resolving came from a different hygiene context.
@@ -1077,7 +1077,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
10771077
);
10781078
}
10791079
}
1080-
} else if let Some(item_kind) = self.diagnostic_metadata.current_item {
1080+
} else if let Some(item_kind) = self.diag_metadata.current_item {
10811081
err.span_label(
10821082
item_kind.ident.span,
10831083
format!(
@@ -1095,7 +1095,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
10951095
err: &mut Diag<'_>,
10961096
path: &[Segment],
10971097
) {
1098-
let Some(pat) = self.diagnostic_metadata.current_pat else { return };
1098+
let Some(pat) = self.diag_metadata.current_pat else { return };
10991099
let (bound, side, range) = match &pat.kind {
11001100
ast::PatKind::Range(Some(bound), None, range) => (bound, Side::Start, range),
11011101
ast::PatKind::Range(None, Some(bound), range) => (bound, Side::End, range),
@@ -1137,7 +1137,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
11371137
span: Span,
11381138
) {
11391139
if let Some((trait_ref, self_ty)) =
1140-
self.diagnostic_metadata.currently_processing_impl_trait.clone()
1140+
self.diag_metadata.currently_processing_impl_trait.clone()
11411141
&& let TyKind::Path(_, self_ty_path) = &self_ty.kind
11421142
&& let PathResult::Module(ModuleOrUniformRoot::Module(module)) =
11431143
self.resolve_path(&Segment::from_path(self_ty_path), Some(TypeNS), None)
@@ -1158,7 +1158,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
11581158
}
11591159

11601160
fn suggest_bare_struct_literal(&mut self, err: &mut Diag<'_>) {
1161-
if let Some(span) = self.diagnostic_metadata.current_block_could_be_bare_struct_literal {
1161+
if let Some(span) = self.diag_metadata.current_block_could_be_bare_struct_literal {
11621162
err.multipart_suggestion(
11631163
"you might have meant to write a `struct` literal",
11641164
vec![
@@ -1195,7 +1195,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
11951195
_ => return,
11961196
};
11971197

1198-
let Some(item) = self.diagnostic_metadata.current_item else { return };
1198+
let Some(item) = self.diag_metadata.current_item else { return };
11991199
let Some(generics) = item.kind.generics() else { return };
12001200

12011201
let param = generics.params.iter().find_map(|param| {
@@ -1230,7 +1230,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
12301230
) -> bool {
12311231
if let PathSource::Expr(_) = source
12321232
&& let Some(Expr { span: expr_span, kind: ExprKind::Assign(lhs, _, _), .. }) =
1233-
self.diagnostic_metadata.in_if_condition
1233+
self.diag_metadata.in_if_condition
12341234
{
12351235
// Icky heuristic so we don't suggest:
12361236
// `if (i + 2) = 2` => `if let (i + 2) = 2` (approximately pattern)
@@ -1287,7 +1287,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
12871287
bound_generic_params,
12881288
bounds,
12891289
span,
1290-
})) = self.diagnostic_metadata.current_where_predicate
1290+
})) = self.diag_metadata.current_where_predicate
12911291
{
12921292
if !bound_generic_params.is_empty() {
12931293
return false;
@@ -2018,7 +2018,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
20182018
// Fields are generally expected in the same contexts as locals.
20192019
if filter_fn(Res::Local(ast::DUMMY_NODE_ID)) {
20202020
if let Some(node_id) =
2021-
self.diagnostic_metadata.current_self_type.as_ref().and_then(extract_node_id)
2021+
self.diag_metadata.current_self_type.as_ref().and_then(extract_node_id)
20222022
{
20232023
// Look for a field with the same name in the current self_type.
20242024
if let Some(resolution) = self.r.partial_res_map.get(&node_id) {
@@ -2038,7 +2038,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
20382038
}
20392039
}
20402040

2041-
if let Some(items) = self.diagnostic_metadata.current_trait_assoc_items {
2041+
if let Some(items) = self.diag_metadata.current_trait_assoc_items {
20422042
for assoc_item in items {
20432043
if assoc_item.ident == ident {
20442044
return Some(match &assoc_item.kind {
@@ -2253,8 +2253,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
22532253
// try to give a suggestion for this pattern: `name = blah`, which is common in other languages
22542254
// suggest `let name = blah` to introduce a new binding
22552255
fn let_binding_suggestion(&mut self, err: &mut Diag<'_>, ident_span: Span) -> bool {
2256-
if let Some(Expr { kind: ExprKind::Assign(lhs, ..), .. }) =
2257-
self.diagnostic_metadata.in_assignment
2256+
if let Some(Expr { kind: ExprKind::Assign(lhs, ..), .. }) = self.diag_metadata.in_assignment
22582257
&& let ast::ExprKind::Path(None, ref path) = lhs.kind
22592258
{
22602259
if !ident_span.from_expansion() {
@@ -2505,10 +2504,10 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
25052504
let mut iter = ident.chars().map(|c| c.is_uppercase());
25062505
let single_uppercase_char =
25072506
matches!(iter.next(), Some(true)) && matches!(iter.next(), None);
2508-
if !self.diagnostic_metadata.currently_processing_generic_args && !single_uppercase_char {
2507+
if !self.diag_metadata.currently_processing_generic_args && !single_uppercase_char {
25092508
return None;
25102509
}
2511-
match (self.diagnostic_metadata.current_item, single_uppercase_char, self.diagnostic_metadata.currently_processing_generic_args) {
2510+
match (self.diag_metadata.current_item, single_uppercase_char, self.diag_metadata.currently_processing_generic_args) {
25122511
(Some(Item { kind: ItemKind::Fn(..), ident, .. }), _, _) if ident.name == sym::main => {
25132512
// Ignore `fn main()` as we don't want to suggest `fn main<T>()`
25142513
}
@@ -3082,7 +3081,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
30823081
|| lt.kind == MissingLifetimeKind::Underscore)
30833082
{
30843083
let pre = if lt.kind == MissingLifetimeKind::Ampersand
3085-
&& let Some((kind, _span)) = self.diagnostic_metadata.current_function
3084+
&& let Some((kind, _span)) = self.diag_metadata.current_function
30863085
&& let FnKind::Fn(_, _, sig, _, _, _) = kind
30873086
&& !sig.decl.inputs.is_empty()
30883087
&& let sugg = sig
@@ -3123,7 +3122,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
31233122
"...or alternatively, you might want"
31243123
} else if (lt.kind == MissingLifetimeKind::Ampersand
31253124
|| lt.kind == MissingLifetimeKind::Underscore)
3126-
&& let Some((kind, _span)) = self.diagnostic_metadata.current_function
3125+
&& let Some((kind, _span)) = self.diag_metadata.current_function
31273126
&& let FnKind::Fn(_, _, sig, _, _, _) = kind
31283127
&& let ast::FnRetTy::Ty(ret_ty) = &sig.decl.output
31293128
&& !sig.decl.inputs.is_empty()
@@ -3183,7 +3182,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
31833182
};
31843183
let mut owned_sugg = lt.kind == MissingLifetimeKind::Ampersand;
31853184
let mut sugg = vec![(lt.span, String::new())];
3186-
if let Some((kind, _span)) = self.diagnostic_metadata.current_function
3185+
if let Some((kind, _span)) = self.diag_metadata.current_function
31873186
&& let FnKind::Fn(_, _, sig, _, _, _) = kind
31883187
&& let ast::FnRetTy::Ty(ty) = &sig.decl.output
31893188
{

0 commit comments

Comments
 (0)
Please sign in to comment.