Skip to content

Commit 3160f10

Browse files
committed
Auto merge of rust-lang#128650 - matthiaskrgr:rollup-gvrnowj, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#127655 (turn `invalid_type_param_default` into a `FutureReleaseErrorReportInDeps`) - rust-lang#127974 (force compiling std from source if modified) - rust-lang#128026 (std::thread: available_parallelism implementation for vxWorks proposal.) - rust-lang#128362 (add test for symbol visibility of `#[naked]` functions) - rust-lang#128500 (Add test for updating enum discriminant through pointer) - rust-lang#128630 (docs(resolve): more explain about `target`) - rust-lang#128638 (run-make: enable msvc for `link-dedup`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents ab1527f + 0c0354d commit 3160f10

File tree

20 files changed

+371
-48
lines changed

20 files changed

+371
-48
lines changed

compiler/rustc_feature/src/removed.rs

+3
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ declare_features! (
8282
/// Allows the use of `#[derive(Anything)]` as sugar for `#[derive_Anything]`.
8383
(removed, custom_derive, "1.32.0", Some(29644),
8484
Some("subsumed by `#[proc_macro_derive]`")),
85+
/// Allows default type parameters to influence type inference.
86+
(removed, default_type_parameter_fallback, "CURRENT_RUSTC_VERSION", Some(27336),
87+
Some("never properly implemented; requires significant design work")),
8588
/// Allows using `#[doc(keyword = "...")]`.
8689
(removed, doc_keyword, "1.28.0", Some(51315),
8790
Some("merged into `#![feature(rustdoc_internals)]`")),

compiler/rustc_feature/src/unstable.rs

-2
Original file line numberDiff line numberDiff line change
@@ -431,8 +431,6 @@ declare_features! (
431431
(unstable, custom_test_frameworks, "1.30.0", Some(50297)),
432432
/// Allows declarative macros 2.0 (`macro`).
433433
(unstable, decl_macro, "1.17.0", Some(39412)),
434-
/// Allows default type parameters to influence type inference.
435-
(unstable, default_type_parameter_fallback, "1.3.0", Some(27336)),
436434
/// Allows using `#[deprecated_safe]` to deprecate the safeness of a function or trait
437435
(unstable, deprecated_safe, "1.61.0", Some(94978)),
438436
/// Allows having using `suggestion` in the `#[deprecated]` attribute.

compiler/rustc_hir_analysis/src/collect/generics_of.rs

-2
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,6 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
338338
if default.is_some() {
339339
match allow_defaults {
340340
Defaults::Allowed => {}
341-
Defaults::FutureCompatDisallowed
342-
if tcx.features().default_type_parameter_fallback => {}
343341
Defaults::FutureCompatDisallowed => {
344342
tcx.node_span_lint(
345343
lint::builtin::INVALID_TYPE_PARAM_DEFAULT,

compiler/rustc_lint_defs/src/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1267,7 +1267,7 @@ declare_lint! {
12671267
Deny,
12681268
"type parameter default erroneously allowed in invalid location",
12691269
@future_incompatible = FutureIncompatibleInfo {
1270-
reason: FutureIncompatibilityReason::FutureReleaseErrorDontReportInDeps,
1270+
reason: FutureIncompatibilityReason::FutureReleaseErrorReportInDeps,
12711271
reference: "issue #36887 <https://github.com/rust-lang/rust/issues/36887>",
12721272
};
12731273
}

compiler/rustc_resolve/src/imports.rs

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ pub(crate) enum ImportKind<'a> {
4848
/// `source` in `use prefix::source as target`.
4949
source: Ident,
5050
/// `target` in `use prefix::source as target`.
51+
/// It will directly use `source` when the format is `use prefix::source`.
5152
target: Ident,
5253
/// Bindings to which `source` refers to.
5354
source_bindings: PerNS<Cell<Result<NameBinding<'a>, Determinacy>>>,

config.example.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,8 @@
472472
# This is mostly useful for tools; if you have changes to `compiler/` or `library/` they will be ignored.
473473
#
474474
# Set this to "if-unchanged" to only download if the compiler and standard library have not been modified.
475-
# Set this to `true` to download unconditionally (useful if e.g. you are only changing doc-comments).
475+
# Set this to `true` to download unconditionally. This is useful if you are working on tools, doc-comments,
476+
# or library (you will be able to build the standard library without needing to build the compiler).
476477
#download-rustc = false
477478

478479
# Number of codegen units to use for each compiler invocation. A value of 0

library/std/src/sys/pal/unix/thread.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -455,8 +455,18 @@ pub fn available_parallelism() -> io::Result<NonZero<usize>> {
455455

456456
Ok(NonZero::new_unchecked(sinfo.cpu_count as usize))
457457
}
458+
} else if #[cfg(target_os = "vxworks")] {
459+
// Note: there is also `vxCpuConfiguredGet`, closer to _SC_NPROCESSORS_CONF
460+
// expectations than the actual cores availability.
461+
extern "C" {
462+
fn vxCpuEnabledGet() -> libc::cpuset_t;
463+
}
464+
465+
// always fetches a valid bitmask
466+
let set = unsafe { vxCpuEnabledGet() };
467+
Ok(NonZero::new_unchecked(set.count_ones() as usize))
458468
} else {
459-
// FIXME: implement on vxWorks, Redox, l4re
469+
// FIXME: implement on Redox, l4re
460470
Err(io::const_io_error!(io::ErrorKind::Unsupported, "Getting the number of hardware threads is not supported on the target platform"))
461471
}
462472
}

src/bootstrap/src/core/build_steps/compile.rs

+31-8
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ use crate::core::builder::{
2626
use crate::core::config::{DebuginfoLevel, LlvmLibunwind, RustcLto, TargetSelection};
2727
use crate::utils::exec::command;
2828
use crate::utils::helpers::{
29-
exe, get_clang_cl_resource_dir, is_debug_info, is_dylib, symlink_dir, t, up_to_date,
29+
self, exe, get_clang_cl_resource_dir, get_closest_merge_base_commit, is_debug_info, is_dylib,
30+
symlink_dir, t, up_to_date,
3031
};
3132
use crate::{CLang, Compiler, DependencyType, GitRepo, Mode, LLVM_TOOLS};
3233

@@ -114,21 +115,43 @@ impl Step for Std {
114115
const DEFAULT: bool = true;
115116

116117
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
117-
// When downloading stage1, the standard library has already been copied to the sysroot, so
118-
// there's no need to rebuild it.
119-
let builder = run.builder;
120-
run.crate_or_deps("sysroot")
121-
.path("library")
122-
.lazy_default_condition(Box::new(|| !builder.download_rustc()))
118+
run.crate_or_deps("sysroot").path("library")
123119
}
124120

125121
fn make_run(run: RunConfig<'_>) {
126122
let crates = std_crates_for_run_make(&run);
123+
let builder = run.builder;
124+
125+
// Force compilation of the standard library from source if the `library` is modified. This allows
126+
// library team to compile the standard library without needing to compile the compiler with
127+
// the `rust.download-rustc=true` option.
128+
let force_recompile =
129+
if builder.rust_info().is_managed_git_subrepository() && builder.download_rustc() {
130+
let closest_merge_commit = get_closest_merge_base_commit(
131+
Some(&builder.src),
132+
&builder.config.git_config(),
133+
&builder.config.stage0_metadata.config.git_merge_commit_email,
134+
&[],
135+
)
136+
.unwrap();
137+
138+
// Check if `library` has changes (returns false otherwise)
139+
!t!(helpers::git(Some(&builder.src))
140+
.args(["diff-index", "--quiet", &closest_merge_commit])
141+
.arg("--")
142+
.arg(builder.src.join("library"))
143+
.as_command_mut()
144+
.status())
145+
.success()
146+
} else {
147+
false
148+
};
149+
127150
run.builder.ensure(Std {
128151
compiler: run.builder.compiler(run.builder.top_stage, run.build_triple()),
129152
target: run.target,
130153
crates,
131-
force_recompile: false,
154+
force_recompile,
132155
extra_rust_args: &[],
133156
is_for_mir_opt_tests: false,
134157
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//@ compile-flags: -O
2+
//@ min-llvm-version: 19
3+
4+
#![crate_type = "lib"]
5+
6+
pub enum State {
7+
A([u8; 753]),
8+
B([u8; 753]),
9+
}
10+
11+
// CHECK-LABEL: @update
12+
#[no_mangle]
13+
pub unsafe fn update(s: *mut State) {
14+
// CHECK-NEXT: start:
15+
// CHECK-NEXT: store i8
16+
// CHECK-NEXT: ret
17+
let State::A(v) = s.read() else { std::hint::unreachable_unchecked() };
18+
s.write(State::B(v));
19+
}

tests/run-make/link-dedup/rmake.rs

+25-8
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,37 @@
55
// Without the --cfg flag, there should be a single -ltesta, no more, no less.
66
// See https://github.com/rust-lang/rust/pull/84794
77

8-
//@ ignore-msvc
8+
use std::fmt::Write;
99

10-
use run_make_support::rustc;
10+
use run_make_support::{is_msvc, rustc};
1111

1212
fn main() {
1313
rustc().input("depa.rs").run();
1414
rustc().input("depb.rs").run();
1515
rustc().input("depc.rs").run();
16+
1617
let output = rustc().input("empty.rs").cfg("bar").run_fail();
17-
output.assert_stderr_contains(r#""-ltesta" "-ltestb" "-ltesta""#);
18-
let output = rustc().input("empty.rs").run_fail();
19-
output.assert_stderr_contains(r#""-ltesta""#);
20-
let output = rustc().input("empty.rs").run_fail();
21-
output.assert_stderr_not_contains(r#""-ltestb""#);
18+
output.assert_stderr_contains(needle_from_libs(&["testa", "testb", "testa"]));
19+
2220
let output = rustc().input("empty.rs").run_fail();
23-
output.assert_stderr_not_contains(r#""-ltesta" "-ltesta" "-ltesta""#);
21+
output.assert_stderr_contains(needle_from_libs(&["testa"]));
22+
output.assert_stderr_not_contains(needle_from_libs(&["testb"]));
23+
output.assert_stderr_not_contains(needle_from_libs(&["testa", "testa", "testa"]));
24+
// Adjacent identical native libraries are no longer deduplicated if
25+
// they come from different crates (https://github.com/rust-lang/rust/pull/103311)
26+
// so the following will fail:
27+
//output.assert_stderr_not_contains(needle_from_libs(&["testa", "testa"]));
28+
}
29+
30+
fn needle_from_libs(libs: &[&str]) -> String {
31+
let mut needle = String::new();
32+
for lib in libs {
33+
if is_msvc() {
34+
let _ = needle.write_fmt(format_args!(r#""{lib}.lib" "#));
35+
} else {
36+
let _ = needle.write_fmt(format_args!(r#""-l{lib}" "#));
37+
}
38+
}
39+
needle.pop(); // remove trailing space
40+
needle
2441
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#![feature(naked_functions, asm_const, linkage)]
2+
#![crate_type = "dylib"]
3+
4+
use std::arch::asm;
5+
6+
pub trait TraitWithConst {
7+
const COUNT: u32;
8+
}
9+
10+
struct Test;
11+
12+
impl TraitWithConst for Test {
13+
const COUNT: u32 = 1;
14+
}
15+
16+
#[no_mangle]
17+
fn entry() {
18+
private_vanilla_rust_function_from_rust_dylib();
19+
private_naked_rust_function_from_rust_dylib();
20+
21+
public_vanilla_generic_function_from_rust_dylib::<Test>();
22+
public_naked_generic_function_from_rust_dylib::<Test>();
23+
}
24+
25+
extern "C" fn private_vanilla_rust_function_from_rust_dylib() -> u32 {
26+
42
27+
}
28+
29+
#[no_mangle]
30+
pub extern "C" fn public_vanilla_rust_function_from_rust_dylib() -> u32 {
31+
42
32+
}
33+
34+
pub extern "C" fn public_vanilla_generic_function_from_rust_dylib<T: TraitWithConst>() -> u32 {
35+
T::COUNT
36+
}
37+
38+
#[linkage = "weak"]
39+
extern "C" fn vanilla_weak_linkage() -> u32 {
40+
42
41+
}
42+
43+
#[linkage = "external"]
44+
extern "C" fn vanilla_external_linkage() -> u32 {
45+
42
46+
}
47+
48+
#[naked]
49+
extern "C" fn private_naked_rust_function_from_rust_dylib() -> u32 {
50+
unsafe { asm!("mov rax, 42", "ret", options(noreturn)) }
51+
}
52+
53+
#[naked]
54+
#[no_mangle]
55+
pub extern "C" fn public_naked_rust_function_from_rust_dylib() -> u32 {
56+
unsafe { asm!("mov rax, 42", "ret", options(noreturn)) }
57+
}
58+
59+
#[naked]
60+
pub extern "C" fn public_naked_generic_function_from_rust_dylib<T: TraitWithConst>() -> u32 {
61+
unsafe { asm!("mov rax, {}", "ret", const T::COUNT, options(noreturn)) }
62+
}
63+
64+
#[naked]
65+
#[linkage = "weak"]
66+
extern "C" fn naked_weak_linkage() -> u32 {
67+
unsafe { asm!("mov rax, 42", "ret", options(noreturn)) }
68+
}
69+
70+
#[naked]
71+
#[linkage = "external"]
72+
extern "C" fn naked_external_linkage() -> u32 {
73+
unsafe { asm!("mov rax, 42", "ret", options(noreturn)) }
74+
}
75+
76+
// functions that are declared in an `extern "C"` block are currently not exported
77+
// this maybe should change in the future, this is just tracking the current behavior
78+
// reported in https://github.com/rust-lang/rust/issues/128071
79+
std::arch::global_asm! {
80+
".globl function_defined_in_global_asm",
81+
"function_defined_in_global_asm:",
82+
"ret",
83+
}
84+
85+
extern "C" {
86+
pub fn function_defined_in_global_asm();
87+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
//@ only-x86_64
2+
use run_make_support::object::read::{File, Object, Symbol};
3+
use run_make_support::object::ObjectSymbol;
4+
use run_make_support::{dynamic_lib_name, rfs, rustc};
5+
6+
fn main() {
7+
let rdylib_name = dynamic_lib_name("a_rust_dylib");
8+
rustc().arg("-Zshare-generics=no").input("a_rust_dylib.rs").run();
9+
10+
let binary_data = rfs::read(&rdylib_name);
11+
let rdylib = File::parse(&*binary_data).unwrap();
12+
13+
// check vanilla symbols
14+
not_exported(&rdylib, "private_vanilla_rust_function_from_rust_dylib");
15+
global_function(&rdylib, "public_vanilla_rust_function_from_rust_dylib");
16+
not_exported(&rdylib, "public_vanilla_generic_function_from_rust_dylib");
17+
18+
weak_function(&rdylib, "vanilla_weak_linkage");
19+
global_function(&rdylib, "vanilla_external_linkage");
20+
21+
// naked should mirror vanilla
22+
not_exported(&rdylib, "private_naked_rust_function_from_rust_dylib");
23+
global_function(&rdylib, "public_naked_rust_function_from_rust_dylib");
24+
not_exported(&rdylib, "public_naked_generic_function_from_rust_dylib");
25+
26+
weak_function(&rdylib, "naked_weak_linkage");
27+
global_function(&rdylib, "naked_external_linkage");
28+
29+
// functions that are declared in an `extern "C"` block are currently not exported
30+
// this maybe should change in the future, this is just tracking the current behavior
31+
// reported in https://github.com/rust-lang/rust/issues/128071
32+
not_exported(&rdylib, "function_defined_in_global_asm");
33+
34+
// share generics should expose the generic functions
35+
rustc().arg("-Zshare-generics=yes").input("a_rust_dylib.rs").run();
36+
let binary_data = rfs::read(&rdylib_name);
37+
let rdylib = File::parse(&*binary_data).unwrap();
38+
39+
global_function(&rdylib, "public_vanilla_generic_function_from_rust_dylib");
40+
global_function(&rdylib, "public_naked_generic_function_from_rust_dylib");
41+
}
42+
43+
#[track_caller]
44+
fn global_function(file: &File, symbol_name: &str) {
45+
let symbols = find_dynamic_symbol(file, symbol_name);
46+
let [symbol] = symbols.as_slice() else {
47+
panic!("symbol {symbol_name} occurs {} times", symbols.len())
48+
};
49+
50+
assert!(symbol.is_definition(), "`{symbol_name}` is not a function");
51+
assert!(symbol.is_global(), "`{symbol_name}` is not marked as global");
52+
}
53+
54+
#[track_caller]
55+
fn weak_function(file: &File, symbol_name: &str) {
56+
let symbols = find_dynamic_symbol(file, symbol_name);
57+
let [symbol] = symbols.as_slice() else {
58+
panic!("symbol {symbol_name} occurs {} times", symbols.len())
59+
};
60+
61+
assert!(symbol.is_definition(), "`{symbol_name}` is not a function");
62+
assert!(symbol.is_weak(), "`{symbol_name}` is not marked as weak");
63+
}
64+
65+
#[track_caller]
66+
fn not_exported(file: &File, symbol_name: &str) {
67+
assert_eq!(find_dynamic_symbol(file, symbol_name).len(), 0)
68+
}
69+
70+
fn find_dynamic_symbol<'file, 'data>(
71+
file: &'file File<'data>,
72+
expected: &str,
73+
) -> Vec<Symbol<'data, 'file>> {
74+
file.dynamic_symbols()
75+
.filter(|symbol| {
76+
let name = symbol.name().unwrap();
77+
!name.contains("__imp_") && name.contains(expected)
78+
})
79+
.collect()
80+
}

tests/ui/feature-gates/feature-gate-default_type_parameter_fallback.stderr

-21
This file was deleted.

0 commit comments

Comments
 (0)