Skip to content

Commit 978a0ad

Browse files
committed
Auto merge of #154951 - JonathanBrouwer:rollup-feqrNw3, r=<try>
Rollup of 10 pull requests try-job: dist-various-1 try-job: test-various try-job: x86_64-gnu-aux try-job: x86_64-gnu-llvm-21-3 try-job: x86_64-msvc-1 try-job: aarch64-apple try-job: x86_64-mingw-1
2 parents 49b6ac0 + 79aa68b commit 978a0ad

73 files changed

Lines changed: 1116 additions & 1656 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

compiler/rustc_ast_lowering/src/delegation.rs

Lines changed: 34 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
//! also be emitted during HIR ty lowering.
3838
3939
use std::iter;
40-
use std::marker::PhantomData;
4140

4241
use ast::visit::Visitor;
4342
use hir::def::{DefKind, PartialRes, Res};
@@ -128,14 +127,12 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
128127
{
129128
self.get_sig_id(delegation_info.resolution_node, span)
130129
} else {
131-
return self.generate_delegation_error(
132-
self.dcx().span_delayed_bug(
133-
span,
134-
format!("LoweringContext: the delegation {:?} is unresolved", item_id),
135-
),
130+
self.dcx().span_delayed_bug(
136131
span,
137-
delegation,
132+
format!("LoweringContext: the delegation {:?} is unresolved", item_id),
138133
);
134+
135+
return self.generate_delegation_error(span, delegation);
139136
};
140137

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

173170
DelegationResults { body_id, sig, ident, generics }
174171
}
175-
Err(err) => self.generate_delegation_error(err, span, delegation),
172+
Err(_) => self.generate_delegation_error(span, delegation),
176173
}
177174
}
178175

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

605601
fn generate_delegation_error(
606602
&mut self,
607-
err: ErrorGuaranteed,
608603
span: Span,
609604
delegation: &Delegation,
610605
) -> DelegationResults<'hir> {
@@ -622,36 +617,35 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
622617
let ident = self.lower_ident(delegation.ident);
623618

624619
let body_id = self.lower_body(|this| {
625-
let body_expr = match delegation.body.as_ref() {
626-
Some(box block) => {
627-
// Generates a block when we failed to resolve delegation, where a target expression is its only statement,
628-
// thus there will be no ICEs on further stages of analysis (see #144594)
629-
630-
// As we generate a void function we want to convert target expression to statement to avoid additional
631-
// errors, such as mismatched return type
632-
let stmts = this.arena.alloc_from_iter([hir::Stmt {
633-
hir_id: this.next_id(),
634-
kind: rustc_hir::StmtKind::Semi(
635-
this.arena.alloc(this.lower_target_expr(block)),
636-
),
637-
span,
638-
}]);
639-
640-
let block = this.arena.alloc(hir::Block {
641-
stmts,
642-
expr: None,
643-
hir_id: this.next_id(),
644-
rules: hir::BlockCheckMode::DefaultBlock,
645-
span,
646-
targeted_by_break: false,
647-
});
620+
let path = this.lower_qpath(
621+
delegation.id,
622+
&delegation.qself,
623+
&delegation.path,
624+
ParamMode::Optional,
625+
AllowReturnTypeNotation::No,
626+
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
627+
None,
628+
);
648629

649-
hir::ExprKind::Block(block, None)
650-
}
651-
None => hir::ExprKind::Err(err),
630+
let callee_path = this.arena.alloc(this.mk_expr(hir::ExprKind::Path(path), span));
631+
let args = if let Some(box block) = delegation.body.as_ref() {
632+
this.arena.alloc_slice(&[this.lower_target_expr(block)])
633+
} else {
634+
&mut []
652635
};
653636

654-
(&[], this.mk_expr(body_expr, span))
637+
let call = this.arena.alloc(this.mk_expr(hir::ExprKind::Call(callee_path, args), span));
638+
639+
let block = this.arena.alloc(hir::Block {
640+
stmts: &[],
641+
expr: Some(call),
642+
hir_id: this.next_id(),
643+
rules: hir::BlockCheckMode::DefaultBlock,
644+
span,
645+
targeted_by_break: false,
646+
});
647+
648+
(&[], this.mk_expr(hir::ExprKind::Block(block, None), span))
655649
});
656650

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

676-
struct SelfResolver<'a, 'tcx, R> {
670+
struct SelfResolver<'a, R> {
677671
resolver: &'a mut R,
678672
path_id: NodeId,
679673
self_param_id: NodeId,
680-
phantom: PhantomData<&'tcx ()>,
681674
}
682675

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

695-
impl<'ast, 'a, 'tcx, R: ResolverAstLoweringExt<'tcx>> Visitor<'ast> for SelfResolver<'a, 'tcx, R> {
688+
impl<'ast, 'tcx, R: ResolverAstLoweringExt<'tcx>> Visitor<'ast> for SelfResolver<'_, R> {
696689
fn visit_id(&mut self, id: NodeId) {
697690
self.try_replace_id(id);
698691
}

compiler/rustc_attr_parsing/src/validate_attr.rs

Lines changed: 14 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
//! Meta-syntax validation logic of attributes for post-expansion.
22
33
use std::convert::identity;
4-
use std::slice;
54

65
use rustc_ast::token::Delimiter;
76
use rustc_ast::tokenstream::DelimSpan;
87
use rustc_ast::{
98
self as ast, AttrArgs, Attribute, DelimArgs, MetaItem, MetaItemInner, MetaItemKind, Safety,
109
};
11-
use rustc_errors::{Applicability, FatalError, PResult};
12-
use rustc_feature::{AttributeTemplate, BUILTIN_ATTRIBUTE_MAP, BuiltinAttribute};
10+
use rustc_errors::{Applicability, PResult};
11+
use rustc_feature::{AttributeTemplate, BUILTIN_ATTRIBUTE_MAP};
1312
use rustc_hir::AttrPath;
1413
use rustc_hir::lints::AttributeLintKind;
1514
use rustc_parse::parse_in;
@@ -19,43 +18,23 @@ use rustc_session::lint::builtin::ILL_FORMED_ATTRIBUTE_INPUT;
1918
use rustc_session::parse::ParseSess;
2019
use rustc_span::{Span, Symbol, sym};
2120

22-
use crate::{AttributeParser, Late, session_diagnostics as errors};
21+
use crate::session_diagnostics as errors;
2322

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

30-
let builtin_attr_info = attr.name().and_then(|name| BUILTIN_ATTRIBUTE_MAP.get(&name));
31-
32-
// Check input tokens for built-in and key-value attributes.
33-
match builtin_attr_info {
34-
// `rustc_dummy` doesn't have any restrictions specific to built-in attributes.
35-
Some(BuiltinAttribute { name, template, .. }) => {
36-
if AttributeParser::<Late>::is_parsed_attribute(slice::from_ref(&name)) {
37-
return;
38-
}
39-
match parse_meta(psess, attr) {
40-
// Don't check safety again, we just did that
41-
Ok(meta) => {
42-
check_builtin_meta_item(psess, &meta, attr.style, *name, *template, false)
43-
}
44-
Err(err) => {
45-
err.emit();
46-
}
47-
}
48-
}
49-
_ => {
50-
let attr_item = attr.get_normal_item();
51-
if let AttrArgs::Eq { .. } = attr_item.args.unparsed_ref().unwrap() {
52-
// All key-value attributes are restricted to meta-item syntax.
53-
match parse_meta(psess, attr) {
54-
Ok(_) => {}
55-
Err(err) => {
56-
err.emit();
57-
}
58-
}
31+
let attr_item = attr.get_normal_item();
32+
if let AttrArgs::Eq { .. } = attr_item.args.unparsed_ref().unwrap() {
33+
// All key-value attributes are restricted to meta-item syntax.
34+
match parse_meta(psess, attr) {
35+
Ok(_) => {}
36+
Err(err) => {
37+
err.emit();
5938
}
6039
}
6140
}
@@ -170,7 +149,7 @@ pub fn check_builtin_meta_item(
170149
}
171150
}
172151

173-
fn emit_malformed_attribute(
152+
pub fn emit_malformed_attribute(
174153
psess: &ParseSess,
175154
style: ast::AttrStyle,
176155
span: Span,
@@ -232,15 +211,3 @@ fn emit_malformed_attribute(
232211
err.emit();
233212
}
234213
}
235-
236-
pub fn emit_fatal_malformed_builtin_attribute(
237-
psess: &ParseSess,
238-
attr: &Attribute,
239-
name: Symbol,
240-
) -> ! {
241-
let template = BUILTIN_ATTRIBUTE_MAP.get(&name).expect("builtin attr defined").template;
242-
emit_malformed_attribute(psess, attr.style, attr.span, name, template);
243-
// This is fatal, otherwise it will likely cause a cascade of other errors
244-
// (and an error here is expected to be very rare).
245-
FatalError.raise()
246-
}

compiler/rustc_expand/src/errors.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -603,21 +603,3 @@ pub(crate) struct TrailingMacro {
603603
pub is_trailing: bool,
604604
pub name: Ident,
605605
}
606-
607-
#[derive(Diagnostic)]
608-
#[diag("unused attribute `{$attr_name}`")]
609-
pub(crate) struct UnusedBuiltinAttribute {
610-
#[note(
611-
"the built-in attribute `{$attr_name}` will be ignored, since it's applied to the macro invocation `{$macro_name}`"
612-
)]
613-
pub invoc_span: Span,
614-
pub attr_name: Symbol,
615-
pub macro_name: String,
616-
#[suggestion(
617-
"remove the attribute",
618-
code = "",
619-
applicability = "machine-applicable",
620-
style = "tool-only"
621-
)]
622-
pub attr_span: Span,
623-
}

compiler/rustc_expand/src/expand.rs

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ use rustc_ast::{
1515
use rustc_ast_pretty::pprust;
1616
use rustc_attr_parsing::parser::AllowExprMetavar;
1717
use rustc_attr_parsing::{
18-
AttributeParser, CFG_TEMPLATE, Early, EvalConfigResult, ShouldEmit, eval_config_entry,
19-
parse_cfg, validate_attr,
18+
AttributeParser, CFG_TEMPLATE, EvalConfigResult, ShouldEmit, eval_config_entry, parse_cfg,
19+
validate_attr,
2020
};
2121
use rustc_data_structures::flat_map_in_place::FlatMapInPlace;
2222
use rustc_data_structures::stack::ensure_sufficient_stack;
@@ -30,7 +30,7 @@ use rustc_parse::parser::{
3030
RecoverColon, RecoverComma, Recovery, token_descr,
3131
};
3232
use rustc_session::Session;
33-
use rustc_session::lint::builtin::{UNUSED_ATTRIBUTES, UNUSED_DOC_COMMENTS};
33+
use rustc_session::lint::builtin::UNUSED_DOC_COMMENTS;
3434
use rustc_session::parse::feature_err;
3535
use rustc_span::hygiene::SyntaxContext;
3636
use rustc_span::{ErrorGuaranteed, FileName, Ident, LocalExpnId, Span, Symbol, sym};
@@ -2274,21 +2274,6 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
22742274
self.cx.current_expansion.lint_node_id,
22752275
crate::errors::MacroCallUnusedDocComment { span: attr.span },
22762276
);
2277-
} else if rustc_attr_parsing::is_builtin_attr(attr)
2278-
&& !AttributeParser::<Early>::is_parsed_attribute(&attr.path())
2279-
{
2280-
let attr_name = attr.name().unwrap();
2281-
self.cx.sess.psess.buffer_lint(
2282-
UNUSED_ATTRIBUTES,
2283-
attr.span,
2284-
self.cx.current_expansion.lint_node_id,
2285-
crate::errors::UnusedBuiltinAttribute {
2286-
attr_name,
2287-
macro_name: pprust::path_to_string(&call.path),
2288-
invoc_span: call.path.span,
2289-
attr_span: attr.span,
2290-
},
2291-
);
22922277
}
22932278
}
22942279
}

compiler/rustc_expand/src/module.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ use std::iter::once;
22
use std::path::{self, Path, PathBuf};
33

44
use rustc_ast::{AttrVec, Attribute, Inline, Item, ModSpans};
5-
use rustc_attr_parsing::validate_attr;
5+
use rustc_attr_parsing::validate_attr::emit_malformed_attribute;
66
use rustc_errors::{Diag, ErrorGuaranteed};
7+
use rustc_feature::template;
78
use rustc_parse::lexer::StripTokens;
89
use rustc_parse::{exp, new_parser_from_file, unwrap_or_emit_fatal};
910
use rustc_session::Session;
1011
use rustc_session::parse::ParseSess;
12+
use rustc_span::fatal_error::FatalError;
1113
use rustc_span::{Ident, Span, sym};
1214
use thin_vec::ThinVec;
1315

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

201214
let path_str = path_sym.as_str();

0 commit comments

Comments
 (0)