Skip to content

Commit eb8e4f9

Browse files
Rollup merge of #155097 - GuillaumeGomez:emit_lint-multispan, r=JonathanBrouwer
Make `rustc_attr_parsing::SharedContext::emit_lint` take a `MultiSpan` instead of a `Span` I'll likely need it for #153721 to allow emitting the lint on one attribute at a time instead of each of the wrong values. r? @JonathanBrouwer
2 parents d07454f + 2c82731 commit eb8e4f9

File tree

6 files changed

+21
-15
lines changed

6 files changed

+21
-15
lines changed

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::sync::LazyLock;
77

88
use private::Sealed;
99
use rustc_ast::{AttrStyle, MetaItemLit, NodeId};
10-
use rustc_errors::{Diag, Diagnostic, Level};
10+
use rustc_errors::{Diag, Diagnostic, Level, MultiSpan};
1111
use rustc_feature::{AttrSuggestionStyle, AttributeTemplate};
1212
use rustc_hir::attrs::AttributeKind;
1313
use rustc_hir::lints::AttributeLintKind;
@@ -457,14 +457,19 @@ impl<'f, 'sess: 'f, S: Stage> SharedContext<'f, 'sess, S> {
457457
/// Emit a lint. This method is somewhat special, since lints emitted during attribute parsing
458458
/// must be delayed until after HIR is built. This method will take care of the details of
459459
/// that.
460-
pub(crate) fn emit_lint(&mut self, lint: &'static Lint, kind: AttributeLintKind, span: Span) {
460+
pub(crate) fn emit_lint<M: Into<MultiSpan>>(
461+
&mut self,
462+
lint: &'static Lint,
463+
kind: AttributeLintKind,
464+
span: M,
465+
) {
461466
if !matches!(
462467
self.stage.should_emit(),
463468
ShouldEmit::ErrorsAndLints { .. } | ShouldEmit::EarlyFatal { also_emit_lints: true }
464469
) {
465470
return;
466471
}
467-
(self.emit_lint)(LintId::of(lint), span, kind);
472+
(self.emit_lint)(LintId::of(lint), span.into(), kind);
468473
}
469474

470475
pub(crate) fn warn_unused_duplicate(&mut self, used_span: Span, unused_span: Span) {
@@ -530,7 +535,7 @@ pub struct SharedContext<'p, 'sess, S: Stage> {
530535

531536
/// The second argument of the closure is a [`NodeId`] if `S` is `Early` and a [`HirId`] if `S`
532537
/// is `Late` and is the ID of the syntactical component this attribute was applied to.
533-
pub(crate) emit_lint: &'p mut dyn FnMut(LintId, Span, AttributeLintKind),
538+
pub(crate) emit_lint: &'p mut dyn FnMut(LintId, MultiSpan, AttributeLintKind),
534539
}
535540

536541
/// Context given to every attribute parser during finalization.

compiler/rustc_attr_parsing/src/interface.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::convert::identity;
33
use rustc_ast as ast;
44
use rustc_ast::token::DocFragmentKind;
55
use rustc_ast::{AttrItemKind, AttrStyle, NodeId, Safety};
6-
use rustc_errors::DiagCtxtHandle;
6+
use rustc_errors::{DiagCtxtHandle, MultiSpan};
77
use rustc_feature::{AttributeTemplate, Features};
88
use rustc_hir::attrs::AttributeKind;
99
use rustc_hir::lints::AttributeLintKind;
@@ -195,7 +195,7 @@ impl<'sess> AttributeParser<'sess, Early> {
195195
sess,
196196
stage: Early { emit_errors },
197197
};
198-
let mut emit_lint = |lint_id: LintId, span: Span, kind: AttributeLintKind| {
198+
let mut emit_lint = |lint_id: LintId, span: MultiSpan, kind: AttributeLintKind| {
199199
sess.psess.buffer_lint(lint_id.lint, span, target_node_id, kind)
200200
};
201201
if let Some(safety) = attr_safety {
@@ -256,7 +256,7 @@ impl<'sess, S: Stage> AttributeParser<'sess, S> {
256256
target: Target,
257257
omit_doc: OmitDoc,
258258
lower_span: impl Copy + Fn(Span) -> Span,
259-
mut emit_lint: impl FnMut(LintId, Span, AttributeLintKind),
259+
mut emit_lint: impl FnMut(LintId, MultiSpan, AttributeLintKind),
260260
) -> Vec<Attribute> {
261261
let mut attributes = Vec::new();
262262
// We store the attributes we intend to discard at the end of this function in order to

compiler/rustc_attr_parsing/src/safety.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use rustc_ast::Safety;
2+
use rustc_errors::MultiSpan;
23
use rustc_feature::{AttributeSafety, BUILTIN_ATTRIBUTE_MAP};
34
use rustc_hir::AttrPath;
45
use rustc_hir::lints::AttributeLintKind;
@@ -15,7 +16,7 @@ impl<'sess, S: Stage> AttributeParser<'sess, S> {
1516
attr_path: &AttrPath,
1617
attr_span: Span,
1718
attr_safety: Safety,
18-
emit_lint: &mut impl FnMut(LintId, Span, AttributeLintKind),
19+
emit_lint: &mut impl FnMut(LintId, MultiSpan, AttributeLintKind),
1920
) {
2021
if matches!(self.stage.should_emit(), ShouldEmit::Nothing) {
2122
return;
@@ -83,7 +84,7 @@ impl<'sess, S: Stage> AttributeParser<'sess, S> {
8384
} else {
8485
emit_lint(
8586
LintId::of(UNSAFE_ATTR_OUTSIDE_UNSAFE),
86-
path_span,
87+
path_span.into(),
8788
AttributeLintKind::UnsafeAttrOutsideUnsafe {
8889
attribute_name_span: path_span,
8990
sugg_spans: not_from_proc_macro

compiler/rustc_error_messages/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::borrow::Cow;
77

88
pub use fluent_bundle::types::FluentType;
99
pub use fluent_bundle::{self, FluentArgs, FluentError, FluentValue};
10-
use rustc_macros::{Decodable, Encodable};
10+
use rustc_macros::{Decodable, Encodable, HashStable_Generic};
1111
use rustc_span::Span;
1212
pub use unic_langid::{LanguageIdentifier, langid};
1313

@@ -28,7 +28,7 @@ pub fn register_functions<R, M>(bundle: &mut fluent_bundle::bundle::FluentBundle
2828
/// diagnostic messages.
2929
///
3030
/// Intended to be removed once diagnostics are entirely translatable.
31-
#[derive(Clone, Debug, PartialEq, Eq, Hash, Encodable, Decodable)]
31+
#[derive(Clone, Debug, PartialEq, Eq, Hash, Encodable, Decodable, HashStable_Generic)]
3232
#[rustc_diagnostic_item = "DiagMessage"]
3333
pub enum DiagMessage {
3434
/// Non-translatable diagnostic message or a message that has been translated eagerly.
@@ -89,7 +89,7 @@ pub struct SpanLabel {
8989
/// the error, and would be rendered with `^^^`.
9090
/// - They can have a *label*. In this case, the label is written next
9191
/// to the mark in the snippet when we render.
92-
#[derive(Clone, Debug, Hash, PartialEq, Eq, Encodable, Decodable)]
92+
#[derive(Clone, Debug, Hash, PartialEq, Eq, Encodable, Decodable, HashStable_Generic)]
9393
pub struct MultiSpan {
9494
primary_spans: Vec<Span>,
9595
span_labels: Vec<(Span, DiagMessage)>,

compiler/rustc_hir/src/lints.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use rustc_data_structures::fingerprint::Fingerprint;
2+
use rustc_error_messages::MultiSpan;
23
use rustc_lint_defs::LintId;
34
pub use rustc_lint_defs::{AttributeLintKind, FormatWarning};
45
use rustc_macros::HashStable_Generic;
5-
use rustc_span::Span;
66

77
use crate::HirId;
88

@@ -28,6 +28,6 @@ pub enum DelayedLint {
2828
pub struct AttributeLint<Id> {
2929
pub lint_id: LintId,
3030
pub id: Id,
31-
pub span: Span,
31+
pub span: MultiSpan,
3232
pub kind: AttributeLintKind,
3333
}

compiler/rustc_interface/src/passes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1037,7 +1037,7 @@ pub fn emit_delayed_lints(tcx: TyCtxt<'_>) {
10371037
tcx.emit_node_span_lint(
10381038
attribute_lint.lint_id.lint,
10391039
attribute_lint.id,
1040-
attribute_lint.span,
1040+
attribute_lint.span.clone(),
10411041
DecorateAttrLint {
10421042
sess: tcx.sess,
10431043
tcx: Some(tcx),

0 commit comments

Comments
 (0)