Skip to content

Commit 1f94abc

Browse files
committed
Auto merge of rust-lang#87808 - JohnTitor:rollup-qqp79xs, r=JohnTitor
Rollup of 9 pull requests Successful merges: - rust-lang#87561 (thread set_name haiku implementation.) - rust-lang#87715 (Add long error explanation for E0625) - rust-lang#87727 (explicit_generic_args_with_impl_trait: fix min expected number of generics) - rust-lang#87742 (Validate FFI-safety warnings on naked functions) - rust-lang#87756 (Add back -Zno-profiler-runtime) - rust-lang#87759 (Re-use std::sealed::Sealed in os/linux/process.) - rust-lang#87760 (Promote `aarch64-apple-ios-sim` to Tier 2) - rust-lang#87770 (permit drop impls with generic constants in where clauses) - rust-lang#87780 (alloc: Use intra doc links for the reserve function) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 7129033 + b98c388 commit 1f94abc

File tree

26 files changed

+179
-46
lines changed

26 files changed

+179
-46
lines changed

compiler/rustc_error_codes/src/error_codes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ E0621: include_str!("./error_codes/E0621.md"),
359359
E0622: include_str!("./error_codes/E0622.md"),
360360
E0623: include_str!("./error_codes/E0623.md"),
361361
E0624: include_str!("./error_codes/E0624.md"),
362+
E0625: include_str!("./error_codes/E0625.md"),
362363
E0626: include_str!("./error_codes/E0626.md"),
363364
E0627: include_str!("./error_codes/E0627.md"),
364365
E0628: include_str!("./error_codes/E0628.md"),
@@ -622,7 +623,6 @@ E0783: include_str!("./error_codes/E0783.md"),
622623
// E0611, // merged into E0616
623624
// E0612, // merged into E0609
624625
// E0613, // Removed (merged with E0609)
625-
E0625, // thread-local statics cannot be accessed at compile-time
626626
// E0629, // missing 'feature' (rustc_const_unstable)
627627
// E0630, // rustc_const_unstable attribute must be paired with stable/unstable
628628
// attribute
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
A compile-time const variable is referring to a thread-local static variable.
2+
3+
Erroneous code example:
4+
5+
```compile_fail,E0625
6+
#![feature(thread_local)]
7+
8+
#[thread_local]
9+
static X: usize = 12;
10+
11+
const Y: usize = 2 * X;
12+
```
13+
14+
Static and const variables can refer to other const variables but a const
15+
variable cannot refer to a thread-local static variable. In this example,
16+
`Y` cannot refer to `X`. To fix this, the value can be extracted as a const
17+
and then used:
18+
19+
```
20+
#![feature(thread_local)]
21+
22+
const C: usize = 12;
23+
24+
#[thread_local]
25+
static X: usize = C;
26+
27+
const Y: usize = 2 * C;
28+
```

compiler/rustc_interface/src/tests.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,7 @@ fn test_debugging_options_tracking_hash() {
740740
tracked!(new_llvm_pass_manager, Some(true));
741741
tracked!(no_generate_arange_section, true);
742742
tracked!(no_link, true);
743+
tracked!(no_profiler_runtime, true);
743744
tracked!(osx_rpath_install_name, true);
744745
tracked!(panic_abort_tests, true);
745746
tracked!(plt, Some(true));
@@ -748,7 +749,7 @@ fn test_debugging_options_tracking_hash() {
748749
tracked!(print_fuel, Some("abc".to_string()));
749750
tracked!(profile, true);
750751
tracked!(profile_emit, Some(PathBuf::from("abc")));
751-
tracked!(profiler_runtime, None);
752+
tracked!(profiler_runtime, "abc".to_string());
752753
tracked!(relax_elf_relocations, Some(true));
753754
tracked!(relro_level, Some(RelroLevel::Full));
754755
tracked!(simulate_remapped_rust_src_base, Some(PathBuf::from("/rustc/abc")));

compiler/rustc_metadata/src/creader.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -777,19 +777,17 @@ impl<'a> CrateLoader<'a> {
777777
}
778778

779779
fn inject_profiler_runtime(&mut self, krate: &ast::Crate) {
780-
let profiler_runtime = &self.sess.opts.debugging_opts.profiler_runtime;
781-
782-
if !(profiler_runtime.is_some()
783-
&& (self.sess.instrument_coverage()
780+
if self.sess.opts.debugging_opts.no_profiler_runtime
781+
|| !(self.sess.instrument_coverage()
784782
|| self.sess.opts.debugging_opts.profile
785-
|| self.sess.opts.cg.profile_generate.enabled()))
783+
|| self.sess.opts.cg.profile_generate.enabled())
786784
{
787785
return;
788786
}
789787

790788
info!("loading profiler");
791789

792-
let name = Symbol::intern(profiler_runtime.as_ref().unwrap());
790+
let name = Symbol::intern(&self.sess.opts.debugging_opts.profiler_runtime);
793791
if name == sym::profiler_builtins && self.sess.contains_name(&krate.attrs, sym::no_core) {
794792
self.sess.err(
795793
"`profiler_builtins` crate (required by compiler options) \

compiler/rustc_metadata/src/locator.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1103,8 +1103,8 @@ impl CrateError {
11031103
if sess.is_nightly_build() {
11041104
err.help("consider building the standard library from source with `cargo build -Zbuild-std`");
11051105
}
1106-
} else if Some(crate_name)
1107-
== sess.opts.debugging_opts.profiler_runtime.as_deref().map(Symbol::intern)
1106+
} else if crate_name
1107+
== Symbol::intern(&sess.opts.debugging_opts.profiler_runtime)
11081108
{
11091109
err.note(&"the compiler may have been built without the profiler runtime");
11101110
}

compiler/rustc_session/src/options.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1172,6 +1172,8 @@ options! {
11721172
"compile without linking"),
11731173
no_parallel_llvm: bool = (false, parse_no_flag, [UNTRACKED],
11741174
"run LLVM in non-parallel mode (while keeping codegen-units and ThinLTO)"),
1175+
no_profiler_runtime: bool = (false, parse_no_flag, [TRACKED],
1176+
"prevent automatic injection of the profiler_builtins crate"),
11751177
normalize_docs: bool = (false, parse_bool, [TRACKED],
11761178
"normalize associated items in rustdoc when generating documentation"),
11771179
osx_rpath_install_name: bool = (false, parse_bool, [TRACKED],
@@ -1217,8 +1219,8 @@ options! {
12171219
profile_emit: Option<PathBuf> = (None, parse_opt_pathbuf, [TRACKED],
12181220
"file path to emit profiling data at runtime when using 'profile' \
12191221
(default based on relative source path)"),
1220-
profiler_runtime: Option<String> = (Some(String::from("profiler_builtins")), parse_opt_string, [TRACKED],
1221-
"name of the profiler runtime crate to automatically inject, or None to disable"),
1222+
profiler_runtime: String = (String::from("profiler_builtins"), parse_string, [TRACKED],
1223+
"name of the profiler runtime crate to automatically inject (default: `profiler_builtins`)"),
12221224
query_dep_graph: bool = (false, parse_bool, [UNTRACKED],
12231225
"enable queries of the dependency graph for regression testing (default: no)"),
12241226
query_stats: bool = (false, parse_bool, [UNTRACKED],

compiler/rustc_typeck/src/astconv/generics.rs

-1
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,6 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
613613
param_counts.consts + named_type_param_count
614614
- default_counts.types
615615
- default_counts.consts
616-
- synth_type_param_count
617616
};
618617
debug!("expected_min: {:?}", expected_min);
619618
debug!("arg_counts.lifetimes: {:?}", gen_args.num_lifetime_params());

compiler/rustc_typeck/src/check/dropck.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,9 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>(
218218

219219
// This closure is a more robust way to check `Predicate` equality
220220
// than simple `==` checks (which were the previous implementation).
221-
// It relies on `ty::relate` for `TraitPredicate` and `ProjectionPredicate`
222-
// (which implement the Relate trait), while delegating on simple equality
223-
// for the other `Predicate`.
221+
// It relies on `ty::relate` for `TraitPredicate`, `ProjectionPredicate`,
222+
// `ConstEvaluatable` and `TypeOutlives` (which implement the Relate trait),
223+
// while delegating on simple equality for the other `Predicate`.
224224
// This implementation solves (Issue #59497) and (Issue #58311).
225225
// It is unclear to me at the moment whether the approach based on `relate`
226226
// could be extended easily also to the other `Predicate`.
@@ -235,6 +235,13 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>(
235235
(ty::PredicateKind::Projection(a), ty::PredicateKind::Projection(b)) => {
236236
relator.relate(predicate.rebind(a), p.rebind(b)).is_ok()
237237
}
238+
(
239+
ty::PredicateKind::ConstEvaluatable(def_a, substs_a),
240+
ty::PredicateKind::ConstEvaluatable(def_b, substs_b),
241+
) => tcx.try_unify_abstract_consts(((def_a, substs_a), (def_b, substs_b))),
242+
(ty::PredicateKind::TypeOutlives(a), ty::PredicateKind::TypeOutlives(b)) => {
243+
relator.relate(predicate.rebind(a.0), p.rebind(b.0)).is_ok()
244+
}
238245
_ => predicate == p,
239246
}
240247
};

library/alloc/src/collections/vec_deque/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,9 @@ impl<T, A: Allocator> VecDeque<T, A> {
697697
///
698698
/// Note that the allocator may give the collection more space than it
699699
/// requests. Therefore, capacity can not be relied upon to be precisely
700-
/// minimal. Prefer `reserve` if future insertions are expected.
700+
/// minimal. Prefer [`reserve`] if future insertions are expected.
701+
///
702+
/// [`reserve`]: VecDeque::reserve
701703
///
702704
/// # Errors
703705
///

library/alloc/src/string.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1035,7 +1035,9 @@ impl String {
10351035
///
10361036
/// Note that the allocator may give the collection more space than it
10371037
/// requests. Therefore, capacity can not be relied upon to be precisely
1038-
/// minimal. Prefer `reserve` if future insertions are expected.
1038+
/// minimal. Prefer [`reserve`] if future insertions are expected.
1039+
///
1040+
/// [`reserve`]: String::reserve
10391041
///
10401042
/// # Errors
10411043
///

library/alloc/src/vec/mod.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,9 @@ impl<T, A: Allocator> Vec<T, A> {
811811
///
812812
/// Note that the allocator may give the collection more space than it
813813
/// requests. Therefore, capacity can not be relied upon to be precisely
814-
/// minimal. Prefer `reserve` if future insertions are expected.
814+
/// minimal. Prefer [`reserve`] if future insertions are expected.
815+
///
816+
/// [`reserve`]: Vec::reserve
815817
///
816818
/// # Panics
817819
///
@@ -875,7 +877,9 @@ impl<T, A: Allocator> Vec<T, A> {
875877
///
876878
/// Note that the allocator may give the collection more space than it
877879
/// requests. Therefore, capacity can not be relied upon to be precisely
878-
/// minimal. Prefer `reserve` if future insertions are expected.
880+
/// minimal. Prefer [`reserve`] if future insertions are expected.
881+
///
882+
/// [`reserve`]: Vec::reserve
879883
///
880884
/// # Errors
881885
///

library/std/src/ffi/os_str.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,9 @@ impl OsString {
271271
///
272272
/// Note that the allocator may give the collection more space than it
273273
/// requests. Therefore, capacity can not be relied upon to be precisely
274-
/// minimal. Prefer reserve if future insertions are expected.
274+
/// minimal. Prefer [`reserve`] if future insertions are expected.
275+
///
276+
/// [`reserve`]: OsString::reserve
275277
///
276278
/// # Examples
277279
///

library/std/src/os/linux/process.rs

+3-12
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use crate::io::Result;
66
use crate::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd};
77
use crate::process;
8+
use crate::sealed::Sealed;
89
#[cfg(not(doc))]
910
use crate::sys::fd::FileDesc;
1011
use crate::sys_common::{AsInner, AsInnerMut, FromInner, IntoInner};
@@ -84,15 +85,10 @@ impl IntoRawFd for PidFd {
8485
}
8586
}
8687

87-
mod private_child_ext {
88-
pub trait Sealed {}
89-
impl Sealed for crate::process::Child {}
90-
}
91-
9288
/// Os-specific extensions for [`Child`]
9389
///
9490
/// [`Child`]: process::Child
95-
pub trait ChildExt: private_child_ext::Sealed {
91+
pub trait ChildExt: Sealed {
9692
/// Obtains a reference to the [`PidFd`] created for this [`Child`], if available.
9793
///
9894
/// A pidfd will only be available if its creation was requested with
@@ -120,15 +116,10 @@ pub trait ChildExt: private_child_ext::Sealed {
120116
fn take_pidfd(&mut self) -> Result<PidFd>;
121117
}
122118

123-
mod private_command_ext {
124-
pub trait Sealed {}
125-
impl Sealed for crate::process::Command {}
126-
}
127-
128119
/// Os-specific extensions for [`Command`]
129120
///
130121
/// [`Command`]: process::Command
131-
pub trait CommandExt: private_command_ext::Sealed {
122+
pub trait CommandExt: Sealed {
132123
/// Sets whether a [`PidFd`](struct@PidFd) should be created for the [`Child`]
133124
/// spawned by this [`Command`].
134125
/// By default, no pidfd will be created.

library/std/src/process.rs

+4
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,10 @@ pub struct Child {
205205
pub stderr: Option<ChildStderr>,
206206
}
207207

208+
/// Allows extension traits within `std`.
209+
#[unstable(feature = "sealed", issue = "none")]
210+
impl crate::sealed::Sealed for Child {}
211+
208212
impl AsInner<imp::Process> for Child {
209213
fn as_inner(&self) -> &imp::Process {
210214
&self.handle

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

+9-2
Original file line numberDiff line numberDiff line change
@@ -164,16 +164,23 @@ impl Thread {
164164
}
165165
}
166166

167+
#[cfg(target_os = "haiku")]
168+
pub fn set_name(name: &CStr) {
169+
unsafe {
170+
let thread_self = libc::find_thread(ptr::null_mut());
171+
libc::rename_thread(thread_self, name.as_ptr());
172+
}
173+
}
174+
167175
#[cfg(any(
168176
target_env = "newlib",
169-
target_os = "haiku",
170177
target_os = "l4re",
171178
target_os = "emscripten",
172179
target_os = "redox",
173180
target_os = "vxworks"
174181
))]
175182
pub fn set_name(_name: &CStr) {
176-
// Newlib, Haiku, Emscripten, and VxWorks have no way to set a thread name.
183+
// Newlib, Emscripten, and VxWorks have no way to set a thread name.
177184
}
178185

179186
pub fn sleep(dur: Duration) {

src/doc/rustc/src/platform-support.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ target | std | notes
165165
`wasm32-unknown-unknown` | ✓ | WebAssembly
166166
`wasm32-wasi` | ✓ | WebAssembly with WASI
167167
`x86_64-apple-ios` | ✓ | 64-bit x86 iOS
168+
[`aarch64-apple-ios-sim`](platform-support/aarch64-apple-ios-sim.md) | ✓ | | Apple iOS Simulator on ARM64
168169
`x86_64-fortanix-unknown-sgx` | ✓ | [Fortanix ABI] for 64-bit Intel SGX
169170
`x86_64-fuchsia` | ✓ | 64-bit Fuchsia
170171
`x86_64-linux-android` | ✓ | 64-bit x86 Android
@@ -196,7 +197,6 @@ host tools.
196197
target | std | host | notes
197198
-------|:---:|:----:|-------
198199
`aarch64-apple-ios-macabi` | ? | | Apple Catalyst on ARM64
199-
[`aarch64-apple-ios-sim`](platform-support/aarch64-apple-ios-sim.md) | ✓ | | Apple iOS Simulator on ARM64
200200
`aarch64-apple-tvos` | * | | ARM64 tvOS
201201
`aarch64-unknown-freebsd` | ✓ | ✓ | ARM64 FreeBSD
202202
`aarch64-unknown-hermit` | ? | |

src/doc/rustc/src/platform-support/aarch64-apple-ios-sim.md

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# aarch64-apple-ios-sim
22

3-
**Tier: 3**
3+
**Tier: 2**
44

55
Apple iOS Simulator on ARM64.
66

@@ -39,17 +39,16 @@ Currently there is no support to run the rustc test suite for this target.
3939

4040
*Note: Building for this target requires the corresponding iOS SDK, as provided by Xcode 12+.*
4141

42-
If `rustc` has support for that target and the library artifacts are available,
43-
then Rust programs can be built for that target:
42+
From Rust Nightly 1.56.0 (2021-08-03) on the artifacts are shipped pre-compiled:
4443

4544
```text
46-
rustc --target aarch64-apple-ios-sim your-code.rs
45+
rustup target add aarch64-apple-ios-sim --toolchain nightly
4746
```
4847

49-
On Rust Nightly it is possible to build without the target artifacts available:
48+
Rust programs can be built for that target:
5049

5150
```text
52-
cargo build -Z build-std --target aarch64-apple-ios-sim
51+
rustc --target aarch64-apple-ios-sim your-code.rs
5352
```
5453

5554
There is no easy way to run simple programs in the iOS simulator.
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// check-pass
2+
// only-x86_64
3+
#![feature(asm)]
4+
#![feature(naked_functions)]
5+
#![crate_type = "lib"]
6+
7+
#[naked]
8+
pub extern "C" fn naked(p: char) -> u128 {
9+
//~^ WARN uses type `char`
10+
//~| WARN uses type `u128`
11+
unsafe { asm!("", options(noreturn)); }
12+
}
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
warning: `extern` fn uses type `char`, which is not FFI-safe
2+
--> $DIR/naked-functions-ffi.rs:8:28
3+
|
4+
LL | pub extern "C" fn naked(p: char) -> u128 {
5+
| ^^^^ not FFI-safe
6+
|
7+
= note: `#[warn(improper_ctypes_definitions)]` on by default
8+
= help: consider using `u32` or `libc::wchar_t` instead
9+
= note: the `char` type has no C equivalent
10+
11+
warning: `extern` fn uses type `u128`, which is not FFI-safe
12+
--> $DIR/naked-functions-ffi.rs:8:37
13+
|
14+
LL | pub extern "C" fn naked(p: char) -> u128 {
15+
| ^^^^ not FFI-safe
16+
|
17+
= note: 128-bit integers don't currently have a known stable ABI
18+
19+
warning: 2 warnings emitted
20+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//check-pass
2+
#![feature(const_generics, const_evaluatable_checked)]
3+
#![allow(incomplete_features)]
4+
5+
struct Foo<const N: usize>
6+
where
7+
[(); N + 1]: ;
8+
9+
impl<const N: usize> Drop for Foo<N>
10+
where
11+
[(); N + 1]: ,
12+
{
13+
fn drop(&mut self) {}
14+
}
15+
16+
fn main() {}

src/test/ui/impl-trait/explicit-generic-args-with-impl-trait/explicit-generic-args-for-impl.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
error[E0107]: this function takes at most 1 generic argument but 2 generic arguments were supplied
1+
error[E0107]: this function takes 1 generic argument but 2 generic arguments were supplied
22
--> $DIR/explicit-generic-args-for-impl.rs:6:5
33
|
44
LL | foo::<str, String>("".to_string());
55
| ^^^ ------ help: remove this generic argument
66
| |
7-
| expected at most 1 generic argument
7+
| expected 1 generic argument
88
|
9-
note: function defined here, with at most 1 generic parameter: `T`
9+
note: function defined here, with 1 generic parameter: `T`
1010
--> $DIR/explicit-generic-args-for-impl.rs:3:4
1111
|
1212
LL | fn foo<T: ?Sized>(_f: impl AsRef<T>) {}

0 commit comments

Comments
 (0)