Skip to content

Commit eedb32d

Browse files
committed
Make Span optional in BufferedEarlyLint
1 parent 6a2cd0d commit eedb32d

File tree

5 files changed

+31
-7
lines changed

5 files changed

+31
-7
lines changed

Diff for: 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 {

Diff for: compiler/rustc_lint/src/context.rs

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

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

Diff for: compiler/rustc_lint/src/early.rs

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

Diff for: compiler/rustc_lint_defs/src/lib.rs

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

758758
/// The `NodeId` of the AST node that generated the lint.
759759
pub node_id: NodeId,
@@ -791,7 +791,7 @@ impl LintBuffer {
791791
self.add_early_lint(BufferedEarlyLint {
792792
lint_id: LintId::of(lint),
793793
node_id,
794-
span: span.into(),
794+
span: Some(span.into()),
795795
diagnostic,
796796
});
797797
}

Diff for: 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)