Skip to content

Commit 957c07f

Browse files
committed
Update all lint diagnostics to store their span
1 parent 115ead1 commit 957c07f

File tree

78 files changed

+1312
-930
lines changed

Some content is hidden

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

78 files changed

+1312
-930
lines changed

compiler/rustc_borrowck/src/lib.rs

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

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

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

415415
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
@@ -165,18 +165,17 @@ pub(super) fn lint<'tcx, 'mir, L>(
165165
tcx: TyCtxtAt<'tcx>,
166166
machine: &CompileTimeInterpreter<'mir, 'tcx>,
167167
lint: &'static rustc_session::lint::Lint,
168-
decorator: impl FnOnce(Vec<errors::FrameNote>) -> L,
168+
decorator: impl FnOnce(Span, Vec<errors::FrameNote>) -> L,
169169
) where
170170
L: for<'a> rustc_errors::LintDiagnostic<'a, ()>,
171171
{
172172
let (span, frames) = get_span_and_frames(tcx, &machine.stack);
173173

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

compiler/rustc_const_eval/src/const_eval/eval_queries.rs

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

compiler/rustc_const_eval/src/const_eval/machine.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -622,11 +622,10 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
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 {
@@ -747,8 +746,8 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
747746
}
748747
// Reject writes through immutable pointers.
749748
if immutable {
750-
super::lint(tcx, machine, WRITES_THROUGH_IMMUTABLE_POINTER, |frames| {
751-
crate::errors::WriteThroughImmutablePointer { frames }
749+
super::lint(tcx, machine, WRITES_THROUGH_IMMUTABLE_POINTER, |span, frames| {
750+
crate::errors::WriteThroughImmutablePointer { span, frames }
752751
});
753752
}
754753
// 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
@@ -288,11 +288,11 @@ fn report_mismatched_rpitit_signature<'tcx>(
288288
});
289289

290290
let span = unmatched_bound.unwrap_or(span);
291-
tcx.emit_node_span_lint(
291+
tcx.emit_node_lint(
292292
if is_internal { REFINING_IMPL_TRAIT_INTERNAL } else { REFINING_IMPL_TRAIT_REACHABLE },
293293
tcx.local_def_id_to_hir_id(impl_m_def_id.expect_local()),
294-
span,
295294
crate::errors::ReturnPositionImplTraitInTraitRefined {
295+
span,
296296
impl_return_span,
297297
trait_return_span,
298298
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
@@ -2127,11 +2127,10 @@ fn lint_redundant_lifetimes<'tcx>(
21272127
&& outlives_env.free_region_map().sub_free_regions(tcx, victim, candidate)
21282128
{
21292129
shadowed.insert(victim);
2130-
tcx.emit_node_span_lint(
2130+
tcx.emit_node_lint(
21312131
rustc_lint_defs::builtin::REDUNDANT_LIFETIMES,
21322132
tcx.local_def_id_to_hir_id(def_id.expect_local()),
2133-
tcx.def_span(def_id),
2134-
RedundantLifetimeArgsLint { candidate, victim },
2133+
RedundantLifetimeArgsLint { span: tcx.def_span(def_id), candidate, victim },
21352134
);
21362135
}
21372136
}
@@ -2142,6 +2141,8 @@ fn lint_redundant_lifetimes<'tcx>(
21422141
#[diag(hir_analysis_redundant_lifetime_args)]
21432142
#[note]
21442143
struct RedundantLifetimeArgsLint<'tcx> {
2144+
#[primary_span]
2145+
pub span: Span,
21452146
/// The lifetime we have found to be redundant.
21462147
victim: ty::Region<'tcx>,
21472148
// 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
@@ -511,16 +511,14 @@ fn lint_uncovered_ty_params<'tcx>(
511511
let name = tcx.item_name(param_def_id);
512512

513513
match local_ty {
514-
Some(local_type) => tcx.emit_node_span_lint(
514+
Some(local_type) => tcx.emit_node_lint(
515515
UNCOVERED_PARAM_IN_PROJECTION,
516516
hir_id,
517-
span,
518517
errors::TyParamFirstLocalLint { span, note: (), param: name, local_type },
519518
),
520-
None => tcx.emit_node_span_lint(
519+
None => tcx.emit_node_lint(
521520
UNCOVERED_PARAM_IN_PROJECTION,
522521
hir_id,
523-
span,
524522
errors::TyParamSomeLint { span, note: (), param: name },
525523
),
526524
};

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
@@ -178,16 +178,15 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
178178
// types's `DefId`, so the following loop removes all the `DefIds` of the associated types that have a
179179
// corresponding `Projection` clause
180180
for def_ids in associated_types.values_mut() {
181-
for (projection_bound, span) in &projection_bounds {
181+
for &(projection_bound, span) in &projection_bounds {
182182
let def_id = projection_bound.projection_def_id();
183183
// FIXME(#120456) - is `swap_remove` correct?
184184
def_ids.swap_remove(&def_id);
185185
if tcx.generics_require_sized_self(def_id) {
186-
tcx.emit_node_span_lint(
186+
tcx.emit_node_lint(
187187
UNUSED_ASSOCIATED_TYPE_BOUNDS,
188188
hir_id,
189-
*span,
190-
crate::errors::UnusedAssociatedTypeBounds { span: *span },
189+
crate::errors::UnusedAssociatedTypeBounds { span },
191190
);
192191
}
193192
}

compiler/rustc_hir_typeck/src/cast.rs

+8-14
Original file line numberDiff line numberDiff line change
@@ -622,11 +622,10 @@ impl<'a, 'tcx> CastCheck<'tcx> {
622622
};
623623
let expr_ty = fcx.resolve_vars_if_possible(self.expr_ty);
624624
let cast_ty = fcx.resolve_vars_if_possible(self.cast_ty);
625-
fcx.tcx.emit_node_span_lint(
625+
fcx.tcx.emit_node_lint(
626626
lint,
627627
self.expr.hir_id,
628-
self.span,
629-
errors::TrivialCast { numeric, expr_ty, cast_ty },
628+
errors::TrivialCast { span: self.span, numeric, expr_ty, cast_ty },
630629
);
631630
}
632631

@@ -935,11 +934,10 @@ impl<'a, 'tcx> CastCheck<'tcx> {
935934
let expr_ty = fcx.resolve_vars_if_possible(self.expr_ty);
936935
let cast_ty = fcx.resolve_vars_if_possible(self.cast_ty);
937936

938-
fcx.tcx.emit_node_span_lint(
937+
fcx.tcx.emit_node_lint(
939938
lint::builtin::CENUM_IMPL_DROP_CAST,
940939
self.expr.hir_id,
941-
self.span,
942-
errors::CastEnumDrop { expr_ty, cast_ty },
940+
errors::CastEnumDrop { span: self.span, expr_ty, cast_ty },
943941
);
944942
}
945943
}
@@ -968,12 +966,10 @@ impl<'a, 'tcx> CastCheck<'tcx> {
968966
(false, false) => errors::LossyProvenancePtr2IntSuggestion::Other { cast_span },
969967
};
970968

971-
let lint = errors::LossyProvenancePtr2Int { expr_ty, cast_ty, sugg };
972-
fcx.tcx.emit_node_span_lint(
969+
fcx.tcx.emit_node_lint(
973970
lint::builtin::LOSSY_PROVENANCE_CASTS,
974971
self.expr.hir_id,
975-
self.span,
976-
lint,
972+
errors::LossyProvenancePtr2Int { span: self.span, expr_ty, cast_ty, sugg },
977973
);
978974
}
979975

@@ -984,12 +980,10 @@ impl<'a, 'tcx> CastCheck<'tcx> {
984980
};
985981
let expr_ty = fcx.resolve_vars_if_possible(self.expr_ty);
986982
let cast_ty = fcx.resolve_vars_if_possible(self.cast_ty);
987-
let lint = errors::LossyProvenanceInt2Ptr { expr_ty, cast_ty, sugg };
988-
fcx.tcx.emit_node_span_lint(
983+
fcx.tcx.emit_node_lint(
989984
lint::builtin::FUZZY_PROVENANCE_CASTS,
990985
self.expr.hir_id,
991-
self.span,
992-
lint,
986+
errors::LossyProvenanceInt2Ptr { span: self.span, expr_ty, cast_ty, sugg },
993987
);
994988
}
995989

compiler/rustc_hir_typeck/src/errors.rs

+28-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
}

0 commit comments

Comments
 (0)