Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
d7cf3cb
only rerun const eval if the const actually references opaques
sjwang05 Aug 16, 2026
e9a87d0
Add regression test for ambiguous trait with mixed import ids
lsunsi Sep 17, 2026
8aa2147
Add `f16` inline ASM support to `spirv.rs`
beetrees Sep 24, 2026
1161c07
Some refactorings around metadata encoding
aerooneqq Sep 30, 2026
7c35df5
Remove #[linkage = "internal"]
bjorn3 Sep 27, 2026
6d02b77
Remove #[linkage = "external"]
bjorn3 Sep 27, 2026
d731eda
Remove #[linkage = "common"]
bjorn3 Sep 27, 2026
3c67da6
Cover macro export on macro_rules definitions
darkraider01 Sep 30, 2026
7f542b6
Check declarative macro exports during attribute finalization
darkraider01 Sep 30, 2026
bf2b89c
Format macro export finalization check
darkraider01 Sep 30, 2026
109c917
Fix ICE for ambiguous candidates on method probing
lsunsi Sep 17, 2026
1ea0af2
Skip deferred attribute checks when not emitting
darkraider01 Sep 30, 2026
82366d5
Provide better doc code example for UnixDatagram::bind_addr and UnixL…
asder8215 Oct 1, 2026
0e70786
ping me for debugger visualizer changes
Walnut356 Oct 1, 2026
1dae79f
add test for overcapture suggestion inside attribute macro expansion
Albab-Hasan Oct 1, 2026
057e810
do not suggest precise capturing when the opaque span is inside a mac…
Albab-Hasan Oct 1, 2026
5764566
`const impl PartialEq` for `f16b`
Jamesbarford Sep 30, 2026
ed7a4d2
Rollup merge of #161380 - sjwang05:retry-consteval-less, r=jdonszelmann
GuillaumeGomez Oct 1, 2026
68c729a
Rollup merge of #162900 - aerooneqq:record-tables-through-macros, r=p…
GuillaumeGomez Oct 1, 2026
2a94a26
Rollup merge of #163580 - asder8215:unix_sockets_bind_addr_docs, r=Da…
GuillaumeGomez Oct 1, 2026
4964682
Rollup merge of #163584 - Walnut356:ping, r=lqd
GuillaumeGomez Oct 1, 2026
7c6f10e
Rollup merge of #162904 - lsunsi:issue162857, r=jackh726
GuillaumeGomez Oct 1, 2026
cd365c0
Rollup merge of #163281 - beetrees:f16-inline-asm-spirv, r=folkertdev
GuillaumeGomez Oct 1, 2026
dbdd1b9
Rollup merge of #163314 - darkraider01:check-macro-export, r=Jonathan…
GuillaumeGomez Oct 1, 2026
2063aa0
Rollup merge of #163405 - bjorn3:less_linkage_options, r=lqd
GuillaumeGomez Oct 1, 2026
7e5c9e0
Rollup merge of #163530 - Jamesbarford:bf16-const-cmp, r=folkertdev
GuillaumeGomez Oct 1, 2026
38ead00
Rollup merge of #163581 - Albab-Hasan:no-use-bound-suggestion-in-macr…
GuillaumeGomez Oct 1, 2026
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
1 change: 0 additions & 1 deletion compiler/rustc_attr_ir/src/data_structures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,6 @@ impl<ScopeId> StrippedCfgItem<ScopeId> {
#[derive(StableHash, PrintAttribute)]
pub enum Linkage {
AvailableExternally,
Common,
ExternalWeak,
External,
Internal,
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_attr_ir/src/encode_cross_crate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,6 @@ impl AttributeKind {
Linkage(linkage, _) => match *linkage {
crate::Linkage::Internal => false,
crate::Linkage::AvailableExternally
| crate::Linkage::Common
| crate::Linkage::External
| crate::Linkage::ExternalWeak
| crate::Linkage::LinkOnceAny
Expand Down
9 changes: 0 additions & 9 deletions compiler/rustc_attr_parsing/src/attributes/link_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -685,10 +685,7 @@ impl SingleAttributeParser for LinkageParser {
]);
const TEMPLATE: AttributeTemplate = template!(NameValueStr: [
"available_externally",
"common",
"extern_weak",
"external",
"internal",
"linkonce",
"linkonce_odr",
"weak",
Expand All @@ -711,10 +708,7 @@ impl SingleAttributeParser for LinkageParser {
// and don't have to be, LLVM treats them as no-ops.
let linkage = match value {
sym::available_externally => Linkage::AvailableExternally,
sym::common => Linkage::Common,
sym::extern_weak => Linkage::ExternalWeak,
sym::external => Linkage::External,
sym::internal => Linkage::Internal,
sym::linkonce => Linkage::LinkOnceAny,
sym::linkonce_odr => Linkage::LinkOnceODR,
sym::weak => Linkage::WeakAny,
Expand All @@ -725,10 +719,7 @@ impl SingleAttributeParser for LinkageParser {
name_value.value_span,
&[
sym::available_externally,
sym::common,
sym::extern_weak,
sym::external,
sym::internal,
sym::linkonce,
sym::linkonce_odr,
sym::weak,
Expand Down
19 changes: 17 additions & 2 deletions compiler/rustc_attr_parsing/src/attributes/macro_attrs.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use rustc_ast::ItemKind;
use rustc_attr_ir::{MacroUseArgs, find_attr};
use rustc_feature::AttributeStability;
use rustc_lint_defs::builtin::INVALID_MACRO_EXPORT_ARGUMENTS;
use rustc_lint_defs::builtin::{INVALID_MACRO_EXPORT_ARGUMENTS, UNUSED_ATTRIBUTES};
use rustc_structures::CollapseMacroDebuginfo;

use super::prelude::*;
use crate::diagnostics::MacroOnlyAttribute;
use crate::diagnostics::{MacroExport, MacroOnlyAttribute};

pub(crate) struct MacroEscapeParser;
impl NoArgsAttributeParser for MacroEscapeParser {
Expand Down Expand Up @@ -175,8 +176,22 @@ impl SingleAttributeParser for MacroExportParser {
return None;
}
};

Some(AttributeKind::MacroExport { span: cx.attr_span, local_inner_macros })
}

fn finalize_check(cx: &mut FinalizeCheckContext<'_, '_>, attr_span: Span) {
if cx.target != Target::MacroDef {
return;
}

let item = cx.target_item.unwrap();
if let ItemKind::MacroDef(_, macro_def) = &item.kind
&& !macro_def.macro_rules
{
cx.emit_lint(UNUSED_ATTRIBUTES, MacroExport::OnDeclMacro, attr_span);
}
}
}

pub(crate) struct CollapseDebugInfoParser;
Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_attr_parsing/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2070,3 +2070,10 @@ pub(crate) struct UnusedDuplicate {
)]
pub warning: bool,
}

#[derive(Diagnostic)]
pub(crate) enum MacroExport {
#[diag("`#[macro_export]` has no effect on declarative macro definitions")]
#[note("declarative macros follow the same exporting rules as regular items")]
OnDeclMacro,
}
34 changes: 18 additions & 16 deletions compiler/rustc_attr_parsing/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,23 +510,25 @@ impl<'sess> AttributeParser<'sess> {

// Now that all attributes have been parsed, run the deferred checks. These can
// inspect the fully parsed attributes via `FinalizeCheckContext::parsed_attrs`.
for (check, attr_span) in deferred_checks {
check(
&mut FinalizeCheckContext {
shared: SharedContext {
cx: self,
target_span,
target,
emit_lint: &mut emit_lint,
#[cfg(debug_assertions)]
has_lint_been_emitted: AtomicBool::new(false),
if !matches!(self.should_emit, ShouldEmit::Nothing) {
for (check, attr_span) in deferred_checks {
check(
&mut FinalizeCheckContext {
shared: SharedContext {
cx: self,
target_span,
target,
emit_lint: &mut emit_lint,
#[cfg(debug_assertions)]
has_lint_been_emitted: AtomicBool::new(false),
},
all_attrs: &attr_paths,
parsed_attrs: &attributes,
target_item,
},
all_attrs: &attr_paths,
parsed_attrs: &attributes,
target_item,
},
attr_span,
);
attr_span,
);
}
}

if !matches!(self.should_emit, ShouldEmit::Nothing) && target == Target::WherePredicate {
Expand Down
19 changes: 4 additions & 15 deletions compiler/rustc_codegen_gcc/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,14 @@ pub fn global_linkage_to_gcc(linkage: Linkage) -> GlobalKind {
| Linkage::LinkOnceODR
| Linkage::WeakAny
| Linkage::WeakODR
| Linkage::ExternalWeak
| Linkage::Common => GlobalKind::Exported,
| Linkage::ExternalWeak => GlobalKind::Exported,
}
}

/// The attribute a global *definition* needs on top of its [`GlobalKind`] to get this linkage.
#[cfg(feature = "master")]
pub fn global_linkage_attribute<'gcc>(linkage: Linkage) -> Option<VarAttribute<'gcc>> {
match linkage {
Linkage::Common => Some(VarAttribute::Common),
_ if linkage_needs_weak_attribute(linkage) => Some(VarAttribute::Weak),
_ => None,
}
if linkage_needs_weak_attribute(linkage) { Some(VarAttribute::Weak) } else { None }
}

/// The type of a function *definition* with an explicit `#[linkage]`.
Expand All @@ -85,26 +80,20 @@ pub fn linkage_to_gcc(linkage: Linkage) -> FunctionType {
| Linkage::LinkOnceODR
| Linkage::WeakAny
| Linkage::WeakODR
| Linkage::ExternalWeak
| Linkage::Common => FunctionType::Exported,
| Linkage::ExternalWeak => FunctionType::Exported,
}
}

/// Whether a definition with this linkage must carry the `weak` attribute, so that a strong
/// definition in another object file wins over it instead of clashing with it.
///
/// `common` is in here for functions only: GCC honours that attribute on a variable, but drops it
/// on a function, so a common function falls back to weak. Globals go through
/// `global_linkage_attribute` instead.
#[cfg(feature = "master")]
pub fn linkage_needs_weak_attribute(linkage: Linkage) -> bool {
match linkage {
Linkage::LinkOnceAny
| Linkage::LinkOnceODR
| Linkage::WeakAny
| Linkage::WeakODR
| Linkage::ExternalWeak
| Linkage::Common => true,
| Linkage::ExternalWeak => true,
Linkage::External | Linkage::AvailableExternally | Linkage::Internal => false,
}
}
Expand Down
21 changes: 2 additions & 19 deletions compiler/rustc_codegen_gcc/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ use rustc_hir::def_id::LOCAL_CRATE;
use rustc_log::tracing::trace;
use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs};
use rustc_middle::mir::interpret::{
self, Allocation, ConstAllocation, CtfeProvenance, ErrorHandled, Scalar as InterpScalar,
read_target_uint,
self, ConstAllocation, CtfeProvenance, ErrorHandled, Scalar as InterpScalar, read_target_uint,
};
use rustc_middle::mono::MonoItem;
use rustc_middle::ty::layout::LayoutOf;
Expand Down Expand Up @@ -113,12 +112,7 @@ impl<'gcc, 'tcx> StaticCodegenMethods for CodegenCx<'gcc, 'tcx> {
// NOTE: Alignment from attributes has already been applied to the allocation.
set_global_alignment(self, global, alloc.align);

// A common symbol is storage the linker allocates and zero-fills, so giving the definition
// an initializer — even an all-zero one — takes it back out of `.comm`. A non-zero one is
// kept: the symbol is then an ordinary definition, which is what GCC does with it too.
if attrs.linkage != Some(Linkage::Common) || !is_zero_initializer(alloc) {
global.global_set_initializer_rvalue(value);
}
global.global_set_initializer_rvalue(value);

// As an optimization, all shared statics which do not have interior
// mutability are placed into read-only memory.
Expand Down Expand Up @@ -458,17 +452,6 @@ pub(crate) fn const_alloc_to_gcc_uncached<'gcc>(
cx.const_struct(&llvals, true)
}

/// Whether this allocation is all zeroes, and so needs no initializer to be spelled out.
fn is_zero_initializer(alloc: &Allocation) -> bool {
alloc.provenance().ptrs().is_empty()
// This `inspect` is okay: it is within the bounds of the allocation, there is no provenance
// to misread, and it does not affect interpreter execution.
&& alloc
.inspect_with_uninit_and_ptr_outside_interpreter(0..alloc.size().bytes_usize())
.iter()
.all(|&byte| byte == 0)
}

fn codegen_static_initializer<'gcc, 'tcx>(
cx: &CodegenCx<'gcc, 'tcx>,
def_id: DefId,
Expand Down
3 changes: 0 additions & 3 deletions compiler/rustc_codegen_gcc/tests/c/import_linkage.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@

#include <stdint.h>

int32_t external_value = 1;
int32_t available_externally_value = 2;
int32_t linkonce_value = 3;
int32_t linkonce_odr_value = 4;
int32_t weak_value = 5;
int32_t weak_odr_value = 6;
int32_t common_value = 7;
int32_t extern_weak_value = 8;
int32_t internal_value = 9;
11 changes: 1 addition & 10 deletions compiler/rustc_codegen_gcc/tests/c/static_linkage.c
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
/* Strong definitions of the statics that `tests/run/static_linkage.rs` also defines, but weakly.
* The linker has to keep these and drop the Rust ones; a backend that emits the Rust definitions
* as ordinary global symbols fails the link with a duplicate definition instead.
*
* `internal_static` is the opposite case: the Rust side keeps its own, and the two definitions
* coexist because the Rust one is local. */
* as ordinary global symbols fails the link with a duplicate definition instead. */

#include <stdint.h>

int32_t weak_static = 1;
int32_t weak_odr_static = 2;
int32_t linkonce_static = 3;
int32_t linkonce_odr_static = 4;
int32_t common_static = 5;
int32_t internal_static = 200;

/* `available_externally` promises the real definition lives elsewhere: a backend may read this one
* or emit an equivalent copy of the Rust initializer, so the two have to hold the same value. */
Expand All @@ -29,9 +24,5 @@ int32_t c_read_all(void)
return 13;
if (linkonce_odr_static != 4)
return 14;
if (common_static != 5)
return 15;
if (internal_static != 200)
return 16;
return 0;
}
18 changes: 0 additions & 18 deletions compiler/rustc_codegen_gcc/tests/run/import_linkage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ extern crate mini_core;
use mini_core::*;

extern "C" {
#[linkage = "external"]
static external_value: *const i32;
#[linkage = "available_externally"]
static available_externally_value: *const i32;
#[linkage = "linkonce"]
Expand All @@ -31,15 +29,8 @@ extern "C" {
static weak_value: *const i32;
#[linkage = "weak_odr"]
static weak_odr_value: *const i32;
#[linkage = "common"]
static common_value: *const i32;
#[linkage = "extern_weak"]
static extern_weak_value: *const i32;
// An import is an undefined reference whatever the flavour says. Upstream bug: rustc lowers
// this one to an internal declaration, which LLVM's verifier rejects ("Global is external, but
// doesn't have external or weak linkage!") and which crashes cg_llvm at -O3.
#[linkage = "internal"]
static internal_value: *const i32;

// Nothing defines this one, so it stays null instead of breaking the link.
#[linkage = "extern_weak"]
Expand All @@ -49,9 +40,6 @@ extern "C" {
#[no_mangle]
extern "C" fn main(_argc: i32, _argv: *const *const u8) -> i32 {
unsafe {
if *external_value != 1 {
return 1;
}
if *available_externally_value != 2 {
return 2;
}
Expand All @@ -67,15 +55,9 @@ extern "C" fn main(_argc: i32, _argv: *const *const u8) -> i32 {
if *weak_odr_value != 6 {
return 6;
}
if *common_value != 7 {
return 7;
}
if *extern_weak_value != 8 {
return 8;
}
if *internal_value != 9 {
return 9;
}
if undefined_value as usize != 0 {
return 10;
}
Expand Down
16 changes: 1 addition & 15 deletions compiler/rustc_codegen_gcc/tests/run/static_linkage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
// `tests/c/static_linkage.c`, which defines the overridable ones strongly.
//
// If `predefine_static` were to ignore its `linkage` argument outright, every static would come out as
// an ordinary global symbol: the overridable ones would clash with the C definitions at link time, and
// `internal` would export a symbol it should have kept private.
// an ordinary global symbol: the overridable ones would clash with the C definitions at link time.

#![feature(linkage, no_core)]
#![no_std]
Expand All @@ -34,16 +33,6 @@ pub static linkonce_static: i32 = 0;
#[no_mangle]
pub static linkonce_odr_static: i32 = 0;

// `common` is only valid on a mutable global: LLVM rejects a constant one.
#[linkage = "common"]
#[no_mangle]
pub static mut common_static: i32 = 0;

// Private to this crate, so the C definition of the same name is a different object.
#[linkage = "internal"]
#[no_mangle]
pub static internal_static: i32 = 100;

// Not overridden by the C side: the definition here is the one that survives.
#[linkage = "weak"]
#[no_mangle]
Expand All @@ -66,9 +55,6 @@ extern "C" fn main(_argc: i32, _argv: *const *const u8) -> i32 {
return result;
}

if internal_static != 100 {
return 1;
}
if only_weak_static != 6 {
return 2;
}
Expand Down
3 changes: 0 additions & 3 deletions compiler/rustc_codegen_gcc/tests/run/weak_function_linkage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ extern "C" fn linkonce_odr_function() -> i32 {
4
}

// `#[linkage = "common"]` is absent on purpose: a common symbol is `SHN_COMMON`, which the object
// format only allows for objects, so no backend can give a function that linkage.

// Not overridden by the C side: the definition here is the one that runs.
#[linkage = "weak"]
#[no_mangle]
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_codegen_llvm/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ pub(crate) fn linkage_to_llvm(linkage: Linkage) -> llvm::Linkage {
Linkage::WeakODR => llvm::Linkage::WeakODRLinkage,
Linkage::Internal => llvm::Linkage::InternalLinkage,
Linkage::ExternalWeak => llvm::Linkage::ExternalWeakLinkage,
Linkage::Common => llvm::Linkage::CommonLinkage,
}
}

Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_codegen_ssa/src/mir/naked_asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ fn prefix_and_suffix<'tcx>(
// LTO can fail when internal linkage is used.
emit_fatal("naked functions may not have internal linkage")
}
Linkage::Common => emit_fatal("Functions may not have common linkage"),
Linkage::AvailableExternally => {
// this would make the function equal an extern definition
emit_fatal("Functions may not have available_externally linkage")
Expand Down
Loading
Loading