Skip to content

Commit c630da4

Browse files
committed
Update all lint diagnostics to store their span
1 parent a31ed16 commit c630da4

File tree

77 files changed

+1299
-924
lines changed

Some content is hidden

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

77 files changed

+1299
-924
lines changed

compiler/rustc_borrowck/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ fn do_mir_borrowck<'tcx>(
408408

409409
let mut_span = tcx.sess.source_map().span_until_non_whitespace(span);
410410

411-
tcx.emit_node_span_lint(UNUSED_MUT, lint_root, span, VarNeedNotMut { span: mut_span })
411+
tcx.emit_node_lint(UNUSED_MUT, lint_root, VarNeedNotMut { span, mut_span })
412412
}
413413

414414
let tainted_by_errors = mbcx.emit_errors();

compiler/rustc_borrowck/src/session_diagnostics.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,10 @@ pub(crate) struct GenericDoesNotLiveLongEnough {
4949
#[derive(LintDiagnostic)]
5050
#[diag(borrowck_var_does_not_need_mut)]
5151
pub(crate) struct VarNeedNotMut {
52-
#[suggestion(style = "short", applicability = "machine-applicable", code = "")]
52+
#[primary_span]
5353
pub span: Span,
54+
#[suggestion(style = "short", applicability = "machine-applicable", code = "")]
55+
pub mut_span: Span,
5456
}
5557
#[derive(Diagnostic)]
5658
#[diag(borrowck_var_cannot_escape_closure)]

compiler/rustc_const_eval/src/const_eval/error.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -164,18 +164,17 @@ pub(super) fn lint<'tcx, 'mir, L>(
164164
tcx: TyCtxtAt<'tcx>,
165165
machine: &CompileTimeInterpreter<'mir, 'tcx>,
166166
lint: &'static rustc_session::lint::Lint,
167-
decorator: impl FnOnce(Vec<errors::FrameNote>) -> L,
167+
decorator: impl FnOnce(Span, Vec<errors::FrameNote>) -> L,
168168
) where
169169
L: for<'a> rustc_errors::LintDiagnostic<'a, ()>,
170170
{
171171
let (span, frames) = get_span_and_frames(tcx, &machine.stack);
172172

173-
tcx.emit_node_span_lint(
173+
tcx.emit_node_lint(
174174
lint,
175175
// We use the root frame for this so the crate that defines the const defines whether the
176176
// lint is emitted.
177177
machine.stack.first().and_then(|frame| frame.lint_root()).unwrap_or(CRATE_HIR_ID),
178-
span,
179-
decorator(frames),
178+
decorator(span, frames),
180179
);
181180
}

compiler/rustc_const_eval/src/const_eval/eval_queries.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,10 @@ fn eval_body_using_ecx<'mir, 'tcx, R: InterpretationResult<'tcx>>(
109109
}
110110
Err(InternResult::FoundBadMutablePointer) => {
111111
// only report mutable pointers if there were no dangling pointers
112-
let err_diag = errors::MutablePtrInFinal { span: ecx.tcx.span, kind: intern_kind };
113-
ecx.tcx.emit_node_span_lint(
112+
ecx.tcx.emit_node_lint(
114113
lint::builtin::CONST_EVAL_MUTABLE_PTR_IN_FINAL_VALUE,
115114
ecx.best_lint_scope(),
116-
err_diag.span,
117-
err_diag,
115+
errors::MutablePtrInFinal { span: ecx.tcx.span, kind: intern_kind },
118116
)
119117
}
120118
}

compiler/rustc_const_eval/src/const_eval/machine.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -620,11 +620,10 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
620620
.0
621621
.is_error();
622622
let span = ecx.cur_span();
623-
ecx.tcx.emit_node_span_lint(
623+
ecx.tcx.emit_node_lint(
624624
rustc_session::lint::builtin::LONG_RUNNING_CONST_EVAL,
625625
hir_id,
626-
span,
627-
LongRunning { item_span: ecx.tcx.span },
626+
LongRunning { span, item_span: ecx.tcx.span },
628627
);
629628
// If this was a hard error, don't bother continuing evaluation.
630629
if is_error {
@@ -745,8 +744,8 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
745744
}
746745
// Reject writes through immutable pointers.
747746
if immutable {
748-
super::lint(tcx, machine, WRITES_THROUGH_IMMUTABLE_POINTER, |frames| {
749-
crate::errors::WriteThroughImmutablePointer { frames }
747+
super::lint(tcx, machine, WRITES_THROUGH_IMMUTABLE_POINTER, |span, frames| {
748+
crate::errors::WriteThroughImmutablePointer { span, frames }
750749
});
751750
}
752751
// Everything else is fine.

compiler/rustc_const_eval/src/errors.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,7 @@ pub(crate) struct NestedStaticInThreadLocal {
3535
#[derive(LintDiagnostic)]
3636
#[diag(const_eval_mutable_ptr_in_final)]
3737
pub(crate) struct MutablePtrInFinal {
38-
// rust-lang/rust#122153: This was marked as `#[primary_span]` under
39-
// `derive(Diagnostic)`. Since we expect we may hard-error in future, we are
40-
// keeping the field (and skipping it under `derive(LintDiagnostic)`).
41-
#[skip_arg]
38+
#[primary_span]
4239
pub span: Span,
4340
pub kind: InternKind,
4441
}
@@ -228,6 +225,8 @@ pub(crate) struct InteriorMutabilityBorrow {
228225
#[diag(const_eval_long_running)]
229226
#[note]
230227
pub struct LongRunning {
228+
#[primary_span]
229+
pub span: Span,
231230
#[help]
232231
pub item_span: Span,
233232
}
@@ -407,6 +406,8 @@ pub struct ConstEvalError {
407406
#[derive(LintDiagnostic)]
408407
#[diag(const_eval_write_through_immutable_pointer)]
409408
pub struct WriteThroughImmutablePointer {
409+
#[primary_span]
410+
pub span: Span,
410411
#[subdiagnostic]
411412
pub frames: Vec<FrameNote>,
412413
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -287,11 +287,11 @@ fn report_mismatched_rpitit_signature<'tcx>(
287287
});
288288

289289
let span = unmatched_bound.unwrap_or(span);
290-
tcx.emit_node_span_lint(
290+
tcx.emit_node_lint(
291291
if is_internal { REFINING_IMPL_TRAIT_INTERNAL } else { REFINING_IMPL_TRAIT_REACHABLE },
292292
tcx.local_def_id_to_hir_id(impl_m_def_id.expect_local()),
293-
span,
294293
crate::errors::ReturnPositionImplTraitInTraitRefined {
294+
span,
295295
impl_return_span,
296296
trait_return_span,
297297
pre,

compiler/rustc_hir_analysis/src/check/errs.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,6 @@ fn handle_static_mut_ref(
6969
} else {
7070
(errors::RefOfMutStaticSugg::Shared { span, var }, "shared")
7171
};
72-
tcx.emit_node_span_lint(
73-
STATIC_MUT_REFS,
74-
hir_id,
75-
span,
76-
errors::RefOfMutStatic { span, sugg, shared },
77-
);
72+
tcx.emit_node_lint(STATIC_MUT_REFS, hir_id, errors::RefOfMutStatic { span, sugg, shared });
7873
}
7974
}

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -2114,11 +2114,10 @@ fn lint_redundant_lifetimes<'tcx>(
21142114
&& outlives_env.free_region_map().sub_free_regions(tcx, victim, candidate)
21152115
{
21162116
shadowed.insert(victim);
2117-
tcx.emit_node_span_lint(
2117+
tcx.emit_node_lint(
21182118
rustc_lint_defs::builtin::REDUNDANT_LIFETIMES,
21192119
tcx.local_def_id_to_hir_id(def_id.expect_local()),
2120-
tcx.def_span(def_id),
2121-
RedundantLifetimeArgsLint { candidate, victim },
2120+
RedundantLifetimeArgsLint { span: tcx.def_span(def_id), candidate, victim },
21222121
);
21232122
}
21242123
}
@@ -2129,6 +2128,8 @@ fn lint_redundant_lifetimes<'tcx>(
21292128
#[diag(hir_analysis_redundant_lifetime_args)]
21302129
#[note]
21312130
struct RedundantLifetimeArgsLint<'tcx> {
2131+
#[primary_span]
2132+
pub span: Span,
21322133
/// The lifetime we have found to be redundant.
21332134
victim: ty::Region<'tcx>,
21342135
// The lifetime we can replace the victim with.

compiler/rustc_hir_analysis/src/coherence/orphan.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -510,16 +510,14 @@ fn lint_uncovered_ty_params<'tcx>(
510510
let name = tcx.item_name(param_def_id);
511511

512512
match local_ty {
513-
Some(local_type) => tcx.emit_node_span_lint(
513+
Some(local_type) => tcx.emit_node_lint(
514514
UNCOVERED_PARAM_IN_PROJECTION,
515515
hir_id,
516-
span,
517516
errors::TyParamFirstLocalLint { span, note: (), param: name, local_type },
518517
),
519-
None => tcx.emit_node_span_lint(
518+
None => tcx.emit_node_lint(
520519
UNCOVERED_PARAM_IN_PROJECTION,
521520
hir_id,
522-
span,
523521
errors::TyParamSomeLint { span, note: (), param: name },
524522
),
525523
};

compiler/rustc_hir_analysis/src/errors.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1108,6 +1108,7 @@ pub(crate) enum LateBoundInApit {
11081108
#[diag(hir_analysis_unused_associated_type_bounds)]
11091109
#[note]
11101110
pub struct UnusedAssociatedTypeBounds {
1111+
#[primary_span]
11111112
#[suggestion(code = "")]
11121113
pub span: Span,
11131114
}
@@ -1117,6 +1118,8 @@ pub struct UnusedAssociatedTypeBounds {
11171118
#[note]
11181119
#[note(hir_analysis_feedback_note)]
11191120
pub(crate) struct ReturnPositionImplTraitInTraitRefined<'tcx> {
1121+
#[primary_span]
1122+
pub span: Span,
11201123
#[suggestion(applicability = "maybe-incorrect", code = "{pre}{return_ty}{post}")]
11211124
pub impl_return_span: Span,
11221125
#[label]
@@ -1374,6 +1377,7 @@ pub struct TyParamFirstLocal<'tcx> {
13741377
#[diag(hir_analysis_ty_param_first_local, code = E0210)]
13751378
#[note]
13761379
pub struct TyParamFirstLocalLint<'tcx> {
1380+
#[primary_span]
13771381
#[label]
13781382
pub span: Span,
13791383
#[note(hir_analysis_case_note)]
@@ -1398,6 +1402,7 @@ pub struct TyParamSome {
13981402
#[diag(hir_analysis_ty_param_some, code = E0210)]
13991403
#[note]
14001404
pub struct TyParamSomeLint {
1405+
#[primary_span]
14011406
#[label]
14021407
pub span: Span,
14031408
#[note(hir_analysis_only_note)]
@@ -1536,6 +1541,7 @@ pub enum StaticMutRefSugg {
15361541
#[note]
15371542
#[note(hir_analysis_why_note)]
15381543
pub struct RefOfMutStatic<'a> {
1544+
#[primary_span]
15391545
#[label]
15401546
pub span: Span,
15411547
#[subdiagnostic]

compiler/rustc_hir_analysis/src/hir_ty_lowering/object_safety.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -177,16 +177,15 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
177177
// types's `DefId`, so the following loop removes all the `DefIds` of the associated types that have a
178178
// corresponding `Projection` clause
179179
for def_ids in associated_types.values_mut() {
180-
for (projection_bound, span) in &projection_bounds {
180+
for &(projection_bound, span) in &projection_bounds {
181181
let def_id = projection_bound.projection_def_id();
182182
// FIXME(#120456) - is `swap_remove` correct?
183183
def_ids.swap_remove(&def_id);
184184
if tcx.generics_require_sized_self(def_id) {
185-
tcx.emit_node_span_lint(
185+
tcx.emit_node_lint(
186186
UNUSED_ASSOCIATED_TYPE_BOUNDS,
187187
hir_id,
188-
*span,
189-
crate::errors::UnusedAssociatedTypeBounds { span: *span },
188+
crate::errors::UnusedAssociatedTypeBounds { span },
190189
);
191190
}
192191
}

compiler/rustc_hir_typeck/src/cast.rs

+8-14
Original file line numberDiff line numberDiff line change
@@ -618,11 +618,10 @@ impl<'a, 'tcx> CastCheck<'tcx> {
618618
};
619619
let expr_ty = fcx.resolve_vars_if_possible(self.expr_ty);
620620
let cast_ty = fcx.resolve_vars_if_possible(self.cast_ty);
621-
fcx.tcx.emit_node_span_lint(
621+
fcx.tcx.emit_node_lint(
622622
lint,
623623
self.expr.hir_id,
624-
self.span,
625-
errors::TrivialCast { numeric, expr_ty, cast_ty },
624+
errors::TrivialCast { span: self.span, numeric, expr_ty, cast_ty },
626625
);
627626
}
628627

@@ -931,11 +930,10 @@ impl<'a, 'tcx> CastCheck<'tcx> {
931930
let expr_ty = fcx.resolve_vars_if_possible(self.expr_ty);
932931
let cast_ty = fcx.resolve_vars_if_possible(self.cast_ty);
933932

934-
fcx.tcx.emit_node_span_lint(
933+
fcx.tcx.emit_node_lint(
935934
lint::builtin::CENUM_IMPL_DROP_CAST,
936935
self.expr.hir_id,
937-
self.span,
938-
errors::CastEnumDrop { expr_ty, cast_ty },
936+
errors::CastEnumDrop { span: self.span, expr_ty, cast_ty },
939937
);
940938
}
941939
}
@@ -964,12 +962,10 @@ impl<'a, 'tcx> CastCheck<'tcx> {
964962
(false, false) => errors::LossyProvenancePtr2IntSuggestion::Other { cast_span },
965963
};
966964

967-
let lint = errors::LossyProvenancePtr2Int { expr_ty, cast_ty, sugg };
968-
fcx.tcx.emit_node_span_lint(
965+
fcx.tcx.emit_node_lint(
969966
lint::builtin::LOSSY_PROVENANCE_CASTS,
970967
self.expr.hir_id,
971-
self.span,
972-
lint,
968+
errors::LossyProvenancePtr2Int { span: self.span, expr_ty, cast_ty, sugg },
973969
);
974970
}
975971

@@ -980,12 +976,10 @@ impl<'a, 'tcx> CastCheck<'tcx> {
980976
};
981977
let expr_ty = fcx.resolve_vars_if_possible(self.expr_ty);
982978
let cast_ty = fcx.resolve_vars_if_possible(self.cast_ty);
983-
let lint = errors::LossyProvenanceInt2Ptr { expr_ty, cast_ty, sugg };
984-
fcx.tcx.emit_node_span_lint(
979+
fcx.tcx.emit_node_lint(
985980
lint::builtin::FUZZY_PROVENANCE_CASTS,
986981
self.expr.hir_id,
987-
self.span,
988-
lint,
982+
errors::LossyProvenanceInt2Ptr { span: self.span, expr_ty, cast_ty, sugg },
989983
);
990984
}
991985

compiler/rustc_hir_typeck/src/errors.rs

+29-5
Original file line numberDiff line numberDiff line change
@@ -168,19 +168,34 @@ pub struct MissingParenthesesInRange {
168168
pub enum NeverTypeFallbackFlowingIntoUnsafe {
169169
#[help]
170170
#[diag(hir_typeck_never_type_fallback_flowing_into_unsafe_call)]
171-
Call,
171+
Call {
172+
#[primary_span]
173+
span: Span,
174+
},
172175
#[help]
173176
#[diag(hir_typeck_never_type_fallback_flowing_into_unsafe_method)]
174-
Method,
177+
Method {
178+
#[primary_span]
179+
span: Span,
180+
},
175181
#[help]
176182
#[diag(hir_typeck_never_type_fallback_flowing_into_unsafe_path)]
177-
Path,
183+
Path {
184+
#[primary_span]
185+
span: Span,
186+
},
178187
#[help]
179188
#[diag(hir_typeck_never_type_fallback_flowing_into_unsafe_union_field)]
180-
UnionField,
189+
UnionField {
190+
#[primary_span]
191+
span: Span,
192+
},
181193
#[help]
182194
#[diag(hir_typeck_never_type_fallback_flowing_into_unsafe_deref)]
183-
Deref,
195+
Deref {
196+
#[primary_span]
197+
span: Span,
198+
},
184199
}
185200

186201
#[derive(Subdiagnostic)]
@@ -237,6 +252,8 @@ impl Subdiagnostic for TypeMismatchFruTypo {
237252
#[diag(hir_typeck_lossy_provenance_int2ptr)]
238253
#[help]
239254
pub struct LossyProvenanceInt2Ptr<'tcx> {
255+
#[primary_span]
256+
pub span: Span,
240257
pub expr_ty: Ty<'tcx>,
241258
pub cast_ty: Ty<'tcx>,
242259
#[subdiagnostic]
@@ -256,6 +273,8 @@ pub struct LossyProvenanceInt2PtrSuggestion {
256273
#[diag(hir_typeck_lossy_provenance_ptr2int)]
257274
#[help]
258275
pub struct LossyProvenancePtr2Int<'tcx> {
276+
#[primary_span]
277+
pub span: Span,
259278
pub expr_ty: Ty<'tcx>,
260279
pub cast_ty: Ty<'tcx>,
261280
#[subdiagnostic]
@@ -502,6 +521,8 @@ pub struct SuggestPtrNullMut {
502521
#[diag(hir_typeck_trivial_cast)]
503522
#[help]
504523
pub struct TrivialCast<'tcx> {
524+
#[primary_span]
525+
pub span: Span,
505526
pub numeric: bool,
506527
pub expr_ty: Ty<'tcx>,
507528
pub cast_ty: Ty<'tcx>,
@@ -542,6 +563,8 @@ pub struct CannotCastToBool<'tcx> {
542563
#[derive(LintDiagnostic)]
543564
#[diag(hir_typeck_cast_enum_drop)]
544565
pub struct CastEnumDrop<'tcx> {
566+
#[primary_span]
567+
pub span: Span,
545568
pub expr_ty: Ty<'tcx>,
546569
pub cast_ty: Ty<'tcx>,
547570
}
@@ -654,6 +677,7 @@ pub enum SuggestBoxingForReturnImplTrait {
654677
#[derive(LintDiagnostic)]
655678
#[diag(hir_typeck_dereferencing_mut_binding)]
656679
pub struct DereferencingMutBinding {
680+
#[primary_span]
657681
#[label]
658682
#[help]
659683
pub span: Span,

0 commit comments

Comments
 (0)