Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 13cfdd8

Browse files
committed
Auto merge of #144850 - Zalathar:rollup-cs1fmbn, r=Zalathar
Rollup of 13 pull requests Successful merges: - #143857 (Port #[macro_export] to the new attribute parsing infrastructure) - #144070 (Implement `hash_map` macro ) - #144322 (Add lint against dangling pointers from local variables) - #144667 (`AlignmentEnum` should just be `repr(usize)` now) - #144706 (Do not give function allocations alignment in consteval and Miri.) - #144790 (Multiple bounds checking elision failures) - #144794 (Port `#[coroutine]` to the new attribute system) - #144805 (compiletest: Preliminary cleanup of `ProcRes` printing/unwinding) - #144808 (`Interner` arg to `EarlyBinder` does not affect auto traits) - #144816 (Update E0562 to account for the new impl trait positions) - #144822 (Return a struct with named fields from `hash_owner_nodes`) - #144824 (Updated test links in compiler) - #144829 (Use full flag name in strip command for Darwin) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 7cd9505 + 92cb665 commit 13cfdd8

File tree

56 files changed

+1205
-305
lines changed

Some content is hidden

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

56 files changed

+1205
-305
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_lowering/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
675675
let bodies = SortedMap::from_presorted_elements(bodies);
676676

677677
// Don't hash unless necessary, because it's expensive.
678-
let (opt_hash_including_bodies, attrs_hash, delayed_lints_hash) =
678+
let rustc_middle::hir::Hashes{opt_hash_including_bodies, attrs_hash, delayed_lints_hash} =
679679
self.tcx.hash_owner_nodes(node, &bodies, &attrs, &delayed_lints, define_opaque);
680680
let num_nodes = self.item_local_id_counter.as_usize();
681681
let (nodes, parenting) = index::index_hir(self.tcx, node, &bodies, num_nodes);

‎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,
2122
OmitGdbPrettyPrinterSectionParser, OptimizeParser, TargetFeatureParser, TrackCallerParser,
@@ -33,7 +34,7 @@ use crate::attributes::lint_helpers::{
3334
AsPtrParser, AutomaticallyDerivedParser, PassByValueParser, PubTransparentParser,
3435
};
3536
use crate::attributes::loop_match::{ConstContinueParser, LoopMatchParser};
36-
use crate::attributes::macro_attrs::{MacroEscapeParser, MacroUseParser};
37+
use crate::attributes::macro_attrs::{MacroEscapeParser, MacroExportParser,MacroUseParser};
3738
use crate::attributes::must_use::MustUseParser;
3839
use crate::attributes::no_implicit_prelude::NoImplicitPreludeParser;
3940
use crate::attributes::non_exhaustive::NonExhaustiveParser;
@@ -165,6 +166,7 @@ attribute_parsers!(
165166
Single<LinkNameParser>,
166167
Single<LinkOrdinalParser>,
167168
Single<LinkSectionParser>,
169+
Single<MacroExportParser>,
168170
Single<MustUseParser>,
169171
Single<OptimizeParser>,
170172
Single<PathAttributeParser>,
@@ -185,6 +187,7 @@ attribute_parsers!(
185187
Single<WithoutArgs<ConstContinueParser>>,
186188
Single<WithoutArgs<ConstStabilityIndirectParser>>,
187189
Single<WithoutArgs<ConstTraitParser>>,
190+
Single<WithoutArgs<CoroutineParser>>,
188191
Single<WithoutArgs<DenyExplicitImplParser>>,
189192
Single<WithoutArgs<DoNotImplementViaObjectParser>>,
190193
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
}

‎compiler/rustc_codegen_ssa/src/back/link.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,11 +1011,12 @@ fn link_natively(
10111011
(Strip::Debuginfo, _) => {
10121012
strip_with_external_utility(sess, stripcmd, out_filename, &["--strip-debug"])
10131013
}
1014-
// Per the manpage, `-x` is the maximum safe strip level for dynamic libraries. (#93988)
1014+
1015+
// Per the manpage, --discard-all is the maximum safe strip level for dynamic libraries. (#93988)
10151016
(
10161017
Strip::Symbols,
10171018
CrateType::Dylib | CrateType::Cdylib | CrateType::ProcMacro | CrateType::Sdylib,
1018-
) => strip_with_external_utility(sess, stripcmd, out_filename, &["-x"]),
1019+
) => strip_with_external_utility(sess, stripcmd, out_filename, &["--discard-all"]),
10191020
(Strip::Symbols, _) => {
10201021
strip_with_external_utility(sess, stripcmd, out_filename, &["--strip-all"])
10211022
}

‎compiler/rustc_const_eval/src/interpret/memory.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -937,8 +937,12 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
937937
// (both global from `alloc_map` and local from `extra_fn_ptr_map`)
938938
if let Some(fn_val) = self.get_fn_alloc(id) {
939939
let align = match fn_val {
940-
FnVal::Instance(instance) => {
941-
self.tcx.codegen_instance_attrs(instance.def).alignment.unwrap_or(Align::ONE)
940+
FnVal::Instance(_instance) => {
941+
// FIXME: Until we have a clear design for the effects of align(N) functions
942+
// on the address of function pointers, we don't consider the align(N)
943+
// attribute on functions in the interpreter.
944+
// See <https://github.com/rust-lang/rust/issues/144661> for more context.
945+
Align::ONE
942946
}
943947
// Machine-specific extra functions currently do not support alignment restrictions.
944948
FnVal::Other(_) => Align::ONE,

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /