Skip to content

Commit 2bbfa02

Browse files
committed
Auto merge of #74667 - Manishearth:rollup-s6k59sw, r=Manishearth
Rollup of 8 pull requests Successful merges: - #74141 (libstd/libcore: fix various typos) - #74490 (add a Backtrace::disabled function) - #74548 (one more Path::with_extension example, to demonstrate behavior) - #74587 (Prefer constant over function) - #74606 (Remove Linux workarounds for missing CLOEXEC support) - #74637 (Make str point to primitive page) - #74654 (require type defaults to be after const generic parameters) - #74659 (Improve codegen for unchecked float casts on wasm) Failed merges: r? @ghost
2 parents fcac119 + 8f02f2c commit 2bbfa02

File tree

36 files changed

+266
-302
lines changed

36 files changed

+266
-302
lines changed

src/liballoc/string.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ use crate::vec::Vec;
6565
///
6666
/// # Examples
6767
///
68-
/// You can create a `String` from [a literal string][str] with [`String::from`]:
68+
/// You can create a `String` from [a literal string][`str`] with [`String::from`]:
6969
///
7070
/// [`String::from`]: From::from
7171
///
@@ -268,7 +268,8 @@ use crate::vec::Vec;
268268
///
269269
/// Here, there's no need to allocate more memory inside the loop.
270270
///
271-
/// [`&str`]: str
271+
/// [`str`]: type@str
272+
/// [`&str`]: type@str
272273
/// [`Deref`]: core::ops::Deref
273274
/// [`as_str()`]: String::as_str
274275
#[derive(PartialOrd, Eq, Ord)]

src/libcore/convert/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ impl AsRef<str> for str {
677677
///
678678
///
679679
/// However there is one case where `!` syntax can be used
680-
/// before `!` is stabilized as a full-fleged type: in the position of a function’s return type.
680+
/// before `!` is stabilized as a full-fledged type: in the position of a function’s return type.
681681
/// Specifically, it is possible implementations for two different function pointer types:
682682
///
683683
/// ```

src/libcore/hash/sip.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ struct SipHasher24 {
4343
///
4444
/// SipHash is a general-purpose hashing function: it runs at a good
4545
/// speed (competitive with Spooky and City) and permits strong _keyed_
46-
/// hashing. This lets you key your hashtables from a strong RNG, such as
46+
/// hashing. This lets you key your hash tables from a strong RNG, such as
4747
/// [`rand::os::OsRng`](https://doc.rust-lang.org/rand/rand/os/struct.OsRng.html).
4848
///
4949
/// Although the SipHash algorithm is considered to be generally strong,

src/libcore/intrinsics.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
//!
1616
//! If an intrinsic is supposed to be used from a `const fn` with a `rustc_const_stable` attribute,
1717
//! the intrinsic's attribute must be `rustc_const_stable`, too. Such a change should not be done
18-
//! without T-lang consulation, because it bakes a feature into the language that cannot be
18+
//! without T-lang consultation, because it bakes a feature into the language that cannot be
1919
//! replicated in user code without compiler support.
2020
//!
2121
//! # Volatiles
@@ -994,7 +994,7 @@ extern "rust-intrinsic" {
994994
/// [`std::mem::align_of`](../../std/mem/fn.align_of.html).
995995
#[rustc_const_stable(feature = "const_min_align_of", since = "1.40.0")]
996996
pub fn min_align_of<T>() -> usize;
997-
/// The prefered alignment of a type.
997+
/// The preferred alignment of a type.
998998
///
999999
/// This intrinsic does not have a stable counterpart.
10001000
#[rustc_const_unstable(feature = "const_pref_align_of", issue = "none")]
@@ -1246,14 +1246,14 @@ extern "rust-intrinsic" {
12461246
/// assert!(mid <= len);
12471247
/// unsafe {
12481248
/// let slice2 = mem::transmute::<&mut [T], &mut [T]>(slice);
1249-
/// // first: transmute is not typesafe; all it checks is that T and
1249+
/// // first: transmute is not type safe; all it checks is that T and
12501250
/// // U are of the same size. Second, right here, you have two
12511251
/// // mutable references pointing to the same memory.
12521252
/// (&mut slice[0..mid], &mut slice2[mid..len])
12531253
/// }
12541254
/// }
12551255
///
1256-
/// // This gets rid of the typesafety problems; `&mut *` will *only* give
1256+
/// // This gets rid of the type safety problems; `&mut *` will *only* give
12571257
/// // you an `&mut T` from an `&mut T` or `*mut T`.
12581258
/// fn split_at_mut_casts<T>(slice: &mut [T], mid: usize)
12591259
/// -> (&mut [T], &mut [T]) {

src/libcore/iter/traits/iterator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1069,7 +1069,7 @@ pub trait Iterator {
10691069
/// let vec = iter.collect::<Vec<_>>();
10701070
///
10711071
/// // We have more elements which could fit in u32 (4, 5), but `map_while` returned `None` for `-3`
1072-
/// // (as the `predicate` returned `None`) and `collect` stops at the first `None` entcountered.
1072+
/// // (as the `predicate` returned `None`) and `collect` stops at the first `None` encountered.
10731073
/// assert_eq!(vec, vec![0, 1, 2]);
10741074
/// ```
10751075
///

src/libcore/macros/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1047,7 +1047,7 @@ pub(crate) mod builtin {
10471047
};
10481048
}
10491049

1050-
/// Includes a utf8-encoded file as a string.
1050+
/// Includes a UTF-8 encoded file as a string.
10511051
///
10521052
/// The file is located relative to the current file (similarly to how
10531053
/// modules are found). The provided path is interpreted in a platform-specific

src/libcore/mem/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -348,11 +348,11 @@ pub fn size_of_val<T: ?Sized>(val: &T) -> usize {
348348
///
349349
/// - If `T` is `Sized`, this function is always safe to call.
350350
/// - If the unsized tail of `T` is:
351-
/// - a [slice], then the length of the slice tail must be an intialized
351+
/// - a [slice], then the length of the slice tail must be an initialized
352352
/// integer, and the size of the *entire value*
353353
/// (dynamic tail length + statically sized prefix) must fit in `isize`.
354354
/// - a [trait object], then the vtable part of the pointer must point
355-
/// to a valid vtable acquired by an unsizing coersion, and the size
355+
/// to a valid vtable acquired by an unsizing coercion, and the size
356356
/// of the *entire value* (dynamic tail length + statically sized prefix)
357357
/// must fit in `isize`.
358358
/// - an (unstable) [extern type], then this function is always safe to
@@ -483,11 +483,11 @@ pub fn align_of_val<T: ?Sized>(val: &T) -> usize {
483483
///
484484
/// - If `T` is `Sized`, this function is always safe to call.
485485
/// - If the unsized tail of `T` is:
486-
/// - a [slice], then the length of the slice tail must be an intialized
486+
/// - a [slice], then the length of the slice tail must be an initialized
487487
/// integer, and the size of the *entire value*
488488
/// (dynamic tail length + statically sized prefix) must fit in `isize`.
489489
/// - a [trait object], then the vtable part of the pointer must point
490-
/// to a valid vtable acquired by an unsizing coersion, and the size
490+
/// to a valid vtable acquired by an unsizing coercion, and the size
491491
/// of the *entire value* (dynamic tail length + statically sized prefix)
492492
/// must fit in `isize`.
493493
/// - an (unstable) [extern type], then this function is always safe to

src/libcore/num/f64.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ impl f64 {
687687
/// signaling NaNs on MIPS are quiet NaNs on x86, and vice-versa.
688688
///
689689
/// Rather than trying to preserve signaling-ness cross-platform, this
690-
/// implementation favours preserving the exact bits. This means that
690+
/// implementation favors preserving the exact bits. This means that
691691
/// any payloads encoded in NaNs will be preserved even if the result of
692692
/// this method is sent over the network from an x86 machine to a MIPS one.
693693
///
@@ -696,7 +696,7 @@ impl f64 {
696696
///
697697
/// If the input isn't NaN, then there is no portability concern.
698698
///
699-
/// If you don't care about signalingness (very likely), then there is no
699+
/// If you don't care about signaling-ness (very likely), then there is no
700700
/// portability concern.
701701
///
702702
/// Note that this function is distinct from `as` casting, which attempts to

src/libcore/pin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@
128128
//!
129129
//! Crucially, we have to be able to rely on [`drop`] being called. If an element
130130
//! could be deallocated or otherwise invalidated without calling [`drop`], the pointers into it
131-
//! from its neighbouring elements would become invalid, which would break the data structure.
131+
//! from its neighboring elements would become invalid, which would break the data structure.
132132
//!
133133
//! Therefore, pinning also comes with a [`drop`]-related guarantee.
134134
//!

src/libcore/ptr/const_ptr.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -331,13 +331,13 @@ impl<T: ?Sized> *const T {
331331
intrinsics::ptr_guaranteed_eq(self, other)
332332
}
333333

334-
/// Returns whether two pointers are guaranteed to be inequal.
334+
/// Returns whether two pointers are guaranteed to be unequal.
335335
///
336336
/// At runtime this function behaves like `self != other`.
337337
/// However, in some contexts (e.g., compile-time evaluation),
338338
/// it is not always possible to determine the inequality of two pointers, so this function may
339-
/// spuriously return `false` for pointers that later actually turn out to be inequal.
340-
/// But when it returns `true`, the pointers are guaranteed to be inequal.
339+
/// spuriously return `false` for pointers that later actually turn out to be unequal.
340+
/// But when it returns `true`, the pointers are guaranteed to be unequal.
341341
///
342342
/// This function is the mirror of [`guaranteed_eq`], but not its inverse. There are pointer
343343
/// comparisons for which both functions return `false`.

src/libcore/ptr/mut_ptr.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -317,13 +317,13 @@ impl<T: ?Sized> *mut T {
317317
intrinsics::ptr_guaranteed_eq(self as *const _, other as *const _)
318318
}
319319

320-
/// Returns whether two pointers are guaranteed to be inequal.
320+
/// Returns whether two pointers are guaranteed to be unequal.
321321
///
322322
/// At runtime this function behaves like `self != other`.
323323
/// However, in some contexts (e.g., compile-time evaluation),
324324
/// it is not always possible to determine the inequality of two pointers, so this function may
325-
/// spuriously return `false` for pointers that later actually turn out to be inequal.
326-
/// But when it returns `true`, the pointers are guaranteed to be inequal.
325+
/// spuriously return `false` for pointers that later actually turn out to be unequal.
326+
/// But when it returns `true`, the pointers are guaranteed to be unequal.
327327
///
328328
/// This function is the mirror of [`guaranteed_eq`], but not its inverse. There are pointer
329329
/// comparisons for which both functions return `false`.

src/libcore/ptr/non_null.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ impl<T> NonNull<[T]> {
172172
/// assert_eq!(unsafe { slice.as_ref()[2] }, 7);
173173
/// ```
174174
///
175-
/// (Note that this example artifically demonstrates a use of this method,
175+
/// (Note that this example artificially demonstrates a use of this method,
176176
/// but `let slice = NonNull::from(&x[..]);` would be a better way to write code like this.)
177177
#[unstable(feature = "nonnull_slice_from_raw_parts", issue = "71941")]
178178
#[rustc_const_unstable(feature = "const_nonnull_slice_from_raw_parts", issue = "71941")]

src/librustc_ast_passes/ast_validation.rs

+19-6
Original file line numberDiff line numberDiff line change
@@ -1118,13 +1118,26 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
11181118
fn visit_generics(&mut self, generics: &'a Generics) {
11191119
let mut prev_ty_default = None;
11201120
for param in &generics.params {
1121-
if let GenericParamKind::Type { ref default, .. } = param.kind {
1122-
if default.is_some() {
1121+
match param.kind {
1122+
GenericParamKind::Lifetime => (),
1123+
GenericParamKind::Type { default: Some(_), .. } => {
11231124
prev_ty_default = Some(param.ident.span);
1124-
} else if let Some(span) = prev_ty_default {
1125-
self.err_handler()
1126-
.span_err(span, "type parameters with a default must be trailing");
1127-
break;
1125+
}
1126+
GenericParamKind::Type { .. } | GenericParamKind::Const { .. } => {
1127+
if let Some(span) = prev_ty_default {
1128+
let mut err = self.err_handler().struct_span_err(
1129+
span,
1130+
"type parameters with a default must be trailing",
1131+
);
1132+
if matches!(param.kind, GenericParamKind::Const { .. }) {
1133+
err.note(
1134+
"using type defaults and const parameters \
1135+
in the same parameter list is currently not permitted",
1136+
);
1137+
}
1138+
err.emit();
1139+
break;
1140+
}
11281141
}
11291142
}
11301143
}

src/librustc_codegen_llvm/context.rs

+8
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,14 @@ impl CodegenCx<'b, 'tcx> {
510510
ifn!("llvm.wasm.trunc.saturate.signed.i32.f64", fn(t_f64) -> t_i32);
511511
ifn!("llvm.wasm.trunc.saturate.signed.i64.f32", fn(t_f32) -> t_i64);
512512
ifn!("llvm.wasm.trunc.saturate.signed.i64.f64", fn(t_f64) -> t_i64);
513+
ifn!("llvm.wasm.trunc.unsigned.i32.f32", fn(t_f32) -> t_i32);
514+
ifn!("llvm.wasm.trunc.unsigned.i32.f64", fn(t_f64) -> t_i32);
515+
ifn!("llvm.wasm.trunc.unsigned.i64.f32", fn(t_f32) -> t_i64);
516+
ifn!("llvm.wasm.trunc.unsigned.i64.f64", fn(t_f64) -> t_i64);
517+
ifn!("llvm.wasm.trunc.signed.i32.f32", fn(t_f32) -> t_i32);
518+
ifn!("llvm.wasm.trunc.signed.i32.f64", fn(t_f64) -> t_i32);
519+
ifn!("llvm.wasm.trunc.signed.i64.f32", fn(t_f32) -> t_i64);
520+
ifn!("llvm.wasm.trunc.signed.i64.f64", fn(t_f64) -> t_i64);
513521

514522
ifn!("llvm.trap", fn() -> void);
515523
ifn!("llvm.debugtrap", fn() -> void);

src/librustc_codegen_llvm/intrinsic.rs

+57-18
Original file line numberDiff line numberDiff line change
@@ -629,27 +629,24 @@ impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
629629
}
630630

631631
sym::float_to_int_unchecked => {
632-
if float_type_width(arg_tys[0]).is_none() {
633-
span_invalid_monomorphization_error(
634-
tcx.sess,
635-
span,
636-
&format!(
637-
"invalid monomorphization of `float_to_int_unchecked` \
632+
let float_width = match float_type_width(arg_tys[0]) {
633+
Some(width) => width,
634+
None => {
635+
span_invalid_monomorphization_error(
636+
tcx.sess,
637+
span,
638+
&format!(
639+
"invalid monomorphization of `float_to_int_unchecked` \
638640
intrinsic: expected basic float type, \
639641
found `{}`",
640-
arg_tys[0]
641-
),
642-
);
643-
return;
644-
}
645-
match int_type_width_signed(ret_ty, self.cx) {
646-
Some((width, signed)) => {
647-
if signed {
648-
self.fptosi(args[0].immediate(), self.cx.type_ix(width))
649-
} else {
650-
self.fptoui(args[0].immediate(), self.cx.type_ix(width))
651-
}
642+
arg_tys[0]
643+
),
644+
);
645+
return;
652646
}
647+
};
648+
let (width, signed) = match int_type_width_signed(ret_ty, self.cx) {
649+
Some(pair) => pair,
653650
None => {
654651
span_invalid_monomorphization_error(
655652
tcx.sess,
@@ -663,7 +660,49 @@ impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
663660
);
664661
return;
665662
}
663+
};
664+
665+
// The LLVM backend can reorder and speculate `fptosi` and
666+
// `fptoui`, so on WebAssembly the codegen for this instruction
667+
// is quite heavyweight. To avoid this heavyweight codegen we
668+
// instead use the raw wasm intrinsics which will lower to one
669+
// instruction in WebAssembly (`iNN.trunc_fMM_{s,u}`). This one
670+
// instruction will trap if the operand is out of bounds, but
671+
// that's ok since this intrinsic is UB if the operands are out
672+
// of bounds, so the behavior can be different on WebAssembly
673+
// than other targets.
674+
//
675+
// Note, however, that when the `nontrapping-fptoint` feature is
676+
// enabled in LLVM then LLVM will lower `fptosi` to
677+
// `iNN.trunc_sat_fMM_{s,u}`, so if that's the case we don't
678+
// bother with intrinsics.
679+
let mut result = None;
680+
if self.sess().target.target.arch == "wasm32"
681+
&& !self.sess().target_features.contains(&sym::nontrapping_dash_fptoint)
682+
{
683+
let name = match (width, float_width, signed) {
684+
(32, 32, true) => Some("llvm.wasm.trunc.signed.i32.f32"),
685+
(32, 64, true) => Some("llvm.wasm.trunc.signed.i32.f64"),
686+
(64, 32, true) => Some("llvm.wasm.trunc.signed.i64.f32"),
687+
(64, 64, true) => Some("llvm.wasm.trunc.signed.i64.f64"),
688+
(32, 32, false) => Some("llvm.wasm.trunc.unsigned.i32.f32"),
689+
(32, 64, false) => Some("llvm.wasm.trunc.unsigned.i32.f64"),
690+
(64, 32, false) => Some("llvm.wasm.trunc.unsigned.i64.f32"),
691+
(64, 64, false) => Some("llvm.wasm.trunc.unsigned.i64.f64"),
692+
_ => None,
693+
};
694+
if let Some(name) = name {
695+
let intrinsic = self.get_intrinsic(name);
696+
result = Some(self.call(intrinsic, &[args[0].immediate()], None));
697+
}
666698
}
699+
result.unwrap_or_else(|| {
700+
if signed {
701+
self.fptosi(args[0].immediate(), self.cx.type_ix(width))
702+
} else {
703+
self.fptoui(args[0].immediate(), self.cx.type_ix(width))
704+
}
705+
})
667706
}
668707

669708
sym::discriminant_value => {

src/libstd/backtrace.rs

+6
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,12 @@ impl Backtrace {
291291
Backtrace::create(Backtrace::force_capture as usize)
292292
}
293293

294+
/// Forcibly captures a disabled backtrace, regardless of environment
295+
/// variable configuration.
296+
pub const fn disabled() -> Backtrace {
297+
Backtrace { inner: Inner::Disabled }
298+
}
299+
294300
// Capture a backtrace which start just before the function addressed by
295301
// `ip`
296302
fn create(ip: usize) -> Backtrace {

src/libstd/f32.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1500,7 +1500,7 @@ mod tests {
15001500
assert_approx_eq!(f32::from_bits(0x44a72000), 1337.0);
15011501
assert_approx_eq!(f32::from_bits(0xc1640000), -14.25);
15021502

1503-
// Check that NaNs roundtrip their bits regardless of signalingness
1503+
// Check that NaNs roundtrip their bits regardless of signaling-ness
15041504
// 0xA is 0b1010; 0x5 is 0b0101 -- so these two together clobbers all the mantissa bits
15051505
let masked_nan1 = f32::NAN.to_bits() ^ 0x002A_AAAA;
15061506
let masked_nan2 = f32::NAN.to_bits() ^ 0x0055_5555;

src/libstd/f64.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1523,7 +1523,7 @@ mod tests {
15231523
assert_approx_eq!(f64::from_bits(0x4094e40000000000), 1337.0);
15241524
assert_approx_eq!(f64::from_bits(0xc02c800000000000), -14.25);
15251525

1526-
// Check that NaNs roundtrip their bits regardless of signalingness
1526+
// Check that NaNs roundtrip their bits regardless of signaling-ness
15271527
// 0xA is 0b1010; 0x5 is 0b0101 -- so these two together clobbers all the mantissa bits
15281528
let masked_nan1 = f64::NAN.to_bits() ^ 0x000A_AAAA_AAAA_AAAA;
15291529
let masked_nan2 = f64::NAN.to_bits() ^ 0x0005_5555_5555_5555;

src/libstd/os/linux/fs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ pub trait MetadataExt {
285285
/// ```
286286
#[stable(feature = "metadata_ext2", since = "1.8.0")]
287287
fn st_ctime_nsec(&self) -> i64;
288-
/// Returns the "preferred" blocksize for efficient filesystem I/O.
288+
/// Returns the "preferred" block size for efficient filesystem I/O.
289289
///
290290
/// # Examples
291291
///

src/libstd/os/redox/fs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ pub trait MetadataExt {
289289
/// ```
290290
#[stable(feature = "metadata_ext2", since = "1.8.0")]
291291
fn st_ctime_nsec(&self) -> i64;
292-
/// Returns the "preferred" blocksize for efficient filesystem I/O.
292+
/// Returns the "preferred" block size for efficient filesystem I/O.
293293
///
294294
/// # Examples
295295
///

src/libstd/path.rs

+3
Original file line numberDiff line numberDiff line change
@@ -2244,6 +2244,9 @@ impl Path {
22442244
///
22452245
/// let path = Path::new("foo.rs");
22462246
/// assert_eq!(path.with_extension("txt"), PathBuf::from("foo.txt"));
2247+
///
2248+
/// let path = Path::new("foo.tar.gz");
2249+
/// assert_eq!(path.with_extension(""), PathBuf::from("foo.tar"));
22472250
/// ```
22482251
#[stable(feature = "rust1", since = "1.0.0")]
22492252
pub fn with_extension<S: AsRef<OsStr>>(&self, extension: S) -> PathBuf {

src/libstd/sys/sgx/fd.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ impl FileDesc {
1919
self.fd
2020
}
2121

22-
/// Extracts the actual filedescriptor without closing it.
22+
/// Extracts the actual file descriptor without closing it.
2323
pub fn into_raw(self) -> Fd {
2424
let fd = self.fd;
2525
mem::forget(self);

0 commit comments

Comments
 (0)