Skip to content

Commit 48dc9c9

Browse files
committed
Update all lint diagnostics to store their span
1 parent 1f6b731 commit 48dc9c9

File tree

85 files changed

+1530
-1092
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+1530
-1092
lines changed

compiler/rustc_borrowck/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ fn do_mir_borrowck<'tcx>(
401401

402402
let mut_span = tcx.sess.source_map().span_until_non_whitespace(span);
403403

404-
tcx.emit_node_span_lint(UNUSED_MUT, lint_root, span, VarNeedNotMut { span: mut_span })
404+
tcx.emit_node_lint(UNUSED_MUT, lint_root, VarNeedNotMut { span, mut_span })
405405
}
406406

407407
let tainted_by_errors = mbcx.emit_errors();

compiler/rustc_borrowck/src/session_diagnostics.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,10 @@ pub(crate) struct GenericDoesNotLiveLongEnough {
5050
#[derive(LintDiagnostic)]
5151
#[diag(borrowck_var_does_not_need_mut)]
5252
pub(crate) struct VarNeedNotMut {
53-
#[suggestion(style = "short", applicability = "machine-applicable", code = "")]
53+
#[primary_span]
5454
pub span: Span,
55+
#[suggestion(style = "short", applicability = "machine-applicable", code = "")]
56+
pub mut_span: Span,
5557
}
5658
#[derive(Diagnostic)]
5759
#[diag(borrowck_var_cannot_escape_closure)]

compiler/rustc_const_eval/src/const_eval/error.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,11 @@ pub(super) fn lint<'tcx, L>(
170170
tcx: TyCtxtAt<'tcx>,
171171
machine: &CompileTimeMachine<'tcx>,
172172
lint: &'static rustc_session::lint::Lint,
173-
decorator: impl FnOnce(Vec<errors::FrameNote>) -> L,
173+
decorator: impl FnOnce(Span, Vec<errors::FrameNote>) -> L,
174174
) where
175175
L: for<'a> rustc_errors::LintDiagnostic<'a, ()>,
176176
{
177177
let (span, frames) = get_span_and_frames(tcx, &machine.stack);
178178

179-
tcx.emit_node_span_lint(lint, machine.best_lint_scope(*tcx), span, decorator(frames));
179+
tcx.emit_node_lint(lint, machine.best_lint_scope(*tcx), decorator(span, frames));
180180
}

compiler/rustc_const_eval/src/const_eval/machine.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -622,11 +622,10 @@ impl<'tcx> interpret::Machine<'tcx> for CompileTimeMachine<'tcx> {
622622
.0
623623
.is_error();
624624
let span = ecx.cur_span();
625-
ecx.tcx.emit_node_span_lint(
625+
ecx.tcx.emit_node_lint(
626626
rustc_session::lint::builtin::LONG_RUNNING_CONST_EVAL,
627627
hir_id,
628-
span,
629-
LongRunning { item_span: ecx.tcx.span },
628+
LongRunning { span, item_span: ecx.tcx.span },
630629
);
631630
// If this was a hard error, don't bother continuing evaluation.
632631
if is_error {

compiler/rustc_const_eval/src/errors.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ pub(crate) struct InteriorMutableRefEscaping {
197197
#[diag(const_eval_long_running)]
198198
#[note]
199199
pub struct LongRunning {
200+
#[primary_span]
201+
pub span: Span,
200202
#[help]
201203
pub item_span: Span,
202204
}

compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,11 +297,11 @@ fn report_mismatched_rpitit_signature<'tcx>(
297297
});
298298

299299
let span = unmatched_bound.unwrap_or(span);
300-
tcx.emit_node_span_lint(
300+
tcx.emit_node_lint(
301301
if is_internal { REFINING_IMPL_TRAIT_INTERNAL } else { REFINING_IMPL_TRAIT_REACHABLE },
302302
tcx.local_def_id_to_hir_id(impl_m_def_id.expect_local()),
303-
span,
304303
crate::errors::ReturnPositionImplTraitInTraitRefined {
304+
span,
305305
impl_return_span,
306306
trait_return_span,
307307
pre,

compiler/rustc_hir_analysis/src/check/errs.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,6 @@ fn handle_static_mut_ref(
7979
} else {
8080
(errors::MutRefSugg::Shared { lo, hi }, "shared")
8181
};
82-
tcx.emit_node_span_lint(STATIC_MUT_REFS, hir_id, span, errors::RefOfMutStatic {
83-
span,
84-
sugg,
85-
shared,
86-
});
82+
tcx.emit_node_lint(STATIC_MUT_REFS, hir_id, errors::RefOfMutStatic { span, sugg, shared });
8783
}
8884
}

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2334,11 +2334,10 @@ fn lint_redundant_lifetimes<'tcx>(
23342334
&& outlives_env.free_region_map().sub_free_regions(tcx, victim, candidate)
23352335
{
23362336
shadowed.insert(victim);
2337-
tcx.emit_node_span_lint(
2337+
tcx.emit_node_lint(
23382338
rustc_lint_defs::builtin::REDUNDANT_LIFETIMES,
23392339
tcx.local_def_id_to_hir_id(def_id.expect_local()),
2340-
tcx.def_span(def_id),
2341-
RedundantLifetimeArgsLint { candidate, victim },
2340+
RedundantLifetimeArgsLint { span: tcx.def_span(def_id), candidate, victim },
23422341
);
23432342
}
23442343
}
@@ -2349,6 +2348,8 @@ fn lint_redundant_lifetimes<'tcx>(
23492348
#[diag(hir_analysis_redundant_lifetime_args)]
23502349
#[note]
23512350
struct RedundantLifetimeArgsLint<'tcx> {
2351+
#[primary_span]
2352+
pub span: Span,
23522353
/// The lifetime we have found to be redundant.
23532354
victim: ty::Region<'tcx>,
23542355
// The lifetime we can replace the victim with.

compiler/rustc_hir_analysis/src/coherence/orphan.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -494,18 +494,18 @@ fn lint_uncovered_ty_params<'tcx>(
494494
let name = tcx.item_name(param_def_id);
495495

496496
match local_ty {
497-
Some(local_type) => tcx.emit_node_span_lint(
497+
Some(local_type) => tcx.emit_node_lint(
498498
UNCOVERED_PARAM_IN_PROJECTION,
499499
hir_id,
500-
span,
501500
errors::TyParamFirstLocalLint { span, note: (), param: name, local_type },
502501
),
503-
None => tcx.emit_node_span_lint(
504-
UNCOVERED_PARAM_IN_PROJECTION,
505-
hir_id,
506-
span,
507-
errors::TyParamSomeLint { span, note: (), param: name },
508-
),
502+
None => {
503+
tcx.emit_node_lint(UNCOVERED_PARAM_IN_PROJECTION, hir_id, errors::TyParamSomeLint {
504+
span,
505+
note: (),
506+
param: name,
507+
})
508+
}
509509
};
510510
}
511511
}

compiler/rustc_hir_analysis/src/errors.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,6 +1132,7 @@ pub(crate) enum LateBoundInApit {
11321132
#[diag(hir_analysis_unused_associated_type_bounds)]
11331133
#[note]
11341134
pub(crate) struct UnusedAssociatedTypeBounds {
1135+
#[primary_span]
11351136
#[suggestion(code = "")]
11361137
pub span: Span,
11371138
}
@@ -1141,6 +1142,8 @@ pub(crate) struct UnusedAssociatedTypeBounds {
11411142
#[note]
11421143
#[note(hir_analysis_feedback_note)]
11431144
pub(crate) struct ReturnPositionImplTraitInTraitRefined<'tcx> {
1145+
#[primary_span]
1146+
pub span: Span,
11441147
#[suggestion(applicability = "maybe-incorrect", code = "{pre}{return_ty}{post}")]
11451148
pub impl_return_span: Span,
11461149
#[label]
@@ -1398,6 +1401,7 @@ pub(crate) struct TyParamFirstLocal<'tcx> {
13981401
#[diag(hir_analysis_ty_param_first_local, code = E0210)]
13991402
#[note]
14001403
pub(crate) struct TyParamFirstLocalLint<'tcx> {
1404+
#[primary_span]
14011405
#[label]
14021406
pub span: Span,
14031407
#[note(hir_analysis_case_note)]
@@ -1422,6 +1426,7 @@ pub(crate) struct TyParamSome {
14221426
#[diag(hir_analysis_ty_param_some, code = E0210)]
14231427
#[note]
14241428
pub(crate) struct TyParamSomeLint {
1429+
#[primary_span]
14251430
#[label]
14261431
pub span: Span,
14271432
#[note(hir_analysis_only_note)]

compiler/rustc_hir_analysis/src/hir_ty_lowering/dyn_compatibility.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,16 +193,15 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
193193
// types's `DefId`, so the following loop removes all the `DefIds` of the associated types that have a
194194
// corresponding `Projection` clause
195195
for def_ids in associated_types.values_mut() {
196-
for (projection_bound, span) in &projection_bounds {
196+
for &(projection_bound, span) in &projection_bounds {
197197
let def_id = projection_bound.projection_def_id();
198198
// FIXME(#120456) - is `swap_remove` correct?
199199
def_ids.swap_remove(&def_id);
200200
if tcx.generics_require_sized_self(def_id) {
201-
tcx.emit_node_span_lint(
201+
tcx.emit_node_lint(
202202
UNUSED_ASSOCIATED_TYPE_BOUNDS,
203203
hir_id,
204-
*span,
205-
crate::errors::UnusedAssociatedTypeBounds { span: *span },
204+
crate::errors::UnusedAssociatedTypeBounds { span },
206205
);
207206
}
208207
}

compiler/rustc_hir_typeck/src/cast.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,8 @@ impl<'a, 'tcx> CastCheck<'tcx> {
663663
};
664664
let expr_ty = fcx.resolve_vars_if_possible(self.expr_ty);
665665
let cast_ty = fcx.resolve_vars_if_possible(self.cast_ty);
666-
fcx.tcx.emit_node_span_lint(lint, self.expr.hir_id, self.span, errors::TrivialCast {
666+
fcx.tcx.emit_node_lint(lint, self.expr.hir_id, errors::TrivialCast {
667+
span: self.span,
667668
numeric,
668669
expr_ty,
669670
cast_ty,
@@ -934,11 +935,11 @@ impl<'a, 'tcx> CastCheck<'tcx> {
934935
.collect::<Vec<_>>();
935936

936937
if !added.is_empty() {
937-
tcx.emit_node_span_lint(
938+
tcx.emit_node_lint(
938939
lint::builtin::PTR_CAST_ADD_AUTO_TO_OBJECT,
939940
self.expr.hir_id,
940-
self.span,
941941
errors::PtrCastAddAutoToObject {
942+
span: self.span,
942943
traits_len: added.len(),
943944
traits: {
944945
let mut traits: Vec<_> = added
@@ -1097,11 +1098,10 @@ impl<'a, 'tcx> CastCheck<'tcx> {
10971098
let expr_ty = fcx.resolve_vars_if_possible(self.expr_ty);
10981099
let cast_ty = fcx.resolve_vars_if_possible(self.cast_ty);
10991100

1100-
fcx.tcx.emit_node_span_lint(
1101+
fcx.tcx.emit_node_lint(
11011102
lint::builtin::CENUM_IMPL_DROP_CAST,
11021103
self.expr.hir_id,
1103-
self.span,
1104-
errors::CastEnumDrop { expr_ty, cast_ty },
1104+
errors::CastEnumDrop { span: self.span, expr_ty, cast_ty },
11051105
);
11061106
}
11071107
}
@@ -1130,12 +1130,10 @@ impl<'a, 'tcx> CastCheck<'tcx> {
11301130
(false, false) => errors::LossyProvenancePtr2IntSuggestion::Other { cast_span },
11311131
};
11321132

1133-
let lint = errors::LossyProvenancePtr2Int { expr_ty, cast_ty, sugg };
1134-
fcx.tcx.emit_node_span_lint(
1133+
fcx.tcx.emit_node_lint(
11351134
lint::builtin::LOSSY_PROVENANCE_CASTS,
11361135
self.expr.hir_id,
1137-
self.span,
1138-
lint,
1136+
errors::LossyProvenancePtr2Int { span: self.span, expr_ty, cast_ty, sugg },
11391137
);
11401138
}
11411139

@@ -1146,12 +1144,10 @@ impl<'a, 'tcx> CastCheck<'tcx> {
11461144
};
11471145
let expr_ty = fcx.resolve_vars_if_possible(self.expr_ty);
11481146
let cast_ty = fcx.resolve_vars_if_possible(self.cast_ty);
1149-
let lint = errors::LossyProvenanceInt2Ptr { expr_ty, cast_ty, sugg };
1150-
fcx.tcx.emit_node_span_lint(
1147+
fcx.tcx.emit_node_lint(
11511148
lint::builtin::FUZZY_PROVENANCE_CASTS,
11521149
self.expr.hir_id,
1153-
self.span,
1154-
lint,
1150+
errors::LossyProvenanceInt2Ptr { span: self.span, expr_ty, cast_ty, sugg },
11551151
);
11561152
}
11571153

compiler/rustc_hir_typeck/src/errors.rs

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,25 +169,42 @@ pub(crate) struct MissingParenthesesInRange {
169169
pub(crate) enum NeverTypeFallbackFlowingIntoUnsafe {
170170
#[help]
171171
#[diag(hir_typeck_never_type_fallback_flowing_into_unsafe_call)]
172-
Call,
172+
Call {
173+
#[primary_span]
174+
span: Span,
175+
},
173176
#[help]
174177
#[diag(hir_typeck_never_type_fallback_flowing_into_unsafe_method)]
175-
Method,
178+
Method {
179+
#[primary_span]
180+
span: Span,
181+
},
176182
#[help]
177183
#[diag(hir_typeck_never_type_fallback_flowing_into_unsafe_path)]
178-
Path,
184+
Path {
185+
#[primary_span]
186+
span: Span,
187+
},
179188
#[help]
180189
#[diag(hir_typeck_never_type_fallback_flowing_into_unsafe_union_field)]
181-
UnionField,
190+
UnionField {
191+
#[primary_span]
192+
span: Span,
193+
},
182194
#[help]
183195
#[diag(hir_typeck_never_type_fallback_flowing_into_unsafe_deref)]
184-
Deref,
196+
Deref {
197+
#[primary_span]
198+
span: Span,
199+
},
185200
}
186201

187202
#[derive(LintDiagnostic)]
188203
#[help]
189204
#[diag(hir_typeck_dependency_on_unit_never_type_fallback)]
190205
pub(crate) struct DependencyOnUnitNeverTypeFallback<'tcx> {
206+
#[primary_span]
207+
pub span: Span,
191208
#[note]
192209
pub obligation_span: Span,
193210
pub obligation: ty::Predicate<'tcx>,
@@ -247,6 +264,8 @@ impl Subdiagnostic for TypeMismatchFruTypo {
247264
#[diag(hir_typeck_lossy_provenance_int2ptr)]
248265
#[help]
249266
pub(crate) struct LossyProvenanceInt2Ptr<'tcx> {
267+
#[primary_span]
268+
pub span: Span,
250269
pub expr_ty: Ty<'tcx>,
251270
pub cast_ty: Ty<'tcx>,
252271
#[subdiagnostic]
@@ -256,6 +275,8 @@ pub(crate) struct LossyProvenanceInt2Ptr<'tcx> {
256275
#[derive(LintDiagnostic)]
257276
#[diag(hir_typeck_ptr_cast_add_auto_to_object)]
258277
pub(crate) struct PtrCastAddAutoToObject {
278+
#[primary_span]
279+
pub span: Span,
259280
pub traits_len: usize,
260281
pub traits: DiagSymbolList<String>,
261282
}
@@ -273,6 +294,8 @@ pub(crate) struct LossyProvenanceInt2PtrSuggestion {
273294
#[diag(hir_typeck_lossy_provenance_ptr2int)]
274295
#[help]
275296
pub(crate) struct LossyProvenancePtr2Int<'tcx> {
297+
#[primary_span]
298+
pub span: Span,
276299
pub expr_ty: Ty<'tcx>,
277300
pub cast_ty: Ty<'tcx>,
278301
#[subdiagnostic]
@@ -520,6 +543,8 @@ pub(crate) struct SuggestPtrNullMut {
520543
#[diag(hir_typeck_trivial_cast)]
521544
#[help]
522545
pub(crate) struct TrivialCast<'tcx> {
546+
#[primary_span]
547+
pub span: Span,
523548
pub numeric: bool,
524549
pub expr_ty: Ty<'tcx>,
525550
pub cast_ty: Ty<'tcx>,
@@ -560,6 +585,8 @@ pub(crate) struct CannotCastToBool<'tcx> {
560585
#[derive(LintDiagnostic)]
561586
#[diag(hir_typeck_cast_enum_drop)]
562587
pub(crate) struct CastEnumDrop<'tcx> {
588+
#[primary_span]
589+
pub span: Span,
563590
pub expr_ty: Ty<'tcx>,
564591
pub cast_ty: Ty<'tcx>,
565592
}
@@ -684,6 +711,8 @@ pub(crate) struct SelfCtorFromOuterItem {
684711
#[derive(LintDiagnostic)]
685712
#[diag(hir_typeck_self_ctor_from_outer_item)]
686713
pub(crate) struct SelfCtorFromOuterItemLint {
714+
#[primary_span]
715+
pub span: Span,
687716
#[label]
688717
pub impl_span: Span,
689718
#[subdiagnostic]

0 commit comments

Comments
 (0)