Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
66594ec
Escape grapheme extenders in `str::escape_debug`
Jules-Bertholet Jun 23, 2026
9c8eb44
Flatten and rename `compute_src_directory_via_git`
Zalathar Aug 24, 2026
7faee83
Replace another `#[cfg(test)]` with `if cfg!(test)`
Zalathar Aug 24, 2026
de13fc7
Add gram config to gitignore
clarfonthey Aug 25, 2026
dbea269
Check to ensure we're running against the correct LLVM version
jnkel Aug 25, 2026
5841e10
Look up and print path to wrong LLVM version
jnkel Aug 25, 2026
74ddcf2
Add test cases that demonstrate incorrect diagnostics
fmease Aug 26, 2026
3ff3976
Add regression test for "use of an internal attribute"
JonathanBrouwer Aug 28, 2026
ca095da
Add regression test for "expected item after attributes"
JonathanBrouwer Aug 28, 2026
bf56fa4
Handle multiple action records in EH personality function
nbdd0121 Aug 11, 2026
4f404c1
Use `drop_guard` in some places in {core,alloc,std}
GrigorenkoPV Aug 24, 2026
7b159d5
touch up "get attribute" docs.
mejrs Aug 30, 2026
9b62f13
remove a couple of redundant clones, thanks clippy
matthiaskrgr Aug 30, 2026
7ea63cc
Remove redundant braces from `NonZero` doctests
sorairolake Aug 30, 2026
58f825e
Add regression test for "use of an internal attribute" with a `macro_…
JonathanBrouwer Aug 30, 2026
9b70ab0
Revert "Add `rustc_test_entrypoint_marker`"
JonathanBrouwer Aug 28, 2026
08f3b0e
Unify and improve lint diagnostics for reserved prefixes
fmease Aug 25, 2026
3fca755
Fix the suggestion span used for splitting raw lifetimes apart
fmease Aug 25, 2026
e750bc2
Rollup merge of #160923 - nbdd0121:eh_personality, r=bjorn3
JonathanBrouwer Aug 30, 2026
6f607f4
Rollup merge of #161788 - jnkel:check-llvm-version, r=saethlin
JonathanBrouwer Aug 30, 2026
d378685
Rollup merge of #158303 - Jules-Bertholet:escape-grapheme-extender, r…
JonathanBrouwer Aug 30, 2026
a2551d1
Rollup merge of #161644 - Zalathar:compute-src, r=clubby789
JonathanBrouwer Aug 30, 2026
27e2dc8
Rollup merge of #161702 - GrigorenkoPV:drop-guard, r=clarfonthey
JonathanBrouwer Aug 30, 2026
7e0fcff
Rollup merge of #161713 - clarfonthey:gram-editor, r=Mark-Simulacrum
JonathanBrouwer Aug 30, 2026
dd9c329
Rollup merge of #161792 - fmease:fix-reserved-prefixes-lint-diags, r=…
JonathanBrouwer Aug 30, 2026
e36bc49
Rollup merge of #161931 - JonathanBrouwer:revert-test-entry-point, r=…
JonathanBrouwer Aug 30, 2026
ef26d83
Rollup merge of #162015 - mejrs:hasattr-docs, r=JonathanBrouwer
JonathanBrouwer Aug 30, 2026
aeb12e1
Rollup merge of #162019 - matthiaskrgr:rm_clones, r=JonathanBrouwer
JonathanBrouwer Aug 30, 2026
5c8197f
Rollup merge of #162023 - sorairolake:fix-nonzero-doctests, r=mejrs
JonathanBrouwer Aug 30, 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: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Session.vim
.vim/
.helix/
.zed/
.gram/
.favorites.json
.settings/
.vs/
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4430,6 +4430,7 @@ dependencies = [
"rustc_arena",
"rustc_ast",
"rustc_ast_ir",
"rustc_attr_ir",
"rustc_crate_store",
"rustc_data_structures",
"rustc_errors",
Expand Down
3 changes: 0 additions & 3 deletions compiler/rustc_attr_ir/src/data_structures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1420,9 +1420,6 @@ pub enum AttributeKind {
/// Represents `#[rustc_strict_coherence]`.
RustcStrictCoherence(Span),

/// Represents `#[rustc_test_entrypoint_marker]`
RustcTestEntrypointMarker,

/// Represents `#[rustc_test_marker]`
RustcTestMarker(Symbol),

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 @@ -191,7 +191,6 @@ impl AttributeKind {
RustcSpecializationTrait => No,
RustcStdInternalSymbol => No,
RustcStrictCoherence(..) => Yes,
RustcTestEntrypointMarker => No,
RustcTestMarker(..) => No,
RustcThenThisWouldNeed(..) => No,
RustcTrivialFieldReads => Yes,
Expand Down
72 changes: 45 additions & 27 deletions compiler/rustc_attr_ir/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Data structures for representing parsed attributes in the Rust compiler.
//!
//! For detailed documentation about attribute processing,
//! see [rustc_attr_parsing](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_attr_parsing/index.html).
//! see [rustc_attr_parsing](../rustc_attr_parsing/index.html).

// tidy-alphabetical-start
#![feature(const_default)]
Expand All @@ -20,7 +20,6 @@ pub use lang_items::*;
pub use pretty_printing::PrintAttribute;
pub use stability::*;

// FIXME remove pub on some of these modules? It's fairly inconsistent.
mod attr;
mod canonical_symbols;
mod data_structures;
Expand All @@ -35,40 +34,38 @@ pub mod weak_lang_items;

/// A trait for types that can provide a list of attributes given a `TyCtxt`.
///
/// It allows `find_attr!` to accept either a `DefId`, `LocalDefId`, `OwnerId`, or `HirId`.
/// It is defined here with a generic `Tcx` because `rustc_hir` can't depend on `rustc_middle`.
/// The concrete implementations are in `rustc_middle`.
/// It is an implementation detail of the [`find_attr!`] macro to be able to accept either a
/// [`DefId`], [`LocalDefId`], [`OwnerId`], or [`HirId`]. It is defined here with a generic `Tcx`
/// because this crate can't depend on `rustc_middle`. The concrete implementations are in
/// `rustc_middle`.
///
/// Not to be confused with [`rustc_ast::ast_traits::HasAttrs`].
///
/// [`DefId`]: rustc_span::def_id::DefId
/// [`LocalDefId`]: rustc_span::def_id::LocalDefId
/// [`OwnerId`]: ../rustc_hir/struct.OwnerId.html
/// [`HirId`]: ../rustc_hir/struct.HirId.html
pub trait HasAttrs<'tcx, Tcx> {
fn get_attrs(self, tcx: &Tcx) -> &'tcx [crate::attr::Attribute];
fn get_attrs(self, tcx: &Tcx) -> &'tcx [crate::Attribute];
}

/// Finds attributes in sequences of attributes by pattern matching.
/// Finds attributes by pattern matching.
///
/// A little like `matches` but for attributes.
///
/// ```rust,ignore (illustrative)
/// // finds the repr attribute
/// if let Some(r) = find_attr!(attrs, AttributeKind::Repr(r) => r) {
///
/// }
///
/// // checks if one has matched
/// if find_attr!(attrs, AttributeKind::Repr(_)) {
///
/// }
/// ```
/// Note that this macro accepts several "id" types: [`DefId`], [`LocalDefId`], [`OwnerId`] and
/// [`HirId`].
///
/// Often this requires you to first end up with a list of attributes.
/// Often these are available through the `tcx`.
/// # Examples
///
/// As a convenience, this macro can do that for you!
/// It is most commonly used to check whether something has an attribute or to get its contents
/// if it is present:
/// ```rust,ignore (illustrative)
/// let is_naked: bool = find_attr!(tcx, def_id, Naked(..));
///
/// Instead of providing an attribute list, provide the `tcx` and an id
/// (a `DefId`, `LocalDefId`, `OwnerId` or `HirId`).
/// let is_visible: bool = find_attr!(tcx, def_id, Doc(doc) if doc.hidden.is_none());
///
/// ```rust,ignore (illustrative)
/// find_attr!(tcx, def_id, <pattern>)
/// find_attr!(tcx, hir_id, <pattern>)
/// let link_name: Option<Symbol> = find_attr!(tcx, def_id, LinkName { name, .. } => *name);
/// ```
///
/// Another common case is finding attributes applied to the root of the current crate.
Expand All @@ -77,6 +74,27 @@ pub trait HasAttrs<'tcx, Tcx> {
/// ```rust, ignore (illustrative)
/// find_attr!(tcx, crate, <pattern>)
/// ```
///
/// If you already have a list of attributes in scope, you can also use that:
///
/// ```rust,ignore (illustrative)
/// let attrs = <list of attributes>;
///
/// // finds the repr attribute
/// if let Some(r) = find_attr!(attrs, Repr(r) => r) {
///
/// }
///
/// // checks if one has matched
/// if find_attr!(attrs, Repr(_)) {
///
/// }
/// ```
///
/// [`DefId`]: rustc_span::def_id::DefId
/// [`LocalDefId`]: rustc_span::def_id::LocalDefId
/// [`OwnerId`]: ../rustc_hir/struct.OwnerId.html
/// [`HirId`]: ../rustc_hir/struct.HirId.html
#[macro_export]
macro_rules! find_attr {
($tcx: expr, crate, $pattern: pat $(if $guard: expr)?) => {
Expand All @@ -89,14 +107,14 @@ macro_rules! find_attr {
($tcx: expr, $id: expr, $pattern: pat $(if $guard: expr)?) => {
$crate::find_attr!($tcx, $id, $pattern $(if $guard)? => ()).is_some()
};

($tcx: expr, $id: expr, $pattern: pat $(if $guard: expr)? => $e: expr) => {{
$crate::find_attr!(
$crate::HasAttrs::get_attrs($id, &$tcx),
$pattern $(if $guard)? => $e
)
}};


($attributes_list: expr, $pattern: pat $(if $guard: expr)?) => {{
$crate::find_attr!($attributes_list, $pattern $(if $guard)? => ()).is_some()
}};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ fn parse_directive_items<'p>(
WrappedParserError {
description: e.description,
label: e.label,
span: slice_span(input.span, e.span.clone(), is_snippet),
span: slice_span(input.span, e.span, is_snippet),
},
input.span,
);
Expand Down
11 changes: 0 additions & 11 deletions compiler/rustc_attr_parsing/src/attributes/test_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,3 @@ impl SingleAttributeParser for RustcTestMarkerParser {
Some(AttributeKind::RustcTestMarker(value_str))
}
}

pub(crate) struct RustcTestEntrypointMarkerParser;

impl NoArgsAttributeParser for RustcTestEntrypointMarkerParser {
const PATH: &[Symbol] = &[sym::rustc_test_entrypoint_marker];
const ALLOWED_TARGETS: AllowedTargets<'_> =
AllowedTargets::AllowList(&[Allow(Target::Fn), Allow(Target::Closure)]);
const ON_DUPLICATE: OnDuplicate = OnDuplicate::Warn;
const STABILITY: AttributeStability = unstable!(rustc_attrs);
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcTestEntrypointMarker;
}
1 change: 0 additions & 1 deletion compiler/rustc_attr_parsing/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,6 @@ attribute_parsers!(
Single<WithoutArgs<RustcSpecializationTraitParser>>,
Single<WithoutArgs<RustcStdInternalSymbolParser>>,
Single<WithoutArgs<RustcStrictCoherenceParser>>,
Single<WithoutArgs<RustcTestEntrypointMarkerParser>>,
Single<WithoutArgs<RustcTrivialFieldReadsParser>>,
Single<WithoutArgs<SplatParser>>,
Single<WithoutArgs<ThreadLocalParser>>,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_builtin_macros/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub(crate) fn expand_option_env<'cx>(
Err(guar) => return ExpandResult::Ready(DummyResult::any(sp, guar)),
};
let ExpandResult::Ready(mac) =
expr_to_string(cx, var_expr.clone(), "argument must be a string literal")
expr_to_string(cx, var_expr, "argument must be a string literal")
else {
return ExpandResult::Retry(());
};
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_builtin_macros/src/offload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ pub(crate) fn expand_kernel(
// host function
let mut host_fn = Box::new(ast::Fn {
defaultness: ast::Defaultness::Implicit,
sig: sig.clone(),
sig,
ident,
generics: generics.clone(),
generics,
contract: None,
body: Some(body),
define_opaque: None,
Expand Down Expand Up @@ -176,7 +176,7 @@ pub(crate) fn expand_kernel(
thin_vec![rustc_offload_kernel, inline_never],
ast::ItemKind::Fn(host_fn),
);
item.vis = vis.clone();
item.vis = vis;
Annotatable::Item(item)
};

Expand Down
9 changes: 0 additions & 9 deletions compiler/rustc_builtin_macros/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ use crate::util::{check_builtin_macro_attribute, warn_on_duplicate_attribute};
///
/// We mark item with an inert attribute "rustc_test_marker" which the test generation
/// logic will pick up on.
///
/// The test function also gains a `#[rustc_test_entrypoint_marker]` attribute for tools to pick up
/// on. This behavior is *unstable*.
pub(crate) fn expand_test_case(
ecx: &mut ExtCtxt<'_>,
attr_sp: Span,
Expand Down Expand Up @@ -380,12 +377,6 @@ pub(crate) fn expand_test_or_bench(
let test_extern =
cx.item(sp, ast::AttrVec::new(), ast::ItemKind::ExternCrate(None, test_ident));

let item = {
let mut item = item;
item.attrs.push(cx.attr_word(sym::rustc_test_entrypoint_marker, attr_sp));
item
};

debug!("synthetic test item:\n{}\n", pprust::item_to_string(&test_const));

if is_stmt {
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_codegen_llvm/src/llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,8 @@ unsafe extern "C" {
SLen: c_uint,
) -> MetadataKindId;

pub(crate) fn LLVMGetVersion(major: &mut c_uint, minor: &mut c_uint, patch: &mut c_uint);

pub(crate) fn LLVMDisposeTargetMachine(T: ptr::NonNull<TargetMachine>);

// Create modules.
Expand Down
25 changes: 25 additions & 0 deletions compiler/rustc_codegen_llvm/src/llvm_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,31 @@ unsafe fn configure_llvm(sess: &Session) {
let mut llvm_c_strs = Vec::with_capacity(n_args + 1);
let mut llvm_args = Vec::with_capacity(n_args + 1);

// Check to ensure we're running against the correct LLVM version.
unsafe {
let mut llvm_major = 0;
let mut llvm_minor = 0;
let mut llvm_patch = 0;
llvm::LLVMGetVersion(&mut llvm_major, &mut llvm_minor, &mut llvm_patch);
let expected_version = llvm::LLVMRustVersionMajor();
if llvm_major != expected_version {
panic!(
concat!(
"LLVM version mismatch: this compiler was built for LLVM {}, ",
"but LLVM {}.{}.{} was found{}"
),
expected_version,
llvm_major,
llvm_minor,
llvm_patch,
match rustc_session::filesearch::dll_path(llvm::LLVMGetVersion as *mut _) {
Ok(path) => format!(" at {}", path.display()),
Err(_) => String::new(),
}
);
}
}

unsafe {
llvm::LLVMRustInstallErrorHandlers();
}
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_feature/src/builtin_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,6 @@ pub static BUILTIN_ATTRIBUTES: &[Symbol] = &[
sym::prelude_import,
sym::rustc_paren_sugar,
sym::rustc_inherit_overflow_checks,
sym::rustc_test_entrypoint_marker,
sym::rustc_test_marker,
sym::rustc_allow_lifetime_dependent_specialization,
sym::rustc_specialization_trait,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3657,7 +3657,7 @@ declare_lint! {
Allow,
"identifiers that will be parsed as a prefix in Rust 2021",
@future_incompatible = FutureIncompatibleInfo {
reason: fcw!(EditionError 2021 "reserving-syntax"),
reason: fcw!(EditionSemanticsChange 2021 "reserving-syntax"),
};
crate_level_only
}
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_middle/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ rustc_apfloat = "0.2.0"
rustc_arena = { path = "../rustc_arena" }
rustc_ast = { path = "../rustc_ast" }
rustc_ast_ir = { path = "../rustc_ast_ir" }
rustc_attr_ir = { path = "../rustc_attr_ir" }
rustc_crate_store = { path = "../rustc_crate_store" }
rustc_data_structures = { path = "../rustc_data_structures" }
rustc_errors = { path = "../rustc_errors" }
Expand Down
12 changes: 8 additions & 4 deletions compiler/rustc_middle/src/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ use rustc_arena::TypedArena;
use rustc_ast as ast;
use rustc_ast::expand::allocator::AllocatorKind;
use rustc_ast::tokenstream::TokenStream;
use rustc_attr_ir::lang_items::{LangItem, LanguageItems};
use rustc_attr_ir::{CanonicalSymbols, EiiDecl, EiiImpl, StrippedCfgItem};
use rustc_crate_store::{
CrateDepKind, CrateSource, ExternCrate, ForeignModule, LinkagePreference, NativeLib,
};
Expand All @@ -63,8 +65,6 @@ use rustc_data_structures::svh::Svh;
use rustc_data_structures::unord::{UnordMap, UnordSet};
use rustc_errors::{ErrorGuaranteed, catch_fatal_errors};
use rustc_hir as hir;
use rustc_hir::attrs::lang_items::{LangItem, LanguageItems};
use rustc_hir::attrs::{CanonicalSymbols, EiiDecl, EiiImpl, StrippedCfgItem};
use rustc_hir::def::{DefKind, DocLinkResMap};
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, LocalDefIdSet, LocalModId};
use rustc_hir::{ItemLocalId, PreciseCapturingArgKind};
Expand Down Expand Up @@ -1524,8 +1524,12 @@ rustc_queries! {

/// Returns the attributes on the item at `def_id`.
///
/// Do not use this directly, use `tcx.get_attrs` instead.
query attrs_for_def(def_id: DefId) -> &'tcx [hir::Attribute] {
/// <div class="warning">
///
/// Do not use this directly, use [`rustc_attr_ir::find_attr`] instead.
///
/// </div>
query attrs_for_def(def_id: DefId) -> &'tcx [rustc_attr_ir::Attribute] {
desc { "collecting attributes of `{}`", tcx.def_path_str(def_id) }
separate_provide_extern
}
Expand Down
Loading
Loading