Skip to content

Commit c722941

Browse files
committed
Auto merge of #143916 - jhpratt:rollup-oykjepf, r=jhpratt
Rollup of 17 pull requests Successful merges: - #142885 (core: Add `BorrowedCursor::with_unfilled_buf`) - #143217 (Port #[link_ordinal] to the new attribute parsing infrastructure) - #143355 (wrapping shift: remove first bitmask and table) - #143448 (remote-test-client: Exit code `128 + <signal-number>` instead of `3`) - #143681 (bootstrap/miri: avoid rebuilds for test builds) - #143710 (Updates to random number generation APIs) - #143724 (Tidy cleanup) - #143738 (Move several float tests to floats/mod.rs) - #143820 (Fixed a core crate compilation failure when enabling the `optimize_for_size` feature on some targets) - #143850 (Compiletest: Simplify {Html,Json}DocCk directive handling) - #143855 (Port `#[omit_gdb_pretty_printer_section]` to the new attribute parsing) - #143868 (warn on align on fields to avoid breaking changes) - #143875 (update issue number for `const_trait_impl`) - #143881 (Use zero for initialized Once state) - #143887 (Run bootstrap tests sooner in the `x test` pipeline) - #143893 (Don't require `eh_personality` lang item on targets that have a personality) - #143901 (Region constraint nits) Failed merges: - #143878 (Port `#[pointee]` to the new attribute parsing infrastructure) - #143891 (Port `#[coverage]` to the new attribute system) r? `@ghost` `@rustbot` modify labels: rollup
2 parents ad635e5 + 5b8ac1b commit c722941

File tree

120 files changed

+1130
-1473
lines changed

Some content is hidden

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

120 files changed

+1130
-1473
lines changed

compiler/rustc_attr_data_structures/src/attributes.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,9 @@ pub enum AttributeKind {
297297
/// Represents `#[link_name]`.
298298
LinkName { name: Symbol, span: Span },
299299

300+
/// Represents `#[link_ordinal]`.
301+
LinkOrdinal { ordinal: u16, span: Span },
302+
300303
/// Represents [`#[link_section]`](https://doc.rust-lang.org/reference/abi.html#the-link_section-attribute)
301304
LinkSection { name: Symbol, span: Span },
302305

@@ -331,6 +334,9 @@ pub enum AttributeKind {
331334
/// Represents `#[non_exhaustive]`
332335
NonExhaustive(Span),
333336

337+
/// Represents `#[omit_gdb_pretty_printer_section]`
338+
OmitGdbPrettyPrinterSection,
339+
334340
/// Represents `#[optimize(size|speed)]`
335341
Optimize(OptimizeAttr, Span),
336342

compiler/rustc_attr_data_structures/src/encode_cross_crate.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ impl AttributeKind {
4141
Ignore { .. } => No,
4242
Inline(..) => No,
4343
LinkName { .. } => Yes,
44+
LinkOrdinal { .. } => No,
4445
LinkSection { .. } => No,
4546
LoopMatch(..) => No,
4647
MacroTransparency(..) => Yes,
@@ -51,6 +52,7 @@ impl AttributeKind {
5152
NoImplicitPrelude(..) => No,
5253
NoMangle(..) => No,
5354
NonExhaustive(..) => Yes,
55+
OmitGdbPrettyPrinterSection => No,
5456
Optimize(..) => No,
5557
ParenSugar(..) => No,
5658
PassByValue(..) => Yes,

compiler/rustc_attr_parsing/messages.ftl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ attr_parsing_invalid_repr_hint_no_value =
7878
attr_parsing_invalid_since =
7979
'since' must be a Rust version number, such as "1.31.0"
8080
81+
attr_parsing_link_ordinal_out_of_range = ordinal value in `link_ordinal` is too large: `{$ordinal}`
82+
.note = the value may not exceed `u16::MAX`
83+
8184
attr_parsing_missing_feature =
8285
missing 'feature'
8386

compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,3 +334,11 @@ impl<S: Stage> CombineAttributeParser<S> for TargetFeatureParser {
334334
features
335335
}
336336
}
337+
338+
pub(crate) struct OmitGdbPrettyPrinterSectionParser;
339+
340+
impl<S: Stage> NoArgsAttributeParser<S> for OmitGdbPrettyPrinterSectionParser {
341+
const PATH: &[Symbol] = &[sym::omit_gdb_pretty_printer_section];
342+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
343+
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::OmitGdbPrettyPrinterSection;
344+
}

compiler/rustc_attr_parsing/src/attributes/link_attrs.rs

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
use rustc_attr_data_structures::AttributeKind;
2-
use rustc_attr_data_structures::AttributeKind::{LinkName, LinkSection};
2+
use rustc_attr_data_structures::AttributeKind::{LinkName, LinkOrdinal, LinkSection};
33
use rustc_feature::{AttributeTemplate, template};
44
use rustc_span::{Span, Symbol, sym};
55

66
use crate::attributes::{
77
AttributeOrder, NoArgsAttributeParser, OnDuplicate, SingleAttributeParser,
88
};
9-
use crate::context::{AcceptContext, Stage};
9+
use crate::context::{AcceptContext, Stage, parse_single_integer};
1010
use crate::parser::ArgParser;
11-
use crate::session_diagnostics::NullOnLinkSection;
11+
use crate::session_diagnostics::{LinkOrdinalOutOfRange, NullOnLinkSection};
1212

1313
pub(crate) struct LinkNameParser;
1414

@@ -87,3 +87,36 @@ impl<S: Stage> NoArgsAttributeParser<S> for StdInternalSymbolParser {
8787
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
8888
const CREATE: fn(Span) -> AttributeKind = AttributeKind::StdInternalSymbol;
8989
}
90+
91+
pub(crate) struct LinkOrdinalParser;
92+
93+
impl<S: Stage> SingleAttributeParser<S> for LinkOrdinalParser {
94+
const PATH: &[Symbol] = &[sym::link_ordinal];
95+
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost;
96+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
97+
const TEMPLATE: AttributeTemplate = template!(List: "ordinal");
98+
99+
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
100+
let ordinal = parse_single_integer(cx, args)?;
101+
102+
// According to the table at
103+
// https://docs.microsoft.com/en-us/windows/win32/debug/pe-format#import-header, the
104+
// ordinal must fit into 16 bits. Similarly, the Ordinal field in COFFShortExport (defined
105+
// in llvm/include/llvm/Object/COFFImportFile.h), which we use to communicate import
106+
// information to LLVM for `#[link(kind = "raw-dylib"_])`, is also defined to be uint16_t.
107+
//
108+
// FIXME: should we allow an ordinal of 0? The MSVC toolchain has inconsistent support for
109+
// this: both LINK.EXE and LIB.EXE signal errors and abort when given a .DEF file that
110+
// specifies a zero ordinal. However, llvm-dlltool is perfectly happy to generate an import
111+
// library for such a .DEF file, and MSVC's LINK.EXE is also perfectly happy to consume an
112+
// import library produced by LLVM with an ordinal of 0, and it generates an .EXE. (I
113+
// don't know yet if the resulting EXE runs, as I haven't yet built the necessary DLL --
114+
// see earlier comment about LINK.EXE failing.)
115+
let Ok(ordinal) = ordinal.try_into() else {
116+
cx.emit_err(LinkOrdinalOutOfRange { span: cx.attr_span, ordinal });
117+
return None;
118+
};
119+
120+
Some(LinkOrdinal { ordinal, span: cx.attr_span })
121+
}
122+
}

compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
use rustc_ast::LitKind;
21
use rustc_attr_data_structures::AttributeKind;
32
use rustc_feature::{AttributeTemplate, template};
43
use rustc_span::{Symbol, sym};
54

65
use crate::attributes::{AttributeOrder, OnDuplicate, SingleAttributeParser};
7-
use crate::context::{AcceptContext, Stage};
6+
use crate::context::{AcceptContext, Stage, parse_single_integer};
87
use crate::parser::ArgParser;
98

109
pub(crate) struct RustcLayoutScalarValidRangeStart;
@@ -16,8 +15,8 @@ impl<S: Stage> SingleAttributeParser<S> for RustcLayoutScalarValidRangeStart {
1615
const TEMPLATE: AttributeTemplate = template!(List: "start");
1716

1817
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
19-
parse_rustc_layout_scalar_valid_range(cx, args)
20-
.map(|n| AttributeKind::RustcLayoutScalarValidRangeStart(n, cx.attr_span))
18+
parse_single_integer(cx, args)
19+
.map(|n| AttributeKind::RustcLayoutScalarValidRangeStart(Box::new(n), cx.attr_span))
2120
}
2221
}
2322

@@ -30,34 +29,11 @@ impl<S: Stage> SingleAttributeParser<S> for RustcLayoutScalarValidRangeEnd {
3029
const TEMPLATE: AttributeTemplate = template!(List: "end");
3130

3231
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
33-
parse_rustc_layout_scalar_valid_range(cx, args)
34-
.map(|n| AttributeKind::RustcLayoutScalarValidRangeEnd(n, cx.attr_span))
32+
parse_single_integer(cx, args)
33+
.map(|n| AttributeKind::RustcLayoutScalarValidRangeEnd(Box::new(n), cx.attr_span))
3534
}
3635
}
3736

38-
fn parse_rustc_layout_scalar_valid_range<S: Stage>(
39-
cx: &mut AcceptContext<'_, '_, S>,
40-
args: &ArgParser<'_>,
41-
) -> Option<Box<u128>> {
42-
let Some(list) = args.list() else {
43-
cx.expected_list(cx.attr_span);
44-
return None;
45-
};
46-
let Some(single) = list.single() else {
47-
cx.expected_single_argument(list.span);
48-
return None;
49-
};
50-
let Some(lit) = single.lit() else {
51-
cx.expected_integer_literal(single.span());
52-
return None;
53-
};
54-
let LitKind::Int(num, _ty) = lit.kind else {
55-
cx.expected_integer_literal(single.span());
56-
return None;
57-
};
58-
Some(Box::new(num.0))
59-
}
60-
6137
pub(crate) struct RustcObjectLifetimeDefaultParser;
6238

6339
impl<S: Stage> SingleAttributeParser<S> for RustcObjectLifetimeDefaultParser {

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::ops::{Deref, DerefMut};
55
use std::sync::LazyLock;
66

77
use private::Sealed;
8-
use rustc_ast::{self as ast, MetaItemLit, NodeId};
8+
use rustc_ast::{self as ast, LitKind, MetaItemLit, NodeId};
99
use rustc_attr_data_structures::AttributeKind;
1010
use rustc_attr_data_structures::lints::{AttributeLint, AttributeLintKind};
1111
use rustc_errors::{DiagCtxtHandle, Diagnostic};
@@ -16,16 +16,16 @@ use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span, Symbol, sym};
1616

1717
use crate::attributes::allow_unstable::{AllowConstFnUnstableParser, AllowInternalUnstableParser};
1818
use crate::attributes::codegen_attrs::{
19-
ColdParser, ExportNameParser, NakedParser, NoMangleParser, OptimizeParser, TargetFeatureParser,
20-
TrackCallerParser, UsedParser,
19+
ColdParser, ExportNameParser, NakedParser, NoMangleParser, OmitGdbPrettyPrinterSectionParser,
20+
OptimizeParser, TargetFeatureParser, TrackCallerParser, UsedParser,
2121
};
2222
use crate::attributes::confusables::ConfusablesParser;
2323
use crate::attributes::deprecation::DeprecationParser;
2424
use crate::attributes::dummy::DummyParser;
2525
use crate::attributes::inline::{InlineParser, RustcForceInlineParser};
2626
use crate::attributes::link_attrs::{
27-
ExportStableParser, FfiConstParser, FfiPureParser, LinkNameParser, LinkSectionParser,
28-
StdInternalSymbolParser,
27+
ExportStableParser, FfiConstParser, FfiPureParser, LinkNameParser, LinkOrdinalParser,
28+
LinkSectionParser, StdInternalSymbolParser,
2929
};
3030
use crate::attributes::lint_helpers::{
3131
AsPtrParser, AutomaticallyDerivedParser, PassByValueParser, PubTransparentParser,
@@ -143,6 +143,7 @@ attribute_parsers!(
143143
Single<IgnoreParser>,
144144
Single<InlineParser>,
145145
Single<LinkNameParser>,
146+
Single<LinkOrdinalParser>,
146147
Single<LinkSectionParser>,
147148
Single<MustUseParser>,
148149
Single<OptimizeParser>,
@@ -174,6 +175,7 @@ attribute_parsers!(
174175
Single<WithoutArgs<NoImplicitPreludeParser>>,
175176
Single<WithoutArgs<NoMangleParser>>,
176177
Single<WithoutArgs<NonExhaustiveParser>>,
178+
Single<WithoutArgs<OmitGdbPrettyPrinterSectionParser>>,
177179
Single<WithoutArgs<ParenSugarParser>>,
178180
Single<WithoutArgs<PassByValueParser>>,
179181
Single<WithoutArgs<PubTransparentParser>>,
@@ -775,3 +777,32 @@ impl<'sess, S: Stage> AttributeParser<'sess, S> {
775777
}
776778
}
777779
}
780+
781+
/// Parse a single integer.
782+
///
783+
/// Used by attributes that take a single integer as argument, such as
784+
/// `#[link_ordinal]` and `#[rustc_layout_scalar_valid_range_start]`.
785+
/// `cx` is the context given to the attribute.
786+
/// `args` is the parser for the attribute arguments.
787+
pub(crate) fn parse_single_integer<S: Stage>(
788+
cx: &mut AcceptContext<'_, '_, S>,
789+
args: &ArgParser<'_>,
790+
) -> Option<u128> {
791+
let Some(list) = args.list() else {
792+
cx.expected_list(cx.attr_span);
793+
return None;
794+
};
795+
let Some(single) = list.single() else {
796+
cx.expected_single_argument(list.span);
797+
return None;
798+
};
799+
let Some(lit) = single.lit() else {
800+
cx.expected_integer_literal(single.span());
801+
return None;
802+
};
803+
let LitKind::Int(num, _ty) = lit.kind else {
804+
cx.expected_integer_literal(single.span());
805+
return None;
806+
};
807+
Some(num.0)
808+
}

compiler/rustc_attr_parsing/src/session_diagnostics.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,15 @@ pub(crate) struct NakedFunctionIncompatibleAttribute {
514514
pub attr: String,
515515
}
516516

517+
#[derive(Diagnostic)]
518+
#[diag(attr_parsing_link_ordinal_out_of_range)]
519+
#[note]
520+
pub(crate) struct LinkOrdinalOutOfRange {
521+
#[primary_span]
522+
pub span: Span,
523+
pub ordinal: u128,
524+
}
525+
517526
pub(crate) enum AttributeParseErrorReason {
518527
ExpectedNoArgs,
519528
ExpectedStringLiteral { byte_string: Option<Span> },

compiler/rustc_borrowck/src/type_check/constraint_conversion.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
159159
}
160160

161161
GenericArgKind::Type(mut t1) => {
162+
// Scraped constraints may have had inference vars.
163+
t1 = self.infcx.resolve_vars_if_possible(t1);
164+
162165
// Normalize the type we receive from a `TypeOutlives` obligation
163166
// in the new trait solver.
164167
if infcx.next_trait_solver() {

compiler/rustc_codegen_llvm/src/debuginfo/gdb.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
// .debug_gdb_scripts binary section.
22

3-
use rustc_ast::attr;
3+
use rustc_attr_data_structures::{AttributeKind, find_attr};
44
use rustc_codegen_ssa::base::collect_debugger_visualizers_transitive;
55
use rustc_codegen_ssa::traits::*;
66
use rustc_hir::def_id::LOCAL_CRATE;
77
use rustc_middle::bug;
88
use rustc_middle::middle::debugger_visualizer::DebuggerVisualizerType;
99
use rustc_session::config::{CrateType, DebugInfo};
10-
use rustc_span::sym;
1110

1211
use crate::builder::Builder;
1312
use crate::common::CodegenCx;
@@ -87,7 +86,7 @@ pub(crate) fn get_or_insert_gdb_debug_scripts_section_global<'ll>(
8786

8887
pub(crate) fn needs_gdb_debug_scripts_section(cx: &CodegenCx<'_, '_>) -> bool {
8988
let omit_gdb_pretty_printer_section =
90-
attr::contains_name(cx.tcx.hir_krate_attrs(), sym::omit_gdb_pretty_printer_section);
89+
find_attr!(cx.tcx.hir_krate_attrs(), AttributeKind::OmitGdbPrettyPrinterSection);
9190

9291
// To ensure the section `__rustc_debug_gdb_scripts_section__` will not create
9392
// ODR violations at link time, this section will not be emitted for rlibs since

0 commit comments

Comments
 (0)