Skip to content

Commit 83fabb6

Browse files
committed
Update all lint diagnostics to store their span
1 parent a814d6a commit 83fabb6

File tree

76 files changed

+1297
-921
lines changed

Some content is hidden

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

76 files changed

+1297
-921
lines changed

compiler/rustc_borrowck/src/lib.rs

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 1 deletion
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

Lines changed: 3 additions & 4 deletions
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

Lines changed: 2 additions & 4 deletions
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

Lines changed: 4 additions & 5 deletions
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

Lines changed: 5 additions & 4 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 6 deletions
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

Lines changed: 4 additions & 3 deletions
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

Lines changed: 2 additions & 4 deletions
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
};

0 commit comments

Comments
 (0)