Skip to content

Rollup of 9 pull requests #145519

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
970ac40
updated doc comment
Kivooeo Aug 2, 2025
8fb98ef
mbe: Parse macro `derive` rules
joshtriplett Aug 9, 2025
354fcf2
mbe: Handle applying `macro_rules` derives
joshtriplett Aug 10, 2025
c64c6d8
Use `LLVMSetTailCallKind`
Zalathar Aug 14, 2025
51bccdd
Port `#[custom_mir(..)]` to the new attribute system
scrabsha Aug 10, 2025
e193b53
Use `LLVMGetTypeKind`
Zalathar Aug 14, 2025
1d00627
add static glibc to the nix dev shell
WaffleLapkin Aug 15, 2025
8511e40
rustdoc-search: search backend with partitioned suffix tree
notriddle Nov 22, 2024
9fab380
Fix typo in doc for library/std/src/fs.rs#set_permissions
alurm Aug 15, 2025
5107ac9
Do not call `fs::remove_file` in `cp_link_filtered_recurse`
Kobzol Aug 15, 2025
cdea62d
Optimize `copy_src_dirs`
Kobzol Aug 15, 2025
e8f90b1
Don't show foreign types as an allowed target if the feature is not e…
JonathanBrouwer Aug 16, 2025
a69ba29
Fix deprecation attribute on foreign statics & types
JonathanBrouwer Aug 16, 2025
05dfcc9
Rollup merge of #144476 - notriddle:notriddle/stringdex, r=lolbinaryc…
Zalathar Aug 17, 2025
bbdcc8d
Rollup merge of #144838 - Kivooeo:doc-subtype, r=notriddle
Zalathar Aug 17, 2025
5dfe17f
Rollup merge of #145206 - scrabsha:push-uxovoqzrxnlx, r=jdonszelmann
Zalathar Aug 17, 2025
3ed9c10
Rollup merge of #145208 - joshtriplett:mbe-derive, r=petrochenkov
Zalathar Aug 17, 2025
1956eb2
Rollup merge of #145420 - Zalathar:llvm-c, r=WaffleLapkin
Zalathar Aug 17, 2025
b286f01
Rollup merge of #145451 - WaffleLapkin:norailoveyou, r=Noratrieb
Zalathar Aug 17, 2025
54d2396
Rollup merge of #145460 - Kobzol:bootstrap-speedup-copy-src-dirs, r=j…
Zalathar Aug 17, 2025
7b4ab9c
Rollup merge of #145476 - alurm:patch-1, r=ibraheemdev
Zalathar Aug 17, 2025
453e4fd
Rollup merge of #145485 - JonathanBrouwer:fix-deprecation-targets, r=…
Zalathar Aug 17, 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
10 changes: 10 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4812,6 +4812,7 @@ dependencies = [
"serde_json",
"sha2",
"smallvec",
"stringdex",
"tempfile",
"threadpool",
"tracing",
Expand Down Expand Up @@ -5225,6 +5226,15 @@ dependencies = [
"quote",
]

[[package]]
name = "stringdex"
version = "0.0.1-alpha4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2841fd43df5b1ff1b042e167068a1fe9b163dc93041eae56ab2296859013a9a0"
dependencies = [
"stacker",
]

[[package]]
name = "strsim"
version = "0.11.1"
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_attr_parsing/src/attributes/deprecation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ impl<S: Stage> SingleAttributeParser<S> for DeprecationParser {
Allow(Target::TyAlias),
Allow(Target::Use),
Allow(Target::ForeignFn),
Allow(Target::ForeignStatic),
Allow(Target::ForeignTy),
Allow(Target::Field),
Allow(Target::Trait),
Allow(Target::AssocTy),
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_attr_parsing/src/attributes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ pub(crate) mod no_implicit_prelude;
pub(crate) mod non_exhaustive;
pub(crate) mod path;
pub(crate) mod proc_macro_attrs;
pub(crate) mod prototype;
pub(crate) mod repr;
pub(crate) mod rustc_internal;
pub(crate) mod semantics;
Expand Down
140 changes: 140 additions & 0 deletions compiler/rustc_attr_parsing/src/attributes/prototype.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
//! Attributes that are only used on function prototypes.
use rustc_feature::{AttributeTemplate, template};
use rustc_hir::Target;
use rustc_hir::attrs::{AttributeKind, MirDialect, MirPhase};
use rustc_span::{Span, Symbol, sym};

use super::{AttributeOrder, OnDuplicate};
use crate::attributes::SingleAttributeParser;
use crate::context::{AcceptContext, AllowedTargets, MaybeWarn, Stage};
use crate::parser::ArgParser;

pub(crate) struct CustomMirParser;

impl<S: Stage> SingleAttributeParser<S> for CustomMirParser {
const PATH: &[rustc_span::Symbol] = &[sym::custom_mir];

const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost;

const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;

const ALLOWED_TARGETS: AllowedTargets =
AllowedTargets::AllowList(&[MaybeWarn::Allow(Target::Fn)]);

const TEMPLATE: AttributeTemplate = template!(List: &[r#"dialect = "...", phase = "...""#]);

fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
let Some(list) = args.list() else {
cx.expected_list(cx.attr_span);
return None;
};

let mut dialect = None;
let mut phase = None;
let mut failed = false;

for item in list.mixed() {
let Some(meta_item) = item.meta_item() else {
cx.expected_name_value(item.span(), None);
failed = true;
break;
};

if let Some(arg) = meta_item.word_is(sym::dialect) {
extract_value(cx, sym::dialect, arg, meta_item.span(), &mut dialect, &mut failed);
} else if let Some(arg) = meta_item.word_is(sym::phase) {
extract_value(cx, sym::phase, arg, meta_item.span(), &mut phase, &mut failed);
} else if let Some(word) = meta_item.path().word() {
let word = word.to_string();
cx.unknown_key(meta_item.span(), word, &["dialect", "phase"]);
failed = true;
} else {
cx.expected_name_value(meta_item.span(), None);
failed = true;
};
}

let dialect = parse_dialect(cx, dialect, &mut failed);
let phase = parse_phase(cx, phase, &mut failed);

if failed {
return None;
}

Some(AttributeKind::CustomMir(dialect, phase, cx.attr_span))
}
}

fn extract_value<S: Stage>(
cx: &mut AcceptContext<'_, '_, S>,
key: Symbol,
arg: &ArgParser<'_>,
span: Span,
out_val: &mut Option<(Symbol, Span)>,
failed: &mut bool,
) {
if out_val.is_some() {
cx.duplicate_key(span, key);
*failed = true;
return;
}

let Some(val) = arg.name_value() else {
cx.expected_single_argument(arg.span().unwrap_or(span));
*failed = true;
return;
};

let Some(value_sym) = val.value_as_str() else {
cx.expected_string_literal(val.value_span, Some(val.value_as_lit()));
*failed = true;
return;
};

*out_val = Some((value_sym, val.value_span));
}

fn parse_dialect<S: Stage>(
cx: &mut AcceptContext<'_, '_, S>,
dialect: Option<(Symbol, Span)>,
failed: &mut bool,
) -> Option<(MirDialect, Span)> {
let (dialect, span) = dialect?;

let dialect = match dialect {
sym::analysis => MirDialect::Analysis,
sym::built => MirDialect::Built,
sym::runtime => MirDialect::Runtime,

_ => {
cx.expected_specific_argument(span, vec!["analysis", "built", "runtime"]);
*failed = true;
return None;
}
};

Some((dialect, span))
}

fn parse_phase<S: Stage>(
cx: &mut AcceptContext<'_, '_, S>,
phase: Option<(Symbol, Span)>,
failed: &mut bool,
) -> Option<(MirPhase, Span)> {
let (phase, span) = phase?;

let phase = match phase {
sym::initial => MirPhase::Initial,
sym::post_cleanup => MirPhase::PostCleanup,
sym::optimized => MirPhase::Optimized,

_ => {
cx.expected_specific_argument(span, vec!["initial", "post-cleanup", "optimized"]);
*failed = true;
return None;
}
};

Some((phase, span))
}
5 changes: 5 additions & 0 deletions compiler/rustc_attr_parsing/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ use crate::attributes::path::PathParser as PathAttributeParser;
use crate::attributes::proc_macro_attrs::{
ProcMacroAttributeParser, ProcMacroDeriveParser, ProcMacroParser, RustcBuiltinMacroParser,
};
use crate::attributes::prototype::CustomMirParser;
use crate::attributes::repr::{AlignParser, ReprParser};
use crate::attributes::rustc_internal::{
RustcLayoutScalarValidRangeEnd, RustcLayoutScalarValidRangeStart,
Expand Down Expand Up @@ -167,6 +168,7 @@ attribute_parsers!(

// tidy-alphabetical-start
Single<CoverageParser>,
Single<CustomMirParser>,
Single<DeprecationParser>,
Single<DummyParser>,
Single<ExportNameParser>,
Expand Down Expand Up @@ -1060,6 +1062,9 @@ pub(crate) fn allowed_targets_applied(
if !features.stmt_expr_attributes() {
allowed_targets.retain(|t| !matches!(t, Target::Expression | Target::Statement));
}
if !features.extern_types() {
allowed_targets.retain(|t| !matches!(t, Target::ForeignTy));
}
}

// We define groups of "similar" targets.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1453,7 +1453,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
instance: Option<Instance<'tcx>>,
) {
let call = self.call(llty, fn_attrs, Some(fn_abi), llfn, args, funclet, instance);
llvm::LLVMRustSetTailCallKind(call, llvm::TailCallKind::MustTail);
llvm::LLVMSetTailCallKind(call, llvm::TailCallKind::MustTail);

match &fn_abi.ret.mode {
PassMode::Ignore | PassMode::Indirect { .. } => self.ret_void(),
Expand Down
19 changes: 12 additions & 7 deletions compiler/rustc_codegen_llvm/src/llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ pub(crate) enum ModuleFlagMergeBehavior {

// Consts for the LLVM CallConv type, pre-cast to usize.

/// Must match the layout of `LLVMTailCallKind`.
#[derive(Copy, Clone, PartialEq, Debug)]
#[repr(C)]
#[allow(dead_code)]
Expand Down Expand Up @@ -332,10 +333,15 @@ impl RealPredicate {
}
}

/// LLVMTypeKind
#[derive(Copy, Clone, PartialEq, Debug)]
/// Must match the layout of `LLVMTypeKind`.
///
/// Use [`RawEnum<TypeKind>`] for values of `LLVMTypeKind` returned from LLVM,
/// to avoid risk of UB if LLVM adds new enum values.
///
/// All of LLVM's variants should be declared here, even if no Rust-side code refers
/// to them, because unknown variants will cause [`RawEnum::to_rust`] to panic.
#[derive(Copy, Clone, PartialEq, Debug, TryFromU32)]
#[repr(C)]
#[expect(dead_code, reason = "Some variants are unused, but are kept to match LLVM-C")]
pub(crate) enum TypeKind {
Void = 0,
Half = 1,
Expand Down Expand Up @@ -1046,6 +1052,8 @@ unsafe extern "C" {
CanThrow: llvm::Bool,
) -> &'ll Value;

pub(crate) safe fn LLVMGetTypeKind(Ty: &Type) -> RawEnum<TypeKind>;

// Operations on integer types
pub(crate) fn LLVMInt1TypeInContext(C: &Context) -> &Type;
pub(crate) fn LLVMInt8TypeInContext(C: &Context) -> &Type;
Expand Down Expand Up @@ -1197,7 +1205,7 @@ unsafe extern "C" {
pub(crate) safe fn LLVMIsGlobalConstant(GlobalVar: &Value) -> Bool;
pub(crate) safe fn LLVMSetGlobalConstant(GlobalVar: &Value, IsConstant: Bool);
pub(crate) safe fn LLVMSetTailCall(CallInst: &Value, IsTailCall: Bool);
pub(crate) safe fn LLVMRustSetTailCallKind(CallInst: &Value, Kind: TailCallKind);
pub(crate) safe fn LLVMSetTailCallKind(CallInst: &Value, kind: TailCallKind);

// Operations on attributes
pub(crate) fn LLVMCreateStringAttribute(
Expand Down Expand Up @@ -1841,9 +1849,6 @@ unsafe extern "C" {
// Create and destroy contexts.
pub(crate) fn LLVMRustContextCreate(shouldDiscardNames: bool) -> &'static mut Context;

/// See llvm::LLVMTypeKind::getTypeID.
pub(crate) fn LLVMRustGetTypeKind(Ty: &Type) -> TypeKind;

// Operations on all values
pub(crate) fn LLVMRustGlobalAddMetadata<'a>(
Val: &'a Value,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/type_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ impl<'ll, CX: Borrow<SCx<'ll>>> BaseTypeCodegenMethods for GenericCx<'ll, CX> {
}

fn type_kind(&self, ty: &'ll Type) -> TypeKind {
unsafe { llvm::LLVMRustGetTypeKind(ty).to_generic() }
llvm::LLVMGetTypeKind(ty).to_rust().to_generic()
}

fn type_ptr(&self) -> &'ll Type {
Expand Down
23 changes: 23 additions & 0 deletions compiler/rustc_errors/src/diagnostic_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use rustc_abi::TargetDataLayoutErrors;
use rustc_ast::util::parser::ExprPrecedence;
use rustc_ast_pretty::pprust;
use rustc_hir::RustcVersion;
use rustc_hir::attrs::{MirDialect, MirPhase};
use rustc_macros::Subdiagnostic;
use rustc_span::edition::Edition;
use rustc_span::{Ident, MacroRulesNormalizedIdent, Span, Symbol};
Expand Down Expand Up @@ -312,6 +313,28 @@ impl IntoDiagArg for ExprPrecedence {
}
}

impl IntoDiagArg for MirDialect {
fn into_diag_arg(self, _path: &mut Option<PathBuf>) -> DiagArgValue {
let arg = match self {
MirDialect::Analysis => "analysis",
MirDialect::Built => "built",
MirDialect::Runtime => "runtime",
};
DiagArgValue::Str(Cow::Borrowed(arg))
}
}

impl IntoDiagArg for MirPhase {
fn into_diag_arg(self, _path: &mut Option<PathBuf>) -> DiagArgValue {
let arg = match self {
MirPhase::Initial => "initial",
MirPhase::PostCleanup => "post-cleanup",
MirPhase::Optimized => "optimized",
};
DiagArgValue::Str(Cow::Borrowed(arg))
}
}

#[derive(Clone)]
pub struct DiagSymbolList<S = Symbol>(Vec<S>);

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_expand/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ expand_invalid_fragment_specifier =
invalid fragment specifier `{$fragment}`
.help = {$help}
expand_macro_args_bad_delim = macro attribute argument matchers require parentheses
expand_macro_args_bad_delim = `{$rule_kw}` rule argument matchers require parentheses
expand_macro_args_bad_delim_sugg = the delimiters should be `(` and `)`
expand_macro_body_stability =
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_expand/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,7 @@ pub(crate) struct MacroArgsBadDelim {
pub span: Span,
#[subdiagnostic]
pub sugg: MacroArgsBadDelimSugg,
pub rule_kw: Symbol,
}

#[derive(Subdiagnostic)]
Expand Down
31 changes: 31 additions & 0 deletions compiler/rustc_expand/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use rustc_attr_parsing::{EvalConfigResult, ShouldEmit};
use rustc_data_structures::flat_map_in_place::FlatMapInPlace;
use rustc_errors::PResult;
use rustc_feature::Features;
use rustc_hir::def::MacroKinds;
use rustc_parse::parser::{
AttemptLocalParseRecovery, CommaRecoveryMode, ForceCollect, Parser, RecoverColon, RecoverComma,
token_descr,
Expand Down Expand Up @@ -565,6 +566,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
.map(|DeriveResolution { path, item, exts: _, is_const }| {
// FIXME: Consider using the derive resolutions (`_exts`)
// instead of enqueuing the derives to be resolved again later.
// Note that this can result in duplicate diagnostics.
let expn_id = LocalExpnId::fresh_empty();
derive_invocations.push((
Invocation {
Expand Down Expand Up @@ -922,6 +924,35 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
}
fragment
}
SyntaxExtensionKind::MacroRules(expander)
if expander.kinds().contains(MacroKinds::DERIVE) =>
{
if is_const {
let guar = self
.cx
.dcx()
.span_err(span, "macro `derive` does not support const derives");
return ExpandResult::Ready(fragment_kind.dummy(span, guar));
}
let body = item.to_tokens();
match expander.expand_derive(self.cx, span, &body) {
Ok(tok_result) => {
let fragment =
self.parse_ast_fragment(tok_result, fragment_kind, &path, span);
if macro_stats {
update_derive_macro_stats(
self.cx,
fragment_kind,
span,
&path,
&fragment,
);
}
fragment
}
Err(guar) => return ExpandResult::Ready(fragment_kind.dummy(span, guar)),
}
}
_ => unreachable!(),
},
InvocationKind::GlobDelegation { item, of_trait } => {
Expand Down
Loading
Loading