1
Fork 0

Change span field accesses to method calls

This commit is contained in:
Jana Dönszelmann 2025-02-09 22:49:28 +01:00
parent f43e549b88
commit 115b3b03b0
No known key found for this signature in database
27 changed files with 264 additions and 202 deletions

View file

@ -1,12 +1,25 @@
mod allow_unstable; //! You can find more docs on what groups are on [`AttributeParser`] itself.
mod cfg; //! However, for many types of attributes, implementing [`AttributeParser`] is not necessary.
mod confusables; //! It allows for a lot of flexibility you might not want.
mod deprecation; //!
mod repr; //! Specifically, you might not care about managing the state of your [`AttributeParser`]
mod stability; //! state machine yourself. In this case you can choose to implement:
mod transparency; //!
//! - [`SingleAttributeParser`]: makes it easy to implement an attribute which should error if it
//! appears more than once in a list of attributes
//! - [`CombineAttributeParser`]: makes it easy to implement an attribute which should combine the
//! contents of attributes, if an attribute appear multiple times in a list
//!
//! Attributes should be added to [`ATTRIBUTE_GROUP_MAPPING`](crate::context::ATTRIBUTE_GROUP_MAPPING) to be parsed.
pub mod util; pub(crate) mod allow_unstable;
pub(crate) mod cfg;
pub(crate) mod confusables;
pub(crate) mod deprecation;
pub(crate) mod repr;
pub(crate) mod stability;
pub(crate) mod transparency;
pub(crate) mod util;
pub use allow_unstable::*; pub use allow_unstable::*;
pub use cfg::*; pub use cfg::*;

View file

@ -1,8 +1,41 @@
//! Functions and types dealing with attributes and meta items. //! Centralized logic for parsing and attributes.
//! //!
//! FIXME(Centril): For now being, much of the logic is still in `rustc_ast::attr`. //! Part of a series of crates:
//! The goal is to move the definition of `MetaItem` and things that don't need to be in `syntax` //! - rustc_attr_data_structures: contains types that the parsers parse into
//! to this crate. //! - rustc_attr_parsing: this crate
//! - (in the future): rustc_attr_validation
//!
//! History: Check out [#131229](https://github.com/rust-lang/rust/issues/131229).
//! There used to be only one definition of attributes in the compiler: `ast::Attribute`.
//! These were then parsed or validated or both in places distributed all over the compiler.
//! This was a mess...
//!
//! Attributes are markers on items. Most are actually attribute-like proc-macros, and are expanded
//! but some remain as the so-called built-in attributes. These are not macros at all, and really
//! are just markers to guide the compilation process. An example is `#[inline(...)]` which changes
//! how code for functions is generated. Built-in attributes aren't macros because there's no rust
//! syntax they could expand to.
//!
//! In this crate, syntactical attributes (sequences of tokens that look like
//! `#[something(something else)]`) are parsed into more semantic attributes, markers on items.
//! Multiple syntactic attributes might influence a single semantic attribute. For example,
//! `#[stable(...)]` and `#[unstable()]` cannot occur together, and both semantically define
//! a "stability" of an item. So, the stability attribute has an
//! [`AttributeParser`](attributes::AttributeParser) that recognizes both the `#[stable()]`
//! and `#[unstable()]` syntactic attributes, and at the end produce a single [`AttributeKind::Stability`].
//!
//! As a rule of thumb, when a syntactical attribute can be applied more than once, they should be
//! combined into a single semantic attribute. For example:
//!
//! ```
//! #[repr(C)]
//! #[repr(packed)]
//! struct Meow {}
//! ```
//!
//! should result in a single `AttributeKind::Repr` containing a list of repr annotations, in this
//! case `C` and `packed`. This is equivalent to writing `#[repr(C, packed)]` in a single
//! syntactical annotation.
// tidy-alphabetical-start // tidy-alphabetical-start
#![allow(internal_features)] #![allow(internal_features)]

View file

@ -94,7 +94,7 @@ impl<'tcx> AssertModuleSource<'tcx> {
other => { other => {
self.tcx self.tcx
.dcx() .dcx()
.emit_fatal(errors::UnknownReuseKind { span: attr.span, kind: other }); .emit_fatal(errors::UnknownReuseKind { span: attr.span(), kind: other });
} }
} }
} else { } else {
@ -102,7 +102,7 @@ impl<'tcx> AssertModuleSource<'tcx> {
}; };
if !self.tcx.sess.opts.unstable_opts.query_dep_graph { if !self.tcx.sess.opts.unstable_opts.query_dep_graph {
self.tcx.dcx().emit_fatal(errors::MissingQueryDepGraph { span: attr.span }); self.tcx.dcx().emit_fatal(errors::MissingQueryDepGraph { span: attr.span() });
} }
if !self.check_config(attr) { if !self.check_config(attr) {
@ -115,7 +115,7 @@ impl<'tcx> AssertModuleSource<'tcx> {
if !user_path.starts_with(&crate_name) { if !user_path.starts_with(&crate_name) {
self.tcx.dcx().emit_fatal(errors::MalformedCguName { self.tcx.dcx().emit_fatal(errors::MalformedCguName {
span: attr.span, span: attr.span(),
user_path, user_path,
crate_name, crate_name,
}); });
@ -145,7 +145,7 @@ impl<'tcx> AssertModuleSource<'tcx> {
let cgu_names: Vec<&str> = let cgu_names: Vec<&str> =
self.available_cgus.items().map(|cgu| cgu.as_str()).into_sorted_stable_ord(); self.available_cgus.items().map(|cgu| cgu.as_str()).into_sorted_stable_ord();
self.tcx.dcx().emit_err(errors::NoModuleNamed { self.tcx.dcx().emit_err(errors::NoModuleNamed {
span: attr.span, span: attr.span(),
user_path, user_path,
cgu_name, cgu_name,
cgu_names: cgu_names.join(", "), cgu_names: cgu_names.join(", "),
@ -155,7 +155,7 @@ impl<'tcx> AssertModuleSource<'tcx> {
self.cgu_reuse_tracker.set_expectation( self.cgu_reuse_tracker.set_expectation(
cgu_name, cgu_name,
user_path, user_path,
attr.span, attr.span(),
expected_reuse, expected_reuse,
comp_kind, comp_kind,
); );
@ -175,7 +175,7 @@ impl<'tcx> AssertModuleSource<'tcx> {
} }
} }
self.tcx.dcx().emit_fatal(errors::NoField { span: attr.span, name }); self.tcx.dcx().emit_fatal(errors::NoField { span: attr.span(), name });
} }
/// Scan for a `cfg="foo"` attribute and check whether we have a /// Scan for a `cfg="foo"` attribute and check whether we have a

View file

@ -104,8 +104,10 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
if let Fn | AssocFn | Variant | Ctor(..) = def_kind { if let Fn | AssocFn | Variant | Ctor(..) = def_kind {
Some(tcx.fn_sig(did)) Some(tcx.fn_sig(did))
} else { } else {
tcx.dcx() tcx.dcx().span_delayed_bug(
.span_delayed_bug(attr.span, "this attribute can only be applied to functions"); attr.span(),
"this attribute can only be applied to functions",
);
None None
} }
}; };
@ -130,14 +132,14 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
if tcx.opt_item_name(did.to_def_id()).is_some() { if tcx.opt_item_name(did.to_def_id()).is_some() {
codegen_fn_attrs.flags |= CodegenFnAttrFlags::NO_MANGLE; codegen_fn_attrs.flags |= CodegenFnAttrFlags::NO_MANGLE;
mixed_export_name_no_mangle_lint_state.track_no_mangle( mixed_export_name_no_mangle_lint_state.track_no_mangle(
attr.span, attr.span(),
tcx.local_def_id_to_hir_id(did), tcx.local_def_id_to_hir_id(did),
attr, attr,
); );
} else { } else {
tcx.dcx() tcx.dcx()
.struct_span_err( .struct_span_err(
attr.span, attr.span(),
format!( format!(
"`#[no_mangle]` cannot be used on {} {} as it has no name", "`#[no_mangle]` cannot be used on {} {} as it has no name",
tcx.def_descr_article(did.to_def_id()), tcx.def_descr_article(did.to_def_id()),
@ -158,7 +160,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
feature_err( feature_err(
&tcx.sess, &tcx.sess,
sym::used_with_arg, sym::used_with_arg,
attr.span, attr.span(),
"`#[used(linker)]` is currently unstable", "`#[used(linker)]` is currently unstable",
) )
.emit(); .emit();
@ -170,7 +172,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
feature_err( feature_err(
&tcx.sess, &tcx.sess,
sym::used_with_arg, sym::used_with_arg,
attr.span, attr.span(),
"`#[used(compiler)]` is currently unstable", "`#[used(compiler)]` is currently unstable",
) )
.emit(); .emit();
@ -178,7 +180,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
codegen_fn_attrs.flags |= CodegenFnAttrFlags::USED; codegen_fn_attrs.flags |= CodegenFnAttrFlags::USED;
} }
Some(_) => { Some(_) => {
tcx.dcx().emit_err(errors::ExpectedUsedSymbol { span: attr.span }); tcx.dcx().emit_err(errors::ExpectedUsedSymbol { span: attr.span() });
} }
None => { None => {
// Unfortunately, unconditionally using `llvm.used` causes // Unfortunately, unconditionally using `llvm.used` causes
@ -223,7 +225,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
{ {
struct_span_code_err!( struct_span_code_err!(
tcx.dcx(), tcx.dcx(),
attr.span, attr.span(),
E0737, E0737,
"`#[track_caller]` requires Rust ABI" "`#[track_caller]` requires Rust ABI"
) )
@ -231,12 +233,12 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
} }
if is_closure if is_closure
&& !tcx.features().closure_track_caller() && !tcx.features().closure_track_caller()
&& !attr.span.allows_unstable(sym::closure_track_caller) && !attr.span().allows_unstable(sym::closure_track_caller)
{ {
feature_err( feature_err(
&tcx.sess, &tcx.sess,
sym::closure_track_caller, sym::closure_track_caller,
attr.span, attr.span(),
"`#[track_caller]` on closures is currently unstable", "`#[track_caller]` on closures is currently unstable",
) )
.emit(); .emit();
@ -250,19 +252,19 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
// so it may not contain any null characters. // so it may not contain any null characters.
struct_span_code_err!( struct_span_code_err!(
tcx.dcx(), tcx.dcx(),
attr.span, attr.span(),
E0648, E0648,
"`export_name` may not contain null characters" "`export_name` may not contain null characters"
) )
.emit(); .emit();
} }
codegen_fn_attrs.export_name = Some(s); codegen_fn_attrs.export_name = Some(s);
mixed_export_name_no_mangle_lint_state.track_export_name(attr.span); mixed_export_name_no_mangle_lint_state.track_export_name(attr.span());
} }
} }
sym::target_feature => { sym::target_feature => {
let Some(sig) = tcx.hir_node_by_def_id(did).fn_sig() else { let Some(sig) = tcx.hir_node_by_def_id(did).fn_sig() else {
tcx.dcx().span_delayed_bug(attr.span, "target_feature applied to non-fn"); tcx.dcx().span_delayed_bug(attr.span(), "target_feature applied to non-fn");
continue; continue;
}; };
let safe_target_features = let safe_target_features =
@ -292,7 +294,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
// `main`, `start`, and other functions that are not usually // `main`, `start`, and other functions that are not usually
// allowed. // allowed.
} else { } else {
check_target_feature_trait_unsafe(tcx, did, attr.span); check_target_feature_trait_unsafe(tcx, did, attr.span());
} }
} }
from_target_feature_attr( from_target_feature_attr(
@ -310,7 +312,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
if tcx.is_mutable_static(did.into()) { if tcx.is_mutable_static(did.into()) {
let mut diag = tcx.dcx().struct_span_err( let mut diag = tcx.dcx().struct_span_err(
attr.span, attr.span(),
"extern mutable statics are not allowed with `#[linkage]`", "extern mutable statics are not allowed with `#[linkage]`",
); );
diag.note( diag.note(
@ -329,7 +331,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
if let Some(val) = attr.value_str() { if let Some(val) = attr.value_str() {
if val.as_str().bytes().any(|b| b == 0) { if val.as_str().bytes().any(|b| b == 0) {
let msg = format!("illegal null byte in link_section value: `{val}`"); let msg = format!("illegal null byte in link_section value: `{val}`");
tcx.dcx().span_err(attr.span, msg); tcx.dcx().span_err(attr.span(), msg);
} else { } else {
codegen_fn_attrs.link_section = Some(val); codegen_fn_attrs.link_section = Some(val);
} }
@ -337,13 +339,13 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
} }
sym::link_name => codegen_fn_attrs.link_name = attr.value_str(), sym::link_name => codegen_fn_attrs.link_name = attr.value_str(),
sym::link_ordinal => { sym::link_ordinal => {
link_ordinal_span = Some(attr.span); link_ordinal_span = Some(attr.span());
if let ordinal @ Some(_) = check_link_ordinal(tcx, attr) { if let ordinal @ Some(_) = check_link_ordinal(tcx, attr) {
codegen_fn_attrs.link_ordinal = ordinal; codegen_fn_attrs.link_ordinal = ordinal;
} }
} }
sym::no_sanitize => { sym::no_sanitize => {
no_sanitize_span = Some(attr.span); no_sanitize_span = Some(attr.span());
if let Some(list) = attr.meta_item_list() { if let Some(list) = attr.meta_item_list() {
for item in list.iter() { for item in list.iter() {
match item.name_or_empty() { match item.name_or_empty() {
@ -381,7 +383,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
{ {
struct_span_code_err!( struct_span_code_err!(
tcx.dcx(), tcx.dcx(),
attr.span, attr.span(),
E0779, E0779,
"target does not support `#[instruction_set]`" "target does not support `#[instruction_set]`"
) )
@ -393,7 +395,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
_ => { _ => {
struct_span_code_err!( struct_span_code_err!(
tcx.dcx(), tcx.dcx(),
attr.span, attr.span(),
E0779, E0779,
"invalid instruction set specified", "invalid instruction set specified",
) )
@ -405,7 +407,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
[] => { [] => {
struct_span_code_err!( struct_span_code_err!(
tcx.dcx(), tcx.dcx(),
attr.span, attr.span(),
E0778, E0778,
"`#[instruction_set]` requires an argument" "`#[instruction_set]` requires an argument"
) )
@ -415,7 +417,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
_ => { _ => {
struct_span_code_err!( struct_span_code_err!(
tcx.dcx(), tcx.dcx(),
attr.span, attr.span(),
E0779, E0779,
"cannot specify more than one instruction set" "cannot specify more than one instruction set"
) )
@ -510,7 +512,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
} }
if let (None, None) = (prefix, entry) { if let (None, None) = (prefix, entry) {
tcx.dcx().span_err(attr.span, "must specify at least one parameter"); tcx.dcx().span_err(attr.span(), "must specify at least one parameter");
} }
Some(PatchableFunctionEntry::from_prefix_and_entry( Some(PatchableFunctionEntry::from_prefix_and_entry(
@ -536,18 +538,19 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
let Some(ref items) = attr.meta_item_list() else { let Some(ref items) = attr.meta_item_list() else {
return ia; return ia;
}; };
inline_span = Some(attr.span());
inline_span = Some(attr.span);
let [item] = &items[..] else { let [item] = &items[..] else {
struct_span_code_err!(tcx.dcx(), attr.span, E0534, "expected one argument").emit(); struct_span_code_err!(tcx.dcx(), attr.span(), E0534, "expected one argument").emit();
return InlineAttr::None; return InlineAttr::None;
}; };
if item.has_name(sym::always) { if item.has_name(sym::always) {
InlineAttr::Always InlineAttr::Always
} else if item.has_name(sym::never) { } else if item.has_name(sym::never) {
InlineAttr::Never InlineAttr::Never
} else { } else {
struct_span_code_err!(tcx.dcx(), item.span(), E0535, "invalid argument") struct_span_code_err!(tcx.dcx(), items[0].span(), E0535, "invalid argument")
.with_help("valid inline arguments are `always` and `never`") .with_help("valid inline arguments are `always` and `never`")
.emit(); .emit();
@ -560,9 +563,9 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
} }
if attr.is_word() { if attr.is_word() {
InlineAttr::Force { attr_span: attr.span, reason: None } InlineAttr::Force { attr_span: attr.span(), reason: None }
} else if let Some(val) = attr.value_str() { } else if let Some(val) = attr.value_str() {
InlineAttr::Force { attr_span: attr.span, reason: Some(val) } InlineAttr::Force { attr_span: attr.span(), reason: Some(val) }
} else { } else {
debug!("`rustc_force_inline` not checked by attribute validation"); debug!("`rustc_force_inline` not checked by attribute validation");
ia ia
@ -582,16 +585,16 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
} }
let err = |sp, s| struct_span_code_err!(tcx.dcx(), sp, E0722, "{}", s).emit(); let err = |sp, s| struct_span_code_err!(tcx.dcx(), sp, E0722, "{}", s).emit();
if attr.is_word() { if attr.is_word() {
err(attr.span, "expected one argument"); err(attr.span(), "expected one argument");
return ia; return ia;
} }
let Some(ref items) = attr.meta_item_list() else { let Some(ref items) = attr.meta_item_list() else {
return OptimizeAttr::Default; return OptimizeAttr::Default;
}; };
inline_span = Some(attr.span); inline_span = Some(attr.span());
let [item] = &items[..] else { let [item] = &items[..] else {
err(attr.span, "expected one argument"); err(attr.span(), "expected one argument");
return OptimizeAttr::Default; return OptimizeAttr::Default;
}; };
if item.has_name(sym::size) { if item.has_name(sym::size) {
@ -703,7 +706,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
let span = tcx let span = tcx
.get_attrs(did, sym::target_feature) .get_attrs(did, sym::target_feature)
.next() .next()
.map_or_else(|| tcx.def_span(did), |a| a.span); .map_or_else(|| tcx.def_span(did), |a| a.span());
tcx.dcx() tcx.dcx()
.create_err(errors::TargetFeatureDisableOrEnable { .create_err(errors::TargetFeatureDisableOrEnable {
features, features,
@ -752,7 +755,7 @@ fn check_link_ordinal(tcx: TyCtxt<'_>, attr: &hir::Attribute) -> Option<u16> {
use rustc_ast::{LitIntType, LitKind, MetaItemLit}; use rustc_ast::{LitIntType, LitKind, MetaItemLit};
let meta_item_list = attr.meta_item_list()?; let meta_item_list = attr.meta_item_list()?;
let [sole_meta_list] = &meta_item_list[..] else { let [sole_meta_list] = &meta_item_list[..] else {
tcx.dcx().emit_err(errors::InvalidLinkOrdinalNargs { span: attr.span }); tcx.dcx().emit_err(errors::InvalidLinkOrdinalNargs { span: attr.span() });
return None; return None;
}; };
if let Some(MetaItemLit { kind: LitKind::Int(ordinal, LitIntType::Unsuffixed), .. }) = if let Some(MetaItemLit { kind: LitKind::Int(ordinal, LitIntType::Unsuffixed), .. }) =
@ -776,13 +779,13 @@ fn check_link_ordinal(tcx: TyCtxt<'_>, attr: &hir::Attribute) -> Option<u16> {
} else { } else {
let msg = format!("ordinal value in `link_ordinal` is too large: `{ordinal}`"); let msg = format!("ordinal value in `link_ordinal` is too large: `{ordinal}`");
tcx.dcx() tcx.dcx()
.struct_span_err(attr.span, msg) .struct_span_err(attr.span(), msg)
.with_note("the value may not exceed `u16::MAX`") .with_note("the value may not exceed `u16::MAX`")
.emit(); .emit();
None None
} }
} else { } else {
tcx.dcx().emit_err(errors::InvalidLinkOrdinalFormat { span: attr.span }); tcx.dcx().emit_err(errors::InvalidLinkOrdinalFormat { span: attr.span() });
None None
} }
} }

View file

@ -1114,7 +1114,7 @@ fn check_impl_items_against_trait<'tcx>(
if let Some(missing_items) = must_implement_one_of { if let Some(missing_items) = must_implement_one_of {
let attr_span = tcx let attr_span = tcx
.get_attr(trait_ref.def_id, sym::rustc_must_implement_one_of) .get_attr(trait_ref.def_id, sym::rustc_must_implement_one_of)
.map(|attr| attr.span); .map(|attr| attr.span());
missing_items_must_implement_one_of_err( missing_items_must_implement_one_of_err(
tcx, tcx,
@ -1422,7 +1422,7 @@ fn check_enum(tcx: TyCtxt<'_>, def_id: LocalDefId) {
if let Some(attr) = tcx.get_attrs(def_id, sym::repr).next() { if let Some(attr) = tcx.get_attrs(def_id, sym::repr).next() {
struct_span_code_err!( struct_span_code_err!(
tcx.dcx(), tcx.dcx(),
attr.span, attr.span(),
E0084, E0084,
"unsupported representation for zero-variant enum" "unsupported representation for zero-variant enum"
) )

View file

@ -99,7 +99,7 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
} }
for attr in tcx.get_attrs(main_def_id, sym::track_caller) { for attr in tcx.get_attrs(main_def_id, sym::track_caller) {
tcx.dcx().emit_err(errors::TrackCallerOnMain { span: attr.span, annotated: main_span }); tcx.dcx().emit_err(errors::TrackCallerOnMain { span: attr.span(), annotated: main_span });
error = true; error = true;
} }

View file

@ -1202,7 +1202,7 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef {
// and that they are all identifiers // and that they are all identifiers
.and_then(|attr| match attr.meta_item_list() { .and_then(|attr| match attr.meta_item_list() {
Some(items) if items.len() < 2 => { Some(items) if items.len() < 2 => {
tcx.dcx().emit_err(errors::MustImplementOneOfAttribute { span: attr.span }); tcx.dcx().emit_err(errors::MustImplementOneOfAttribute { span: attr.span() });
None None
} }
@ -1214,7 +1214,7 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef {
tcx.dcx().emit_err(errors::MustBeNameOfAssociatedFunction { span }); tcx.dcx().emit_err(errors::MustBeNameOfAssociatedFunction { span });
}) })
.ok() .ok()
.zip(Some(attr.span)), .zip(Some(attr.span())),
// Error is reported by `rustc_attr!` // Error is reported by `rustc_attr!`
None => None, None => None,
}) })

View file

@ -1656,13 +1656,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
fn check_expr_unsafe_binder_cast( fn check_expr_unsafe_binder_cast(
&self, &self,
span: Span, span: Span,
kind: hir::UnsafeBinderCastKind, kind: ast::UnsafeBinderCastKind,
inner_expr: &'tcx hir::Expr<'tcx>, inner_expr: &'tcx hir::Expr<'tcx>,
hir_ty: Option<&'tcx hir::Ty<'tcx>>, hir_ty: Option<&'tcx hir::Ty<'tcx>>,
expected: Expectation<'tcx>, expected: Expectation<'tcx>,
) -> Ty<'tcx> { ) -> Ty<'tcx> {
match kind { match kind {
hir::UnsafeBinderCastKind::Wrap => { ast::UnsafeBinderCastKind::Wrap => {
let ascribed_ty = let ascribed_ty =
hir_ty.map(|hir_ty| self.lower_ty_saving_user_provided_ty(hir_ty)); hir_ty.map(|hir_ty| self.lower_ty_saving_user_provided_ty(hir_ty));
let expected_ty = expected.only_has_type(self); let expected_ty = expected.only_has_type(self);
@ -1706,7 +1706,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
binder_ty binder_ty
} }
hir::UnsafeBinderCastKind::Unwrap => { ast::UnsafeBinderCastKind::Unwrap => {
let ascribed_ty = let ascribed_ty =
hir_ty.map(|hir_ty| self.lower_ty_saving_user_provided_ty(hir_ty)); hir_ty.map(|hir_ty| self.lower_ty_saving_user_provided_ty(hir_ty));
let hint_ty = ascribed_ty.unwrap_or_else(|| self.next_ty_var(inner_expr.span)); let hint_ty = ascribed_ty.unwrap_or_else(|| self.next_ty_var(inner_expr.span));

View file

@ -137,13 +137,13 @@ impl<'tcx> IfThisChanged<'tcx> {
match DepNode::from_label_string(self.tcx, n.as_str(), def_path_hash) { match DepNode::from_label_string(self.tcx, n.as_str(), def_path_hash) {
Ok(n) => n, Ok(n) => n,
Err(()) => self.tcx.dcx().emit_fatal(errors::UnrecognizedDepNode { Err(()) => self.tcx.dcx().emit_fatal(errors::UnrecognizedDepNode {
span: attr.span, span: attr.span(),
name: n, name: n,
}), }),
} }
} }
}; };
self.if_this_changed.push((attr.span, def_id.to_def_id(), dep_node)); self.if_this_changed.push((attr.span(), def_id.to_def_id(), dep_node));
} else if attr.has_name(sym::rustc_then_this_would_need) { } else if attr.has_name(sym::rustc_then_this_would_need) {
let dep_node_interned = self.argument(attr); let dep_node_interned = self.argument(attr);
let dep_node = match dep_node_interned { let dep_node = match dep_node_interned {
@ -151,17 +151,17 @@ impl<'tcx> IfThisChanged<'tcx> {
match DepNode::from_label_string(self.tcx, n.as_str(), def_path_hash) { match DepNode::from_label_string(self.tcx, n.as_str(), def_path_hash) {
Ok(n) => n, Ok(n) => n,
Err(()) => self.tcx.dcx().emit_fatal(errors::UnrecognizedDepNode { Err(()) => self.tcx.dcx().emit_fatal(errors::UnrecognizedDepNode {
span: attr.span, span: attr.span(),
name: n, name: n,
}), }),
} }
} }
None => { None => {
self.tcx.dcx().emit_fatal(errors::MissingDepNode { span: attr.span }); self.tcx.dcx().emit_fatal(errors::MissingDepNode { span: attr.span() });
} }
}; };
self.then_this_would_need.push(( self.then_this_would_need.push((
attr.span, attr.span(),
dep_node_interned.unwrap(), dep_node_interned.unwrap(),
hir_id, hir_id,
dep_node, dep_node,

View file

@ -199,7 +199,7 @@ impl<'tcx> DirtyCleanVisitor<'tcx> {
let loaded_from_disk = self.loaded_from_disk(attr); let loaded_from_disk = self.loaded_from_disk(attr);
for e in except.items().into_sorted_stable_ord() { for e in except.items().into_sorted_stable_ord() {
if !auto.remove(e) { if !auto.remove(e) {
self.tcx.dcx().emit_fatal(errors::AssertionAuto { span: attr.span, name, e }); self.tcx.dcx().emit_fatal(errors::AssertionAuto { span: attr.span(), name, e });
} }
} }
Assertion { clean: auto, dirty: except, loaded_from_disk } Assertion { clean: auto, dirty: except, loaded_from_disk }
@ -282,7 +282,7 @@ impl<'tcx> DirtyCleanVisitor<'tcx> {
HirItem::Impl { .. } => ("ItemKind::Impl", LABELS_IMPL), HirItem::Impl { .. } => ("ItemKind::Impl", LABELS_IMPL),
_ => self.tcx.dcx().emit_fatal(errors::UndefinedCleanDirtyItem { _ => self.tcx.dcx().emit_fatal(errors::UndefinedCleanDirtyItem {
span: attr.span, span: attr.span(),
kind: format!("{:?}", item.kind), kind: format!("{:?}", item.kind),
}), }),
} }
@ -298,7 +298,7 @@ impl<'tcx> DirtyCleanVisitor<'tcx> {
ImplItemKind::Type(..) => ("NodeImplType", LABELS_CONST_IN_IMPL), ImplItemKind::Type(..) => ("NodeImplType", LABELS_CONST_IN_IMPL),
}, },
_ => self.tcx.dcx().emit_fatal(errors::UndefinedCleanDirty { _ => self.tcx.dcx().emit_fatal(errors::UndefinedCleanDirty {
span: attr.span, span: attr.span(),
kind: format!("{node:?}"), kind: format!("{node:?}"),
}), }),
}; };
@ -375,7 +375,7 @@ impl<'tcx> DirtyCleanVisitor<'tcx> {
let Some(assertion) = self.assertion_maybe(item_id, attr) else { let Some(assertion) = self.assertion_maybe(item_id, attr) else {
continue; continue;
}; };
self.checked_attrs.insert(attr.id); self.checked_attrs.insert(attr.id());
for label in assertion.clean.items().into_sorted_stable_ord() { for label in assertion.clean.items().into_sorted_stable_ord() {
let dep_node = DepNode::from_label_string(self.tcx, label, def_path_hash).unwrap(); let dep_node = DepNode::from_label_string(self.tcx, label, def_path_hash).unwrap();
self.assert_clean(item_span, dep_node); self.assert_clean(item_span, dep_node);
@ -405,12 +405,13 @@ fn check_config(tcx: TyCtxt<'_>, attr: &Attribute) -> bool {
debug!("check_config: searching for cfg {:?}", value); debug!("check_config: searching for cfg {:?}", value);
cfg = Some(config.contains(&(value, None))); cfg = Some(config.contains(&(value, None)));
} else if !(item.has_name(EXCEPT) || item.has_name(LOADED_FROM_DISK)) { } else if !(item.has_name(EXCEPT) || item.has_name(LOADED_FROM_DISK)) {
tcx.dcx().emit_err(errors::UnknownItem { span: attr.span, name: item.name_or_empty() }); tcx.dcx()
.emit_err(errors::UnknownItem { span: attr.span(), name: item.name_or_empty() });
} }
} }
match cfg { match cfg {
None => tcx.dcx().emit_fatal(errors::NoCfg { span: attr.span }), None => tcx.dcx().emit_fatal(errors::NoCfg { span: attr.span() }),
Some(c) => c, Some(c) => c,
} }
} }
@ -444,9 +445,9 @@ impl<'tcx> FindAllAttrs<'tcx> {
fn report_unchecked_attrs(&self, mut checked_attrs: FxHashSet<ast::AttrId>) { fn report_unchecked_attrs(&self, mut checked_attrs: FxHashSet<ast::AttrId>) {
for attr in &self.found_attrs { for attr in &self.found_attrs {
if !checked_attrs.contains(&attr.id) { if !checked_attrs.contains(&attr.id()) {
self.tcx.dcx().emit_err(errors::UncheckedClean { span: attr.span }); self.tcx.dcx().emit_err(errors::UncheckedClean { span: attr.span() });
checked_attrs.insert(attr.id); checked_attrs.insert(attr.id());
} }
} }
} }

View file

@ -1011,7 +1011,7 @@ impl<'tcx> LateLintPass<'tcx> for InvalidNoMangleItems {
cx.emit_span_lint( cx.emit_span_lint(
NO_MANGLE_GENERIC_ITEMS, NO_MANGLE_GENERIC_ITEMS,
span, span,
BuiltinNoMangleGeneric { suggestion: no_mangle_attr.span }, BuiltinNoMangleGeneric { suggestion: no_mangle_attr.span() },
); );
break; break;
} }
@ -1226,7 +1226,7 @@ impl<'tcx> LateLintPass<'tcx> for UngatedAsyncFnTrackCaller {
{ {
cx.emit_span_lint( cx.emit_span_lint(
UNGATED_ASYNC_FN_TRACK_CALLER, UNGATED_ASYNC_FN_TRACK_CALLER,
attr.span, attr.span(),
BuiltinUngatedAsyncFnTrackCaller { label: span, session: &cx.tcx.sess }, BuiltinUngatedAsyncFnTrackCaller { label: span, session: &cx.tcx.sess },
); );
} }

View file

@ -38,7 +38,7 @@ fn check_expectations(tcx: TyCtxt<'_>, tool_filter: Option<Symbol>) {
} }
LintExpectationId::Stable { hir_id, attr_index, lint_index: Some(lint_index) } => { LintExpectationId::Stable { hir_id, attr_index, lint_index: Some(lint_index) } => {
// We are an `eval_always` query, so looking at the attribute's `AttrId` is ok. // We are an `eval_always` query, so looking at the attribute's `AttrId` is ok.
let attr_id = tcx.hir().attrs(hir_id)[attr_index as usize].id; let attr_id = tcx.hir().attrs(hir_id)[attr_index as usize].id();
(attr_id, lint_index) (attr_id, lint_index)
} }
_ => panic!("fulfilled expectations must have a lint index"), _ => panic!("fulfilled expectations must have a lint index"),

View file

@ -182,7 +182,7 @@ fn name_of_extern_decl(tcx: TyCtxt<'_>, fi: hir::OwnerId) -> SymbolName {
// information, we could have codegen_fn_attrs also give span information back for // information, we could have codegen_fn_attrs also give span information back for
// where the attribute was defined. However, until this is found to be a // where the attribute was defined. However, until this is found to be a
// bottleneck, this does just fine. // bottleneck, this does just fine.
(overridden_link_name, tcx.get_attr(fi, sym::link_name).unwrap().span) (overridden_link_name, tcx.get_attr(fi, sym::link_name).unwrap().span())
}) })
{ {
SymbolName::Link(overridden_link_name, overridden_link_name_span) SymbolName::Link(overridden_link_name, overridden_link_name_span)

View file

@ -450,7 +450,7 @@ impl<'tcx> Collector<'tcx> {
(name, kind) = (wasm_import_module, Some(NativeLibKind::WasmImportModule)); (name, kind) = (wasm_import_module, Some(NativeLibKind::WasmImportModule));
} }
let Some((name, name_span)) = name else { let Some((name, name_span)) = name else {
sess.dcx().emit_err(errors::LinkRequiresName { span: m.span }); sess.dcx().emit_err(errors::LinkRequiresName { span: m.span() });
continue; continue;
}; };
@ -485,7 +485,7 @@ impl<'tcx> Collector<'tcx> {
let link_ordinal_attr = let link_ordinal_attr =
self.tcx.get_attr(child_item, sym::link_ordinal).unwrap(); self.tcx.get_attr(child_item, sym::link_ordinal).unwrap();
sess.dcx().emit_err(errors::LinkOrdinalRawDylib { sess.dcx().emit_err(errors::LinkOrdinalRawDylib {
span: link_ordinal_attr.span, span: link_ordinal_attr.span(),
}); });
} }
} }

View file

@ -75,7 +75,7 @@ impl OverlapMode {
tcx.hir().attrs(tcx.local_def_id_to_hir_id(local_def_id)) tcx.hir().attrs(tcx.local_def_id_to_hir_id(local_def_id))
}) })
.find(|attr| attr.has_name(sym::rustc_strict_coherence)) .find(|attr| attr.has_name(sym::rustc_strict_coherence))
.map(|attr| attr.span); .map(|attr| attr.span());
tcx.dcx().emit_err(StrictCoherenceNeedsNegativeCoherence { tcx.dcx().emit_err(StrictCoherenceNeedsNegativeCoherence {
span: tcx.def_span(trait_id), span: tcx.def_span(trait_id),
attr_span, attr_span,

View file

@ -1542,7 +1542,7 @@ impl<'tcx> TyCtxt<'tcx> {
Bound::Included(a.get()) Bound::Included(a.get())
} else { } else {
self.dcx().span_delayed_bug( self.dcx().span_delayed_bug(
attr.span, attr.span(),
"invalid rustc_layout_scalar_valid_range attribute", "invalid rustc_layout_scalar_valid_range attribute",
); );
Bound::Unbounded Bound::Unbounded

View file

@ -65,7 +65,7 @@ fn coverage_attr_on(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
Some(_) | None => { Some(_) | None => {
// Other possibilities should have been rejected by `rustc_parse::validate_attr`. // Other possibilities should have been rejected by `rustc_parse::validate_attr`.
// Use `span_delayed_bug` to avoid an ICE in failing builds (#127880). // Use `span_delayed_bug` to avoid an ICE in failing builds (#127880).
tcx.dcx().span_delayed_bug(attr.span, "unexpected value of coverage attribute"); tcx.dcx().span_delayed_bug(attr.span(), "unexpected value of coverage attribute");
} }
} }
} }

View file

@ -115,10 +115,10 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
for attr in attrs { for attr in attrs {
match attr.path().as_slice() { match attr.path().as_slice() {
[sym::diagnostic, sym::do_not_recommend, ..] => { [sym::diagnostic, sym::do_not_recommend, ..] => {
self.check_do_not_recommend(attr.span, hir_id, target, attr, item) self.check_do_not_recommend(attr.span(), hir_id, target, attr, item)
} }
[sym::diagnostic, sym::on_unimplemented, ..] => { [sym::diagnostic, sym::on_unimplemented, ..] => {
self.check_diagnostic_on_unimplemented(attr.span, hir_id, target) self.check_diagnostic_on_unimplemented(attr.span(), hir_id, target)
} }
[sym::inline, ..] => self.check_inline(hir_id, attr, span, target), [sym::inline, ..] => self.check_inline(hir_id, attr, span, target),
[sym::coverage, ..] => self.check_coverage(attr, span, target), [sym::coverage, ..] => self.check_coverage(attr, span, target),
@ -131,7 +131,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
} }
[sym::thread_local, ..] => self.check_thread_local(attr, span, target), [sym::thread_local, ..] => self.check_thread_local(attr, span, target),
[sym::track_caller, ..] => { [sym::track_caller, ..] => {
self.check_track_caller(hir_id, attr.span, attrs, span, target) self.check_track_caller(hir_id, attr.span(), attrs, span, target)
} }
[sym::doc, ..] => self.check_doc_attrs( [sym::doc, ..] => self.check_doc_attrs(
attr, attr,
@ -199,8 +199,8 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
[sym::rustc_has_incoherent_inherent_impls, ..] => { [sym::rustc_has_incoherent_inherent_impls, ..] => {
self.check_has_incoherent_inherent_impls(attr, span, target) self.check_has_incoherent_inherent_impls(attr, span, target)
} }
[sym::ffi_pure, ..] => self.check_ffi_pure(attr.span, attrs, target), [sym::ffi_pure, ..] => self.check_ffi_pure(attr.span(), attrs, target),
[sym::ffi_const, ..] => self.check_ffi_const(attr.span, target), [sym::ffi_const, ..] => self.check_ffi_const(attr.span(), target),
[sym::rustc_const_unstable, ..] [sym::rustc_const_unstable, ..]
| [sym::rustc_const_stable, ..] | [sym::rustc_const_stable, ..]
| [sym::unstable, ..] | [sym::unstable, ..]
@ -247,7 +247,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
self.check_coroutine(attr, target); self.check_coroutine(attr, target);
} }
[sym::linkage, ..] => self.check_linkage(attr, span, target), [sym::linkage, ..] => self.check_linkage(attr, span, target),
[sym::rustc_pub_transparent, ..] => self.check_rustc_pub_transparent(attr.span, span, attrs), [sym::rustc_pub_transparent, ..] => self.check_rustc_pub_transparent(attr.span(), span, attrs),
[ [
// ok // ok
sym::allow sym::allow
@ -288,7 +288,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
// attributes by name. That should allow trimming the above list, too. // attributes by name. That should allow trimming the above list, too.
if !name.as_str().starts_with("rustc_") { if !name.as_str().starts_with("rustc_") {
span_bug!( span_bug!(
attr.span, attr.span(),
"builtin attribute {name:?} not handled by `CheckAttrVisitor`" "builtin attribute {name:?} not handled by `CheckAttrVisitor`"
) )
} }
@ -305,17 +305,17 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
if let Some(BuiltinAttribute { type_: AttributeType::CrateLevel, .. }) = if let Some(BuiltinAttribute { type_: AttributeType::CrateLevel, .. }) =
attr.ident().and_then(|ident| BUILTIN_ATTRIBUTE_MAP.get(&ident.name)) attr.ident().and_then(|ident| BUILTIN_ATTRIBUTE_MAP.get(&ident.name))
{ {
match attr.style { match attr.style() {
ast::AttrStyle::Outer => self.tcx.emit_node_span_lint( ast::AttrStyle::Outer => self.tcx.emit_node_span_lint(
UNUSED_ATTRIBUTES, UNUSED_ATTRIBUTES,
hir_id, hir_id,
attr.span, attr.span(),
errors::OuterCrateLevelAttr, errors::OuterCrateLevelAttr,
), ),
ast::AttrStyle::Inner => self.tcx.emit_node_span_lint( ast::AttrStyle::Inner => self.tcx.emit_node_span_lint(
UNUSED_ATTRIBUTES, UNUSED_ATTRIBUTES,
hir_id, hir_id,
attr.span, attr.span(),
errors::InnerCrateLevelAttr, errors::InnerCrateLevelAttr,
), ),
} }
@ -338,7 +338,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
self.tcx.emit_node_span_lint( self.tcx.emit_node_span_lint(
UNUSED_ATTRIBUTES, UNUSED_ATTRIBUTES,
hir_id, hir_id,
attr.span, attr.span(),
errors::IgnoredAttrWithMacro { sym }, errors::IgnoredAttrWithMacro { sym },
); );
} }
@ -347,7 +347,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
self.tcx.emit_node_span_lint( self.tcx.emit_node_span_lint(
UNUSED_ATTRIBUTES, UNUSED_ATTRIBUTES,
hir_id, hir_id,
attr.span, attr.span(),
errors::IgnoredAttr { sym }, errors::IgnoredAttr { sym },
); );
} }
@ -407,7 +407,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
self.tcx.emit_node_span_lint( self.tcx.emit_node_span_lint(
UNUSED_ATTRIBUTES, UNUSED_ATTRIBUTES,
hir_id, hir_id,
attr.span, attr.span(),
errors::IgnoredInlineAttrFnProto, errors::IgnoredInlineAttrFnProto,
) )
} }
@ -418,7 +418,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
Target::AssocConst => self.tcx.emit_node_span_lint( Target::AssocConst => self.tcx.emit_node_span_lint(
UNUSED_ATTRIBUTES, UNUSED_ATTRIBUTES,
hir_id, hir_id,
attr.span, attr.span(),
errors::IgnoredInlineAttrConstants, errors::IgnoredInlineAttrConstants,
), ),
// FIXME(#80564): Same for fields, arms, and macro defs // FIXME(#80564): Same for fields, arms, and macro defs
@ -427,7 +427,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
} }
_ => { _ => {
self.dcx().emit_err(errors::InlineNotFnOrClosure { self.dcx().emit_err(errors::InlineNotFnOrClosure {
attr_span: attr.span, attr_span: attr.span(),
defn_span: span, defn_span: span,
}); });
} }
@ -459,7 +459,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
} }
self.dcx().emit_err(errors::CoverageAttributeNotAllowed { self.dcx().emit_err(errors::CoverageAttributeNotAllowed {
attr_span: attr.span, attr_span: attr.span(),
not_fn_impl_mod, not_fn_impl_mod,
no_body, no_body,
help: (), help: (),
@ -477,7 +477,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
); );
if !is_valid { if !is_valid {
self.dcx().emit_err(errors::OptimizeInvalidTarget { self.dcx().emit_err(errors::OptimizeInvalidTarget {
attr_span: attr.span, attr_span: attr.span(),
defn_span: span, defn_span: span,
on_crate: hir_id == CRATE_HIR_ID, on_crate: hir_id == CRATE_HIR_ID,
}); });
@ -528,7 +528,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
self.tcx.emit_node_span_lint( self.tcx.emit_node_span_lint(
UNUSED_ATTRIBUTES, UNUSED_ATTRIBUTES,
hir_id, hir_id,
attr.span, attr.span(),
errors::OnlyHasEffectOn { errors::OnlyHasEffectOn {
attr_name: attr.name_or_empty(), attr_name: attr.name_or_empty(),
target_name: allowed_target.name().replace(' ', "_"), target_name: allowed_target.name().replace(' ', "_"),
@ -597,8 +597,8 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
if !ALLOW_LIST.iter().any(|name| other_attr.has_name(*name)) { if !ALLOW_LIST.iter().any(|name| other_attr.has_name(*name)) {
self.dcx().emit_err(errors::NakedFunctionIncompatibleAttribute { self.dcx().emit_err(errors::NakedFunctionIncompatibleAttribute {
span: other_attr.span, span: other_attr.span(),
naked_span: attr.span, naked_span: attr.span(),
attr: other_attr.name_or_empty(), attr: other_attr.name_or_empty(),
}); });
@ -615,7 +615,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
} }
_ => { _ => {
self.dcx().emit_err(errors::AttrShouldBeAppliedToFn { self.dcx().emit_err(errors::AttrShouldBeAppliedToFn {
attr_span: attr.span, attr_span: attr.span(),
defn_span: span, defn_span: span,
on_crate: hir_id == CRATE_HIR_ID, on_crate: hir_id == CRATE_HIR_ID,
}); });
@ -648,9 +648,10 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
match target { match target {
Target::MacroDef => {} Target::MacroDef => {}
_ => { _ => {
self.tcx self.tcx.dcx().emit_err(errors::CollapseDebuginfo {
.dcx() attr_span: attr.span(),
.emit_err(errors::CollapseDebuginfo { attr_span: attr.span, defn_span: span }); defn_span: span,
});
} }
} }
} }
@ -720,7 +721,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
&& fields.iter().any(|f| f.default.is_some()) && fields.iter().any(|f| f.default.is_some())
{ {
self.dcx().emit_err(errors::NonExhaustiveWithDefaultFieldValues { self.dcx().emit_err(errors::NonExhaustiveWithDefaultFieldValues {
attr_span: attr.span, attr_span: attr.span(),
defn_span: span, defn_span: span,
}); });
} }
@ -735,7 +736,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
} }
_ => { _ => {
self.dcx().emit_err(errors::NonExhaustiveWrongLocation { self.dcx().emit_err(errors::NonExhaustiveWrongLocation {
attr_span: attr.span, attr_span: attr.span(),
defn_span: span, defn_span: span,
}); });
} }
@ -755,7 +756,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
} }
_ => { _ => {
self.dcx().emit_err(errors::AttrShouldBeAppliedToTrait { self.dcx().emit_err(errors::AttrShouldBeAppliedToTrait {
attr_span: attr.span, attr_span: attr.span(),
defn_span: span, defn_span: span,
}); });
} }
@ -784,7 +785,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
let sig = self.tcx.hir_node(hir_id).fn_sig().unwrap(); let sig = self.tcx.hir_node(hir_id).fn_sig().unwrap();
self.dcx().emit_err(errors::LangItemWithTargetFeature { self.dcx().emit_err(errors::LangItemWithTargetFeature {
attr_span: attr.span, attr_span: attr.span(),
name: lang_item, name: lang_item,
sig_span: sig.span, sig_span: sig.span,
}); });
@ -796,7 +797,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
self.tcx.emit_node_span_lint( self.tcx.emit_node_span_lint(
UNUSED_ATTRIBUTES, UNUSED_ATTRIBUTES,
hir_id, hir_id,
attr.span, attr.span(),
errors::TargetFeatureOnStatement, errors::TargetFeatureOnStatement,
); );
} }
@ -809,7 +810,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
} }
_ => { _ => {
self.dcx().emit_err(errors::AttrShouldBeAppliedToFn { self.dcx().emit_err(errors::AttrShouldBeAppliedToFn {
attr_span: attr.span, attr_span: attr.span(),
defn_span: span, defn_span: span,
on_crate: hir_id == CRATE_HIR_ID, on_crate: hir_id == CRATE_HIR_ID,
}); });
@ -823,7 +824,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
Target::ForeignStatic | Target::Static => {} Target::ForeignStatic | Target::Static => {}
_ => { _ => {
self.dcx().emit_err(errors::AttrShouldBeAppliedToStatic { self.dcx().emit_err(errors::AttrShouldBeAppliedToStatic {
attr_span: attr.span, attr_span: attr.span(),
defn_span: span, defn_span: span,
}); });
} }
@ -1093,7 +1094,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
meta.span(), meta.span(),
errors::DocInlineOnlyUse { errors::DocInlineOnlyUse {
attr_span: meta.span(), attr_span: meta.span(),
item_span: (attr.style == AttrStyle::Outer) item_span: (attr.style() == AttrStyle::Outer)
.then(|| self.tcx.hir().span(hir_id)), .then(|| self.tcx.hir().span(hir_id)),
}, },
); );
@ -1115,7 +1116,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
meta.span(), meta.span(),
errors::DocMaskedOnlyExternCrate { errors::DocMaskedOnlyExternCrate {
attr_span: meta.span(), attr_span: meta.span(),
item_span: (attr.style == AttrStyle::Outer) item_span: (attr.style() == AttrStyle::Outer)
.then(|| self.tcx.hir().span(hir_id)), .then(|| self.tcx.hir().span(hir_id)),
}, },
); );
@ -1129,7 +1130,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
meta.span(), meta.span(),
errors::DocMaskedNotExternCrateSelf { errors::DocMaskedNotExternCrateSelf {
attr_span: meta.span(), attr_span: meta.span(),
item_span: (attr.style == AttrStyle::Outer) item_span: (attr.style() == AttrStyle::Outer)
.then(|| self.tcx.hir().span(hir_id)), .then(|| self.tcx.hir().span(hir_id)),
}, },
); );
@ -1159,11 +1160,11 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
) -> bool { ) -> bool {
if hir_id != CRATE_HIR_ID { if hir_id != CRATE_HIR_ID {
// insert a bang between `#` and `[...` // insert a bang between `#` and `[...`
let bang_span = attr.span.lo() + BytePos(1); let bang_span = attr.span().lo() + BytePos(1);
let sugg = (attr.style == AttrStyle::Outer let sugg = (attr.style() == AttrStyle::Outer
&& self.tcx.hir_get_parent_item(hir_id) == CRATE_OWNER_ID) && self.tcx.hir_get_parent_item(hir_id) == CRATE_OWNER_ID)
.then_some(errors::AttrCrateLevelOnlySugg { .then_some(errors::AttrCrateLevelOnlySugg {
attr: attr.span.with_lo(bang_span).with_hi(bang_span), attr: attr.span().with_lo(bang_span).with_hi(bang_span),
}); });
self.tcx.emit_node_span_lint( self.tcx.emit_node_span_lint(
INVALID_DOC_ATTRIBUTES, INVALID_DOC_ATTRIBUTES,
@ -1337,11 +1338,11 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
errors::DocTestUnknownInclude { errors::DocTestUnknownInclude {
path, path,
value: value.to_string(), value: value.to_string(),
inner: match attr.style { inner: match attr.style() {
AttrStyle::Inner => "!", AttrStyle::Inner => "!",
AttrStyle::Outer => "", AttrStyle::Outer => "",
}, },
sugg: (attr.span, applicability), sugg: (attr.span(), applicability),
}, },
); );
} else if i_meta.has_name(sym::passes) } else if i_meta.has_name(sym::passes)
@ -1387,7 +1388,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
match target { match target {
Target::Struct | Target::Enum | Target::TyAlias => {} Target::Struct | Target::Enum | Target::TyAlias => {}
_ => { _ => {
self.dcx().emit_err(errors::PassByValue { attr_span: attr.span, span }); self.dcx().emit_err(errors::PassByValue { attr_span: attr.span(), span });
} }
} }
} }
@ -1396,7 +1397,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
match target { match target {
Target::Method(MethodKind::Inherent) => {} Target::Method(MethodKind::Inherent) => {}
_ => { _ => {
self.dcx().emit_err(errors::AllowIncoherentImpl { attr_span: attr.span, span }); self.dcx().emit_err(errors::AllowIncoherentImpl { attr_span: attr.span(), span });
} }
} }
} }
@ -1407,7 +1408,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
_ => { _ => {
self.tcx self.tcx
.dcx() .dcx()
.emit_err(errors::HasIncoherentInherentImpl { attr_span: attr.span, span }); .emit_err(errors::HasIncoherentInherentImpl { attr_span: attr.span(), span });
} }
} }
} }
@ -1480,7 +1481,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
match target { match target {
Target::Struct | Target::Enum | Target::Union | Target::Trait => {} Target::Struct | Target::Enum | Target::Union | Target::Trait => {}
_ => { _ => {
self.dcx().emit_err(errors::MustNotSuspend { attr_span: attr.span, span }); self.dcx().emit_err(errors::MustNotSuspend { attr_span: attr.span(), span });
} }
} }
} }
@ -1503,7 +1504,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
return; return;
} }
self.dcx().emit_err(errors::InvalidMayDangle { attr_span: attr.span }); self.dcx().emit_err(errors::InvalidMayDangle { attr_span: attr.span() });
} }
/// Checks if `#[cold]` is applied to a non-function. /// Checks if `#[cold]` is applied to a non-function.
@ -1523,7 +1524,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
self.tcx.emit_node_span_lint( self.tcx.emit_node_span_lint(
UNUSED_ATTRIBUTES, UNUSED_ATTRIBUTES,
hir_id, hir_id,
attr.span, attr.span(),
errors::Cold { span, on_crate: hir_id == CRATE_HIR_ID }, errors::Cold { span, on_crate: hir_id == CRATE_HIR_ID },
); );
} }
@ -1543,7 +1544,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
self.tcx.emit_node_span_lint( self.tcx.emit_node_span_lint(
UNUSED_ATTRIBUTES, UNUSED_ATTRIBUTES,
hir_id, hir_id,
attr.span, attr.span(),
errors::Link { span: (target != Target::ForeignMod).then_some(span) }, errors::Link { span: (target != Target::ForeignMod).then_some(span) },
); );
} }
@ -1562,19 +1563,19 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
_ => { _ => {
// FIXME: #[cold] was previously allowed on non-functions/statics and some crates // FIXME: #[cold] was previously allowed on non-functions/statics and some crates
// used this, so only emit a warning. // used this, so only emit a warning.
let attr_span = matches!(target, Target::ForeignMod).then_some(attr.span); let attr_span = matches!(target, Target::ForeignMod).then_some(attr.span());
if let Some(s) = attr.value_str() { if let Some(s) = attr.value_str() {
self.tcx.emit_node_span_lint( self.tcx.emit_node_span_lint(
UNUSED_ATTRIBUTES, UNUSED_ATTRIBUTES,
hir_id, hir_id,
attr.span, attr.span(),
errors::LinkName { span, attr_span, value: s.as_str() }, errors::LinkName { span, attr_span, value: s.as_str() },
); );
} else { } else {
self.tcx.emit_node_span_lint( self.tcx.emit_node_span_lint(
UNUSED_ATTRIBUTES, UNUSED_ATTRIBUTES,
hir_id, hir_id,
attr.span, attr.span(),
errors::LinkName { span, attr_span, value: "..." }, errors::LinkName { span, attr_span, value: "..." },
); );
}; };
@ -1594,7 +1595,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
self.inline_attr_str_error_with_macro_def(hir_id, attr, "no_link"); self.inline_attr_str_error_with_macro_def(hir_id, attr, "no_link");
} }
_ => { _ => {
self.dcx().emit_err(errors::NoLink { attr_span: attr.span, span }); self.dcx().emit_err(errors::NoLink { attr_span: attr.span(), span });
} }
} }
} }
@ -1616,7 +1617,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
self.inline_attr_str_error_with_macro_def(hir_id, attr, "export_name"); self.inline_attr_str_error_with_macro_def(hir_id, attr, "export_name");
} }
_ => { _ => {
self.dcx().emit_err(errors::ExportName { attr_span: attr.span, span }); self.dcx().emit_err(errors::ExportName { attr_span: attr.span(), span });
} }
} }
} }
@ -1624,7 +1625,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
fn check_rustc_layout_scalar_valid_range(&self, attr: &Attribute, span: Span, target: Target) { fn check_rustc_layout_scalar_valid_range(&self, attr: &Attribute, span: Span, target: Target) {
if target != Target::Struct { if target != Target::Struct {
self.dcx().emit_err(errors::RustcLayoutScalarValidRangeNotStruct { self.dcx().emit_err(errors::RustcLayoutScalarValidRangeNotStruct {
attr_span: attr.span, attr_span: attr.span(),
span, span,
}); });
return; return;
@ -1637,7 +1638,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
if !matches!(&list[..], &[MetaItemInner::Lit(MetaItemLit { kind: LitKind::Int(..), .. })]) { if !matches!(&list[..], &[MetaItemInner::Lit(MetaItemLit { kind: LitKind::Int(..), .. })]) {
self.tcx self.tcx
.dcx() .dcx()
.emit_err(errors::RustcLayoutScalarValidRangeArg { attr_span: attr.span }); .emit_err(errors::RustcLayoutScalarValidRangeArg { attr_span: attr.span() });
} }
} }
@ -1653,7 +1654,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
let is_function = matches!(target, Target::Fn); let is_function = matches!(target, Target::Fn);
if !is_function { if !is_function {
self.dcx().emit_err(errors::AttrShouldBeAppliedToFn { self.dcx().emit_err(errors::AttrShouldBeAppliedToFn {
attr_span: attr.span, attr_span: attr.span(),
defn_span: span, defn_span: span,
on_crate: hir_id == CRATE_HIR_ID, on_crate: hir_id == CRATE_HIR_ID,
}); });
@ -1678,7 +1679,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
hir::GenericParamKind::Const { .. } => {} hir::GenericParamKind::Const { .. } => {}
_ => { _ => {
self.dcx().emit_err(errors::RustcLegacyConstGenericsOnly { self.dcx().emit_err(errors::RustcLegacyConstGenericsOnly {
attr_span: attr.span, attr_span: attr.span(),
param_span: param.span, param_span: param.span,
}); });
return; return;
@ -1688,7 +1689,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
if list.len() != generics.params.len() { if list.len() != generics.params.len() {
self.dcx().emit_err(errors::RustcLegacyConstGenericsIndex { self.dcx().emit_err(errors::RustcLegacyConstGenericsIndex {
attr_span: attr.span, attr_span: attr.span(),
generics_span: generics.span, generics_span: generics.span,
}); });
return; return;
@ -1728,7 +1729,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
let is_function = matches!(target, Target::Fn | Target::Method(..)); let is_function = matches!(target, Target::Fn | Target::Method(..));
if !is_function { if !is_function {
self.dcx().emit_err(errors::AttrShouldBeAppliedToFn { self.dcx().emit_err(errors::AttrShouldBeAppliedToFn {
attr_span: attr.span, attr_span: attr.span(),
defn_span: span, defn_span: span,
on_crate: hir_id == CRATE_HIR_ID, on_crate: hir_id == CRATE_HIR_ID,
}); });
@ -1740,7 +1741,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
match target { match target {
Target::Struct => {} Target::Struct => {}
_ => { _ => {
self.dcx().emit_err(errors::RustcLintOptTy { attr_span: attr.span, span }); self.dcx().emit_err(errors::RustcLintOptTy { attr_span: attr.span(), span });
} }
} }
} }
@ -1752,7 +1753,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
_ => { _ => {
self.tcx self.tcx
.dcx() .dcx()
.emit_err(errors::RustcLintOptDenyFieldAccess { attr_span: attr.span, span }); .emit_err(errors::RustcLintOptDenyFieldAccess { attr_span: attr.span(), span });
} }
} }
} }
@ -1761,7 +1762,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
/// option is passed to the compiler. /// option is passed to the compiler.
fn check_rustc_dirty_clean(&self, attr: &Attribute) { fn check_rustc_dirty_clean(&self, attr: &Attribute) {
if !self.tcx.sess.opts.unstable_opts.query_dep_graph { if !self.tcx.sess.opts.unstable_opts.query_dep_graph {
self.dcx().emit_err(errors::RustcDirtyClean { span: attr.span }); self.dcx().emit_err(errors::RustcDirtyClean { span: attr.span() });
} }
} }
@ -1771,7 +1772,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
Target::Trait => {} Target::Trait => {}
_ => { _ => {
self.dcx().emit_err(errors::AttrShouldBeAppliedToTrait { self.dcx().emit_err(errors::AttrShouldBeAppliedToTrait {
attr_span: attr.span, attr_span: attr.span(),
defn_span: span, defn_span: span,
}); });
} }
@ -1795,7 +1796,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
self.tcx.emit_node_span_lint( self.tcx.emit_node_span_lint(
UNUSED_ATTRIBUTES, UNUSED_ATTRIBUTES,
hir_id, hir_id,
attr.span, attr.span(),
errors::LinkSection { span }, errors::LinkSection { span },
); );
} }
@ -1826,8 +1827,8 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
self.tcx.emit_node_span_lint( self.tcx.emit_node_span_lint(
UNUSED_ATTRIBUTES, UNUSED_ATTRIBUTES,
hir_id, hir_id,
attr.span, attr.span(),
errors::NoMangleForeign { span, attr_span: attr.span, foreign_item_kind }, errors::NoMangleForeign { span, attr_span: attr.span(), foreign_item_kind },
); );
} }
_ => { _ => {
@ -1836,7 +1837,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
self.tcx.emit_node_span_lint( self.tcx.emit_node_span_lint(
UNUSED_ATTRIBUTES, UNUSED_ATTRIBUTES,
hir_id, hir_id,
attr.span, attr.span(),
errors::NoMangle { span }, errors::NoMangle { span },
); );
} }
@ -2096,7 +2097,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
for attr in attrs.iter().filter(|attr| attr.has_name(sym::used)) { for attr in attrs.iter().filter(|attr| attr.has_name(sym::used)) {
if target != Target::Static { if target != Target::Static {
self.dcx().emit_err(errors::UsedStatic { self.dcx().emit_err(errors::UsedStatic {
attr_span: attr.span, attr_span: attr.span(),
span: target_span, span: target_span,
target: target.name(), target: target.name(),
}); });
@ -2105,12 +2106,12 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
match inner.as_deref() { match inner.as_deref() {
Some([item]) if item.has_name(sym::linker) => { Some([item]) if item.has_name(sym::linker) => {
if used_linker_span.is_none() { if used_linker_span.is_none() {
used_linker_span = Some(attr.span); used_linker_span = Some(attr.span());
} }
} }
Some([item]) if item.has_name(sym::compiler) => { Some([item]) if item.has_name(sym::compiler) => {
if used_compiler_span.is_none() { if used_compiler_span.is_none() {
used_compiler_span = Some(attr.span); used_compiler_span = Some(attr.span());
} }
} }
Some(_) => { Some(_) => {
@ -2119,7 +2120,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
None => { None => {
// Default case (compiler) when arg isn't defined. // Default case (compiler) when arg isn't defined.
if used_compiler_span.is_none() { if used_compiler_span.is_none() {
used_compiler_span = Some(attr.span); used_compiler_span = Some(attr.span());
} }
} }
} }
@ -2165,7 +2166,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
_ => { _ => {
self.tcx self.tcx
.dcx() .dcx()
.emit_err(errors::AllowInternalUnstable { attr_span: attr.span, span }); .emit_err(errors::AllowInternalUnstable { attr_span: attr.span(), span });
} }
} }
} }
@ -2179,7 +2180,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
match target { match target {
Target::Mod => {} Target::Mod => {}
_ => { _ => {
self.dcx().emit_err(errors::DebugVisualizerPlacement { span: attr.span }); self.dcx().emit_err(errors::DebugVisualizerPlacement { span: attr.span() });
} }
} }
} }
@ -2206,7 +2207,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
_ => { _ => {
self.tcx self.tcx
.dcx() .dcx()
.emit_err(errors::RustcAllowConstFnUnstable { attr_span: attr.span, span }); .emit_err(errors::RustcAllowConstFnUnstable { attr_span: attr.span(), span });
} }
} }
} }
@ -2217,7 +2218,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
_ => { _ => {
self.tcx self.tcx
.dcx() .dcx()
.emit_err(errors::RustcStdInternalSymbol { attr_span: attr.span, span }); .emit_err(errors::RustcStdInternalSymbol { attr_span: attr.span(), span });
} }
} }
} }
@ -2225,7 +2226,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
fn check_stability_promotable(&self, attr: &Attribute, target: Target) { fn check_stability_promotable(&self, attr: &Attribute, target: Target) {
match target { match target {
Target::Expression => { Target::Expression => {
self.dcx().emit_err(errors::StabilityPromotable { attr_span: attr.span }); self.dcx().emit_err(errors::StabilityPromotable { attr_span: attr.span() });
} }
_ => {} _ => {}
} }
@ -2235,7 +2236,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
match target { match target {
Target::ForeignFn | Target::ForeignStatic => {} Target::ForeignFn | Target::ForeignStatic => {}
_ => { _ => {
self.dcx().emit_err(errors::LinkOrdinal { attr_span: attr.span }); self.dcx().emit_err(errors::LinkOrdinal { attr_span: attr.span() });
} }
} }
} }
@ -2264,11 +2265,11 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
} }
if candidates.is_empty() { if candidates.is_empty() {
self.dcx().emit_err(errors::EmptyConfusables { span: attr.span }); self.dcx().emit_err(errors::EmptyConfusables { span: attr.span() });
} }
} }
_ => { _ => {
self.dcx().emit_err(errors::Confusables { attr_span: attr.span }); self.dcx().emit_err(errors::Confusables { attr_span: attr.span() });
} }
} }
} }
@ -2279,7 +2280,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
self.tcx.emit_node_span_lint( self.tcx.emit_node_span_lint(
UNUSED_ATTRIBUTES, UNUSED_ATTRIBUTES,
hir_id, hir_id,
attr.span, attr.span(),
errors::Deprecated, errors::Deprecated,
); );
} }
@ -2295,7 +2296,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
self.tcx.emit_node_span_lint( self.tcx.emit_node_span_lint(
UNUSED_ATTRIBUTES, UNUSED_ATTRIBUTES,
hir_id, hir_id,
attr.span, attr.span(),
errors::MacroUse { name }, errors::MacroUse { name },
); );
} }
@ -2307,7 +2308,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
self.tcx.emit_node_span_lint( self.tcx.emit_node_span_lint(
UNUSED_ATTRIBUTES, UNUSED_ATTRIBUTES,
hir_id, hir_id,
attr.span, attr.span(),
errors::MacroExport::Normal, errors::MacroExport::Normal,
); );
} else if let Some(meta_item_list) = attr.meta_item_list() } else if let Some(meta_item_list) = attr.meta_item_list()
@ -2317,7 +2318,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
self.tcx.emit_node_span_lint( self.tcx.emit_node_span_lint(
INVALID_MACRO_EXPORT_ARGUMENTS, INVALID_MACRO_EXPORT_ARGUMENTS,
hir_id, hir_id,
attr.span, attr.span(),
errors::MacroExport::TooManyItems, errors::MacroExport::TooManyItems,
); );
} else if meta_item_list[0].name_or_empty() != sym::local_inner_macros { } else if meta_item_list[0].name_or_empty() != sym::local_inner_macros {
@ -2337,7 +2338,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
self.tcx.emit_node_span_lint( self.tcx.emit_node_span_lint(
UNUSED_ATTRIBUTES, UNUSED_ATTRIBUTES,
hir_id, hir_id,
attr.span, attr.span(),
errors::MacroExport::OnDeclMacro, errors::MacroExport::OnDeclMacro,
); );
} }
@ -2415,7 +2416,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
self.tcx.emit_node_span_lint( self.tcx.emit_node_span_lint(
UNUSED_ATTRIBUTES, UNUSED_ATTRIBUTES,
hir_id, hir_id,
attr.span, attr.span(),
errors::Unused { attr_span: attr.span, note }, errors::Unused { attr_span: attr.span, note },
); );
} }
@ -2532,7 +2533,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
match target { match target {
Target::Closure => return, Target::Closure => return,
_ => { _ => {
self.dcx().emit_err(errors::CoroutineOnNonClosure { span: attr.span }); self.dcx().emit_err(errors::CoroutineOnNonClosure { span: attr.span() });
} }
} }
} }
@ -2545,7 +2546,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
| Target::ForeignStatic | Target::ForeignStatic
| Target::ForeignFn => {} | Target::ForeignFn => {}
_ => { _ => {
self.dcx().emit_err(errors::Linkage { attr_span: attr.span, span }); self.dcx().emit_err(errors::Linkage { attr_span: attr.span(), span });
} }
} }
} }
@ -2588,14 +2589,14 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
&& is_coro && is_coro
{ {
self.dcx().emit_err(errors::RustcForceInlineCoro { self.dcx().emit_err(errors::RustcForceInlineCoro {
attr_span: attr.span, attr_span: attr.span(),
span: parent_span, span: parent_span,
}); });
} }
} }
(Target::Fn, _) => (), (Target::Fn, _) => (),
(_, Some(attr)) => { (_, Some(attr)) => {
self.dcx().emit_err(errors::RustcForceInline { attr_span: attr.span, span }); self.dcx().emit_err(errors::RustcForceInline { attr_span: attr.span(), span });
} }
(_, None) => (), (_, None) => (),
} }
@ -2747,7 +2748,7 @@ fn check_invalid_crate_level_attr(tcx: TyCtxt<'_>, attrs: &[Attribute]) {
for attr in attrs { for attr in attrs {
// This function should only be called with crate attributes // This function should only be called with crate attributes
// which are inner attributes always but lets check to make sure // which are inner attributes always but lets check to make sure
if attr.style == AttrStyle::Inner { if attr.style() == AttrStyle::Inner {
for attr_to_check in ATTRS_TO_CHECK { for attr_to_check in ATTRS_TO_CHECK {
if attr.has_name(*attr_to_check) { if attr.has_name(*attr_to_check) {
let item = tcx let item = tcx
@ -2795,7 +2796,7 @@ fn check_non_exported_macro_for_invalid_attrs(tcx: TyCtxt<'_>, item: &Item<'_>)
for attr in attrs { for attr in attrs {
if attr.has_name(sym::inline) { if attr.has_name(sym::inline) {
tcx.dcx().emit_err(errors::NonExportedMacroInvalidAttrs { attr_span: attr.span }); tcx.dcx().emit_err(errors::NonExportedMacroInvalidAttrs { attr_span: attr.span() });
} }
} }
} }
@ -2833,10 +2834,10 @@ fn check_duplicates(
match seen.entry(attr.name_or_empty()) { match seen.entry(attr.name_or_empty()) {
Entry::Occupied(mut entry) => { Entry::Occupied(mut entry) => {
let (this, other) = if matches!(duplicates, FutureWarnPreceding) { let (this, other) = if matches!(duplicates, FutureWarnPreceding) {
let to_remove = entry.insert(attr.span); let to_remove = entry.insert(attr.span());
(to_remove, attr.span) (to_remove, attr.span())
} else { } else {
(attr.span, *entry.get()) (attr.span(), *entry.get())
}; };
tcx.emit_node_span_lint( tcx.emit_node_span_lint(
UNUSED_ATTRIBUTES, UNUSED_ATTRIBUTES,
@ -2853,17 +2854,17 @@ fn check_duplicates(
); );
} }
Entry::Vacant(entry) => { Entry::Vacant(entry) => {
entry.insert(attr.span); entry.insert(attr.span());
} }
} }
} }
ErrorFollowing | ErrorPreceding => match seen.entry(attr.name_or_empty()) { ErrorFollowing | ErrorPreceding => match seen.entry(attr.name_or_empty()) {
Entry::Occupied(mut entry) => { Entry::Occupied(mut entry) => {
let (this, other) = if matches!(duplicates, ErrorPreceding) { let (this, other) = if matches!(duplicates, ErrorPreceding) {
let to_remove = entry.insert(attr.span); let to_remove = entry.insert(attr.span());
(to_remove, attr.span) (to_remove, attr.span())
} else { } else {
(attr.span, *entry.get()) (attr.span(), *entry.get())
}; };
tcx.dcx().emit_err(errors::UnusedMultiple { tcx.dcx().emit_err(errors::UnusedMultiple {
this, this,
@ -2872,7 +2873,7 @@ fn check_duplicates(
}); });
} }
Entry::Vacant(entry) => { Entry::Vacant(entry) => {
entry.insert(attr.span); entry.insert(attr.span());
} }
}, },
} }

View file

@ -46,7 +46,7 @@ fn entry_fn(tcx: TyCtxt<'_>, (): ()) -> Option<(DefId, EntryFnType)> {
fn attr_span_by_symbol(ctxt: &EntryContext<'_>, id: ItemId, sym: Symbol) -> Option<Span> { fn attr_span_by_symbol(ctxt: &EntryContext<'_>, id: ItemId, sym: Symbol) -> Option<Span> {
let attrs = ctxt.tcx.hir().attrs(id.hir_id()); let attrs = ctxt.tcx.hir().attrs(id.hir_id());
attr::find_by_name(attrs, sym).map(|attr| attr.span) attr::find_by_name(attrs, sym).map(|attr| attr.span())
} }
fn check_and_search_item(id: ItemId, ctxt: &mut EntryContext<'_>) { fn check_and_search_item(id: ItemId, ctxt: &mut EntryContext<'_>) {

View file

@ -68,10 +68,14 @@ impl<'tcx> LibFeatureCollector<'tcx> {
| sym::rustc_default_body_unstable | sym::rustc_default_body_unstable
); );
if is_unstable { if is_unstable {
return Some((feature, FeatureStability::Unstable, attr.span)); return Some((feature, FeatureStability::Unstable, attr.span()));
} }
if let Some(since) = since { if let Some(since) = since {
return Some((feature, FeatureStability::AcceptedSince(since), attr.span)); return Some((
feature,
FeatureStability::AcceptedSince(since),
attr.span(),
));
} }
} }
// We need to iterate over the other attributes, because // We need to iterate over the other attributes, because

View file

@ -1806,7 +1806,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
&& !def_id.is_local() && !def_id.is_local()
&& let Some(attr) = self.tcx.get_attr(def_id, sym::non_exhaustive) && let Some(attr) = self.tcx.get_attr(def_id, sym::non_exhaustive)
{ {
non_exhaustive = Some(attr.span); non_exhaustive = Some(attr.span());
} else if let Some(span) = ctor_fields_span { } else if let Some(span) = ctor_fields_span {
let label = errors::ConstructorPrivateIfAnyFieldPrivate { span }; let label = errors::ConstructorPrivateIfAnyFieldPrivate { span };
err.subdiagnostic(label); err.subdiagnostic(label);

View file

@ -468,7 +468,7 @@ pub(crate) fn encode_ty<'tcx>(
)] )]
tcx.dcx() tcx.dcx()
.struct_span_err( .struct_span_err(
cfi_encoding.span, cfi_encoding.span(),
format!("invalid `cfi_encoding` for `{:?}`", ty.kind()), format!("invalid `cfi_encoding` for `{:?}`", ty.kind()),
) )
.emit(); .emit();
@ -519,7 +519,7 @@ pub(crate) fn encode_ty<'tcx>(
)] )]
tcx.dcx() tcx.dcx()
.struct_span_err( .struct_span_err(
cfi_encoding.span, cfi_encoding.span(),
format!("invalid `cfi_encoding` for `{:?}`", ty.kind()), format!("invalid `cfi_encoding` for `{:?}`", ty.kind()),
) )
.emit(); .emit();

View file

@ -255,7 +255,7 @@ impl<'tcx> Context for TablesWrapper<'tcx> {
tcx.get_attrs_by_path(did, &attr_name) tcx.get_attrs_by_path(did, &attr_name)
.map(|attribute| { .map(|attribute| {
let attr_str = rustc_hir_pretty::attribute_to_string(&tcx, attribute); let attr_str = rustc_hir_pretty::attribute_to_string(&tcx, attribute);
let span = attribute.span; let span = attribute.span();
stable_mir::crate_def::Attribute::new(attr_str, span.stable(&mut *tables)) stable_mir::crate_def::Attribute::new(attr_str, span.stable(&mut *tables))
}) })
.collect() .collect()
@ -265,8 +265,7 @@ impl<'tcx> Context for TablesWrapper<'tcx> {
let mut tables = self.0.borrow_mut(); let mut tables = self.0.borrow_mut();
let tcx = tables.tcx; let tcx = tables.tcx;
let did = tables[def_id]; let did = tables[def_id];
let filter_fn = let filter_fn = move |a: &&rustc_hir::Attribute| !a.is_doc_comment();
move |a: &&rustc_hir::Attribute| matches!(a.kind, rustc_hir::AttrKind::Normal(_));
let attrs_iter = if let Some(did) = did.as_local() { let attrs_iter = if let Some(did) = did.as_local() {
tcx.hir().attrs(tcx.local_def_id_to_hir_id(did)).iter().filter(filter_fn) tcx.hir().attrs(tcx.local_def_id_to_hir_id(did)).iter().filter(filter_fn)
} else { } else {
@ -275,7 +274,7 @@ impl<'tcx> Context for TablesWrapper<'tcx> {
attrs_iter attrs_iter
.map(|attribute| { .map(|attribute| {
let attr_str = rustc_hir_pretty::attribute_to_string(&tcx, attribute); let attr_str = rustc_hir_pretty::attribute_to_string(&tcx, attribute);
let span = attribute.span; let span = attribute.span();
stable_mir::crate_def::Attribute::new(attr_str, span.stable(&mut *tables)) stable_mir::crate_def::Attribute::new(attr_str, span.stable(&mut *tables))
}) })
.collect() .collect()

View file

@ -62,18 +62,18 @@ impl SymbolNamesTest<'_> {
); );
let mangled = tcx.symbol_name(instance); let mangled = tcx.symbol_name(instance);
tcx.dcx().emit_err(TestOutput { tcx.dcx().emit_err(TestOutput {
span: attr.span, span: attr.span(),
kind: Kind::SymbolName, kind: Kind::SymbolName,
content: format!("{mangled}"), content: format!("{mangled}"),
}); });
if let Ok(demangling) = rustc_demangle::try_demangle(mangled.name) { if let Ok(demangling) = rustc_demangle::try_demangle(mangled.name) {
tcx.dcx().emit_err(TestOutput { tcx.dcx().emit_err(TestOutput {
span: attr.span, span: attr.span(),
kind: Kind::Demangling, kind: Kind::Demangling,
content: format!("{demangling}"), content: format!("{demangling}"),
}); });
tcx.dcx().emit_err(TestOutput { tcx.dcx().emit_err(TestOutput {
span: attr.span, span: attr.span(),
kind: Kind::DemanglingAlt, kind: Kind::DemanglingAlt,
content: format!("{demangling:#}"), content: format!("{demangling:#}"),
}); });
@ -82,7 +82,7 @@ impl SymbolNamesTest<'_> {
for attr in tcx.get_attrs(def_id, DEF_PATH) { for attr in tcx.get_attrs(def_id, DEF_PATH) {
tcx.dcx().emit_err(TestOutput { tcx.dcx().emit_err(TestOutput {
span: attr.span, span: attr.span(),
kind: Kind::DefPath, kind: Kind::DefPath,
content: with_no_trimmed_paths!(tcx.def_path_str(def_id)), content: with_no_trimmed_paths!(tcx.def_path_str(def_id)),
}); });

View file

@ -522,7 +522,8 @@ impl<T> Trait<T> for X {
} }
} }
TypeError::TargetFeatureCast(def_id) => { TypeError::TargetFeatureCast(def_id) => {
let target_spans = tcx.get_attrs(def_id, sym::target_feature).map(|attr| attr.span); let target_spans =
tcx.get_attrs(def_id, sym::target_feature).map(|attr| attr.span());
diag.note( diag.note(
"functions with `#[target_feature]` can only be coerced to `unsafe` function pointers" "functions with `#[target_feature]` can only be coerced to `unsafe` function pointers"
); );

View file

@ -622,7 +622,14 @@ impl<'tcx> OnUnimplementedDirective {
item_def_id: DefId, item_def_id: DefId,
) -> Result<Option<Self>, ErrorGuaranteed> { ) -> Result<Option<Self>, ErrorGuaranteed> {
let result = if let Some(items) = attr.meta_item_list() { let result = if let Some(items) = attr.meta_item_list() {
Self::parse(tcx, item_def_id, &items, attr.span, true, is_diagnostic_namespace_variant) Self::parse(
tcx,
item_def_id,
&items,
attr.span(),
true,
is_diagnostic_namespace_variant,
)
} else if let Some(value) = attr.value_str() { } else if let Some(value) = attr.value_str() {
if !is_diagnostic_namespace_variant { if !is_diagnostic_namespace_variant {
Ok(Some(OnUnimplementedDirective { Ok(Some(OnUnimplementedDirective {
@ -633,7 +640,7 @@ impl<'tcx> OnUnimplementedDirective {
tcx, tcx,
item_def_id, item_def_id,
value, value,
attr.span, attr.span(),
is_diagnostic_namespace_variant, is_diagnostic_namespace_variant,
)?), )?),
notes: Vec::new(), notes: Vec::new(),
@ -665,8 +672,8 @@ impl<'tcx> OnUnimplementedDirective {
tcx.emit_node_span_lint( tcx.emit_node_span_lint(
UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES, UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES,
tcx.local_def_id_to_hir_id(item_def_id), tcx.local_def_id_to_hir_id(item_def_id),
attr.span, attr.span(),
MalformedOnUnimplementedAttrLint::new(attr.span), MalformedOnUnimplementedAttrLint::new(attr.span()),
); );
} }
} }
@ -675,7 +682,7 @@ impl<'tcx> OnUnimplementedDirective {
tcx.emit_node_span_lint( tcx.emit_node_span_lint(
UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES, UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES,
tcx.local_def_id_to_hir_id(item_def_id), tcx.local_def_id_to_hir_id(item_def_id),
attr.span, attr.span(),
MissingOptionsForOnUnimplementedAttr, MissingOptionsForOnUnimplementedAttr,
) )
} }

@ -1 +1 @@
Subproject commit 1d1d646c06a84c1aa53967b394b7f1218f85db82 Subproject commit ce948f4616e3d4277e30c75c8bb01e094910df39