Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
3339fa5
check args in new_coroutine_witness
lcnr Aug 12, 2025
f979bf0
`fn new_coroutine_witness_for_coroutine` woops
lcnr Aug 12, 2025
4d84149
add test
lcnr Aug 12, 2025
4d62bf1
All weak lang items have an explicit link name and vice versa
bjorn3 Aug 15, 2025
f3ef465
Combining no_mangle and rustc_std_internal_symbol is not allowed
bjorn3 Aug 15, 2025
460519a
Merge link_name and export_name
bjorn3 Aug 15, 2025
f94a0d0
Remove unused feature gate
bjorn3 Aug 15, 2025
ef3bb6f
Do not strip binaries in bootstrap everytime if they are unchanged
Kobzol Aug 15, 2025
b79ab44
stabilize const pathbuf osstring new
Kivooeo Aug 15, 2025
eb3e0d4
Properly recover from parenthesized use-bounds (precise capturing)
fmease Aug 15, 2025
e906a59
Fix `unicode_data.rs` mention message
Urgau Aug 16, 2025
3450975
remove `should_render` in `PrintAttribute` derive
fee1-dead Aug 16, 2025
f8f7c27
Clean up parsers related to generic bounds
fmease Aug 15, 2025
6c15339
Simplify decode_span.
cjgillot Aug 16, 2025
a843730
Simplify span_data_to_lines_and_cols.
cjgillot Aug 16, 2025
f35d001
Visit and print async_fut local for async drop.
cjgillot Aug 13, 2025
8792010
Rust build fails on OpenBSD after using file_lock feature
semarie Aug 16, 2025
9878616
resolve: debug for block module
bvanjoi Aug 17, 2025
cbfa17a
Reorder `lto` options from most to least optimizing
smoelius Aug 17, 2025
c7cd1b3
Do not consider a `T: !Sized` candidate to satisfy a `T: !MetaSized` …
zachs18 Aug 10, 2025
abecf68
Trace some basic I/O operations in bootstrap
Kobzol Aug 16, 2025
f0addd0
Make tool-only suggestion to remove attributes on invalid targets
JonathanBrouwer Aug 16, 2025
c1c204d
Port `must_use` to the new target checking
JonathanBrouwer Aug 16, 2025
d5dc797
Update uitests
JonathanBrouwer Aug 16, 2025
99de64b
Rollup merge of #145338 - lcnr:coroutine-witness-yikes, r=compiler-er…
jieyouxu Aug 19, 2025
6222733
Rollup merge of #145429 - bjorn3:codegen_fn_attrs_improvements, r=jdo…
jieyouxu Aug 19, 2025
b1a7bac
Rollup merge of #145452 - Kobzol:bootstrap-strip, r=jieyouxu
jieyouxu Aug 19, 2025
9a5c00a
Rollup merge of #145464 - Kivooeo:stabilize-const_pathbuf_osstring_ne…
jieyouxu Aug 19, 2025
b638266
Rollup merge of #145474 - fmease:paren-use-bounds-fix, r=fee1-dead
jieyouxu Aug 19, 2025
32c20b9
Rollup merge of #145486 - Urgau:unicode-mention, r=lqd
jieyouxu Aug 19, 2025
caabaf7
Rollup merge of #145490 - Kobzol:bootstrap-io-tracing, r=jieyouxu
jieyouxu Aug 19, 2025
3a3c4db
Rollup merge of #145493 - fee1-dead-contrib:push-rsqlqymxyyqp, r=jdon…
jieyouxu Aug 19, 2025
758866d
Rollup merge of #145500 - JonathanBrouwer:must_use_target, r=jdonszel…
jieyouxu Aug 19, 2025
3134f22
Rollup merge of #145505 - cjgillot:tweak-span-cache, r=petrochenkov
jieyouxu Aug 19, 2025
e3576b2
Rollup merge of #145510 - cjgillot:visit-async-drop, r=davidtwco
jieyouxu Aug 19, 2025
dc945d9
Rollup merge of #145511 - semarie:push-rnytptsoxrxn, r=joshtriplett
jieyouxu Aug 19, 2025
b709cf5
Rollup merge of #145532 - bvanjoi:debug-resolve-module, r=petrochenkov
jieyouxu Aug 19, 2025
e392952
Rollup merge of #145533 - smoelius:patch-2, r=lqd
jieyouxu Aug 19, 2025
4090d98
Rollup merge of #145537 - zachs18:metasized-negative-bound-fix, r=dav…
jieyouxu Aug 19, 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
2 changes: 2 additions & 0 deletions compiler/rustc_attr_parsing/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ attr_parsing_empty_attribute =

attr_parsing_invalid_target = `#[{$name}]` attribute cannot be used on {$target}
.help = `#[{$name}]` can {$only}be applied to {$applied}
.suggestion = remove the attribute
attr_parsing_invalid_target_lint = `#[{$name}]` attribute cannot be used on {$target}
.warn = {-attr_parsing_previously_accepted}
.help = `#[{$name}]` can {$only}be applied to {$applied}
.suggestion = remove the attribute

attr_parsing_empty_confusables =
expected at least one confusable name
Expand Down
20 changes: 18 additions & 2 deletions compiler/rustc_attr_parsing/src/attributes/must_use.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use rustc_errors::DiagArgValue;
use rustc_feature::{AttributeTemplate, template};
use rustc_hir::attrs::AttributeKind;
use rustc_hir::{MethodKind, Target};
use rustc_span::{Symbol, sym};

use crate::attributes::{AttributeOrder, OnDuplicate, SingleAttributeParser};
use crate::context::{ALL_TARGETS, AcceptContext, AllowedTargets, Stage};
use crate::context::MaybeWarn::{Allow, Error};
use crate::context::{AcceptContext, AllowedTargets, Stage};
use crate::parser::ArgParser;
use crate::session_diagnostics;
pub(crate) struct MustUseParser;
Expand All @@ -13,7 +15,21 @@ impl<S: Stage> SingleAttributeParser<S> for MustUseParser {
const PATH: &[Symbol] = &[sym::must_use];
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost;
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError;
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(ALL_TARGETS); //FIXME Still checked fully in `check_attr.rs`
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowListWarnRest(&[
Allow(Target::Fn),
Allow(Target::Enum),
Allow(Target::Struct),
Allow(Target::Union),
Allow(Target::Method(MethodKind::Trait { body: false })),
Allow(Target::Method(MethodKind::Trait { body: true })),
Allow(Target::Method(MethodKind::Inherent)),
Allow(Target::ForeignFn),
// `impl Trait` in return position can trip
// `unused_must_use` if `Trait` is marked as
// `#[must_use]`
Allow(Target::Trait),
Error(Target::WherePredicate),
]);
const TEMPLATE: AttributeTemplate = template!(
Word, NameValueStr: "reason",
"https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-must_use-attribute"
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_attr_parsing/src/lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pub fn emit_attribute_lint<L: LintEmitter>(lint: &AttributeLint<HirId>, lint_emi
target: target.plural_name(),
applied: applied.clone(),
only,
attr_span: *span,
},
),
}
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_attr_parsing/src/session_diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,13 +489,16 @@ pub(crate) struct InvalidTargetLint {
pub target: &'static str,
pub applied: String,
pub only: &'static str,
#[suggestion(code = "", applicability = "machine-applicable", style = "tool-only")]
pub attr_span: Span,
}

#[derive(Diagnostic)]
#[help]
#[diag(attr_parsing_invalid_target)]
pub(crate) struct InvalidTarget {
#[primary_span]
#[suggestion(code = "", applicability = "machine-applicable", style = "tool-only")]
pub span: Span,
pub name: Symbol,
pub target: &'static str,
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_builtin_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![doc(rust_logo)]
#![feature(assert_matches)]
#![feature(autodiff)]
#![feature(box_patterns)]
#![feature(decl_macro)]
#![feature(if_let_guard)]
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ pub(crate) fn llfn_attrs_from_instance<'ll, 'tcx>(
to_add.push(llvm::CreateAttrStringValue(cx.llcx, "wasm-import-module", module));

let name =
codegen_fn_attrs.link_name.unwrap_or_else(|| cx.tcx.item_name(instance.def_id()));
codegen_fn_attrs.symbol_name.unwrap_or_else(|| cx.tcx.item_name(instance.def_id()));
let name = name.as_str();
to_add.push(llvm::CreateAttrStringValue(cx.llcx, "wasm-import-name", name));
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,7 @@ pub fn is_call_from_compiler_builtins_to_upstream_monomorphization<'tcx>(
instance: Instance<'tcx>,
) -> bool {
fn is_llvm_intrinsic(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
if let Some(name) = tcx.codegen_fn_attrs(def_id).link_name {
if let Some(name) = tcx.codegen_fn_attrs(def_id).symbol_name {
name.as_str().starts_with("llvm.")
} else {
false
Expand Down
28 changes: 15 additions & 13 deletions compiler/rustc_codegen_ssa/src/codegen_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use rustc_ast::{LitKind, MetaItem, MetaItemInner, attr};
use rustc_hir::attrs::{AttributeKind, InlineAttr, InstructionSetAttr, UsedBy};
use rustc_hir::def::DefKind;
use rustc_hir::def_id::{DefId, LOCAL_CRATE, LocalDefId};
use rustc_hir::weak_lang_items::WEAK_LANG_ITEMS;
use rustc_hir::{self as hir, Attribute, LangItem, find_attr, lang_items};
use rustc_middle::middle::codegen_fn_attrs::{
CodegenFnAttrFlags, CodegenFnAttrs, PatchableFunctionEntry,
Expand Down Expand Up @@ -156,15 +155,21 @@ fn process_builtin_attrs(
match p {
AttributeKind::Cold(_) => codegen_fn_attrs.flags |= CodegenFnAttrFlags::COLD,
AttributeKind::ExportName { name, .. } => {
codegen_fn_attrs.export_name = Some(*name)
codegen_fn_attrs.symbol_name = Some(*name)
}
AttributeKind::Inline(inline, span) => {
codegen_fn_attrs.inline = *inline;
interesting_spans.inline = Some(*span);
}
AttributeKind::Naked(_) => codegen_fn_attrs.flags |= CodegenFnAttrFlags::NAKED,
AttributeKind::Align { align, .. } => codegen_fn_attrs.alignment = Some(*align),
AttributeKind::LinkName { name, .. } => codegen_fn_attrs.link_name = Some(*name),
AttributeKind::LinkName { name, .. } => {
// FIXME Remove check for foreign functions once #[link_name] on non-foreign
// functions is a hard error
if tcx.is_foreign_item(did) {
codegen_fn_attrs.symbol_name = Some(*name);
}
}
AttributeKind::LinkOrdinal { ordinal, span } => {
codegen_fn_attrs.link_ordinal = Some(*ordinal);
interesting_spans.link_ordinal = Some(*span);
Expand Down Expand Up @@ -382,7 +387,7 @@ fn apply_overrides(tcx: TyCtxt<'_>, did: LocalDefId, codegen_fn_attrs: &mut Code
// * `#[rustc_std_internal_symbol]` mangles the symbol name in a special way
// both for exports and imports through foreign items. This is handled further,
// during symbol mangling logic.
} else if codegen_fn_attrs.link_name.is_some() {
} else if codegen_fn_attrs.symbol_name.is_some() {
// * This can be overridden with the `#[link_name]` attribute
} else {
// NOTE: there's one more exception that we cannot apply here. On wasm,
Expand Down Expand Up @@ -437,7 +442,7 @@ fn check_result(
}

// error when specifying link_name together with link_ordinal
if let Some(_) = codegen_fn_attrs.link_name
if let Some(_) = codegen_fn_attrs.symbol_name
&& let Some(_) = codegen_fn_attrs.link_ordinal
{
let msg = "cannot use `#[link_name]` with `#[link_ordinal]`";
Expand Down Expand Up @@ -484,14 +489,11 @@ fn handle_lang_items(
// strippable by the linker.
//
// Additionally weak lang items have predetermined symbol names.
if let Some(lang_item) = lang_item {
if WEAK_LANG_ITEMS.contains(&lang_item) {
codegen_fn_attrs.flags |= CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL;
}
if let Some(link_name) = lang_item.link_name() {
codegen_fn_attrs.export_name = Some(link_name);
codegen_fn_attrs.link_name = Some(link_name);
}
if let Some(lang_item) = lang_item
&& let Some(link_name) = lang_item.link_name()
{
codegen_fn_attrs.flags |= CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL;
codegen_fn_attrs.symbol_name = Some(link_name);
}

// error when using no_mangle on a lang item item
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/foreign_modules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ impl ClashingExternDeclarations {
/// symbol's name.
fn name_of_extern_decl(tcx: TyCtxt<'_>, fi: hir::OwnerId) -> SymbolName {
if let Some((overridden_link_name, overridden_link_name_span)) =
tcx.codegen_fn_attrs(fi).link_name.map(|overridden_link_name| {
tcx.codegen_fn_attrs(fi).symbol_name.map(|overridden_link_name| {
// FIXME: Instead of searching through the attributes again to get span
// 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
Expand Down
60 changes: 20 additions & 40 deletions compiler/rustc_macros/src/print_attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use syn::spanned::Spanned;
use syn::{Data, Fields, Ident};
use synstructure::Structure;

fn print_fields(name: &Ident, fields: &Fields) -> (TokenStream, TokenStream, TokenStream) {
fn print_fields(name: &Ident, fields: &Fields) -> (TokenStream, TokenStream) {
let string_name = name.to_string();
let mut disps = vec![quote! {let mut __printed_anything = false;}];

Expand Down Expand Up @@ -43,7 +43,6 @@ fn print_fields(name: &Ident, fields: &Fields) -> (TokenStream, TokenStream, Tok
#(#disps)*
__p.word("}");
},
quote! { true },
)
}
Fields::Unnamed(fields_unnamed) => {
Expand Down Expand Up @@ -76,10 +75,9 @@ fn print_fields(name: &Ident, fields: &Fields) -> (TokenStream, TokenStream, Tok
#(#disps)*
__p.pclose();
},
quote! { true },
)
}
Fields::Unit => (quote! {}, quote! { __p.word(#string_name) }, quote! { true }),
Fields::Unit => (quote! {}, quote! { __p.word(#string_name) }),
}
}

Expand All @@ -89,51 +87,33 @@ pub(crate) fn print_attribute(input: Structure<'_>) -> TokenStream {
};

// Must be applied to an enum type.
let (code, printed) = match &input.ast().data {
let code = match &input.ast().data {
Data::Enum(e) => {
let (arms, printed) = e
let arms = e
.variants
.iter()
.map(|x| {
let ident = &x.ident;
let (pat, code, printed) = print_fields(ident, &x.fields);
let (pat, code) = print_fields(ident, &x.fields);

(
quote! {
Self::#ident #pat => {#code}
},
quote! {
Self::#ident #pat => {#printed}
},
)
quote! {
Self::#ident #pat => {#code}
}
})
.unzip::<_, _, Vec<_>, Vec<_>>();
.collect::<Vec<_>>();

(
quote! {
match self {
#(#arms)*
}
},
quote! {
match self {
#(#printed)*
}
},
)
quote! {
match self {
#(#arms)*
}
}
}
Data::Struct(s) => {
let (pat, code, printed) = print_fields(&input.ast().ident, &s.fields);
(
quote! {
let Self #pat = self;
#code
},
quote! {
let Self #pat = self;
#printed
},
)
let (pat, code) = print_fields(&input.ast().ident, &s.fields);
quote! {
let Self #pat = self;
#code
}
}
Data::Union(u) => {
return span_error(u.union_token.span(), "can't derive PrintAttribute on unions");
Expand All @@ -144,7 +124,7 @@ pub(crate) fn print_attribute(input: Structure<'_>) -> TokenStream {
input.gen_impl(quote! {
#[allow(unused)]
gen impl PrintAttribute for @Self {
fn should_render(&self) -> bool { #printed }
fn should_render(&self) -> bool { true }
fn print_attribute(&self, __p: &mut rustc_ast_pretty::pp::Printer) { #code }
}
})
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_metadata/src/native_libs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ impl<'tcx> Collector<'tcx> {
.link_ordinal
.map_or(import_name_type, |ord| Some(PeImportNameType::Ordinal(ord)));

let name = codegen_fn_attrs.link_name.unwrap_or_else(|| self.tcx.item_name(item));
let name = codegen_fn_attrs.symbol_name.unwrap_or_else(|| self.tcx.item_name(item));

if self.tcx.sess.target.binary_format == BinaryFormat::Elf {
let name = name.as_str();
Expand Down
17 changes: 6 additions & 11 deletions compiler/rustc_middle/src/middle/codegen_fn_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,10 @@ pub struct CodegenFnAttrs {
pub inline: InlineAttr,
/// Parsed representation of the `#[optimize]` attribute
pub optimize: OptimizeAttr,
/// The `#[export_name = "..."]` attribute, indicating a custom symbol a
/// function should be exported under
pub export_name: Option<Symbol>,
/// The `#[link_name = "..."]` attribute, indicating a custom symbol an
/// imported function should be imported as. Note that `export_name`
/// probably isn't set when this is set, this is for foreign items while
/// `#[export_name]` is for Rust-defined functions.
pub link_name: Option<Symbol>,
/// The name this function will be imported/exported under. This can be set
/// using the `#[export_name = "..."]` or `#[link_name = "..."]` attribute
/// depending on if this is a function definition or foreign function.
pub symbol_name: Option<Symbol>,
/// The `#[link_ordinal = "..."]` attribute, indicating an ordinal an
/// imported function has in the dynamic library. Note that this must not
/// be set when `link_name` is set. This is for foreign items with the
Expand Down Expand Up @@ -167,8 +163,7 @@ impl CodegenFnAttrs {
flags: CodegenFnAttrFlags::empty(),
inline: InlineAttr::None,
optimize: OptimizeAttr::Default,
export_name: None,
link_name: None,
symbol_name: None,
link_ordinal: None,
target_features: vec![],
safe_target_features: false,
Expand Down Expand Up @@ -196,7 +191,7 @@ impl CodegenFnAttrs {

self.flags.contains(CodegenFnAttrFlags::NO_MANGLE)
|| self.flags.contains(CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL)
|| self.export_name.is_some()
|| self.symbol_name.is_some()
|| match self.linkage {
// These are private, so make sure we don't try to consider
// them external.
Expand Down
5 changes: 4 additions & 1 deletion compiler/rustc_middle/src/mir/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,10 @@ impl<'tcx> TerminatorKind<'tcx> {
}
Yield { value, resume_arg, .. } => write!(fmt, "{resume_arg:?} = yield({value:?})"),
Unreachable => write!(fmt, "unreachable"),
Drop { place, .. } => write!(fmt, "drop({place:?})"),
Drop { place, async_fut: None, .. } => write!(fmt, "drop({place:?})"),
Drop { place, async_fut: Some(async_fut), .. } => {
write!(fmt, "async drop({place:?}; poll={async_fut:?})")
}
Call { func, args, destination, .. } => {
write!(fmt, "{destination:?} = ")?;
write!(fmt, "{func:?}(")?;
Expand Down
9 changes: 8 additions & 1 deletion compiler/rustc_middle/src/mir/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -531,13 +531,20 @@ macro_rules! make_mir_visitor {
unwind: _,
replace: _,
drop: _,
async_fut: _,
async_fut,
} => {
self.visit_place(
place,
PlaceContext::MutatingUse(MutatingUseContext::Drop),
location
);
if let Some(async_fut) = async_fut {
self.visit_local(
$(&$mutability)? *async_fut,
PlaceContext::MutatingUse(MutatingUseContext::Borrow),
location
);
}
}

TerminatorKind::Call {
Expand Down
Loading
Loading