Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
bc6d1c2
Remove `[T]::array_chunks(_mut)`
scottmcm Jul 1, 2025
a076bd8
Remove `compiler-builtins-no-asm`
tgross35 Jul 25, 2025
51c5f19
Remove `compiler-builtins-mangled-names`
tgross35 Jul 26, 2025
39235be
Add attributes to AttributeKind
JonathanBrouwer Jul 7, 2025
c4e7cb8
Implement check_attr
JonathanBrouwer Jul 7, 2025
2f50c78
Parsers for the attributes
JonathanBrouwer Jul 7, 2025
ec63700
Use the new attributes throughout the codebase
JonathanBrouwer Jul 7, 2025
fea7809
Update test results
JonathanBrouwer Jul 7, 2025
e64f75b
Remove now un-used code
JonathanBrouwer Jul 7, 2025
97b6521
Fix tooling
JonathanBrouwer Jul 7, 2025
558796b
rustdoc: save target modifiers
ojeda Jul 26, 2025
ad4b869
bump cargo_metadata
klensy Jul 26, 2025
da1991d
check_static_item: explain should_check_for_sync choices
RalfJung Jul 27, 2025
296586f
miri: for ABI mismatch errors, say which argument is the problem
RalfJung Jul 27, 2025
5eb49b3
Rollup merge of #143289 - scottmcm:remove-array-chunks, r=jhpratt
jhpratt Jul 27, 2025
bc2e39f
Rollup merge of #143607 - JonathanBrouwer:proc_macro_attrs, r=jdonsze…
jhpratt Jul 27, 2025
52ca84a
Rollup merge of #144471 - tgross35:compiler-builtins-asm, r=Amanieu
jhpratt Jul 27, 2025
770c3a6
Rollup merge of #144495 - klensy:cargo_metadata, r=lqd
jhpratt Jul 27, 2025
ac60f4c
Rollup merge of #144523 - ojeda:rustdoc-target-modifiers, r=Guillaume…
jhpratt Jul 27, 2025
45c1788
Rollup merge of #144534 - RalfJung:should_check_for_sync, r=compiler-…
jhpratt Jul 27, 2025
e172e1e
Rollup merge of #144535 - RalfJung:abi-mismatch-err, r=compiler-errors
jhpratt Jul 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use the new attributes throughout the codebase
Signed-off-by: Jonathan Brouwer <[email protected]>
  • Loading branch information
JonathanBrouwer committed Jul 26, 2025
commit ec637000c6d5436b165a9b9ab4b008c036d22c99
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,17 @@ fn parse_derive_like<S: Stage>(
trait_name_mandatory: bool,
) -> Option<(Option<Symbol>, ThinVec<Symbol>)> {
let Some(list) = args.list() else {
// For #[rustc_builtin_macro], it is permitted to leave out the trait name
if args.no_args().is_ok() && !trait_name_mandatory {
return Some((None, ThinVec::new()));
}
cx.expected_list(cx.attr_span);
return None;
};
let mut items = list.mixed();

// Parse the name of the trait that is derived.
let Some(trait_attr) = items.next() else {
// For #[rustc_builtin_macro], it is permitted to leave out the trait name
if !trait_name_mandatory {
return None;
}
cx.expected_at_least_one_argument(list.span);
return None;
};
Expand Down
28 changes: 21 additions & 7 deletions compiler/rustc_builtin_macros/src/proc_macro_harness.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use std::mem;
use std::{mem, slice};

use rustc_ast::ptr::P;
use rustc_ast::visit::{self, Visitor};
use rustc_ast::{self as ast, NodeId, attr};
use rustc_ast::{self as ast, HasNodeId, NodeId, attr};
use rustc_ast_pretty::pprust;
use rustc_attr_data_structures::AttributeKind;
use rustc_attr_parsing::AttributeParser;
use rustc_errors::DiagCtxtHandle;
use rustc_expand::base::{ExtCtxt, ResolverExpand, parse_macro_name_and_helper_attrs};
use rustc_expand::base::{ExtCtxt, ResolverExpand};
use rustc_expand::expand::{AstFragment, ExpansionConfig};
use rustc_feature::Features;
use rustc_session::Session;
Expand All @@ -22,7 +24,7 @@ struct ProcMacroDerive {
trait_name: Symbol,
function_ident: Ident,
span: Span,
attrs: Vec<Symbol>,
attrs: ThinVec<Symbol>,
}

struct ProcMacroDef {
Expand All @@ -41,6 +43,7 @@ struct CollectProcMacros<'a> {
macros: Vec<ProcMacro>,
in_root: bool,
dcx: DiagCtxtHandle<'a>,
session: &'a Session,
source_map: &'a SourceMap,
is_proc_macro_crate: bool,
is_test_crate: bool,
Expand All @@ -63,6 +66,7 @@ pub fn inject(
macros: Vec::new(),
in_root: true,
dcx,
session: sess,
source_map: sess.source_map(),
is_proc_macro_crate,
is_test_crate,
Expand Down Expand Up @@ -98,8 +102,18 @@ impl<'a> CollectProcMacros<'a> {
function_ident: Ident,
attr: &'a ast::Attribute,
) {
let Some((trait_name, proc_attrs)) =
parse_macro_name_and_helper_attrs(self.dcx, attr, "derive")
let Some(rustc_hir::Attribute::Parsed(AttributeKind::ProcMacroDerive {
trait_name,
helper_attrs,
..
})) = AttributeParser::parse_limited(
self.session,
slice::from_ref(attr),
sym::proc_macro_derive,
item.span,
item.node_id(),
None,
)
else {
return;
};
Expand All @@ -110,7 +124,7 @@ impl<'a> CollectProcMacros<'a> {
span: item.span,
trait_name,
function_ident,
attrs: proc_attrs,
attrs: helper_attrs,
}));
} else {
let msg = if !self.in_root {
Expand Down
26 changes: 14 additions & 12 deletions compiler/rustc_expand/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,7 @@ impl SyntaxExtension {
/// | (unspecified) | no | if-ext | if-ext | yes |
/// | external | no | if-ext | if-ext | yes |
/// | yes | yes | yes | yes | yes |
fn get_collapse_debuginfo(sess: &Session, attrs: &[impl AttributeExt], ext: bool) -> bool {
fn get_collapse_debuginfo(sess: &Session, attrs: &[hir::Attribute], ext: bool) -> bool {
let flag = sess.opts.cg.collapse_macro_debuginfo;
let attr = ast::attr::find_by_name(attrs, sym::collapse_debuginfo)
.and_then(|attr| {
Expand All @@ -872,7 +872,7 @@ impl SyntaxExtension {
.ok()
})
.unwrap_or_else(|| {
if ast::attr::contains_name(attrs, sym::rustc_builtin_macro) {
if find_attr!(attrs, AttributeKind::RustcBuiltinMacro { .. }) {
CollapseMacroDebuginfo::Yes
} else {
CollapseMacroDebuginfo::Unspecified
Expand Down Expand Up @@ -915,16 +915,18 @@ impl SyntaxExtension {
let collapse_debuginfo = Self::get_collapse_debuginfo(sess, attrs, !is_local);
tracing::debug!(?name, ?local_inner_macros, ?collapse_debuginfo, ?allow_internal_unsafe);

let (builtin_name, helper_attrs) = ast::attr::find_by_name(attrs, sym::rustc_builtin_macro)
.map(|attr| {
// Override `helper_attrs` passed above if it's a built-in macro,
// marking `proc_macro_derive` macros as built-in is not a realistic use case.
parse_macro_name_and_helper_attrs(sess.dcx(), attr, "built-in").map_or_else(
|| (Some(name), Vec::new()),
|(name, helper_attrs)| (Some(name), helper_attrs),
)
})
.unwrap_or_else(|| (None, helper_attrs));
let (builtin_name, helper_attrs) = match find_attr!(attrs, AttributeKind::RustcBuiltinMacro { builtin_name, helper_attrs, .. } => (builtin_name, helper_attrs))
{
// Override `helper_attrs` passed above if it's a built-in macro,
// marking `proc_macro_derive` macros as built-in is not a realistic use case.
Some((Some(name), helper_attrs)) => {
(Some(*name), helper_attrs.iter().copied().collect())
}
Some((None, _)) => (Some(name), Vec::new()),

// Not a built-in macro
None => (None, helper_attrs),
};

let stability = find_attr!(attrs, AttributeKind::Stability { stability, .. } => *stability);

Expand Down
11 changes: 11 additions & 0 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1363,6 +1363,17 @@ impl AttributeExt for Attribute {
_ => None,
}
}

fn is_proc_macro_attr(&self) -> bool {
matches!(
self,
Attribute::Parsed(
AttributeKind::ProcMacro(..)
| AttributeKind::ProcMacroAttribute(..)
| AttributeKind::ProcMacroDerive { .. }
)
)
}
}

// FIXME(fn_delegation): use function delegation instead of manually forwarding
Expand Down
17 changes: 6 additions & 11 deletions compiler/rustc_metadata/src/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::io::{Read, Seek, Write};
use std::path::{Path, PathBuf};
use std::sync::Arc;

use rustc_attr_data_structures::EncodeCrossCrate;
use rustc_attr_data_structures::{AttributeKind, EncodeCrossCrate, find_attr};
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
use rustc_data_structures::memmap::{Mmap, MmapMut};
use rustc_data_structures::sync::{join, par_for_each_in};
Expand Down Expand Up @@ -1965,18 +1965,13 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
// Proc-macros may have attributes like `#[allow_internal_unstable]`,
// so downstream crates need access to them.
let attrs = tcx.hir_attrs(proc_macro);
let macro_kind = if ast::attr::contains_name(attrs, sym::proc_macro) {
let macro_kind = if find_attr!(attrs, AttributeKind::ProcMacro(..)) {
MacroKind::Bang
} else if ast::attr::contains_name(attrs, sym::proc_macro_attribute) {
} else if find_attr!(attrs, AttributeKind::ProcMacroAttribute(..)) {
MacroKind::Attr
} else if let Some(attr) = ast::attr::find_by_name(attrs, sym::proc_macro_derive) {
// This unwrap chain should have been checked by the proc-macro harness.
name = attr.meta_item_list().unwrap()[0]
.meta_item()
.unwrap()
.ident()
.unwrap()
.name;
} else if let Some(trait_name) = find_attr!(attrs, AttributeKind::ProcMacroDerive { trait_name, ..} => trait_name)
{
name = *trait_name;
MacroKind::Derive
} else {
bug!("Unknown proc-macro type for item {:?}", id);
Expand Down
5 changes: 4 additions & 1 deletion compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2024,7 +2024,10 @@ impl<'tcx> TyCtxt<'tcx> {
&& let Some(def_id) = def_id.as_local()
&& let outer = self.def_span(def_id).ctxt().outer_expn_data()
&& matches!(outer.kind, ExpnKind::Macro(MacroKind::Derive, _))
&& self.has_attr(outer.macro_def_id.unwrap(), sym::rustc_builtin_macro)
&& find_attr!(
self.get_all_attrs(outer.macro_def_id.unwrap()),
AttributeKind::RustcBuiltinMacro { .. }
)
{
true
} else {
Expand Down