Skip to content

Commit ec95ac0

Browse files
committed
Auto merge of #144979 - tgross35:rollup-erh9qat, r=tgross35
Rollup of 9 pull requests Successful merges: - #137831 (Tweak auto trait errors) - #138689 (add nvptx_target_feature) - #140267 (implement continue_ok and break_ok for ControlFlow) - #143764 (lower pattern bindings in the order they're written and base drop order on primary bindings' order) - #143857 (Port #[macro_export] to the new attribute parsing infrastructure) - #144650 (Additional tce tests) - #144676 (Add documentation for unstable_feature_bound) - #144794 (Port `#[coroutine]` to the new attribute system) - #144835 (Anonymize binders in tail call sig) r? `@ghost` `@rustbot` modify labels: rollup
2 parents dc0bae1 + b616dfc commit ec95ac0

File tree

77 files changed

+1162
-329
lines changed

Some content is hidden

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

77 files changed

+1162
-329
lines changed

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
9898
}
9999

100100
let expr_hir_id = self.lower_node_id(e.id);
101-
self.lower_attrs(expr_hir_id, &e.attrs, e.span);
101+
let attrs = self.lower_attrs(expr_hir_id, &e.attrs, e.span);
102102

103103
let kind = match &e.kind {
104104
ExprKind::Array(exprs) => hir::ExprKind::Array(self.lower_exprs(exprs)),
@@ -232,10 +232,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
232232
*fn_arg_span,
233233
),
234234
None => self.lower_expr_closure(
235+
attrs,
235236
binder,
236237
*capture_clause,
237238
e.id,
238-
expr_hir_id,
239239
*constness,
240240
*movability,
241241
fn_decl,
@@ -1052,10 +1052,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
10521052

10531053
fn lower_expr_closure(
10541054
&mut self,
1055+
attrs: &[rustc_hir::Attribute],
10551056
binder: &ClosureBinder,
10561057
capture_clause: CaptureBy,
10571058
closure_id: NodeId,
1058-
closure_hir_id: hir::HirId,
10591059
constness: Const,
10601060
movability: Movability,
10611061
decl: &FnDecl,
@@ -1067,15 +1067,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
10671067
let (binder_clause, generic_params) = self.lower_closure_binder(binder);
10681068

10691069
let (body_id, closure_kind) = self.with_new_scopes(fn_decl_span, move |this| {
1070-
let mut coroutine_kind = if this
1071-
.attrs
1072-
.get(&closure_hir_id.local_id)
1073-
.is_some_and(|attrs| attrs.iter().any(|attr| attr.has_name(sym::coroutine)))
1074-
{
1075-
Some(hir::CoroutineKind::Coroutine(Movability::Movable))
1076-
} else {
1077-
None
1078-
};
1070+
1071+
let mut coroutine_kind = find_attr!(attrs, AttributeKind::Coroutine(_) => hir::CoroutineKind::Coroutine(Movability::Movable));
1072+
10791073
// FIXME(contracts): Support contracts on closures?
10801074
let body_id = this.lower_fn_body(decl, None, |this| {
10811075
this.coroutine_kind = coroutine_kind;

compiler/rustc_ast_passes/messages.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ ast_passes_auto_generic = auto traits cannot have generic parameters
4040
4141
ast_passes_auto_items = auto traits cannot have associated items
4242
.label = {ast_passes_auto_items}
43-
.suggestion = remove these associated items
43+
.suggestion = remove the associated items
4444
4545
ast_passes_auto_super_lifetime = auto traits cannot have super traits or lifetime bounds
4646
.label = {ast_passes_auto_super_lifetime}

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -699,19 +699,23 @@ impl<'a> AstValidator<'a> {
699699
}
700700
}
701701

702-
fn deny_super_traits(&self, bounds: &GenericBounds, ident_span: Span) {
702+
fn deny_super_traits(&self, bounds: &GenericBounds, ident: Span) {
703703
if let [.., last] = &bounds[..] {
704-
let span = ident_span.shrink_to_hi().to(last.span());
705-
self.dcx().emit_err(errors::AutoTraitBounds { span, ident: ident_span });
704+
let span = bounds.iter().map(|b| b.span()).collect();
705+
let removal = ident.shrink_to_hi().to(last.span());
706+
self.dcx().emit_err(errors::AutoTraitBounds { span, removal, ident });
706707
}
707708
}
708709

709-
fn deny_where_clause(&self, where_clause: &WhereClause, ident_span: Span) {
710+
fn deny_where_clause(&self, where_clause: &WhereClause, ident: Span) {
710711
if !where_clause.predicates.is_empty() {
711712
// FIXME: The current diagnostic is misleading since it only talks about
712713
// super trait and lifetime bounds while we should just say “bounds”.
713-
self.dcx()
714-
.emit_err(errors::AutoTraitBounds { span: where_clause.span, ident: ident_span });
714+
self.dcx().emit_err(errors::AutoTraitBounds {
715+
span: vec![where_clause.span],
716+
removal: where_clause.span,
717+
ident,
718+
});
715719
}
716720
}
717721

compiler/rustc_ast_passes/src/errors.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ pub(crate) struct ModuleNonAscii {
344344
#[diag(ast_passes_auto_generic, code = E0567)]
345345
pub(crate) struct AutoTraitGeneric {
346346
#[primary_span]
347-
#[suggestion(code = "", applicability = "machine-applicable")]
347+
#[suggestion(code = "", applicability = "machine-applicable", style = "tool-only")]
348348
pub span: Span,
349349
#[label]
350350
pub ident: Span,
@@ -354,8 +354,9 @@ pub(crate) struct AutoTraitGeneric {
354354
#[diag(ast_passes_auto_super_lifetime, code = E0568)]
355355
pub(crate) struct AutoTraitBounds {
356356
#[primary_span]
357-
#[suggestion(code = "", applicability = "machine-applicable")]
358-
pub span: Span,
357+
pub span: Vec<Span>,
358+
#[suggestion(code = "", applicability = "machine-applicable", style = "tool-only")]
359+
pub removal: Span,
359360
#[label]
360361
pub ident: Span,
361362
}
@@ -365,7 +366,7 @@ pub(crate) struct AutoTraitBounds {
365366
pub(crate) struct AutoTraitItems {
366367
#[primary_span]
367368
pub spans: Vec<Span>,
368-
#[suggestion(code = "", applicability = "machine-applicable")]
369+
#[suggestion(code = "", applicability = "machine-applicable", style = "tool-only")]
369370
pub total: Span,
370371
#[label]
371372
pub ident: Span,

compiler/rustc_attr_parsing/messages.ftl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ attr_parsing_ill_formed_attribute_input = {$num_suggestions ->
3232
*[other] valid forms for the attribute are {$suggestions}
3333
}
3434
35+
attr_parsing_invalid_macro_export_arguments = {$num_suggestions ->
36+
[1] attribute must be of the form {$suggestions}
37+
*[other] valid forms for the attribute are {$suggestions}
38+
}
39+
3540
attr_parsing_incorrect_repr_format_align_one_arg =
3641
incorrect `repr(align)` attribute format: `align` takes exactly one argument in parentheses
3742
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//! Attributes that can be found in function body.
2+
3+
use rustc_hir::attrs::AttributeKind;
4+
use rustc_span::{Symbol, sym};
5+
6+
use super::{NoArgsAttributeParser, OnDuplicate};
7+
use crate::context::Stage;
8+
9+
pub(crate) struct CoroutineParser;
10+
11+
impl<S: Stage> NoArgsAttributeParser<S> for CoroutineParser {
12+
const PATH: &[Symbol] = &[sym::coroutine];
13+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
14+
const CREATE: fn(rustc_span::Span) -> AttributeKind = |span| AttributeKind::Coroutine(span);
15+
}

compiler/rustc_attr_parsing/src/attributes/macro_attrs.rs

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
use rustc_errors::DiagArgValue;
22
use rustc_feature::{AttributeTemplate, template};
33
use rustc_hir::attrs::{AttributeKind, MacroUseArgs};
4+
use rustc_hir::lints::AttributeLintKind;
45
use rustc_span::{Span, Symbol, sym};
56
use thin_vec::ThinVec;
67

7-
use crate::attributes::{AcceptMapping, AttributeParser, NoArgsAttributeParser, OnDuplicate};
8+
use crate::attributes::{
9+
AcceptMapping, AttributeOrder, AttributeParser, NoArgsAttributeParser, OnDuplicate,
10+
SingleAttributeParser,
11+
};
812
use crate::context::{AcceptContext, FinalizeContext, Stage};
913
use crate::parser::ArgParser;
1014
use crate::session_diagnostics;
@@ -113,3 +117,58 @@ impl<S: Stage> AttributeParser<S> for MacroUseParser {
113117
Some(AttributeKind::MacroUse { span: self.first_span?, arguments: self.state })
114118
}
115119
}
120+
121+
pub(crate) struct MacroExportParser;
122+
123+
impl<S: Stage> SingleAttributeParser<S> for crate::attributes::macro_attrs::MacroExportParser {
124+
const PATH: &[Symbol] = &[sym::macro_export];
125+
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost;
126+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
127+
const TEMPLATE: AttributeTemplate = template!(Word, List: "local_inner_macros");
128+
129+
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
130+
let suggestions =
131+
|| <Self as SingleAttributeParser<S>>::TEMPLATE.suggestions(false, "macro_export");
132+
let local_inner_macros = match args {
133+
ArgParser::NoArgs => false,
134+
ArgParser::List(list) => {
135+
let Some(l) = list.single() else {
136+
let span = cx.attr_span;
137+
cx.emit_lint(
138+
AttributeLintKind::InvalidMacroExportArguments {
139+
suggestions: suggestions(),
140+
},
141+
span,
142+
);
143+
return None;
144+
};
145+
match l.meta_item().and_then(|i| i.path().word_sym()) {
146+
Some(sym::local_inner_macros) => true,
147+
_ => {
148+
let span = cx.attr_span;
149+
cx.emit_lint(
150+
AttributeLintKind::InvalidMacroExportArguments {
151+
suggestions: suggestions(),
152+
},
153+
span,
154+
);
155+
return None;
156+
}
157+
}
158+
}
159+
ArgParser::NameValue(_) => {
160+
let span = cx.attr_span;
161+
let suggestions = suggestions();
162+
cx.emit_err(session_diagnostics::IllFormedAttributeInputLint {
163+
num_suggestions: suggestions.len(),
164+
suggestions: DiagArgValue::StrListSepByAnd(
165+
suggestions.into_iter().map(|s| format!("`{s}`").into()).collect(),
166+
),
167+
span,
168+
});
169+
return None;
170+
}
171+
};
172+
Some(AttributeKind::MacroExport { span: cx.attr_span, local_inner_macros })
173+
}
174+
}

compiler/rustc_attr_parsing/src/attributes/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use crate::parser::ArgParser;
2626
use crate::session_diagnostics::UnusedMultiple;
2727

2828
pub(crate) mod allow_unstable;
29+
pub(crate) mod body;
2930
pub(crate) mod cfg;
3031
pub(crate) mod cfg_old;
3132
pub(crate) mod codegen_attrs;

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span, Symbol, sym};
1616
use crate::attributes::allow_unstable::{
1717
AllowConstFnUnstableParser, AllowInternalUnstableParser, UnstableFeatureBoundParser,
1818
};
19+
use crate::attributes::body::CoroutineParser;
1920
use crate::attributes::codegen_attrs::{
2021
ColdParser, CoverageParser, ExportNameParser, NakedParser, NoMangleParser, OptimizeParser,
2122
TargetFeatureParser, TrackCallerParser, UsedParser,
@@ -32,7 +33,7 @@ use crate::attributes::lint_helpers::{
3233
AsPtrParser, AutomaticallyDerivedParser, PassByValueParser, PubTransparentParser,
3334
};
3435
use crate::attributes::loop_match::{ConstContinueParser, LoopMatchParser};
35-
use crate::attributes::macro_attrs::{MacroEscapeParser, MacroUseParser};
36+
use crate::attributes::macro_attrs::{MacroEscapeParser, MacroExportParser, MacroUseParser};
3637
use crate::attributes::must_use::MustUseParser;
3738
use crate::attributes::no_implicit_prelude::NoImplicitPreludeParser;
3839
use crate::attributes::non_exhaustive::NonExhaustiveParser;
@@ -164,6 +165,7 @@ attribute_parsers!(
164165
Single<LinkNameParser>,
165166
Single<LinkOrdinalParser>,
166167
Single<LinkSectionParser>,
168+
Single<MacroExportParser>,
167169
Single<MustUseParser>,
168170
Single<OptimizeParser>,
169171
Single<PathAttributeParser>,
@@ -184,6 +186,7 @@ attribute_parsers!(
184186
Single<WithoutArgs<ConstContinueParser>>,
185187
Single<WithoutArgs<ConstStabilityIndirectParser>>,
186188
Single<WithoutArgs<ConstTraitParser>>,
189+
Single<WithoutArgs<CoroutineParser>>,
187190
Single<WithoutArgs<DenyExplicitImplParser>>,
188191
Single<WithoutArgs<DoNotImplementViaObjectParser>>,
189192
Single<WithoutArgs<ExportStableParser>>,

compiler/rustc_attr_parsing/src/lints.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,17 @@ pub fn emit_attribute_lint<L: LintEmitter>(lint: &AttributeLint<HirId>, lint_emi
3434
*first_span,
3535
session_diagnostics::EmptyAttributeList { attr_span: *first_span },
3636
),
37+
AttributeLintKind::InvalidMacroExportArguments { suggestions } => lint_emitter
38+
.emit_node_span_lint(
39+
rustc_session::lint::builtin::INVALID_MACRO_EXPORT_ARGUMENTS,
40+
*id,
41+
*span,
42+
session_diagnostics::IllFormedAttributeInput {
43+
num_suggestions: suggestions.len(),
44+
suggestions: DiagArgValue::StrListSepByAnd(
45+
suggestions.into_iter().map(|s| format!("`{s}`").into()).collect(),
46+
),
47+
},
48+
),
3749
}
3850
}

0 commit comments

Comments
 (0)