Skip to content

Commit ebf019d

Browse files
committed
Merge branch 'master' into expand1-cont
2 parents d5c84d0 + ebd08d8 commit ebf019d

File tree

200 files changed

+2986
-1827
lines changed

Some content is hidden

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

200 files changed

+2986
-1827
lines changed

Cargo.lock

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3282,20 +3282,22 @@ dependencies = [
32823282

32833283
[[package]]
32843284
name = "rinja"
3285-
version = "0.2.0"
3285+
version = "0.3.0"
32863286
source = "registry+https://github.com/rust-lang/crates.io-index"
3287-
checksum = "d2d47a46d7729e891c8accf260e9daa02ae6d570aa2a94fb1fb27eb5364a2323"
3287+
checksum = "6d3762e3740cdbf2fd2be465cc2c26d643ad17353cc2e0223d211c1b096118bd"
32883288
dependencies = [
3289+
"itoa",
32893290
"rinja_derive",
32903291
]
32913292

32923293
[[package]]
32933294
name = "rinja_derive"
3294-
version = "0.2.0"
3295+
version = "0.3.0"
32953296
source = "registry+https://github.com/rust-lang/crates.io-index"
3296-
checksum = "44dae9afe59d58ed8d988d67d1945f3638125d2fd2104058399382e11bd3ea2a"
3297+
checksum = "fd01fd8e15e7d19c8b8052c1d428325131e02ff1633cdcf695190c2e56ab682c"
32973298
dependencies = [
32983299
"basic-toml",
3300+
"memchr",
32993301
"mime",
33003302
"mime_guess",
33013303
"once_map",
@@ -3308,10 +3310,11 @@ dependencies = [
33083310

33093311
[[package]]
33103312
name = "rinja_parser"
3311-
version = "0.2.0"
3313+
version = "0.3.0"
33123314
source = "registry+https://github.com/rust-lang/crates.io-index"
3313-
checksum = "1b1771c78cd5d3b1646ef8d8f2ed100db936e8b291d3cc06e92a339ff346858c"
3315+
checksum = "a2f6bf7cef118c6de21206edf0b3f19f5ede60006be674a58ca21b6e003a1b57"
33143316
dependencies = [
3317+
"memchr",
33153318
"nom",
33163319
]
33173320

@@ -4347,6 +4350,7 @@ dependencies = [
43474350
"rustc_span",
43484351
"rustc_target",
43494352
"rustc_trait_selection",
4353+
"rustc_type_ir",
43504354
"smallvec",
43514355
"tracing",
43524356
]

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -453,11 +453,6 @@ impl<'a> AstValidator<'a> {
453453
item_span: span,
454454
block: Some(self.current_extern_span().shrink_to_lo()),
455455
});
456-
} else if !self.features.unsafe_extern_blocks {
457-
self.dcx().emit_err(errors::InvalidSafetyOnExtern {
458-
item_span: span,
459-
block: None,
460-
});
461456
}
462457
}
463458
}
@@ -1054,32 +1049,19 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
10541049
errors::VisibilityNotPermittedNote::IndividualForeignItems,
10551050
);
10561051

1057-
if this.features.unsafe_extern_blocks {
1058-
if &Safety::Default == safety {
1059-
if item.span.at_least_rust_2024() {
1060-
this.dcx()
1061-
.emit_err(errors::MissingUnsafeOnExtern { span: item.span });
1062-
} else {
1063-
this.lint_buffer.buffer_lint(
1064-
MISSING_UNSAFE_ON_EXTERN,
1065-
item.id,
1066-
item.span,
1067-
BuiltinLintDiag::MissingUnsafeOnExtern {
1068-
suggestion: item.span.shrink_to_lo(),
1069-
},
1070-
);
1071-
}
1052+
if &Safety::Default == safety {
1053+
if item.span.at_least_rust_2024() {
1054+
this.dcx().emit_err(errors::MissingUnsafeOnExtern { span: item.span });
1055+
} else {
1056+
this.lint_buffer.buffer_lint(
1057+
MISSING_UNSAFE_ON_EXTERN,
1058+
item.id,
1059+
item.span,
1060+
BuiltinLintDiag::MissingUnsafeOnExtern {
1061+
suggestion: item.span.shrink_to_lo(),
1062+
},
1063+
);
10721064
}
1073-
} else if let &Safety::Unsafe(span) = safety {
1074-
let mut diag = this
1075-
.dcx()
1076-
.create_err(errors::UnsafeItem { span, kind: "extern block" });
1077-
rustc_session::parse::add_feature_diagnostics(
1078-
&mut diag,
1079-
self.session,
1080-
sym::unsafe_extern_blocks,
1081-
);
1082-
diag.emit();
10831065
}
10841066

10851067
if abi.is_none() {

compiler/rustc_ast_passes/src/feature_gate.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -560,10 +560,6 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
560560
gate_all!(precise_capturing, "precise captures on `impl Trait` are experimental");
561561
gate_all!(global_registration, "global registration is experimental");
562562
gate_all!(unsafe_attributes, "`#[unsafe()]` markers for attributes are experimental");
563-
gate_all!(
564-
unsafe_extern_blocks,
565-
"`unsafe extern {}` blocks and `safe` keyword are experimental"
566-
);
567563
gate_all!(return_type_notation, "return type notation is experimental");
568564

569565
if !visitor.features.never_patterns {

compiler/rustc_builtin_macros/messages.ftl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,9 @@ builtin_macros_format_use_positional = consider using a positional formatting ar
196196
197197
builtin_macros_global_asm_clobber_abi = `clobber_abi` cannot be used with `global_asm!`
198198
199+
builtin_macros_global_asm_unsupported_operand = the `{$symbol}` operand cannot be used with `global_asm!`
200+
.label = the `{$symbol}` operand is not meaningful for global-scoped inline assembly, remove it
201+
199202
builtin_macros_global_asm_unsupported_option = the `{$symbol}` option cannot be used with `global_asm!`
200203
.label = the `{$symbol}` option is not meaningful for global-scoped inline assembly
201204
.suggestion = remove this option

compiler/rustc_builtin_macros/src/asm.rs

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,29 @@ pub struct AsmArgs {
2828
pub options_spans: Vec<Span>,
2929
}
3030

31+
/// Used for better error messages when operand types are used that are not
32+
/// supported by the current macro (e.g. `in` or `out` for `global_asm!`)
33+
///
34+
/// returns
35+
///
36+
/// - `Ok(true)` if the current token matches the keyword, and was expected
37+
/// - `Ok(false)` if the current token does not match the keyword
38+
/// - `Err(_)` if the current token matches the keyword, but was not expected
39+
fn eat_operand_keyword<'a>(p: &mut Parser<'a>, symbol: Symbol, expect: bool) -> PResult<'a, bool> {
40+
if expect {
41+
Ok(p.eat_keyword(symbol))
42+
} else {
43+
let span = p.token.span;
44+
if p.eat_keyword_noexpect(symbol) {
45+
// in gets printed as `r#in` otherwise
46+
let symbol = if symbol == kw::In { "in" } else { symbol.as_str() };
47+
Err(p.dcx().create_err(errors::GlobalAsmUnsupportedOperand { span, symbol }))
48+
} else {
49+
Ok(false)
50+
}
51+
}
52+
}
53+
3154
fn parse_args<'a>(
3255
ecx: &ExtCtxt<'a>,
3356
sp: Span,
@@ -105,23 +128,23 @@ pub fn parse_asm_args<'a>(
105128
};
106129

107130
let mut explicit_reg = false;
108-
let op = if !is_global_asm && p.eat_keyword(kw::In) {
131+
let op = if eat_operand_keyword(p, kw::In, !is_global_asm)? {
109132
let reg = parse_reg(p, &mut explicit_reg)?;
110133
if p.eat_keyword(kw::Underscore) {
111134
let err = dcx.create_err(errors::AsmUnderscoreInput { span: p.token.span });
112135
return Err(err);
113136
}
114137
let expr = p.parse_expr()?;
115138
ast::InlineAsmOperand::In { reg, expr }
116-
} else if !is_global_asm && p.eat_keyword(sym::out) {
139+
} else if eat_operand_keyword(p, sym::out, !is_global_asm)? {
117140
let reg = parse_reg(p, &mut explicit_reg)?;
118141
let expr = if p.eat_keyword(kw::Underscore) { None } else { Some(p.parse_expr()?) };
119142
ast::InlineAsmOperand::Out { reg, expr, late: false }
120-
} else if !is_global_asm && p.eat_keyword(sym::lateout) {
143+
} else if eat_operand_keyword(p, sym::lateout, !is_global_asm)? {
121144
let reg = parse_reg(p, &mut explicit_reg)?;
122145
let expr = if p.eat_keyword(kw::Underscore) { None } else { Some(p.parse_expr()?) };
123146
ast::InlineAsmOperand::Out { reg, expr, late: true }
124-
} else if !is_global_asm && p.eat_keyword(sym::inout) {
147+
} else if eat_operand_keyword(p, sym::inout, !is_global_asm)? {
125148
let reg = parse_reg(p, &mut explicit_reg)?;
126149
if p.eat_keyword(kw::Underscore) {
127150
let err = dcx.create_err(errors::AsmUnderscoreInput { span: p.token.span });
@@ -135,7 +158,7 @@ pub fn parse_asm_args<'a>(
135158
} else {
136159
ast::InlineAsmOperand::InOut { reg, expr, late: false }
137160
}
138-
} else if !is_global_asm && p.eat_keyword(sym::inlateout) {
161+
} else if eat_operand_keyword(p, sym::inlateout, !is_global_asm)? {
139162
let reg = parse_reg(p, &mut explicit_reg)?;
140163
if p.eat_keyword(kw::Underscore) {
141164
let err = dcx.create_err(errors::AsmUnderscoreInput { span: p.token.span });
@@ -149,6 +172,9 @@ pub fn parse_asm_args<'a>(
149172
} else {
150173
ast::InlineAsmOperand::InOut { reg, expr, late: true }
151174
}
175+
} else if eat_operand_keyword(p, sym::label, !is_global_asm)? {
176+
let block = p.parse_block()?;
177+
ast::InlineAsmOperand::Label { block }
152178
} else if p.eat_keyword(kw::Const) {
153179
let anon_const = p.parse_expr_anon_const()?;
154180
ast::InlineAsmOperand::Const { anon_const }
@@ -164,9 +190,6 @@ pub fn parse_asm_args<'a>(
164190
path: path.clone(),
165191
};
166192
ast::InlineAsmOperand::Sym { sym }
167-
} else if !is_global_asm && p.eat_keyword(sym::label) {
168-
let block = p.parse_block()?;
169-
ast::InlineAsmOperand::Label { block }
170193
} else if allow_templates {
171194
let template = p.parse_expr()?;
172195
// If it can't possibly expand to a string, provide diagnostics here to include other

compiler/rustc_builtin_macros/src/errors.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -851,6 +851,15 @@ pub(crate) struct GlobalAsmUnsupportedOption {
851851
pub(crate) full_span: Span,
852852
}
853853

854+
#[derive(Diagnostic)]
855+
#[diag(builtin_macros_global_asm_unsupported_operand)]
856+
pub(crate) struct GlobalAsmUnsupportedOperand<'a> {
857+
#[primary_span]
858+
#[label]
859+
pub(crate) span: Span,
860+
pub(crate) symbol: &'a str,
861+
}
862+
854863
#[derive(Diagnostic)]
855864
#[diag(builtin_macros_test_runner_invalid)]
856865
pub(crate) struct TestRunnerInvalid {

compiler/rustc_codegen_ssa/src/back/link.rs

Lines changed: 60 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2065,17 +2065,61 @@ fn add_local_crate_metadata_objects(
20652065
}
20662066

20672067
/// Add sysroot and other globally set directories to the directory search list.
2068-
fn add_library_search_dirs(cmd: &mut dyn Linker, sess: &Session, self_contained: bool) {
2069-
// The default library location, we need this to find the runtime.
2070-
// The location of crates will be determined as needed.
2071-
let lib_path = sess.target_filesearch(PathKind::All).get_lib_path();
2072-
cmd.include_path(&fix_windows_verbatim_for_gcc(&lib_path));
2068+
fn add_library_search_dirs(
2069+
cmd: &mut dyn Linker,
2070+
sess: &Session,
2071+
self_contained_components: LinkSelfContainedComponents,
2072+
apple_sdk_root: Option<&Path>,
2073+
) {
2074+
if !sess.opts.unstable_opts.link_native_libraries {
2075+
return;
2076+
}
20732077

2074-
// Special directory with libraries used only in self-contained linkage mode
2075-
if self_contained {
2076-
let lib_path = sess.target_filesearch(PathKind::All).get_self_contained_lib_path();
2078+
// Library search paths explicitly supplied by user (`-L` on the command line).
2079+
for search_path in sess.target_filesearch(PathKind::Native).cli_search_paths() {
2080+
cmd.include_path(&fix_windows_verbatim_for_gcc(&search_path.dir));
2081+
}
2082+
for search_path in sess.target_filesearch(PathKind::Framework).cli_search_paths() {
2083+
// Contrary to the `-L` docs only framework-specific paths are considered here.
2084+
if search_path.kind != PathKind::All {
2085+
cmd.framework_path(&search_path.dir);
2086+
}
2087+
}
2088+
2089+
// The toolchain ships some native library components and self-contained linking was enabled.
2090+
// Add the self-contained library directory to search paths.
2091+
if self_contained_components.intersects(
2092+
LinkSelfContainedComponents::LIBC
2093+
| LinkSelfContainedComponents::UNWIND
2094+
| LinkSelfContainedComponents::MINGW,
2095+
) {
2096+
let lib_path = sess.target_filesearch(PathKind::Native).get_self_contained_lib_path();
20772097
cmd.include_path(&fix_windows_verbatim_for_gcc(&lib_path));
20782098
}
2099+
2100+
// Toolchains for some targets may ship `libunwind.a`, but place it into the main sysroot
2101+
// library directory instead of the self-contained directories.
2102+
// Sanitizer libraries have the same issue and are also linked by name on Apple targets.
2103+
// The targets here should be in sync with `copy_third_party_objects` in bootstrap.
2104+
// FIXME: implement `-Clink-self-contained=+/-unwind,+/-sanitizers`, move the shipped libunwind
2105+
// and sanitizers to self-contained directory, and stop adding this search path.
2106+
if sess.target.vendor == "fortanix"
2107+
|| sess.target.os == "linux"
2108+
|| sess.target.os == "fuchsia"
2109+
|| sess.target.is_like_osx && !sess.opts.unstable_opts.sanitizer.is_empty()
2110+
{
2111+
let lib_path = sess.target_filesearch(PathKind::Native).get_lib_path();
2112+
cmd.include_path(&fix_windows_verbatim_for_gcc(&lib_path));
2113+
}
2114+
2115+
// Mac Catalyst uses the macOS SDK, but to link to iOS-specific frameworks
2116+
// we must have the support library stubs in the library search path (#121430).
2117+
if let Some(sdk_root) = apple_sdk_root
2118+
&& sess.target.llvm_target.contains("macabi")
2119+
{
2120+
cmd.include_path(&sdk_root.join("System/iOSSupport/usr/lib"));
2121+
cmd.framework_path(&sdk_root.join("System/iOSSupport/System/Library/Frameworks"));
2122+
}
20792123
}
20802124

20812125
/// Add options making relocation sections in the produced ELF files read-only
@@ -2367,7 +2411,7 @@ fn add_order_independent_options(
23672411
// Take care of the flavors and CLI options requesting the `lld` linker.
23682412
add_lld_args(cmd, sess, flavor, self_contained_components);
23692413

2370-
add_apple_sdk(cmd, sess, flavor);
2414+
let apple_sdk_root = add_apple_sdk(cmd, sess, flavor);
23712415

23722416
add_link_script(cmd, sess, tmpdir, crate_type);
23732417

@@ -2423,7 +2467,7 @@ fn add_order_independent_options(
24232467

24242468
cmd.linker_plugin_lto();
24252469

2426-
add_library_search_dirs(cmd, sess, self_contained_components.are_any_components_enabled());
2470+
add_library_search_dirs(cmd, sess, self_contained_components, apple_sdk_root.as_deref());
24272471

24282472
cmd.output_filename(out_filename);
24292473

@@ -2637,19 +2681,6 @@ fn add_local_native_libraries(
26372681
tmpdir: &Path,
26382682
link_output_kind: LinkOutputKind,
26392683
) {
2640-
if sess.opts.unstable_opts.link_native_libraries {
2641-
// User-supplied library search paths (-L on the command line). These are the same paths
2642-
// used to find Rust crates, so some of them may have been added already by the previous
2643-
// crate linking code. This only allows them to be found at compile time so it is still
2644-
// entirely up to outside forces to make sure that library can be found at runtime.
2645-
for search_path in sess.target_filesearch(PathKind::All).search_paths() {
2646-
match search_path.kind {
2647-
PathKind::Framework => cmd.framework_path(&search_path.dir),
2648-
_ => cmd.include_path(&fix_windows_verbatim_for_gcc(&search_path.dir)),
2649-
}
2650-
}
2651-
}
2652-
26532684
// All static and dynamic native library dependencies are linked to the local crate.
26542685
let link_static = true;
26552686
let link_dynamic = true;
@@ -2944,19 +2975,19 @@ pub(crate) fn are_upstream_rust_objects_already_included(sess: &Session) -> bool
29442975
}
29452976
}
29462977

2947-
fn add_apple_sdk(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
2978+
fn add_apple_sdk(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) -> Option<PathBuf> {
29482979
let arch = &sess.target.arch;
29492980
let os = &sess.target.os;
29502981
let llvm_target = &sess.target.llvm_target;
29512982
if sess.target.vendor != "apple"
29522983
|| !matches!(os.as_ref(), "ios" | "tvos" | "watchos" | "visionos" | "macos")
29532984
|| !matches!(flavor, LinkerFlavor::Darwin(..))
29542985
{
2955-
return;
2986+
return None;
29562987
}
29572988

29582989
if os == "macos" && !matches!(flavor, LinkerFlavor::Darwin(Cc::No, _)) {
2959-
return;
2990+
return None;
29602991
}
29612992

29622993
let sdk_name = match (arch.as_ref(), os.as_ref()) {
@@ -2980,14 +3011,14 @@ fn add_apple_sdk(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
29803011
(_, "macos") => "macosx",
29813012
_ => {
29823013
sess.dcx().emit_err(errors::UnsupportedArch { arch, os });
2983-
return;
3014+
return None;
29843015
}
29853016
};
29863017
let sdk_root = match get_apple_sdk_root(sdk_name) {
29873018
Ok(s) => s,
29883019
Err(e) => {
29893020
sess.dcx().emit_err(e);
2990-
return;
3021+
return None;
29913022
}
29923023
};
29933024

@@ -3007,16 +3038,7 @@ fn add_apple_sdk(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
30073038
_ => unreachable!(),
30083039
}
30093040

3010-
if llvm_target.contains("macabi") {
3011-
// Mac Catalyst uses the macOS SDK, but to link to iOS-specific
3012-
// frameworks, we must have the support library stubs in the library
3013-
// search path.
3014-
3015-
// The flags are called `-L` and `-F` both in Clang, ld64 and ldd.
3016-
let sdk_root = Path::new(&sdk_root);
3017-
cmd.include_path(&sdk_root.join("System/iOSSupport/usr/lib"));
3018-
cmd.framework_path(&sdk_root.join("System/iOSSupport/System/Library/Frameworks"));
3019-
}
3041+
Some(sdk_root.into())
30203042
}
30213043

30223044
fn get_apple_sdk_root(sdk_name: &str) -> Result<String, errors::AppleSdkRootError<'_>> {

0 commit comments

Comments
 (0)