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
67e8a19
[bootstrap] Don't reverse the order of dylib search path entries
jnkel Aug 19, 2026
34bac0b
rework handling of doc attributes on macro calls
mejrs Aug 22, 2026
bb75ebf
loongarch: support passing `u128`/`i128` to inline assembly
heiher Aug 27, 2026
a1fb7b3
add test
qaijuang Aug 27, 2026
0f08915
do not load macro metadata for local definitions in rustdoc
qaijuang Aug 27, 2026
42629e3
better deal with internal features being injected into doctests
RalfJung Aug 27, 2026
a0ec511
fix rustc_lint_defs doctest issues
RalfJung Aug 27, 2026
cdd3fc0
std: uefi: fix File::seek returning the EOF sentinel
devnexen Aug 27, 2026
7047ae8
Add regression test for empty contract attributes with lifetime lints
chenyukang Aug 28, 2026
12f970e
Reject contract attributes without arguments
chenyukang Aug 28, 2026
9c6ebca
Add regression test for the Polonius help default
chenyukang Aug 28, 2026
d471202
fix ICE in generic_const_parameter_types with inherents
khyperia Aug 28, 2026
f31b77f
Report the configured Polonius default in -Z help
chenyukang Aug 28, 2026
66bbc14
Add rustdoc-html regression test for generated macro
GuillaumeGomez Aug 28, 2026
448757d
Retroactively add relnotes for `bool::{ok_or,ok_or_else}`
jieyouxu Aug 28, 2026
60980b5
Rollup merge of #161858 - khyperia:ice-generic_const_parameter_types,…
JonathanBrouwer Aug 28, 2026
339ca93
Rollup merge of #161377 - jnkel:fix-dylib-search-order, r=jieyouxu
JonathanBrouwer Aug 28, 2026
4e736c7
Rollup merge of #161514 - mejrs:move_doc_feature_gating, r=JonathanBr…
JonathanBrouwer Aug 28, 2026
b3470df
Rollup merge of #161865 - heiher:inline-asm-i128, r=folkertdev
JonathanBrouwer Aug 28, 2026
1eed132
Rollup merge of #161877 - qaijuang:156009-follow-up, r=GuillaumeGomez
JonathanBrouwer Aug 28, 2026
d73f3f2
Rollup merge of #161880 - RalfJung:rustc_lint_defs-doctests, r=Jonath…
JonathanBrouwer Aug 28, 2026
6744b61
Rollup merge of #161883 - RalfJung:doctest-internal-features, r=bjorn3
JonathanBrouwer Aug 28, 2026
f50f697
Rollup merge of #161887 - devnexen:uefi_seekfrom_fix, r=ChrisDenton
JonathanBrouwer Aug 28, 2026
4a0fda0
Rollup merge of #161897 - chenyukang:yukang/fix-contracts-ice-146834,…
JonathanBrouwer Aug 28, 2026
75c1006
Rollup merge of #161909 - chenyukang:yukang-fix-161543-polonius-help-…
JonathanBrouwer Aug 28, 2026
68e5367
Rollup merge of #161910 - GuillaumeGomez:generated-macro, r=Urgau
JonathanBrouwer Aug 28, 2026
f986cdd
Rollup merge of #161914 - jieyouxu:relnotes-1.98.0-bool, r=BoxyUwU
JonathanBrouwer Aug 28, 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 Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4026,7 +4026,6 @@ name = "rustc_expand"
version = "0.0.0"
dependencies = [
"rustc_ast",
"rustc_ast_passes",
"rustc_ast_pretty",
"rustc_attr_ir",
"rustc_attr_parsing",
Expand Down
2 changes: 2 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ Stabilized APIs
- [`Atomic<T>::get_mut_slice`](https://doc.rust-lang.org/stable/core/sync/atomic/struct.Atomic.html#method.get_mut_slice)
- [`Atomic<T>::from_mut_slice`](https://doc.rust-lang.org/stable/core/sync/atomic/struct.Atomic.html#method.from_mut_slice)
- [`std::range::legacy`](https://doc.rust-lang.org/stable/std/range/legacy/index.html)
- [`bool::ok_or`](https://doc.rust-lang.org/stable/std/primitive.bool.html#method.ok_or)
- [`bool::ok_or_else`](https://doc.rust-lang.org/stable/std/primitive.bool.html#method.ok_or_else)


<a id="1.98.0-Compatibility-Notes"></a>
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_arena/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#![cfg_attr(bootstrap, feature(never_type))]
#![cfg_attr(test, feature(test))]
#![deny(unsafe_op_in_unsafe_fn)]
#![doc(test(no_crate_inject, attr(deny(warnings), allow(internal_features))))]
#![doc(test(no_crate_inject, attr(deny(warnings))))]
#![feature(decl_macro)]
#![feature(dropck_eyepatch)]
#![feature(rustc_attrs)]
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//! This API is completely unstable and subject to change.

// tidy-alphabetical-start
#![doc(test(attr(deny(warnings), allow(internal_features))))]
#![doc(test(attr(deny(warnings))))]
#![feature(associated_type_defaults)]
#![feature(deref_patterns)]
#![feature(iter_order_by)]
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ use rustc_ast::mut_visit::{self, MutVisitor};
use rustc_ast::node_id::NodeMap;
use rustc_ast::visit::{self, Visitor};
use rustc_ast::{self as ast, *};
use rustc_attr_parsing::{AttributeParser, OmitDoc, Recovery, ShouldEmit};
use rustc_attr_parsing::{AttributeParser, Recovery, ShouldEmit};
use rustc_data_structures::fx::FxIndexMap;
use rustc_data_structures::sorted_map::SortedMap;
use rustc_data_structures::stable_hash::{StableHash, StableHasher};
Expand Down Expand Up @@ -1231,7 +1231,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
attrs,
target_span,
target,
OmitDoc::Lower,
|s| l.lower(s),
|lint_id, span, kind| {
self.delayed_lints.push(DelayedLint {
Expand Down
34 changes: 3 additions & 31 deletions compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ macro_rules! gate_multi {
}};
}

pub fn check_attribute(attr: &ast::Attribute, sess: &Session, features: &Features) {
PostExpansionVisitor { sess, features }.visit_attribute(attr)
}

struct PostExpansionVisitor<'a> {
sess: &'a Session,

Expand Down Expand Up @@ -152,33 +148,9 @@ impl<'a> PostExpansionVisitor<'a> {
}

impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
fn visit_attribute(&mut self, attr: &ast::Attribute) {
// Check unstable flavors of the `#[doc]` attribute.
if attr.has_name(sym::doc) {
for meta_item_inner in attr.meta_item_list().unwrap_or_default() {
macro_rules! gate_doc { ($($s:literal { $($name:ident => $feature:ident)* })*) => {
$($(if meta_item_inner.has_name(sym::$name) {
let msg = concat!("`#[doc(", stringify!($name), ")]` is ", $s);
gate!(self, $feature, attr.span, msg);
})*)*
}}

gate_doc!(
"experimental" {
cfg => doc_cfg
auto_cfg => doc_cfg
masked => doc_masked
notable_trait => doc_notable_trait
}
"meant for internal use only" {
attribute => rustdoc_internals
keyword => rustdoc_internals
fake_variadic => rustdoc_internals
search_unbox => rustdoc_internals
}
);
}
}
fn visit_attribute(&mut self, attr: &'a ast::Attribute) {
// Checked in attribute parsers, do NOT add checks here
visit::walk_attribute(self, attr)
}

fn visit_item(&mut self, i: &'a ast::Item) {
Expand Down
102 changes: 63 additions & 39 deletions compiler/rustc_attr_parsing/src/attributes/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ use rustc_attr_ir::{
DocInline, HideOrShow,
};
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, IndexEntry};
use rustc_errors::{Applicability, msg};
use rustc_errors::Applicability;
use rustc_feature::AttributeStability;
use rustc_lint_defs::builtin::{INVALID_DOC_ATTRIBUTES, UNUSED_ATTRIBUTES};
use rustc_session::diagnostics::feature_err;
use rustc_span::{Span, Symbol, edition, sym};

use super::prelude::{ALL_TARGETS, AllowedTargets};
Expand Down Expand Up @@ -526,19 +525,15 @@ impl DocParser {
}
macro_rules! no_args_and_crate_level {
($ident: ident) => {{
no_args_and_crate_level!($ident, |span| {});
}};
($ident: ident, |$span:ident| $extra_validation:block) => {{
if let Err(span) = args.as_no_args() {
expected_no_args(cx, span);
return;
}
let $span = path.span();
if !check_attr_crate_level(cx, $span) {
let span = path.span();
if !check_attr_crate_level(cx, span) {
return;
}
$extra_validation
self.attribute.$ident = Some($span);
self.attribute.$ident = Some(span);
}};
}
macro_rules! string_arg_and_crate_level {
Expand Down Expand Up @@ -569,6 +564,12 @@ impl DocParser {
self.attribute.$ident = Some((s, path.span()));
}};
}
macro_rules! gated {
($feature:ident $(,$notes:expr)*) => {
let stability = $crate::unstable!($feature $(, $notes)*);
cx.shared.cx.check_attribute_stability(&cx.attr_path, path.span(), stability);
};
}

match path.word_sym() {
Some(sym::alias) => self.parse_alias(cx, path, args),
Expand All @@ -583,37 +584,60 @@ impl DocParser {
}
Some(sym::inline) => self.parse_inline(cx, path, args, DocInline::Inline),
Some(sym::no_inline) => self.parse_inline(cx, path, args, DocInline::NoInline),
Some(sym::masked) => no_args!(masked),
Some(sym::cfg) => self.parse_cfg(cx, args),
Some(sym::notable_trait) => no_args!(notable_trait),
Some(sym::keyword) => parse_keyword_and_attribute(
cx,
path,
args,
&mut self.attribute.keyword,
sym::keyword,
),
Some(sym::attribute) => parse_keyword_and_attribute(
cx,
path,
args,
&mut self.attribute.attribute,
sym::attribute,
),
Some(sym::fake_variadic) => no_args_and_not_crate_level!(fake_variadic),
Some(sym::search_unbox) => no_args_and_not_crate_level!(search_unbox),
Some(sym::rust_logo) => no_args_and_crate_level!(rust_logo, |span| {
if !cx.features().rustdoc_internals() {
feature_err(
cx.sess(),
sym::rustdoc_internals,
span,
msg!("the `#[doc(rust_logo)]` attribute is used for Rust branding"),
)
.emit();
Some(sym::masked) => {
gated!(doc_masked);
no_args!(masked)
}
Some(sym::cfg) => {
gated!(doc_cfg);
self.parse_cfg(cx, args)
}
Some(sym::notable_trait) => {
gated!(doc_notable_trait);
no_args!(notable_trait)
}
Some(sym::keyword) => {
gated!(rustdoc_internals);
parse_keyword_and_attribute(
cx,
path,
args,
&mut self.attribute.keyword,
sym::keyword,
)
}
Some(sym::attribute) => {
gated!(rustdoc_internals);
parse_keyword_and_attribute(
cx,
path,
args,
&mut self.attribute.attribute,
sym::attribute,
)
}
Some(sym::fake_variadic) => {
gated!(rustdoc_internals);
no_args_and_not_crate_level!(fake_variadic)
}
Some(sym::search_unbox) => {
gated!(rustdoc_internals);
no_args_and_not_crate_level!(search_unbox)
}
Some(sym::rust_logo) => {
// FIXME: Only feature gated at the crate level (!!)
if cx.target == Target::Crate {
gated!(
rustdoc_internals,
"the `#[doc(rust_logo)]` attribute is used for Rust branding"
);
}
}),
Some(sym::auto_cfg) => self.parse_auto_cfg(cx, path, args),
no_args_and_crate_level!(rust_logo)
}
Some(sym::auto_cfg) => {
gated!(doc_cfg);
self.parse_auto_cfg(cx, path, args)
}
Some(sym::test) => {
let Some(list) = args.as_list() else {
cx.emit_lint(
Expand Down
6 changes: 0 additions & 6 deletions compiler/rustc_attr_parsing/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -864,12 +864,6 @@ impl<'p, 'sess: 'p> DerefMut for SharedContext<'p, 'sess> {
}
}

#[derive(PartialEq, Clone, Copy, Debug)]
pub enum OmitDoc {
Lower,
Skip,
}

#[derive(Copy, Clone, Debug)]
pub enum ShouldEmit {
/// The operations will emit errors, and lints, and errors are fatal.
Expand Down
34 changes: 17 additions & 17 deletions compiler/rustc_attr_parsing/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::context::{
use crate::diagnostics::ParsedDescription;
use crate::parser::{AllowExprMetavar, ArgParser, PathParser, RefPathParser};
use crate::synthetic::SyntheticAttrState;
use crate::{AttributeTemplate, OmitDoc, ShouldEmit};
use crate::{AttributeTemplate, ShouldEmit};

pub struct EmitAttribute(
pub Box<
Expand Down Expand Up @@ -161,7 +161,6 @@ impl<'sess> AttributeParser<'sess> {
attrs,
target_span,
target,
OmitDoc::Skip,
std::convert::identity,
|lint_id, span, kind| {
sess.psess.dyn_buffer_lint_sess(lint_id.lint, span, target_node_id, kind.0)
Expand Down Expand Up @@ -310,14 +309,12 @@ impl<'sess> AttributeParser<'sess> {

/// Parse a list of attributes.
///
/// `target_span` is the span of the thing this list of attributes is applied to,
/// and when `omit_doc` is set, doc attributes are filtered out.
/// `target_span` is the span of the thing this list of attributes is applied to.
pub fn parse_attribute_list(
&mut self,
attrs: &[ast::Attribute],
target_span: Span,
target: Target,
omit_doc: OmitDoc,
lower_span: impl Copy + Fn(Span) -> Span,
mut emit_lint: impl FnMut(LintId, MultiSpan, EmitAttribute),
) -> Vec<Attribute> {
Expand All @@ -335,23 +332,26 @@ impl<'sess> AttributeParser<'sess> {
}
}

// Sometimes, for example for `#![doc = include_str!("readme.md")]`,
// doc still contains a non-literal. You might say, when we're lowering attributes
// that's expanded right? But no, sometimes, when parsing attributes on macros,
// we already use the lowering logic and these are still there. So, when `omit_doc`
// is set we *also* want to ignore these.
let is_doc_attribute = attr.has_name(sym::doc);
if omit_doc == OmitDoc::Skip && is_doc_attribute {
fn is_doc_non_lit_expr(attr: &ast::Attribute) -> bool {
if !attr.has_name(sym::doc) {
return false;
}
let ast::AttrKind::Normal(n) = &attr.kind else { return false };
let ast::AttrArgs::Eq { expr, .. } = &n.item.args else { return false };
if matches!(expr.kind, ast::ExprKind::Lit(_)) {
return false;
};
true
}

// FIXME accidentally allowed on Stable Rust
if target == Target::MacroCall && is_doc_non_lit_expr(attr) {
continue;
}

let attr_span = lower_span(attr.span);
match &attr.kind {
ast::AttrKind::DocComment(comment_kind, symbol) => {
if omit_doc == OmitDoc::Skip {
continue;
}

attributes.push(Attribute::Parsed(AttributeKind::DocComment {
style: attr.style,
kind: DocFragmentKind::Sugared(*comment_kind),
Expand Down Expand Up @@ -407,7 +407,7 @@ impl<'sess> AttributeParser<'sess> {
// bla
// blob
// a
if is_doc_attribute
if attr.has_name(sym::doc)
&& let ArgParser::NameValue(nv) = &args
// If not a string key/value, it should emit an error, but to make
// things simpler, it's handled in `DocParser` because it's simpler to
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_attr_parsing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ pub use attributes::cfg::{
};
pub use attributes::cfg_select::*;
pub use attributes::util::{is_builtin_attr, parse_version};
pub use context::{OmitDoc, ShouldEmit};
pub use context::ShouldEmit;
pub use diagnostics::ParsedDescription;
pub use interface::{AttributeParser, EmitAttribute};
pub use rustc_parse::parser::Recovery;
Expand Down
16 changes: 15 additions & 1 deletion compiler/rustc_attr_parsing/src/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,24 @@ impl<'sess> AttributeParser<'sess> {
sym::prelude_import => ("the `prelude_import` attribute is for use by rustc only".to_string(), &[]),
sym::profiler_runtime => ("the `profiler_runtime` attribute is used to identify the `profiler_builtins` crate which contains the profiler runtime and will never be stable".to_string(), &[]),
sym::thread_local => ("the `thread_local` attribute is an experimental feature, and does not currently handle destructors".to_string(), &[]),
sym::rustdoc_internals => ("this subset of the `doc` attribute is meant for internal use only".to_string(), &[]),
sym::doc_notable_trait => ("the `doc(notable_trait)` attribute is experimental".to_string(), &[]),
sym::doc_cfg => ("the `doc(cfg)` and `doc(auto_cfg)` attributes are experimental".to_string(), &[]),
sym::doc_masked => ("the `doc(masked)` attribute is experimental".to_string(), &[]),
_ => (format!("the `{attr_path}` attribute is an experimental feature"), &[]),
};

let mut diag = feature_err(self.sess, gate_name, attr_path.span, explain);
// For unstable subsets of an attribute, point at that
let err_span = if matches!(
gate_name,
sym::rustdoc_internals | sym::doc_notable_trait | sym::doc_cfg | sym::doc_masked
) {
attr_span
} else {
attr_path.span
};

let mut diag = feature_err(self.sess, gate_name, err_span, explain);

// Remove the suggestion for `#![feature(staged_api)]` as these attributes are currently
// not usable outside std. If we do ever expose `#[stable]` etc under a different feature
Expand Down
15 changes: 15 additions & 0 deletions compiler/rustc_builtin_macros/src/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,21 @@ fn expand_contract_clause_tts(
annotated: TokenStream,
clause_keyword: rustc_span::Symbol,
) -> Result<TokenStream, ErrorGuaranteed> {
if annotation.is_empty() {
let (name, example) = if clause_keyword == kw::ContractRequires {
("requires", "condition")
} else {
("ensures", "|result: &T| condition")
};
ecx.sess.dcx().span_err(
attr_span,
format!("`{name}` attribute requires an argument, e.g., `#[{name}({example})]`"),
);
// Returning `Err` would replace it with a dummy fragment and cause cascading name-resolution errors.
// Instead, we return the original token stream so that there is no later noises.
return Ok(annotated);
}

let feature_span = ecx.with_def_site_ctxt(attr_span);
expand_contract_clause(ecx, attr_span, annotated, |new_tts| {
new_tts.push(TokenTree::Token(
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_expand/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ doctest = false
[dependencies]
# tidy-alphabetical-start
rustc_ast = { path = "../rustc_ast" }
rustc_ast_passes = { path = "../rustc_ast_passes" }
rustc_ast_pretty = { path = "../rustc_ast_pretty" }
rustc_attr_ir = { path = "../rustc_attr_ir" }
rustc_attr_parsing = { path = "../rustc_attr_parsing" }
Expand Down
Loading
Loading