Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
c0b383c
Add more info about where autodiff can be applied
ZuseZ4 Apr 4, 2026
3a7ffdc
add current autodiff limitations
ZuseZ4 Apr 4, 2026
c324d6e
Simplify attribute validation
JonathanBrouwer Apr 3, 2026
abb15f5
Remove `emit_fatal_malformed_builtin_attribute`
JonathanBrouwer Apr 4, 2026
cb87c36
Remove template from BUILTIN_ATTRIBUTES
JonathanBrouwer Apr 4, 2026
f967bf3
Remove EncodeCrossCrate from BUILTIN_ATTRIBUTES
JonathanBrouwer Apr 4, 2026
eecf63c
Remove AttributeDuplicates from BUILTIN_ATTRIBUTES
JonathanBrouwer Apr 4, 2026
9058b5f
Remove AttributeType from BUILTIN_ATTRIBUTES
JonathanBrouwer Apr 4, 2026
dfa2e24
Enable diagnostic::on_const for local impls
mejrs Mar 30, 2026
14ab39c
on_const doesn't support parent_label
mejrs Mar 30, 2026
4bc2a55
Fix diagnostic::on_const label span
mejrs Apr 6, 2026
8930f50
c-b: Export inverse hyperbolic trigonometric functions
tgross35 Apr 7, 2026
6b6bf8d
Remove unused attribute check for unparsed builtin attributes
JonathanBrouwer Apr 4, 2026
89db636
Reformat builtin_attrs.rs
JonathanBrouwer Apr 7, 2026
fe1e292
Revert performing basic const checks in typeck on stable
oli-obk Apr 7, 2026
7f06f55
Remove not needed PhantomData
aerooneqq Apr 7, 2026
7ce2d51
add regression test
Kcang-gna Apr 6, 2026
db37383
Fix pin docs
guiyuanju Apr 7, 2026
eacf5b8
Generate more verbose error delegation
aerooneqq Apr 7, 2026
03b453c
Fix no results when searching for == in doc
chenyukang Apr 7, 2026
3ee4e6a
Rollup merge of #150965 - chenyukang:yukang-fix-doc-search-150921, r=…
JonathanBrouwer Apr 7, 2026
c21ff2b
Rollup merge of #154928 - guiyuanju:fix-pin-doc, r=chenyukang
JonathanBrouwer Apr 7, 2026
f94542c
Rollup merge of #154930 - oli-obk:revert-const-check, r=chenyukang
JonathanBrouwer Apr 7, 2026
5847690
Rollup merge of #154942 - aerooneqq:delegation-unlowered-path-ice, r=…
JonathanBrouwer Apr 7, 2026
7bc2be9
Rollup merge of #154609 - mejrs:local_on_const, r=fmease
JonathanBrouwer Apr 7, 2026
67f2a16
Rollup merge of #154795 - ZuseZ4:autodiff-general-docs, r=oli-obk
JonathanBrouwer Apr 7, 2026
602d0d4
Rollup merge of #154808 - JonathanBrouwer:attr_cleanup, r=jdonszelmann
JonathanBrouwer Apr 7, 2026
fca347a
Rollup merge of #154866 - Kcang-gna:add-regression-test-for-#146514, …
JonathanBrouwer Apr 7, 2026
0bacabe
Rollup merge of #154922 - tgross35:builtins-inverse-trig, r=RalfJung
JonathanBrouwer Apr 7, 2026
79aa68b
Rollup merge of #154931 - aerooneqq:delegation-small-cleanup, r=petro…
JonathanBrouwer Apr 7, 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
75 changes: 34 additions & 41 deletions compiler/rustc_ast_lowering/src/delegation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
//! also be emitted during HIR ty lowering.

use std::iter;
use std::marker::PhantomData;

use ast::visit::Visitor;
use hir::def::{DefKind, PartialRes, Res};
Expand Down Expand Up @@ -128,14 +127,12 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
{
self.get_sig_id(delegation_info.resolution_node, span)
} else {
return self.generate_delegation_error(
self.dcx().span_delayed_bug(
span,
format!("LoweringContext: the delegation {:?} is unresolved", item_id),
),
self.dcx().span_delayed_bug(
span,
delegation,
format!("LoweringContext: the delegation {:?} is unresolved", item_id),
);

return self.generate_delegation_error(span, delegation);
};

match sig_id {
Expand Down Expand Up @@ -172,7 +169,7 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {

DelegationResults { body_id, sig, ident, generics }
}
Err(err) => self.generate_delegation_error(err, span, delegation),
Err(_) => self.generate_delegation_error(span, delegation),
}
}

Expand Down Expand Up @@ -420,7 +417,6 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
resolver: this.resolver,
path_id: delegation.id,
self_param_id: pat_node_id,
phantom: PhantomData,
};
self_resolver.visit_block(block);
// Target expr needs to lower `self` path.
Expand Down Expand Up @@ -604,7 +600,6 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {

fn generate_delegation_error(
&mut self,
err: ErrorGuaranteed,
span: Span,
delegation: &Delegation,
) -> DelegationResults<'hir> {
Expand All @@ -622,36 +617,35 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
let ident = self.lower_ident(delegation.ident);

let body_id = self.lower_body(|this| {
let body_expr = match delegation.body.as_ref() {
Some(box block) => {
// Generates a block when we failed to resolve delegation, where a target expression is its only statement,
// thus there will be no ICEs on further stages of analysis (see #144594)

// As we generate a void function we want to convert target expression to statement to avoid additional
// errors, such as mismatched return type
let stmts = this.arena.alloc_from_iter([hir::Stmt {
hir_id: this.next_id(),
kind: rustc_hir::StmtKind::Semi(
this.arena.alloc(this.lower_target_expr(block)),
),
span,
}]);

let block = this.arena.alloc(hir::Block {
stmts,
expr: None,
hir_id: this.next_id(),
rules: hir::BlockCheckMode::DefaultBlock,
span,
targeted_by_break: false,
});
let path = this.lower_qpath(
delegation.id,
&delegation.qself,
&delegation.path,
ParamMode::Optional,
AllowReturnTypeNotation::No,
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
None,
);

hir::ExprKind::Block(block, None)
}
None => hir::ExprKind::Err(err),
let callee_path = this.arena.alloc(this.mk_expr(hir::ExprKind::Path(path), span));
let args = if let Some(box block) = delegation.body.as_ref() {
this.arena.alloc_slice(&[this.lower_target_expr(block)])
} else {
&mut []
};

(&[], this.mk_expr(body_expr, span))
let call = this.arena.alloc(this.mk_expr(hir::ExprKind::Call(callee_path, args), span));

let block = this.arena.alloc(hir::Block {
stmts: &[],
expr: Some(call),
hir_id: this.next_id(),
rules: hir::BlockCheckMode::DefaultBlock,
span,
targeted_by_break: false,
});

(&[], this.mk_expr(hir::ExprKind::Block(block, None), span))
});

let generics = hir::Generics::empty();
Expand All @@ -673,14 +667,13 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
}
}

struct SelfResolver<'a, 'tcx, R> {
struct SelfResolver<'a, R> {
resolver: &'a mut R,
path_id: NodeId,
self_param_id: NodeId,
phantom: PhantomData<&'tcx ()>,
}

impl<'tcx, R: ResolverAstLoweringExt<'tcx>> SelfResolver<'_, 'tcx, R> {
impl<'tcx, R: ResolverAstLoweringExt<'tcx>> SelfResolver<'_, R> {
fn try_replace_id(&mut self, id: NodeId) {
if let Some(res) = self.resolver.get_partial_res(id)
&& let Some(Res::Local(sig_id)) = res.full_res()
Expand All @@ -692,7 +685,7 @@ impl<'tcx, R: ResolverAstLoweringExt<'tcx>> SelfResolver<'_, 'tcx, R> {
}
}

impl<'ast, 'a, 'tcx, R: ResolverAstLoweringExt<'tcx>> Visitor<'ast> for SelfResolver<'a, 'tcx, R> {
impl<'ast, 'tcx, R: ResolverAstLoweringExt<'tcx>> Visitor<'ast> for SelfResolver<'_, R> {
fn visit_id(&mut self, id: NodeId) {
self.try_replace_id(id);
}
Expand Down
61 changes: 14 additions & 47 deletions compiler/rustc_attr_parsing/src/validate_attr.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
//! Meta-syntax validation logic of attributes for post-expansion.

use std::convert::identity;
use std::slice;

use rustc_ast::token::Delimiter;
use rustc_ast::tokenstream::DelimSpan;
use rustc_ast::{
self as ast, AttrArgs, Attribute, DelimArgs, MetaItem, MetaItemInner, MetaItemKind, Safety,
};
use rustc_errors::{Applicability, FatalError, PResult};
use rustc_feature::{AttributeTemplate, BUILTIN_ATTRIBUTE_MAP, BuiltinAttribute};
use rustc_errors::{Applicability, PResult};
use rustc_feature::{AttributeTemplate, BUILTIN_ATTRIBUTE_MAP};
use rustc_hir::AttrPath;
use rustc_hir::lints::AttributeLintKind;
use rustc_parse::parse_in;
Expand All @@ -19,43 +18,23 @@ use rustc_session::lint::builtin::ILL_FORMED_ATTRIBUTE_INPUT;
use rustc_session::parse::ParseSess;
use rustc_span::{Span, Symbol, sym};

use crate::{AttributeParser, Late, session_diagnostics as errors};
use crate::session_diagnostics as errors;

pub fn check_attr(psess: &ParseSess, attr: &Attribute) {
if attr.is_doc_comment() || attr.has_name(sym::cfg_trace) || attr.has_name(sym::cfg_attr_trace)
// Built-in attributes are parsed in their respective attribute parsers, so can be ignored here
if attr.is_doc_comment()
|| attr.name().is_some_and(|name| BUILTIN_ATTRIBUTE_MAP.contains_key(&name))
{
return;
}

let builtin_attr_info = attr.name().and_then(|name| BUILTIN_ATTRIBUTE_MAP.get(&name));

// Check input tokens for built-in and key-value attributes.
match builtin_attr_info {
// `rustc_dummy` doesn't have any restrictions specific to built-in attributes.
Some(BuiltinAttribute { name, template, .. }) => {
if AttributeParser::<Late>::is_parsed_attribute(slice::from_ref(&name)) {
return;
}
match parse_meta(psess, attr) {
// Don't check safety again, we just did that
Ok(meta) => {
check_builtin_meta_item(psess, &meta, attr.style, *name, *template, false)
}
Err(err) => {
err.emit();
}
}
}
_ => {
let attr_item = attr.get_normal_item();
if let AttrArgs::Eq { .. } = attr_item.args.unparsed_ref().unwrap() {
// All key-value attributes are restricted to meta-item syntax.
match parse_meta(psess, attr) {
Ok(_) => {}
Err(err) => {
err.emit();
}
}
let attr_item = attr.get_normal_item();
if let AttrArgs::Eq { .. } = attr_item.args.unparsed_ref().unwrap() {
// All key-value attributes are restricted to meta-item syntax.
match parse_meta(psess, attr) {
Ok(_) => {}
Err(err) => {
err.emit();
}
}
}
Expand Down Expand Up @@ -170,7 +149,7 @@ pub fn check_builtin_meta_item(
}
}

fn emit_malformed_attribute(
pub fn emit_malformed_attribute(
psess: &ParseSess,
style: ast::AttrStyle,
span: Span,
Expand Down Expand Up @@ -232,15 +211,3 @@ fn emit_malformed_attribute(
err.emit();
}
}

pub fn emit_fatal_malformed_builtin_attribute(
psess: &ParseSess,
attr: &Attribute,
name: Symbol,
) -> ! {
let template = BUILTIN_ATTRIBUTE_MAP.get(&name).expect("builtin attr defined").template;
emit_malformed_attribute(psess, attr.style, attr.span, name, template);
// This is fatal, otherwise it will likely cause a cascade of other errors
// (and an error here is expected to be very rare).
FatalError.raise()
}
18 changes: 0 additions & 18 deletions compiler/rustc_expand/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -603,21 +603,3 @@ pub(crate) struct TrailingMacro {
pub is_trailing: bool,
pub name: Ident,
}

#[derive(Diagnostic)]
#[diag("unused attribute `{$attr_name}`")]
pub(crate) struct UnusedBuiltinAttribute {
#[note(
"the built-in attribute `{$attr_name}` will be ignored, since it's applied to the macro invocation `{$macro_name}`"
)]
pub invoc_span: Span,
pub attr_name: Symbol,
pub macro_name: String,
#[suggestion(
"remove the attribute",
code = "",
applicability = "machine-applicable",
style = "tool-only"
)]
pub attr_span: Span,
}
21 changes: 3 additions & 18 deletions compiler/rustc_expand/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ use rustc_ast::{
use rustc_ast_pretty::pprust;
use rustc_attr_parsing::parser::AllowExprMetavar;
use rustc_attr_parsing::{
AttributeParser, CFG_TEMPLATE, Early, EvalConfigResult, ShouldEmit, eval_config_entry,
parse_cfg, validate_attr,
AttributeParser, CFG_TEMPLATE, EvalConfigResult, ShouldEmit, eval_config_entry, parse_cfg,
validate_attr,
};
use rustc_data_structures::flat_map_in_place::FlatMapInPlace;
use rustc_data_structures::stack::ensure_sufficient_stack;
Expand All @@ -30,7 +30,7 @@ use rustc_parse::parser::{
RecoverColon, RecoverComma, Recovery, token_descr,
};
use rustc_session::Session;
use rustc_session::lint::builtin::{UNUSED_ATTRIBUTES, UNUSED_DOC_COMMENTS};
use rustc_session::lint::builtin::UNUSED_DOC_COMMENTS;
use rustc_session::parse::feature_err;
use rustc_span::hygiene::SyntaxContext;
use rustc_span::{ErrorGuaranteed, FileName, Ident, LocalExpnId, Span, Symbol, sym};
Expand Down Expand Up @@ -2274,21 +2274,6 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
self.cx.current_expansion.lint_node_id,
crate::errors::MacroCallUnusedDocComment { span: attr.span },
);
} else if rustc_attr_parsing::is_builtin_attr(attr)
&& !AttributeParser::<Early>::is_parsed_attribute(&attr.path())
{
let attr_name = attr.name().unwrap();
self.cx.sess.psess.buffer_lint(
UNUSED_ATTRIBUTES,
attr.span,
self.cx.current_expansion.lint_node_id,
crate::errors::UnusedBuiltinAttribute {
attr_name,
macro_name: pprust::path_to_string(&call.path),
invoc_span: call.path.span,
attr_span: attr.span,
},
);
}
}
}
Expand Down
17 changes: 15 additions & 2 deletions compiler/rustc_expand/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ use std::iter::once;
use std::path::{self, Path, PathBuf};

use rustc_ast::{AttrVec, Attribute, Inline, Item, ModSpans};
use rustc_attr_parsing::validate_attr;
use rustc_attr_parsing::validate_attr::emit_malformed_attribute;
use rustc_errors::{Diag, ErrorGuaranteed};
use rustc_feature::template;
use rustc_parse::lexer::StripTokens;
use rustc_parse::{exp, new_parser_from_file, unwrap_or_emit_fatal};
use rustc_session::Session;
use rustc_session::parse::ParseSess;
use rustc_span::fatal_error::FatalError;
use rustc_span::{Ident, Span, sym};
use thin_vec::ThinVec;

Expand Down Expand Up @@ -184,6 +186,7 @@ pub(crate) fn mod_file_path_from_attr(
attrs: &[Attribute],
dir_path: &Path,
) -> Option<PathBuf> {
// FIXME(154781) use a parsed attribute here
// Extract path string from first `#[path = "path_string"]` attribute.
let first_path = attrs.iter().find(|at| at.has_name(sym::path))?;
let Some(path_sym) = first_path.value_str() else {
Expand All @@ -195,7 +198,17 @@ pub(crate) fn mod_file_path_from_attr(
// Usually bad forms are checked during semantic analysis via
// `TyCtxt::check_mod_attrs`), but by the time that runs the macro
// is expanded, and it doesn't give an error.
validate_attr::emit_fatal_malformed_builtin_attribute(&sess.psess, first_path, sym::path);
emit_malformed_attribute(
&sess.psess,
first_path.style,
first_path.span,
sym::path,
template!(
NameValueStr: "file",
"https://doc.rust-lang.org/reference/items/modules.html#the-path-attribute"
),
);
FatalError.raise()
};

let path_str = path_sym.as_str();
Expand Down
Loading
Loading