Skip to content

Commit 0cf65bb

Browse files
committed
Auto merge of #165056 - JonathanBrouwer:rollup-ZFCUK9j, r=JonathanBrouwer
Rollup of 21 pull requests Successful merges: - #159580 (Reject cfg on expressions that cannot be safely removed) - #162597 (raise ambiguity error on attribute macro that could be tool attribute) - #162808 (Enable `--generate-link-to-definition` rustdoc option on std docs) - #163059 (Recover invalid return type until `{`, `}` or `;`) - #163672 (Use runCodeGen Abstraction for new LLVM) - #164028 (Add a future incompat warning for #[no_link]) - #164188 (Suggest adding lifetime for `dyn Trait` in return type) - #164345 (fix: handle `false` in root contexts) - #164494 (drop ands which are a superset of other ands) - #164785 (delegation: emit error when there is no field for `Self` mapping) - #164799 (Don't use `IntoIterator` in parallel API) - #164871 (Refactor call argument codegen) - #164648 (parse inline and rustc_force_inline with same parser) - #164811 (fix: Prevent ICE when comparing EII impl against generic declaration) - #164900 (make tool_attrs method to retrieve tool attributes.) - #164993 (copy_nonoverlapping: dont skip ovelrap check when src is fully uninit) - #164996 (miri: add missing alignment check in write_bytes) - #165012 (Remove Span::eq_ctxt()) - #165013 ([tiny] Add missing backticks around lifetime name) - #165024 (rustdoc-search: rank re-export lower) - #165028 (Update enzyme to fix one bug related to higher-order derivatives)
2 parents 41089d0 + a0422c0 commit 0cf65bb

228 files changed

Lines changed: 2627 additions & 983 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎compiler/rustc_ast_lowering/src/lib.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1330,7 +1330,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
13301330
.gen_args
13311331
.as_ref()
13321332
.map_or(constraint.ident.span, |args| args.span());
1333-
if bound_end_span.eq_ctxt(constraint.span) {
1333+
if bound_end_span.ctxt() == constraint.span.ctxt() {
13341334
Some(self.tcx.sess.source_map().next_point(bound_end_span))
13351335
} else {
13361336
None

‎compiler/rustc_ast_passes/src/ast_validation.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1703,7 +1703,7 @@ impl Visitor<'_> for AstValidator<'_> {
17031703
}
17041704
if ident.name == kw::Underscore
17051705
&& !matches!(item.vis.kind, VisibilityKind::Inherited)
1706-
&& ident.span.eq_ctxt(item.vis.span)
1706+
&& ident.span.ctxt() == item.vis.span.ctxt()
17071707
{
17081708
self.lint_buffer.buffer_lint(
17091709
UNUSED_VISIBILITIES,

‎compiler/rustc_attr_ir/src/attr.rs‎

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_ast::{AttrStyle, DelimArgs, MetaItemLit, ast, join_path_idents};
66
use rustc_data_structures::stable_hash::{StableHash, StableHashCtxt, StableHasher};
77
use rustc_error_messages::{DiagArgValue, IntoDiagArg};
88
use rustc_macros::{Decodable, Encodable, StableHash};
9-
use rustc_span::{AttrId, DUMMY_SP, Ident, Span, Symbol, sym};
9+
use rustc_span::{AttrId, DUMMY_SP, Ident, Span, Symbol};
1010
use smallvec::SmallVec;
1111
use thin_vec::ThinVec;
1212

@@ -72,7 +72,6 @@ pub struct AttrItem {
7272
// Not lowered to hir::Path because we have no NodeId to resolve to.
7373
pub path: AttrPath,
7474
pub args: AttrArgs,
75-
pub id: HashIgnoredAttrId,
7675
/// Denotes if the attribute decorates the following construct (outer)
7776
/// or the construct this attribute is contained within (inner).
7877
pub style: AttrStyle,
@@ -110,16 +109,25 @@ pub enum Attribute {
110109
/// [`AttributeKind::Stability`] attribute. Most `Attribute` variants do have a [`Span`] field,
111110
/// though, mostly for the purpose of generating diagnostics later in the compilation process.
112111
Parsed(AttributeKind),
113-
/// Represents non built-in attributes, which are not converted into a parsed form.
112+
113+
/// A tool attribute.
114+
///
115+
/// Tool attributes, with the exception of diagnostic attributes, are not converted into a
116+
/// parsed form.
117+
Tool(Box<AttrItem>),
118+
119+
/// A derive helper attribute.
114120
///
115-
/// This is the case for custom tool attributes and derive helper attributes.
116-
Unparsed(Box<AttrItem>),
121+
/// Derive helper attributes serve no use beyond macro expansion, but they are useful to
122+
/// consumers of `rustdoc-json`, so we keep them around. See
123+
/// <https://github.com/rust-lang/rust/issues/157107> for context.
124+
DeriveHelper(Box<AttrItem>),
117125
}
118126

119127
impl Attribute {
120128
pub fn value_lit(&self) -> Option<&MetaItemLit> {
121129
match &self {
122-
Attribute::Unparsed(n) => match n.as_ref() {
130+
Attribute::Tool(n) | Attribute::DeriveHelper(n) => match n.as_ref() {
123131
AttrItem { args: AttrArgs::Eq { eq_span: _, expr }, .. } => Some(expr),
124132
_ => None,
125133
},
@@ -129,7 +137,9 @@ impl Attribute {
129137

130138
pub fn is_prefix_attr_for_suggestions(&self) -> bool {
131139
match self {
132-
Attribute::Unparsed(attr) => attr.span.desugaring_kind().is_none(),
140+
Attribute::Tool(attr) | Attribute::DeriveHelper(attr) => {
141+
attr.span.desugaring_kind().is_none()
142+
}
133143
// Other parsed attributes that can appear on expressions originate from source and
134144
// should make suggestions treat the expression like a prefixed form.
135145
Attribute::Parsed(_) => true,
@@ -141,7 +151,7 @@ impl AttributeExt for Attribute {
141151
#[inline]
142152
fn meta_item_list(&self) -> Option<ThinVec<ast::MetaItemInner>> {
143153
match &self {
144-
Attribute::Unparsed(n) => match n.as_ref() {
154+
Attribute::Tool(n) | Attribute::DeriveHelper(n) => match n.as_ref() {
145155
AttrItem { args: AttrArgs::Delimited(d), .. } => {
146156
ast::MetaItemKind::list_from_tokens(d.tokens.clone())
147157
}
@@ -165,21 +175,23 @@ impl AttributeExt for Attribute {
165175
#[inline]
166176
fn name(&self) -> Option<Symbol> {
167177
match &self {
168-
Attribute::Unparsed(n) => {
178+
Attribute::DeriveHelper(n) => {
169179
if let [ident] = n.path.segments.as_ref() {
170180
Some(*ident)
171181
} else {
172182
None
173183
}
174184
}
175-
_ => None,
185+
Attribute::Parsed(..) => None,
186+
// Tools are never single segment attributes
187+
Attribute::Tool(..) => None,
176188
}
177189
}
178190

179191
#[inline]
180192
fn path_matches(&self, name: &[Symbol]) -> bool {
181193
match &self {
182-
Attribute::Unparsed(n) => n.path.segments.iter().eq(name),
194+
Attribute::Tool(n) | Attribute::DeriveHelper(n) => n.path.segments.iter().eq(name),
183195
_ => false,
184196
}
185197
}
@@ -196,7 +208,7 @@ impl AttributeExt for Attribute {
196208
#[inline]
197209
fn is_word(&self) -> bool {
198210
match &self {
199-
Attribute::Unparsed(n) => {
211+
Attribute::Tool(n) | Attribute::DeriveHelper(n) => {
200212
matches!(n.args, AttrArgs::Empty)
201213
}
202214
_ => false,
@@ -206,14 +218,16 @@ impl AttributeExt for Attribute {
206218
#[inline]
207219
fn symbol_path(&self) -> Option<SmallVec<[Symbol; 1]>> {
208220
match &self {
209-
Attribute::Unparsed(n) => Some(n.path.segments.iter().copied().collect()),
221+
Attribute::Tool(n) | Attribute::DeriveHelper(n) => {
222+
Some(n.path.segments.iter().copied().collect())
223+
}
210224
_ => None,
211225
}
212226
}
213227

214228
fn path_span(&self) -> Option<Span> {
215229
match &self {
216-
Attribute::Unparsed(attr) => Some(attr.path.span),
230+
Attribute::Tool(attr) | Attribute::DeriveHelper(attr) => Some(attr.path.span),
217231
Attribute::Parsed(_) => None,
218232
}
219233
}
@@ -239,9 +253,6 @@ impl AttributeExt for Attribute {
239253
fn doc_resolution_scope(&self) -> Option<AttrStyle> {
240254
match self {
241255
Attribute::Parsed(AttributeKind::DocComment { style, .. }) => Some(*style),
242-
Attribute::Unparsed(attr) if self.has_name(sym::doc) && self.value_str().is_some() => {
243-
Some(attr.style)
244-
}
245256
_ => None,
246257
}
247258
}

‎compiler/rustc_attr_ir/src/lib.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ macro_rules! find_attr {
132132
$crate::Attribute::Parsed($pattern) $(if $guard)? => {
133133
break 'done Some($e);
134134
}
135-
$crate::Attribute::Unparsed(..) => {}
135+
$crate::Attribute::Tool(..) | $crate::Attribute::DeriveHelper(..) => {}
136136
// In lint emitting, there's a specific exception for this warning.
137137
// It's not usually emitted from inside macros from other crates
138138
// (see https://github.com/rust-lang/rust/issues/110613)

0 commit comments

Comments
 (0)