Skip to content

Commit d29e478

Browse files
committed
Auto merge of #151480 - jhpratt:rollup-kUkiF2m, r=jhpratt
Rollup of 4 pull requests Successful merges: - #151118 (Support slices in type reflection) - #151439 (Bump bootstrap compiler to 1.94) - #151442 (Port `#![crate_type]` to the attribute parser) - #151457 (Improve error message for assert!() macro in functions returning bool) r? @ghost
2 parents b765963 + d43b667 commit d29e478

File tree

87 files changed

+1379
-1087
lines changed

Some content is hidden

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

87 files changed

+1379
-1087
lines changed

‎compiler/rustc_ast/src/lib.rs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
//! This API is completely unstable and subject to change.
66
77
// tidy-alphabetical-start
8-
#![cfg_attr(bootstrap, feature(array_windows))]
98
#![doc(test(attr(deny(warnings), allow(internal_features))))]
109
#![feature(associated_type_defaults)]
1110
#![feature(box_patterns)]

‎compiler/rustc_attr_parsing/src/attributes/crate_level.rs‎

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
use rustc_hir::attrs::WindowsSubsystemKind;
1+
use rustc_hir::attrs::{CrateType, WindowsSubsystemKind};
2+
use rustc_hir::lints::AttributeLintKind;
3+
use rustc_session::lint::builtin::UNKNOWN_CRATE_TYPES;
4+
use rustc_span::Symbol;
5+
use rustc_span::edit_distance::find_best_match_for_name;
26

37
use super::prelude::*;
48

@@ -26,6 +30,56 @@ impl<S: Stage> SingleAttributeParser<S> for CrateNameParser {
2630
}
2731
}
2832

33+
pub(crate) struct CrateTypeParser;
34+
35+
impl<S: Stage> CombineAttributeParser<S> for CrateTypeParser {
36+
const PATH: &[Symbol] = &[sym::crate_type];
37+
type Item = CrateType;
38+
const CONVERT: ConvertFn<Self::Item> = |items, _| AttributeKind::CrateType(items);
39+
40+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
41+
42+
const TEMPLATE: AttributeTemplate =
43+
template!(NameValueStr: "crate type", "https://doc.rust-lang.org/reference/linkage.html");
44+
45+
fn extend(
46+
cx: &mut AcceptContext<'_, '_, S>,
47+
args: &ArgParser,
48+
) -> impl IntoIterator<Item = Self::Item> {
49+
let ArgParser::NameValue(n) = args else {
50+
cx.expected_name_value(cx.attr_span, None);
51+
return None;
52+
};
53+
54+
let Some(crate_type) = n.value_as_str() else {
55+
cx.expected_string_literal(n.value_span, Some(n.value_as_lit()));
56+
return None;
57+
};
58+
59+
let Ok(crate_type) = crate_type.try_into() else {
60+
// We don't error on invalid `#![crate_type]` when not applied to a crate
61+
if cx.shared.target == Target::Crate {
62+
let candidate = find_best_match_for_name(
63+
&CrateType::all_stable().iter().map(|(name, _)| *name).collect::<Vec<_>>(),
64+
crate_type,
65+
None,
66+
);
67+
cx.emit_lint(
68+
UNKNOWN_CRATE_TYPES,
69+
AttributeLintKind::CrateTypeUnknown {
70+
span: n.value_span,
71+
suggested: candidate,
72+
},
73+
n.value_span,
74+
);
75+
}
76+
return None;
77+
};
78+
79+
Some(crate_type)
80+
}
81+
}
82+
2983
pub(crate) struct RecursionLimitParser;
3084

3185
impl<S: Stage> SingleAttributeParser<S> for RecursionLimitParser {

‎compiler/rustc_attr_parsing/src/context.rs‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ use crate::attributes::codegen_attrs::{
2828
};
2929
use crate::attributes::confusables::ConfusablesParser;
3030
use crate::attributes::crate_level::{
31-
CrateNameParser, MoveSizeLimitParser, NeedsPanicRuntimeParser, NoBuiltinsParser, NoCoreParser,
32-
NoMainParser, NoStdParser, PanicRuntimeParser, PatternComplexityLimitParser,
33-
ProfilerRuntimeParser, RecursionLimitParser, RustcCoherenceIsCoreParser, TypeLengthLimitParser,
34-
WindowsSubsystemParser,
31+
CrateNameParser, CrateTypeParser, MoveSizeLimitParser, NeedsPanicRuntimeParser,
32+
NoBuiltinsParser, NoCoreParser, NoMainParser, NoStdParser, PanicRuntimeParser,
33+
PatternComplexityLimitParser, ProfilerRuntimeParser, RecursionLimitParser,
34+
RustcCoherenceIsCoreParser, TypeLengthLimitParser, WindowsSubsystemParser,
3535
};
3636
use crate::attributes::debugger::DebuggerViualizerParser;
3737
use crate::attributes::deprecation::DeprecationParser;
@@ -193,6 +193,7 @@ attribute_parsers!(
193193
// tidy-alphabetical-start
194194
Combine<AllowConstFnUnstableParser>,
195195
Combine<AllowInternalUnstableParser>,
196+
Combine<CrateTypeParser>,
196197
Combine<DebuggerViualizerParser>,
197198
Combine<ForceTargetFeatureParser>,
198199
Combine<LinkParser>,

‎compiler/rustc_codegen_llvm/src/debuginfo/gdb.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ pub(crate) fn needs_gdb_debug_scripts_section(cx: &CodegenCx<'_, '_>) -> bool {
9292
CrateType::Executable
9393
| CrateType::Dylib
9494
| CrateType::Cdylib
95-
| CrateType::Staticlib
95+
| CrateType::StaticLib
9696
| CrateType::Sdylib => {
9797
// These are crate types for which we will embed pretty printers since they
9898
// are treated as leaf crates.

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ pub fn link_binary(
136136
)
137137
.build(&out_filename);
138138
}
139-
CrateType::Staticlib => {
139+
CrateType::StaticLib => {
140140
link_staticlib(
141141
sess,
142142
archive_builder_builder,
@@ -474,7 +474,7 @@ fn link_staticlib(
474474

475475
let res = each_linked_rlib(
476476
&codegen_results.crate_info,
477-
Some(CrateType::Staticlib),
477+
Some(CrateType::StaticLib),
478478
&mut |cnum, path| {
479479
let lto = are_upstream_rust_objects_already_included(sess)
480480
&& !ignored_for_lto(sess, &codegen_results.crate_info, cnum);
@@ -532,7 +532,7 @@ fn link_staticlib(
532532
let fmts = codegen_results
533533
.crate_info
534534
.dependency_formats
535-
.get(&CrateType::Staticlib)
535+
.get(&CrateType::StaticLib)
536536
.expect("no dependency formats for staticlib");
537537

538538
let mut all_rust_dylibs = vec![];
@@ -1210,7 +1210,7 @@ fn add_sanitizer_libraries(
12101210
return;
12111211
}
12121212

1213-
if matches!(crate_type, CrateType::Rlib | CrateType::Staticlib) {
1213+
if matches!(crate_type, CrateType::Rlib | CrateType::StaticLib) {
12141214
return;
12151215
}
12161216

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1857,7 +1857,7 @@ pub(crate) fn linked_symbols(
18571857
| CrateType::Cdylib
18581858
| CrateType::Dylib
18591859
| CrateType::Sdylib => (),
1860-
CrateType::Staticlib | CrateType::Rlib => {
1860+
CrateType::StaticLib | CrateType::Rlib => {
18611861
// These are not linked, so no need to generate symbols.o for them.
18621862
return Vec::new();
18631863
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ fn crate_type_allows_lto(crate_type: CrateType) -> bool {
6767
match crate_type {
6868
CrateType::Executable
6969
| CrateType::Dylib
70-
| CrateType::Staticlib
70+
| CrateType::StaticLib
7171
| CrateType::Cdylib
7272
| CrateType::ProcMacro
7373
| CrateType::Sdylib => true,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ fn threshold(tcx: TyCtxt<'_>) -> SymbolExportLevel {
2828

2929
fn crate_export_threshold(crate_type: CrateType) -> SymbolExportLevel {
3030
match crate_type {
31-
CrateType::Executable | CrateType::Staticlib | CrateType::ProcMacro | CrateType::Cdylib => {
31+
CrateType::Executable | CrateType::StaticLib | CrateType::ProcMacro | CrateType::Cdylib => {
3232
SymbolExportLevel::C
3333
}
3434
CrateType::Rlib | CrateType::Dylib | CrateType::Sdylib => SymbolExportLevel::Rust,

‎compiler/rustc_codegen_ssa/src/base.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,7 @@ impl CrateInfo {
10091009
info.linked_symbols
10101010
.iter_mut()
10111011
.filter(|(crate_type, _)| {
1012-
!matches!(crate_type, CrateType::Rlib | CrateType::Staticlib)
1012+
!matches!(crate_type, CrateType::Rlib | CrateType::StaticLib)
10131013
})
10141014
.for_each(|(_, linked_symbols)| {
10151015
let mut symbols = missing_weak_lang_items
@@ -1041,7 +1041,7 @@ impl CrateInfo {
10411041
// this is a rare use case and we don't want to slow down the common case.
10421042
false
10431043
}
1044-
CrateType::Staticlib | CrateType::Rlib => {
1044+
CrateType::StaticLib | CrateType::Rlib => {
10451045
// We don't invoke the linker for these, so we don't need to collect the NatVis for
10461046
// them.
10471047
false

‎compiler/rustc_codegen_ssa/src/traits/backend.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ pub trait CodegenBackend {
6767
CrateType::Executable,
6868
CrateType::Dylib,
6969
CrateType::Rlib,
70-
CrateType::Staticlib,
70+
CrateType::StaticLib,
7171
CrateType::Cdylib,
7272
CrateType::ProcMacro,
7373
CrateType::Sdylib,

0 commit comments

Comments
 (0)