Skip to content

Commit ff63c14

Browse files
committed
Make Span optional in BufferedEarlyLint
1 parent 1138036 commit ff63c14

File tree

5 files changed

+31
-7
lines changed

5 files changed

+31
-7
lines changed

compiler/rustc_builtin_macros/src/format.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ fn make_format_args(
555555
};
556556
let arg_name = args.explicit_args()[index].kind.ident().unwrap();
557557
ecx.buffered_early_lint.push(BufferedEarlyLint {
558-
span: arg_name.span.into(),
558+
span: Some(arg_name.span.into()),
559559
node_id: rustc_ast::CRATE_NODE_ID,
560560
lint_id: LintId::of(NAMED_ARGUMENTS_USED_POSITIONALLY),
561561
diagnostic: BuiltinLintDiag::NamedArgumentUsedPositionally {

compiler/rustc_lint/src/context.rs

+16-2
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ pub struct EarlyContext<'a> {
532532
}
533533

534534
impl EarlyContext<'_> {
535-
/// Emit a lint at the appropriate level, with an optional associated span and an existing
535+
/// Emit a lint at the appropriate level, with an associated span and an existing
536536
/// diagnostic.
537537
///
538538
/// [`lint_level`]: rustc_middle::lint::lint_level#decorate-signature
@@ -543,7 +543,21 @@ impl EarlyContext<'_> {
543543
span: MultiSpan,
544544
diagnostic: BuiltinLintDiag,
545545
) {
546-
self.opt_span_lint(lint, Some(span), |diag| {
546+
self.opt_span_lint_with_diagnostics(lint, Some(span), diagnostic);
547+
}
548+
549+
/// Emit a lint at the appropriate level, with an optional associated span and an existing
550+
/// diagnostic.
551+
///
552+
/// [`lint_level`]: rustc_middle::lint::lint_level#decorate-signature
553+
#[rustc_lint_diagnostics]
554+
pub fn opt_span_lint_with_diagnostics(
555+
&self,
556+
lint: &'static Lint,
557+
span: Option<MultiSpan>,
558+
diagnostic: BuiltinLintDiag,
559+
) {
560+
self.opt_span_lint(lint, span, |diag| {
547561
diagnostics::decorate_lint(self.sess(), diagnostic, diag);
548562
});
549563
}

compiler/rustc_lint/src/early.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl<'a, T: EarlyLintPass> EarlyContextAndPass<'a, T> {
4646
fn inlined_check_id(&mut self, id: ast::NodeId) {
4747
for early_lint in self.context.buffered.take(id) {
4848
let BufferedEarlyLint { span, node_id: _, lint_id, diagnostic } = early_lint;
49-
self.context.span_lint_with_diagnostics(lint_id.lint, span, diagnostic);
49+
self.context.opt_span_lint_with_diagnostics(lint_id.lint, span, diagnostic);
5050
}
5151
}
5252

compiler/rustc_lint_defs/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ pub enum BuiltinLintDiag {
749749
#[derive(Debug)]
750750
pub struct BufferedEarlyLint {
751751
/// The span of code that we are linting on.
752-
pub span: MultiSpan,
752+
pub span: Option<MultiSpan>,
753753

754754
/// The `NodeId` of the AST node that generated the lint.
755755
pub node_id: NodeId,
@@ -787,7 +787,7 @@ impl LintBuffer {
787787
self.add_early_lint(BufferedEarlyLint {
788788
lint_id: LintId::of(lint),
789789
node_id,
790-
span: span.into(),
790+
span: Some(span.into()),
791791
diagnostic,
792792
});
793793
}

compiler/rustc_session/src/parse.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -306,10 +306,20 @@ impl ParseSess {
306306
span: impl Into<MultiSpan>,
307307
node_id: NodeId,
308308
diagnostic: BuiltinLintDiag,
309+
) {
310+
self.opt_span_buffer_lint(lint, Some(span.into()), node_id, diagnostic)
311+
}
312+
313+
pub fn opt_span_buffer_lint(
314+
&self,
315+
lint: &'static Lint,
316+
span: Option<MultiSpan>,
317+
node_id: NodeId,
318+
diagnostic: BuiltinLintDiag,
309319
) {
310320
self.buffered_lints.with_lock(|buffered_lints| {
311321
buffered_lints.push(BufferedEarlyLint {
312-
span: span.into(),
322+
span,
313323
node_id,
314324
lint_id: LintId::of(lint),
315325
diagnostic,

0 commit comments

Comments
 (0)