Skip to content

Commit 60e50fc

Browse files
committed
Auto merge of rust-lang#95653 - Dylan-DPC:rollup-2p9hzi3, r=Dylan-DPC
Rollup of 7 pull requests Successful merges: - rust-lang#92942 (stabilize windows_process_extensions_raw_arg) - rust-lang#94817 (Release notes for 1.60.0) - rust-lang#95343 (Reduce unnecessary escaping in proc_macro::Literal::character/string) - rust-lang#95431 (Stabilize total_cmp) - rust-lang#95438 (Add SyncUnsafeCell.) - rust-lang#95467 (Windows: Synchronize asynchronous pipe reads and writes) - rust-lang#95609 (Suggest borrowing when trying to coerce unsized type into `dyn Trait`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 6a9080b + 0c5f879 commit 60e50fc

File tree

19 files changed

+499
-23
lines changed

19 files changed

+499
-23
lines changed

RELEASES.md

+155
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,158 @@
1+
Version 1.60.0 (2022-04-07)
2+
==========================
3+
4+
Language
5+
--------
6+
- [Stabilize `#[cfg(panic = "...")]` for either `"unwind"` or `"abort"`.][93658]
7+
- [Stabilize `#[cfg(target_has_atomic = "...")]` for each integer size and `"ptr"`.][93824]
8+
9+
Compiler
10+
--------
11+
- [Enable combining `+crt-static` and `relocation-model=pic` on `x86_64-unknown-linux-gnu`][86374]
12+
- [Fixes wrong `unreachable_pub` lints on nested and glob public reexport][87487]
13+
- [Stabilize `-Z instrument-coverage` as `-C instrument-coverage`][90132]
14+
- [Stabilize `-Z print-link-args` as `--print link-args`][91606]
15+
- [Add new Tier 3 target `mips64-openwrt-linux-musl`\*][92300]
16+
- [Add new Tier 3 target `armv7-unknown-linux-uclibceabi` (softfloat)\*][92383]
17+
- [Fix invalid removal of newlines from doc comments][92357]
18+
- [Add kernel target for RustyHermit][92670]
19+
- [Deny mixing bin crate type with lib crate types][92933]
20+
- [Make rustc use `RUST_BACKTRACE=full` by default][93566]
21+
- [Upgrade to LLVM 14][93577]
22+
23+
\* Refer to Rust's [platform support page][platform-support-doc] for more
24+
information on Rust's tiered platform support.
25+
26+
Libraries
27+
---------
28+
- [Guarantee call order for `sort_by_cached_key`][89621]
29+
- [Improve `Duration::try_from_secs_f32`/`f64` accuracy by directly processing exponent and mantissa][90247]
30+
- [Make `Instant::{duration_since, elapsed, sub}` saturating][89926]
31+
- [Remove non-monotonic clocks workarounds in `Instant::now`][89926]
32+
- [Make `BuildHasherDefault`, `iter::Empty` and `future::Pending` covariant][92630]
33+
34+
Stabilized APIs
35+
---------------
36+
- [`Arc::new_cyclic`][arc_new_cyclic]
37+
- [`Rc::new_cyclic`][rc_new_cyclic]
38+
- [`slice::EscapeAscii`][slice_escape_ascii]
39+
- [`<[u8]>::escape_ascii`][slice_u8_escape_ascii]
40+
- [`u8::escape_ascii`][u8_escape_ascii]
41+
- [`Vec::spare_capacity_mut`][vec_spare_capacity_mut]
42+
- [`MaybeUninit::assume_init_drop`][assume_init_drop]
43+
- [`MaybeUninit::assume_init_read`][assume_init_read]
44+
- [`i8::abs_diff`][i8_abs_diff]
45+
- [`i16::abs_diff`][i16_abs_diff]
46+
- [`i32::abs_diff`][i32_abs_diff]
47+
- [`i64::abs_diff`][i64_abs_diff]
48+
- [`i128::abs_diff`][i128_abs_diff]
49+
- [`isize::abs_diff`][isize_abs_diff]
50+
- [`u8::abs_diff`][u8_abs_diff]
51+
- [`u16::abs_diff`][u16_abs_diff]
52+
- [`u32::abs_diff`][u32_abs_diff]
53+
- [`u64::abs_diff`][u64_abs_diff]
54+
- [`u128::abs_diff`][u128_abs_diff]
55+
- [`usize::abs_diff`][usize_abs_diff]
56+
- [`Display for io::ErrorKind`][display_error_kind]
57+
- [`From<u8> for ExitCode`][from_u8_exit_code]
58+
- [`Not for !` (the "never" type)][not_never]
59+
- [_Op_`Assign<$t> for Wrapping<$t>`][wrapping_assign_ops]
60+
- [`arch::is_aarch64_feature_detected!`][is_aarch64_feature_detected]
61+
62+
Cargo
63+
-----
64+
- [Port cargo from `toml-rs` to `toml_edit`][cargo/10086]
65+
- [Stabilize `-Ztimings` as `--timings`][cargo/10245]
66+
- [Stabilize namespaced and weak dependency features.][cargo/10269]
67+
- [Accept more `cargo:rustc-link-arg-*` types from build script output.][cargo/10274]
68+
- [cargo-new should not add ignore rule on Cargo.lock inside subdirs][cargo/10379]
69+
70+
Misc
71+
----
72+
- [Ship docs on Tier 2 platforms by reusing the closest Tier 1 platform docs][92800]
73+
- [Drop rustc-docs from complete profile][93742]
74+
- [bootstrap: tidy up flag handling for llvm build][93918]
75+
76+
Compatibility Notes
77+
-------------------
78+
- [Remove compiler-rt linking hack on Android][83822]
79+
- [Mitigations for platforms with non-monotonic clocks have been removed from
80+
`Instant::now`][89926]. On platforms that don't provide monotonic clocks, an
81+
instant is not guaranteed to be greater than an earlier instant anymore.
82+
- [`Instant::{duration_since, elapsed, sub}` do not panic anymore on underflow,
83+
saturating to `0` instead][89926]. In the real world the panic happened mostly
84+
on platforms with buggy monotonic clock implementations rather than catching
85+
programming errors like reversing the start and end times. Such programming
86+
errors will now results in `0` rather than a panic.
87+
- In a future release we're planning to increase the baseline requirements for
88+
the Linux kernel to version 3.2, and for glibc to version 2.17. We'd love
89+
your feedback in [PR #95026][95026].
90+
91+
Internal Changes
92+
----------------
93+
94+
These changes provide no direct user facing benefits, but represent significant
95+
improvements to the internals and overall performance of rustc
96+
and related tools.
97+
98+
- [Switch all libraries to the 2021 edition][92068]
99+
100+
[83822]: https://github.com/rust-lang/rust/pull/83822
101+
[86374]: https://github.com/rust-lang/rust/pull/86374
102+
[87487]: https://github.com/rust-lang/rust/pull/87487
103+
[89621]: https://github.com/rust-lang/rust/pull/89621
104+
[89926]: https://github.com/rust-lang/rust/pull/89926
105+
[90132]: https://github.com/rust-lang/rust/pull/90132
106+
[90247]: https://github.com/rust-lang/rust/pull/90247
107+
[91606]: https://github.com/rust-lang/rust/pull/91606
108+
[92068]: https://github.com/rust-lang/rust/pull/92068
109+
[92300]: https://github.com/rust-lang/rust/pull/92300
110+
[92357]: https://github.com/rust-lang/rust/pull/92357
111+
[92383]: https://github.com/rust-lang/rust/pull/92383
112+
[92630]: https://github.com/rust-lang/rust/pull/92630
113+
[92670]: https://github.com/rust-lang/rust/pull/92670
114+
[92800]: https://github.com/rust-lang/rust/pull/92800
115+
[92933]: https://github.com/rust-lang/rust/pull/92933
116+
[93566]: https://github.com/rust-lang/rust/pull/93566
117+
[93577]: https://github.com/rust-lang/rust/pull/93577
118+
[93658]: https://github.com/rust-lang/rust/pull/93658
119+
[93742]: https://github.com/rust-lang/rust/pull/93742
120+
[93824]: https://github.com/rust-lang/rust/pull/93824
121+
[93918]: https://github.com/rust-lang/rust/pull/93918
122+
[95026]: https://github.com/rust-lang/rust/pull/95026
123+
124+
[cargo/10086]: https://github.com/rust-lang/cargo/pull/10086
125+
[cargo/10245]: https://github.com/rust-lang/cargo/pull/10245
126+
[cargo/10269]: https://github.com/rust-lang/cargo/pull/10269
127+
[cargo/10274]: https://github.com/rust-lang/cargo/pull/10274
128+
[cargo/10379]: https://github.com/rust-lang/cargo/pull/10379
129+
130+
[arc_new_cyclic]: https://doc.rust-lang.org/stable/std/sync/struct.Arc.html#method.new_cyclic
131+
[rc_new_cyclic]: https://doc.rust-lang.org/stable/std/rc/struct.Rc.html#method.new_cyclic
132+
[slice_escape_ascii]: https://doc.rust-lang.org/stable/std/slice/struct.EscapeAscii.html
133+
[slice_u8_escape_ascii]: https://doc.rust-lang.org/stable/std/primitive.slice.html#method.escape_ascii
134+
[u8_escape_ascii]: https://doc.rust-lang.org/stable/std/primitive.u8.html#method.escape_ascii
135+
[vec_spare_capacity_mut]: https://doc.rust-lang.org/stable/std/vec/struct.Vec.html#method.spare_capacity_mut
136+
[assume_init_drop]: https://doc.rust-lang.org/stable/std/mem/union.MaybeUninit.html#method.assume_init_drop
137+
[assume_init_read]: https://doc.rust-lang.org/stable/std/mem/union.MaybeUninit.html#method.assume_init_read
138+
[i8_abs_diff]: https://doc.rust-lang.org/stable/std/primitive.i8.html#method.abs_diff
139+
[i16_abs_diff]: https://doc.rust-lang.org/stable/std/primitive.i16.html#method.abs_diff
140+
[i32_abs_diff]: https://doc.rust-lang.org/stable/std/primitive.i32.html#method.abs_diff
141+
[i64_abs_diff]: https://doc.rust-lang.org/stable/std/primitive.i64.html#method.abs_diff
142+
[i128_abs_diff]: https://doc.rust-lang.org/stable/std/primitive.i128.html#method.abs_diff
143+
[isize_abs_diff]: https://doc.rust-lang.org/stable/std/primitive.isize.html#method.abs_diff
144+
[u8_abs_diff]: https://doc.rust-lang.org/stable/std/primitive.u8.html#method.abs_diff
145+
[u16_abs_diff]: https://doc.rust-lang.org/stable/std/primitive.u16.html#method.abs_diff
146+
[u32_abs_diff]: https://doc.rust-lang.org/stable/std/primitive.u32.html#method.abs_diff
147+
[u64_abs_diff]: https://doc.rust-lang.org/stable/std/primitive.u64.html#method.abs_diff
148+
[u128_abs_diff]: https://doc.rust-lang.org/stable/std/primitive.u128.html#method.abs_diff
149+
[usize_abs_diff]: https://doc.rust-lang.org/stable/std/primitive.usize.html#method.abs_diff
150+
[display_error_kind]: https://doc.rust-lang.org/stable/std/io/enum.ErrorKind.html#impl-Display
151+
[from_u8_exit_code]: https://doc.rust-lang.org/stable/std/process/struct.ExitCode.html#impl-From%3Cu8%3E
152+
[not_never]: https://doc.rust-lang.org/stable/std/primitive.never.html#impl-Not
153+
[wrapping_assign_ops]: https://doc.rust-lang.org/stable/std/num/struct.Wrapping.html#trait-implementations
154+
[is_aarch64_feature_detected]: https://doc.rust-lang.org/stable/std/arch/macro.is_aarch64_feature_detected.html
155+
1156
Version 1.59.0 (2022-02-24)
2157
==========================
3158

compiler/rustc_expand/src/proc_macro_server.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -658,16 +658,16 @@ impl server::Literal for Rustc<'_, '_> {
658658
self.lit(token::Float, Symbol::intern(n), Some(sym::f64))
659659
}
660660
fn string(&mut self, string: &str) -> Self::Literal {
661-
let mut escaped = String::new();
662-
for ch in string.chars() {
663-
escaped.extend(ch.escape_debug());
664-
}
665-
self.lit(token::Str, Symbol::intern(&escaped), None)
661+
let quoted = format!("{:?}", string);
662+
assert!(quoted.starts_with('"') && quoted.ends_with('"'));
663+
let symbol = &quoted[1..quoted.len() - 1];
664+
self.lit(token::Str, Symbol::intern(symbol), None)
666665
}
667666
fn character(&mut self, ch: char) -> Self::Literal {
668-
let mut escaped = String::new();
669-
escaped.extend(ch.escape_unicode());
670-
self.lit(token::Char, Symbol::intern(&escaped), None)
667+
let quoted = format!("{:?}", ch);
668+
assert!(quoted.starts_with('\'') && quoted.ends_with('\''));
669+
let symbol = &quoted[1..quoted.len() - 1];
670+
self.lit(token::Char, Symbol::intern(symbol), None)
671671
}
672672
fn byte_string(&mut self, bytes: &[u8]) -> Self::Literal {
673673
let string = bytes

compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,12 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
474474
err.span_label(span, explanation);
475475
}
476476

477+
if let ObligationCauseCode::ObjectCastObligation(obj_ty) = obligation.cause.code().peel_derives() &&
478+
let Some(self_ty) = trait_predicate.self_ty().no_bound_vars() &&
479+
Some(trait_ref.def_id()) == self.tcx.lang_items().sized_trait() {
480+
self.suggest_borrowing_for_object_cast(&mut err, &obligation, self_ty, *obj_ty);
481+
}
482+
477483
if trait_predicate.is_const_if_const() && obligation.param_env.is_const() {
478484
let non_const_predicate = trait_ref.without_const();
479485
let non_const_obligation = Obligation {

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+37
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@ pub trait InferCtxtExt<'tcx> {
7777
has_custom_message: bool,
7878
) -> bool;
7979

80+
fn suggest_borrowing_for_object_cast(
81+
&self,
82+
err: &mut Diagnostic,
83+
obligation: &PredicateObligation<'tcx>,
84+
self_ty: Ty<'tcx>,
85+
object_ty: Ty<'tcx>,
86+
);
87+
8088
fn suggest_remove_reference(
8189
&self,
8290
obligation: &PredicateObligation<'tcx>,
@@ -801,6 +809,35 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
801809
}
802810
}
803811

812+
// Suggest borrowing the type
813+
fn suggest_borrowing_for_object_cast(
814+
&self,
815+
err: &mut Diagnostic,
816+
obligation: &PredicateObligation<'tcx>,
817+
self_ty: Ty<'tcx>,
818+
object_ty: Ty<'tcx>,
819+
) {
820+
let ty::Dynamic(predicates, _) = object_ty.kind() else { return; };
821+
let self_ref_ty = self.tcx.mk_imm_ref(self.tcx.lifetimes.re_erased, self_ty);
822+
823+
for predicate in predicates.iter() {
824+
if !self.predicate_must_hold_modulo_regions(
825+
&obligation.with(predicate.with_self_ty(self.tcx, self_ref_ty)),
826+
) {
827+
return;
828+
}
829+
}
830+
831+
err.span_suggestion(
832+
obligation.cause.span.shrink_to_lo(),
833+
&format!(
834+
"consider borrowing the value, since `&{self_ty}` can be coerced into `{object_ty}`"
835+
),
836+
"&".to_string(),
837+
Applicability::MaybeIncorrect,
838+
);
839+
}
840+
804841
/// Whenever references are used by mistake, like `for (i, e) in &vec.iter().enumerate()`,
805842
/// suggest removing these references until we reach a type that implements the trait.
806843
fn suggest_remove_reference(

library/core/src/cell.rs

+100-3
Original file line numberDiff line numberDiff line change
@@ -1990,9 +1990,106 @@ impl<T> const From<T> for UnsafeCell<T> {
19901990
#[unstable(feature = "coerce_unsized", issue = "27732")]
19911991
impl<T: CoerceUnsized<U>, U> CoerceUnsized<UnsafeCell<U>> for UnsafeCell<T> {}
19921992

1993+
/// [`UnsafeCell`], but [`Sync`].
1994+
///
1995+
/// This is just an `UnsafeCell`, except it implements `Sync`
1996+
/// if `T` implements `Sync`.
1997+
///
1998+
/// `UnsafeCell` doesn't implement `Sync`, to prevent accidental mis-use.
1999+
/// You can use `SyncUnsafeCell` instead of `UnsafeCell` to allow it to be
2000+
/// shared between threads, if that's intentional.
2001+
/// Providing proper synchronization is still the task of the user,
2002+
/// making this type just as unsafe to use.
2003+
///
2004+
/// See [`UnsafeCell`] for details.
2005+
#[unstable(feature = "sync_unsafe_cell", issue = "95439")]
2006+
#[repr(transparent)]
2007+
pub struct SyncUnsafeCell<T: ?Sized> {
2008+
value: UnsafeCell<T>,
2009+
}
2010+
2011+
#[unstable(feature = "sync_unsafe_cell", issue = "95439")]
2012+
unsafe impl<T: ?Sized + Sync> Sync for SyncUnsafeCell<T> {}
2013+
2014+
#[unstable(feature = "sync_unsafe_cell", issue = "95439")]
2015+
impl<T> SyncUnsafeCell<T> {
2016+
/// Constructs a new instance of `SyncUnsafeCell` which will wrap the specified value.
2017+
#[inline]
2018+
pub const fn new(value: T) -> Self {
2019+
Self { value: UnsafeCell { value } }
2020+
}
2021+
2022+
/// Unwraps the value.
2023+
#[inline]
2024+
pub const fn into_inner(self) -> T {
2025+
self.value.into_inner()
2026+
}
2027+
}
2028+
2029+
#[unstable(feature = "sync_unsafe_cell", issue = "95439")]
2030+
impl<T: ?Sized> SyncUnsafeCell<T> {
2031+
/// Gets a mutable pointer to the wrapped value.
2032+
///
2033+
/// This can be cast to a pointer of any kind.
2034+
/// Ensure that the access is unique (no active references, mutable or not)
2035+
/// when casting to `&mut T`, and ensure that there are no mutations
2036+
/// or mutable aliases going on when casting to `&T`
2037+
#[inline]
2038+
pub const fn get(&self) -> *mut T {
2039+
self.value.get()
2040+
}
2041+
2042+
/// Returns a mutable reference to the underlying data.
2043+
///
2044+
/// This call borrows the `SyncUnsafeCell` mutably (at compile-time) which
2045+
/// guarantees that we possess the only reference.
2046+
#[inline]
2047+
pub const fn get_mut(&mut self) -> &mut T {
2048+
self.value.get_mut()
2049+
}
2050+
2051+
/// Gets a mutable pointer to the wrapped value.
2052+
///
2053+
/// See [`UnsafeCell::get`] for details.
2054+
#[inline]
2055+
pub const fn raw_get(this: *const Self) -> *mut T {
2056+
// We can just cast the pointer from `SyncUnsafeCell<T>` to `T` because
2057+
// of #[repr(transparent)] on both SyncUnsafeCell and UnsafeCell.
2058+
// See UnsafeCell::raw_get.
2059+
this as *const T as *mut T
2060+
}
2061+
}
2062+
2063+
#[unstable(feature = "sync_unsafe_cell", issue = "95439")]
2064+
impl<T: Default> Default for SyncUnsafeCell<T> {
2065+
/// Creates an `SyncUnsafeCell`, with the `Default` value for T.
2066+
fn default() -> SyncUnsafeCell<T> {
2067+
SyncUnsafeCell::new(Default::default())
2068+
}
2069+
}
2070+
2071+
#[unstable(feature = "sync_unsafe_cell", issue = "95439")]
2072+
#[rustc_const_unstable(feature = "const_convert", issue = "88674")]
2073+
impl<T> const From<T> for SyncUnsafeCell<T> {
2074+
/// Creates a new `SyncUnsafeCell<T>` containing the given value.
2075+
fn from(t: T) -> SyncUnsafeCell<T> {
2076+
SyncUnsafeCell::new(t)
2077+
}
2078+
}
2079+
2080+
#[unstable(feature = "coerce_unsized", issue = "27732")]
2081+
//#[unstable(feature = "sync_unsafe_cell", issue = "95439")]
2082+
impl<T: CoerceUnsized<U>, U> CoerceUnsized<SyncUnsafeCell<U>> for SyncUnsafeCell<T> {}
2083+
19932084
#[allow(unused)]
1994-
fn assert_coerce_unsized(a: UnsafeCell<&i32>, b: Cell<&i32>, c: RefCell<&i32>) {
2085+
fn assert_coerce_unsized(
2086+
a: UnsafeCell<&i32>,
2087+
b: SyncUnsafeCell<&i32>,
2088+
c: Cell<&i32>,
2089+
d: RefCell<&i32>,
2090+
) {
19952091
let _: UnsafeCell<&dyn Send> = a;
1996-
let _: Cell<&dyn Send> = b;
1997-
let _: RefCell<&dyn Send> = c;
2092+
let _: SyncUnsafeCell<&dyn Send> = b;
2093+
let _: Cell<&dyn Send> = c;
2094+
let _: RefCell<&dyn Send> = d;
19982095
}

library/core/src/fmt/mod.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
#![stable(feature = "rust1", since = "1.0.0")]
44

5-
use crate::cell::{Cell, Ref, RefCell, RefMut, UnsafeCell};
5+
use crate::cell::{Cell, Ref, RefCell, RefMut, SyncUnsafeCell, UnsafeCell};
66
use crate::char::EscapeDebugExtArgs;
77
use crate::marker::PhantomData;
88
use crate::mem;
@@ -2400,6 +2400,13 @@ impl<T: ?Sized> Debug for UnsafeCell<T> {
24002400
}
24012401
}
24022402

2403+
#[unstable(feature = "sync_unsafe_cell", issue = "95439")]
2404+
impl<T: ?Sized> Debug for SyncUnsafeCell<T> {
2405+
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
2406+
f.debug_struct("SyncUnsafeCell").finish_non_exhaustive()
2407+
}
2408+
}
2409+
24032410
// If you expected tests to be here, look instead at the core/tests/fmt.rs file,
24042411
// it's a lot easier than creating all of the rt::Piece structures here.
24052412
// There are also tests in the alloc crate, for those that need allocations.

library/core/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@
139139
#![feature(const_type_id)]
140140
#![feature(const_type_name)]
141141
#![feature(const_default_impls)]
142+
#![feature(const_unsafecell_get_mut)]
142143
#![feature(core_panic)]
143144
#![feature(duration_consts_float)]
144145
#![feature(maybe_uninit_uninit_array)]

0 commit comments

Comments
 (0)