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
a812bac
Render `Deref` methods on aliased items
GuillaumeGomez Sep 30, 2026
0c442ea
Improve `is_doc_subtype_of` to work better for doc aliases
GuillaumeGomez Oct 2, 2026
a388dd0
Add new `is_deref[_mut]_trait` methods to simplify code
GuillaumeGomez Oct 2, 2026
6e5f760
Remove duplicated code to query `Deref` impls
GuillaumeGomez Oct 2, 2026
e1e1dc8
Remove `is_same_generic` test as it cannot work with the new argument…
GuillaumeGomez Oct 2, 2026
b747376
Add rustdoc-html test to illustrate known limits to dereferencing to …
GuillaumeGomez Oct 5, 2026
a4924b1
remove outdated documentation
cyrgani Oct 21, 2026
eecbff1
rename `expand_deriving_*` to `expand_derive_*`
cyrgani Oct 21, 2026
bdd7aa5
replace `combine_substructure` with `Box::new` and two type annotations
cyrgani Oct 22, 2026
e3e76c9
rename `combine_substructure` field to `body`
cyrgani Oct 22, 2026
97ba214
remove the `cs_` prefix terminology
cyrgani Oct 22, 2026
9b92b6d
remove other strange names in favor of `*_body`
cyrgani Oct 22, 2026
186f383
rename `cx.expr_addr_of` to `cx.expr_ref`
cyrgani Oct 24, 2026
4b7fbba
swap the order of type and ident in `MethodDef`
cyrgani Oct 27, 2026
27abbf3
inline `create_fields` and `create_struct_field_access_fields`
cyrgani Oct 24, 2026
360c8d5
inline the other two `FieldInfo` producers
cyrgani Oct 25, 2026
766f1bd
inline or rename some things
cyrgani Oct 30, 2026
c35fb45
change `create_method` to take `self` instead of `&self`
cyrgani Oct 30, 2026
ccaad2a
iterate over `params` once, not thrice
cyrgani Oct 30, 2026
2e1670b
Strenghten `deref` and `deref_mut` checks to ensure we don't compare …
GuillaumeGomez Nov 5, 2026
dc5ab20
Add multi-level `Deref` test
GuillaumeGomez Nov 5, 2026
88cbcf7
Reject unexpanded attributes in key-value attributes
fmease Oct 21, 2026
70382f6
library: std: process: Make Command::status platform specific
Ayush1325 Nov 8, 2026
be22bf5
library: std: sys: process: uefi: Add status impl
Ayush1325 Nov 8, 2026
48b0aa8
avoid repeated gated spans snapshots during macro matching
TaKO8Ki Nov 8, 2026
93e596a
Point at array length instead of whole array type
estebank Nov 5, 2026
104b112
Add regression test for issue 118449
maxdexh Nov 9, 2026
5ea937e
Make `Proxy` weak reference as it seems that it is not dropped at all
aerooneqq Nov 9, 2026
7f87df9
Only call `type_of` on `DefId` that actually are types (so not primit…
GuillaumeGomez Nov 9, 2026
cc47114
Add regression test for unsafe diagnostic attributes
JonathanBrouwer Nov 9, 2026
3c9f986
Rollup merge of #165161 - cyrgani:builtin-macros-9, r=nnethercote
JonathanBrouwer Nov 9, 2026
3ce8a80
Rollup merge of #165663 - TaKO8Ki:hoist-macro-gating-snapshot, r=nnet…
JonathanBrouwer Nov 9, 2026
17d8004
Rollup merge of #165637 - Ayush1325:uefi-tests, r=joboet
JonathanBrouwer Nov 9, 2026
6c0fa26
Rollup merge of #163571 - GuillaumeGomez:deref-on-aliased, r=Urgau
JonathanBrouwer Nov 9, 2026
d76eff8
Rollup merge of #164712 - fmease:early-attr-nested-attr, r=JonathanBr…
JonathanBrouwer Nov 9, 2026
972028e
Rollup merge of #165516 - estebank:point-at-arr-len, r=nnethercote
JonathanBrouwer Nov 9, 2026
01c23f5
Rollup merge of #165674 - maxdexh:issue-118449, r=JonathanBrouwer
JonathanBrouwer Nov 9, 2026
020840d
Rollup merge of #165676 - aerooneqq:make-proxy-weak-reference-in-help…
JonathanBrouwer Nov 9, 2026
26453bc
Rollup merge of #165695 - JonathanBrouwer:unsafe-diag, r=mejrs
JonathanBrouwer Nov 9, 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
13 changes: 13 additions & 0 deletions compiler/rustc_attr_parsing/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1931,6 +1931,19 @@ pub(crate) struct SuffixedLiteralInAttribute {
pub span: Span,
}

#[derive(Diagnostic)]
#[diag(
"{$count ->
[one] this attribute is
*[other] these attributes are
} not allowed in this context"
)]
pub(crate) struct AttributeInInvalidContext {
#[primary_span]
pub attrs: Vec<Span>,
pub count: usize,
}

#[derive(Diagnostic)]
#[diag("link name must not be empty", code = E0454)]
pub(crate) struct EmptyLinkName {
Expand Down
20 changes: 12 additions & 8 deletions compiler/rustc_attr_parsing/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ use std::convert::identity;
#[cfg(debug_assertions)]
use std::sync::atomic::{AtomicBool, Ordering};

use rustc_ast as ast;
use rustc_ast::token::DocFragmentKind;
use rustc_ast::{AttrStyle, CRATE_NODE_ID, NodeId, Safety};
use rustc_ast::{self as ast, AttrStyle, CRATE_NODE_ID, NodeId, Safety};
use rustc_attr_ir::target::{AstTarget, Target};
use rustc_attr_ir::{AttrArgs, AttrItem, AttrPath, Attribute, AttributeKind, HashIgnoredAttrId};
use rustc_data_structures::sync::{DynSend, DynSync};
Expand Down Expand Up @@ -600,18 +599,23 @@ impl<'sess> AttributeParser<'sess> {
// after it gets lowered to HIR. Therefore, we can extract literals to handle
// nonterminals in `#[doc]` (e.g. `#[doc = $e]`).
ast::AttrArgs::Eq { eq_span, expr } => {
// In valid code the value always ends up as a single literal. Otherwise, a dummy
// literal suffices because the error is handled elsewhere.
// We perform error handling elsewhere, not here, so we only delay bugs.

if let Err(diag) =
crate::validate_attr::check_attrs_on_rhs_expr(&self.sess.psess, expr)
{
diag.delay_as_bug();
}

let lit = if let ast::ExprKind::Lit(token_lit) = expr.kind
&& let Ok(lit) =
ast::MetaItemLit::from_token_lit(token_lit, lower_span(expr.span))
{
lit
} else {
let guar = self.dcx().span_delayed_bug(
args.span().unwrap_or(DUMMY_SP),
"expr in place where literal is expected (builtin attr parsing)",
);
let span = args.span().unwrap_or(DUMMY_SP);
let guar =
self.dcx().span_delayed_bug(span, "non-literal expr in key-value attr");
ast::MetaItemLit {
symbol: sym::dummy,
suffix: None,
Expand Down
12 changes: 9 additions & 3 deletions compiler/rustc_attr_parsing/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ impl ArgParser {
}
AttrArgs::Eq { eq_span, expr } => Self::NameValue(NameValueParser {
eq_span: *eq_span,
value: expr_to_lit(psess, expr, expr.span, should_emit)
value: expr_to_lit(psess, expr, should_emit)
.map_err(|e| should_emit.emit_err(e))
.ok()??,
value_span: expr.span,
Expand Down Expand Up @@ -408,9 +408,10 @@ impl NameValueParser {
fn expr_to_lit<'sess>(
psess: &'sess ParseSess,
expr: &Expr,
span: Span,
should_emit: ShouldEmit,
) -> PResult<'sess, Option<MetaItemLit>> {
crate::validate_attr::check_attrs_on_rhs_expr(psess, expr)?;

if let ExprKind::Lit(token_lit) = expr.kind {
let res = MetaItemLit::from_token_lit(token_lit, expr.span);
match res {
Expand Down Expand Up @@ -451,7 +452,7 @@ fn expr_to_lit<'sess>(
// - `#[foo = include_str!("nonexistent-file.rs")]`:
// results in `ast::ExprKind::Err`.
let msg = "attribute value must be a literal";
let mut err = psess.dcx().struct_span_err(span, msg);
let mut err = psess.dcx().struct_span_err(expr.span, msg);

// Suggest adding quotation marks to turn an identifier into a string literal
if let ExprKind::Path(None, ref path) = expr.kind
Expand Down Expand Up @@ -618,6 +619,11 @@ impl<'a, 'sess> MetaItemListParserContext<'a, 'sess> {
}

fn expected_lit(&mut self) -> Diag<'sess> {
// FIXME: We currently emit a very confusing diagnostic if somebody tries to apply an
// attribute to the literal. For example, given `#![doc(key = #[a] "..")]` we say
// "expected a literal (..) here, found expression" and highlight the string literal
// only.

let mut err = InvalidMetaItem {
span: self.parser.token.span,
descr: token_descr(&self.parser.token),
Expand Down
27 changes: 27 additions & 0 deletions compiler/rustc_attr_parsing/src/validate_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use std::convert::identity;
use std::slice;

use rustc_ast::SyntheticAttr::CfgAttrTrace;
use rustc_ast::token::Delimiter;
use rustc_ast::tokenstream::DelimSpan;
use rustc_ast::{
Expand Down Expand Up @@ -82,6 +83,8 @@ pub fn parse_meta<'a>(psess: &'a ParseSess, attr: &Attribute) -> PResult<'a, Met
MetaItemKind::List(nmis)
}
AttrArgs::Eq { expr, .. } => {
check_attrs_on_rhs_expr(psess, expr)?;

if let ast::ExprKind::Lit(token_lit) = expr.kind {
let res = ast::MetaItemLit::from_token_lit(token_lit, expr.span);

Expand Down Expand Up @@ -140,6 +143,30 @@ fn check_meta_bad_delim(psess: &ParseSess, span: DelimSpan, delim: Delimiter) {
});
}

pub(crate) fn check_attrs_on_rhs_expr<'sess>(
psess: &'sess ParseSess,
expr: &ast::Expr,
) -> PResult<'sess, ()> {
// Cfg traces are not real attrs, they're just a marker that cfg expansion has occurred which is
// perfectly legal, so don't trigger on them. We only need to worry about `cfg_attr` traces and
// not about `cfg` ones because macro expansion would've already bailed out with an error if
// there was a `cfg` on an expr.
let attrs: Vec<_> = expr
.attrs
.iter()
.filter(|attr| !matches!(attr.kind, AttrKind::Synthetic(CfgAttrTrace(_))))
.map(|attr| attr.span)
.collect();

if !attrs.is_empty() {
return Err(psess
.dcx()
.create_err(errors::AttributeInInvalidContext { count: attrs.len(), attrs }));
}

Ok(())
}

/// Checks that the given meta-item is compatible with this `AttributeTemplate`.
fn is_attr_template_compatible(template: &AttributeTemplate, meta: &ast::MetaItemKind) -> bool {
let is_one_allowed_subword = |items: &[MetaItemInner]| match items {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_builtin_macros/src/assert/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ impl<'cx, 'a> Context<'cx, 'a> {
self.span,
false,
local_bind,
self.cx.expr_addr_of(self.span, expr.clone()),
self.cx.expr_ref(self.span, expr.clone()),
));
let wrapper = self.cx.expr_call(
self.span,
Expand All @@ -377,7 +377,7 @@ impl<'cx, 'a> Context<'cx, 'a> {
.cx
.stmt_expr(self.cx.expr_method_call(
self.span,
self.cx.expr_paren(self.span, self.cx.expr_addr_of(self.span, wrapper)),
self.cx.expr_paren(self.span, self.cx.expr_ref(self.span, wrapper)),
Ident::new(sym::try_capture, self.span),
thin_vec![expr_addr_of_mut(
self.cx,
Expand Down
18 changes: 8 additions & 10 deletions compiler/rustc_builtin_macros/src/deriving/clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use thin_vec::{ThinVec, thin_vec};
use crate::deriving::generic::*;
use crate::deriving::path_std;

pub(crate) fn expand_deriving_clone(
pub(crate) fn expand_derive_clone(
cx: &ExtCtxt<'_>,
span: Span,
item: &ast::Item,
Expand All @@ -28,7 +28,7 @@ pub(crate) fn expand_deriving_clone(
// enough. Whether Clone is implemented for fields is irrelevant so we
// don't assert it.)
let bounds;
let substructure;
let body: MethodBodyFunc<'_>;
let is_simple;
match &item.kind {
ItemKind::Struct(_, Generics { params, .. }, _)
Expand All @@ -42,18 +42,16 @@ pub(crate) fn expand_deriving_clone(
.any(|param| matches!(param.kind, ast::GenericParamKind::Type { .. }))
{
is_simple = true;
substructure = combine_substructure(|c, s, sub| cs_clone_simple(c, s, sub, false));
body = Box::new(|c, s, sub| clone_simple_body(c, s, sub, false));
} else {
is_simple = false;
substructure = combine_substructure(|c, s, sub| {
cs_clone(c, s, sub, item.kind.ident().unwrap())
});
body = Box::new(|c, s, sub| clone_body(c, s, sub, item.kind.ident().unwrap()));
}
}
ItemKind::Union(..) => {
bounds = smallvec![path_std!(cx, span, marker::Copy)];
is_simple = true;
substructure = combine_substructure(|c, s, sub| cs_clone_simple(c, s, sub, true));
body = Box::new(|c, s, sub| clone_simple_body(c, s, sub, true));
}
_ => cx.dcx().span_bug(span, "`derive(Clone)` on wrong item kind"),
}
Expand Down Expand Up @@ -94,7 +92,7 @@ pub(crate) fn expand_deriving_clone(
ret_ty: cx.ty_self(span),
attributes: thin_vec![cx.generated_attr(span, ast::GeneratedAttr::Inline)],
fieldless_variants_strategy: FieldlessVariantsStrategy::Default,
combine_substructure: substructure,
body,
}],
is_const,
..
Expand All @@ -103,7 +101,7 @@ pub(crate) fn expand_deriving_clone(
trait_def.expand_ext(cx, item, push, is_simple)
}

fn cs_clone_simple(
fn clone_simple_body(
cx: &ExtCtxt<'_>,
trait_span: Span,
substr: Substructure<'_>,
Expand Down Expand Up @@ -162,7 +160,7 @@ fn cs_clone_simple(
BlockOrExpr::new_mixed(stmts, Some(cx.expr_deref(trait_span, cx.expr_self(trait_span))))
}

fn cs_clone(
fn clone_body(
cx: &ExtCtxt<'_>,
trait_span: Span,
substr: Substructure<'_>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::deriving::generic::*;
use crate::deriving::path_std;
use crate::diagnostics;

pub(crate) fn expand_deriving_coerce_pointee(
pub(crate) fn expand_derive_coerce_pointee(
cx: &ExtCtxt<'_>,
span: Span,
item: &ast::Item,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use rustc_span::Span;
use crate::deriving::generic::*;
use crate::deriving::path_std;

pub(crate) fn expand_deriving_const_param_ty(
pub(crate) fn expand_derive_const_param_ty(
cx: &ExtCtxt<'_>,
span: Span,
item: &ast::Item,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_builtin_macros/src/deriving/copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use rustc_span::Span;
use crate::deriving::generic::*;
use crate::deriving::path_std;

pub(crate) fn expand_deriving_copy(
pub(crate) fn expand_derive_copy(
cx: &ExtCtxt<'_>,
span: Span,
item: &ast::Item,
Expand Down
18 changes: 9 additions & 9 deletions compiler/rustc_builtin_macros/src/deriving/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use thin_vec::{ThinVec, thin_vec};
use crate::deriving::generic::*;
use crate::deriving::path_std;

pub(crate) fn expand_deriving_debug(
pub(crate) fn expand_derive_debug(
cx: &ExtCtxt<'_>,
span: Span,
item: &ast::Item,
Expand Down Expand Up @@ -39,12 +39,12 @@ pub(crate) fn expand_deriving_debug(
name: sym::fmt,
generics: cx.empty_generics(span),
explicit_self: true,
nonself_args: smallvec![(fmtr, sym::f)],
nonself_args: smallvec![(sym::f, fmtr)],
has_other_selflike_arg: false,
ret_ty: cx.ty_path(path_std!(cx, span, fmt::Result)),
attributes: thin_vec![cx.generated_attr(span, ast::GeneratedAttr::Inline)],
fieldless_variants_strategy: FieldlessVariantsStrategy::Default,
combine_substructure: combine_substructure(|cx, span, substr| show_substructure(
body: Box::new(|cx, span, substr| debug_body(
cx,
span,
substr,
Expand All @@ -57,7 +57,7 @@ pub(crate) fn expand_deriving_debug(
trait_def.expand_ext(cx, item, push, all_fieldless);
}

fn show_substructure(
fn debug_body(
cx: &ExtCtxt<'_>,
span: Span,
substr: Substructure<'_>,
Expand All @@ -71,7 +71,7 @@ fn show_substructure(
let (ident, vdata, fields) = match substr {
Struct(vdata, fields) => (type_ident, vdata, fields),
EnumMatching(v, fields) => (v.ident, &v.data, fields),
StaticEnum(enum_def) => return show_fieldless_enum(cx, span, enum_def, type_ident),
StaticEnum(enum_def) => return debug_fieldless_enum(cx, span, enum_def, type_ident),
_ => cx.dcx().span_bug(span, "unexpected substructure in `derive(Debug)`"),
};

Expand Down Expand Up @@ -107,7 +107,7 @@ fn show_substructure(
} else {
// Unsized types need an extra indirection, but only the last field
// may be unsized.
cx.expr_addr_of(field.span, field.self_expr)
cx.expr_ref(field.span, field.self_expr)
}
};

Expand Down Expand Up @@ -227,13 +227,13 @@ fn show_substructure(
/// }
/// }
/// ```
fn show_fieldless_enum(
fn debug_fieldless_enum(
cx: &ExtCtxt<'_>,
span: Span,
def: &EnumDef,
type_ident: Ident,
) -> BlockOrExpr {
if let Some(expr) = show_fieldless_enum_concat_str(cx, span, def, type_ident) {
if let Some(expr) = debug_fieldless_enum_concat_str(cx, span, def, type_ident) {
return BlockOrExpr::new_expr(expr);
}
let fmt = cx.expr_name(span, sym::f);
Expand Down Expand Up @@ -278,7 +278,7 @@ fn show_fieldless_enum(
/// }
/// }
/// ```
fn show_fieldless_enum_concat_str(
fn debug_fieldless_enum_concat_str(
cx: &ExtCtxt<'_>,
span: Span,
def: &EnumDef,
Expand Down
14 changes: 6 additions & 8 deletions compiler/rustc_builtin_macros/src/deriving/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use thin_vec::{ThinVec, thin_vec};
use crate::deriving::generic::*;
use crate::diagnostics;

pub(crate) fn expand_deriving_default(
pub(crate) fn expand_derive_default(
cx: &ExtCtxt<'_>,
span: Span,
item: &ast::Item,
Expand All @@ -35,18 +35,16 @@ pub(crate) fn expand_deriving_default(
ret_ty: cx.ty_self(span),
attributes: thin_vec![cx.generated_attr(span, ast::GeneratedAttr::Inline)],
fieldless_variants_strategy: FieldlessVariantsStrategy::Default,
combine_substructure: combine_substructure(|cx, trait_span, substr| {
body: Box::new(|cx, trait_span, substr| {
match substr {
StaticStruct(variant_data) => default_struct_substructure(
StaticStruct(variant_data) => default_struct_body(
cx,
trait_span,
variant_data,
// We cannot use `Self` here, see https://github.com/rust-lang/rust/issues/163800
item.kind.ident().unwrap(),
),
StaticEnum(enum_def) => {
default_enum_substructure(cx, trait_span, enum_def, item.span)
}
StaticEnum(enum_def) => default_enum_body(cx, trait_span, enum_def, item.span),
_ => cx
.dcx()
.span_bug(trait_span, "unexpected substructure in `derive(Default)`"),
Expand All @@ -65,7 +63,7 @@ fn default_call(cx: &ExtCtxt<'_>, span: Span) -> Box<ast::Expr> {
cx.expr_call_global(span, default_ident, ThinVec::new())
}

fn default_struct_substructure(
fn default_struct_body(
cx: &ExtCtxt<'_>,
trait_span: Span,
variant_data: &VariantData,
Expand Down Expand Up @@ -112,7 +110,7 @@ fn default_struct_substructure(
BlockOrExpr::new_expr(expr)
}

fn default_enum_substructure(
fn default_enum_body(
cx: &ExtCtxt<'_>,
trait_span: Span,
enum_def: &EnumDef,
Expand Down
Loading
Loading