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

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

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
@@ -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

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

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

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
@@ -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

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
@@ -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

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

0 commit comments

Comments
 (0)