Skip to content

Commit 7ce1b3b

Browse files
committed
Auto merge of rust-lang#81545 - JohnTitor:rollup-zlt3tn6, r=JohnTitor
Rollup of 16 pull requests Successful merges: - rust-lang#79023 (Add `core::stream::Stream`) - rust-lang#80562 (Consider Scalar to be a bool only if its unsigned) - rust-lang#80886 (Stabilize raw ref macros) - rust-lang#80959 (Stabilize `unsigned_abs`) - rust-lang#81291 (Support FRU pattern with `[feature(capture_disjoint_fields)]`) - rust-lang#81409 (Slight simplification of chars().count()) - rust-lang#81468 (cfg(version): treat nightlies as complete) - rust-lang#81473 (Warn write-only fields) - rust-lang#81495 (rustdoc: Remove unnecessary optional) - rust-lang#81499 (Updated Vec::splice documentation) - rust-lang#81501 (update rustfmt to v1.4.34) - rust-lang#81505 (`fn cold_path` doesn't need to be pub) - rust-lang#81512 (Add missing variants in match binding) - rust-lang#81515 (Fix typo in pat.rs) - rust-lang#81519 (Don't print error output from rustup when detecting default build triple) - rust-lang#81520 (Don't clone LLVM submodule when download-ci-llvm is set) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents ebaea9e + 31e7634 commit 7ce1b3b

File tree

52 files changed

+598
-95
lines changed

Some content is hidden

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

52 files changed

+598
-95
lines changed

Cargo.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -4442,7 +4442,7 @@ dependencies = [
44424442

44434443
[[package]]
44444444
name = "rustfmt-nightly"
4445-
version = "1.4.32"
4445+
version = "1.4.34"
44464446
dependencies = [
44474447
"annotate-snippets 0.6.1",
44484448
"anyhow",

compiler/rustc_arena/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use std::slice;
3232

3333
#[inline(never)]
3434
#[cold]
35-
pub fn cold_path<F: FnOnce() -> R, R>(f: F) -> R {
35+
fn cold_path<F: FnOnce() -> R, R>(f: F) -> R {
3636
f()
3737
}
3838

compiler/rustc_attr/src/builtin.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -586,12 +586,14 @@ pub fn eval_condition(
586586
return false;
587587
}
588588
};
589-
let channel = env!("CFG_RELEASE_CHANNEL");
590-
let nightly = channel == "nightly" || channel == "dev";
591589
let rustc_version = parse_version(env!("CFG_RELEASE"), true).unwrap();
592590

593-
// See https://github.com/rust-lang/rust/issues/64796#issuecomment-625474439 for details
594-
if nightly { rustc_version > min_version } else { rustc_version >= min_version }
591+
// See https://github.com/rust-lang/rust/issues/64796#issuecomment-640851454 for details
592+
if sess.assume_incomplete_release {
593+
rustc_version > min_version
594+
} else {
595+
rustc_version >= min_version
596+
}
595597
}
596598
ast::MetaItemKind::List(ref mis) => {
597599
for mi in mis.iter() {

compiler/rustc_interface/src/tests.rs

+1
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,7 @@ fn test_debugging_options_tracking_hash() {
540540
// This list is in alphabetical order.
541541
tracked!(allow_features, Some(vec![String::from("lang_items")]));
542542
tracked!(always_encode_mir, true);
543+
tracked!(assume_incomplete_release, true);
543544
tracked!(asm_comments, true);
544545
tracked!(binary_dep_depinfo, true);
545546
tracked!(chalk, true);

compiler/rustc_middle/src/mir/interpret/mod.rs

-9
Original file line numberDiff line numberDiff line change
@@ -588,12 +588,3 @@ pub fn read_target_uint(endianness: Endian, mut source: &[u8]) -> Result<u128, i
588588
debug_assert!(source.len() == 0); // We should have consumed the source buffer.
589589
uint
590590
}
591-
592-
/// Computes the unsigned absolute value without wrapping or panicking.
593-
#[inline]
594-
pub fn uabs(value: i64) -> u64 {
595-
// The only tricky part here is if value == i64::MIN. In that case,
596-
// wrapping_abs() returns i64::MIN == -2^63. Casting this value to a u64
597-
// gives 2^63, the correct value.
598-
value.wrapping_abs() as u64
599-
}

compiler/rustc_middle/src/mir/interpret/pointer.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::{uabs, AllocId, InterpResult};
1+
use super::{AllocId, InterpResult};
22

33
use rustc_macros::HashStable;
44
use rustc_target::abi::{HasDataLayout, Size};
@@ -57,7 +57,7 @@ pub trait PointerArithmetic: HasDataLayout {
5757
#[inline]
5858
fn overflowing_signed_offset(&self, val: u64, i: i64) -> (u64, bool) {
5959
// We need to make sure that i fits in a machine isize.
60-
let n = uabs(i);
60+
let n = i.unsigned_abs();
6161
if i >= 0 {
6262
let (val, over) = self.overflowing_offset(val, n);
6363
(val, over || i > self.machine_isize_max())

compiler/rustc_mir/src/interpret/intrinsics.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::convert::TryFrom;
77
use rustc_hir::def_id::DefId;
88
use rustc_middle::mir::{
99
self,
10-
interpret::{uabs, ConstValue, GlobalId, InterpResult, Scalar},
10+
interpret::{ConstValue, GlobalId, InterpResult, Scalar},
1111
BinOp,
1212
};
1313
use rustc_middle::ty;
@@ -542,7 +542,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
542542
// memory between these pointers must be accessible. Note that we do not require the
543543
// pointers to be properly aligned (unlike a read/write operation).
544544
let min_ptr = if offset_bytes >= 0 { ptr } else { offset_ptr };
545-
let size: u64 = uabs(offset_bytes);
545+
let size = offset_bytes.unsigned_abs();
546546
// This call handles checking for integer/NULL pointers.
547547
self.memory.check_ptr_access_align(
548548
min_ptr,

compiler/rustc_mir_build/src/build/expr/as_place.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ impl<'tcx> PlaceBuilder<'tcx> {
303303
self.base
304304
}
305305

306-
fn field(self, f: Field, ty: Ty<'tcx>) -> Self {
306+
crate fn field(self, f: Field, ty: Ty<'tcx>) -> Self {
307307
self.project(PlaceElem::Field(f, ty))
308308
}
309309

compiler/rustc_mir_build/src/build/expr/into.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
296296
let field_names = this.hir.all_fields(adt_def, variant_index);
297297

298298
let fields: Vec<_> = if let Some(FruInfo { base, field_types }) = base {
299-
let base = unpack!(block = this.as_place(block, base));
299+
let place_builder = unpack!(block = this.as_place_builder(block, base));
300300

301301
// MIR does not natively support FRU, so for each
302302
// base-supplied field, generate an operand that
@@ -306,9 +306,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
306306
.zip(field_types.into_iter())
307307
.map(|(n, ty)| match fields_map.get(&n) {
308308
Some(v) => v.clone(),
309-
None => this.consume_by_copy_or_move(
310-
this.hir.tcx().mk_place_field(base, n, ty),
311-
),
309+
None => {
310+
let place_builder = place_builder.clone();
311+
this.consume_by_copy_or_move(
312+
place_builder
313+
.field(n, ty)
314+
.into_place(this.hir.tcx(), this.hir.typeck_results()),
315+
)
316+
},
312317
})
313318
.collect()
314319
} else {

compiler/rustc_parse/src/parser/pat.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ impl<'a> Parser<'a> {
240240
Err(err)
241241
}
242242

243-
/// Parse and throw away a parentesized comma separated
243+
/// Parse and throw away a parenthesized comma separated
244244
/// sequence of patterns until `)` is reached.
245245
fn skip_pat_list(&mut self) -> PResult<'a, ()> {
246246
while !self.check(&token::CloseDelim(token::Paren)) {

compiler/rustc_passes/src/dead.rs

+15
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ fn should_explore(tcx: TyCtxt<'_>, hir_id: hir::HirId) -> bool {
3737
)
3838
}
3939

40+
fn base_expr<'a>(mut expr: &'a hir::Expr<'a>) -> &'a hir::Expr<'a> {
41+
loop {
42+
match expr.kind {
43+
hir::ExprKind::Field(base, ..) => expr = base,
44+
_ => return expr,
45+
}
46+
}
47+
}
48+
4049
struct MarkSymbolVisitor<'tcx> {
4150
worklist: Vec<hir::HirId>,
4251
tcx: TyCtxt<'tcx>,
@@ -263,6 +272,12 @@ impl<'tcx> Visitor<'tcx> for MarkSymbolVisitor<'tcx> {
263272
hir::ExprKind::MethodCall(..) => {
264273
self.lookup_and_handle_method(expr.hir_id);
265274
}
275+
hir::ExprKind::Assign(ref left, ref right, ..) => {
276+
// Ignore write to field
277+
self.visit_expr(base_expr(left));
278+
self.visit_expr(right);
279+
return;
280+
}
266281
hir::ExprKind::Field(ref lhs, ..) => {
267282
self.handle_field_access(&lhs, expr.hir_id);
268283
}

compiler/rustc_resolve/src/diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -977,7 +977,7 @@ impl<'a> Resolver<'a> {
977977
});
978978
if let Some(def_span) = def_span {
979979
if span.overlaps(def_span) {
980-
// Don't suggest typo suggestion for itself like in the followoing:
980+
// Don't suggest typo suggestion for itself like in the following:
981981
// error[E0423]: expected function, tuple struct or tuple variant, found struct `X`
982982
// --> $DIR/issue-64792-bad-unicode-ctor.rs:3:14
983983
// |

compiler/rustc_session/src/options.rs

+2
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
854854
"only allow the listed language features to be enabled in code (space separated)"),
855855
always_encode_mir: bool = (false, parse_bool, [TRACKED],
856856
"encode MIR of all functions into the crate metadata (default: no)"),
857+
assume_incomplete_release: bool = (false, parse_bool, [TRACKED],
858+
"make cfg(version) treat the current version as incomplete (default: no)"),
857859
asm_comments: bool = (false, parse_bool, [TRACKED],
858860
"generate comments into the assembly (may change behavior) (default: no)"),
859861
ast_json: bool = (false, parse_bool, [UNTRACKED],

compiler/rustc_session/src/parse.rs

+3
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ pub struct ParseSess {
138138
pub env_depinfo: Lock<FxHashSet<(Symbol, Option<Symbol>)>>,
139139
/// All the type ascriptions expressions that have had a suggestion for likely path typo.
140140
pub type_ascription_path_suggestions: Lock<FxHashSet<Span>>,
141+
/// Whether cfg(version) should treat the current release as incomplete
142+
pub assume_incomplete_release: bool,
141143
}
142144

143145
impl ParseSess {
@@ -164,6 +166,7 @@ impl ParseSess {
164166
reached_eof: Lock::new(false),
165167
env_depinfo: Default::default(),
166168
type_ascription_path_suggestions: Default::default(),
169+
assume_incomplete_release: false,
167170
}
168171
}
169172

compiler/rustc_session/src/session.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1344,7 +1344,8 @@ pub fn build_session(
13441344
None
13451345
};
13461346

1347-
let parse_sess = ParseSess::with_span_handler(span_diagnostic, source_map);
1347+
let mut parse_sess = ParseSess::with_span_handler(span_diagnostic, source_map);
1348+
parse_sess.assume_incomplete_release = sopts.debugging_opts.assume_incomplete_release;
13481349
let sysroot = match &sopts.maybe_sysroot {
13491350
Some(sysroot) => sysroot.clone(),
13501351
None => filesearch::get_or_default_sysroot(),

compiler/rustc_symbol_mangling/src/v0.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ impl Printer<'tcx> for SymbolMangler<'tcx> {
530530
if val < 0 {
531531
neg = true;
532532
}
533-
Some(val.wrapping_abs() as u128)
533+
Some(val.unsigned_abs())
534534
})
535535
}
536536
_ => {

compiler/rustc_target/src/abi/call/mod.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,12 @@ impl ArgAttributes {
103103
}
104104

105105
pub fn ext(&mut self, ext: ArgExtension) -> &mut Self {
106-
assert!(self.arg_ext == ArgExtension::None || self.arg_ext == ext);
106+
assert!(
107+
self.arg_ext == ArgExtension::None || self.arg_ext == ext,
108+
"cannot set {:?} when {:?} is already set",
109+
ext,
110+
self.arg_ext
111+
);
107112
self.arg_ext = ext;
108113
self
109114
}

compiler/rustc_target/src/abi/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ pub struct Scalar {
682682

683683
impl Scalar {
684684
pub fn is_bool(&self) -> bool {
685-
if let Int(I8, _) = self.value { self.valid_range == (0..=1) } else { false }
685+
matches!(self.value, Int(I8, false)) && self.valid_range == (0..=1)
686686
}
687687

688688
/// Returns the valid range as a `x..y` range.

library/alloc/src/boxed.rs

+14
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ use core::ops::{
149149
};
150150
use core::pin::Pin;
151151
use core::ptr::{self, Unique};
152+
use core::stream::Stream;
152153
use core::task::{Context, Poll};
153154

154155
use crate::alloc::{handle_alloc_error, AllocError, Allocator, Global, Layout, WriteCloneIntoRaw};
@@ -1621,3 +1622,16 @@ where
16211622
F::poll(Pin::new(&mut *self), cx)
16221623
}
16231624
}
1625+
1626+
#[unstable(feature = "async_stream", issue = "79024")]
1627+
impl<S: ?Sized + Stream + Unpin> Stream for Box<S> {
1628+
type Item = S::Item;
1629+
1630+
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
1631+
Pin::new(&mut **self).poll_next(cx)
1632+
}
1633+
1634+
fn size_hint(&self) -> (usize, Option<usize>) {
1635+
(**self).size_hint()
1636+
}
1637+
}

library/alloc/src/collections/btree/node.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -545,8 +545,8 @@ impl<'a, K, V, Type> NodeRef<marker::ValMut<'a>, K, V, Type> {
545545
// to avoid aliasing with outstanding references to other elements,
546546
// in particular, those returned to the caller in earlier iterations.
547547
let leaf = Self::as_leaf_ptr(&mut self);
548-
let keys = unsafe { &raw const (*leaf).keys };
549-
let vals = unsafe { &raw mut (*leaf).vals };
548+
let keys = unsafe { ptr::addr_of!((*leaf).keys) };
549+
let vals = unsafe { ptr::addr_of_mut!((*leaf).vals) };
550550
// We must coerce to unsized array pointers because of Rust issue #74679.
551551
let keys: *const [_] = keys;
552552
let vals: *mut [_] = vals;

library/alloc/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
#![feature(array_windows)]
8383
#![feature(allow_internal_unstable)]
8484
#![feature(arbitrary_self_types)]
85+
#![feature(async_stream)]
8586
#![feature(box_patterns)]
8687
#![feature(box_syntax)]
8788
#![feature(cfg_sanitize)]
@@ -115,7 +116,6 @@
115116
#![feature(pattern)]
116117
#![feature(ptr_internals)]
117118
#![feature(range_bounds_assert_len)]
118-
#![feature(raw_ref_op)]
119119
#![feature(rustc_attrs)]
120120
#![feature(receiver_trait)]
121121
#![cfg_attr(bootstrap, feature(min_const_generics))]

library/alloc/src/rc.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ impl<T> Rc<T> {
398398

399399
unsafe {
400400
let inner = init_ptr.as_ptr();
401-
ptr::write(&raw mut (*inner).value, data);
401+
ptr::write(ptr::addr_of_mut!((*inner).value), data);
402402

403403
let prev_value = (*inner).strong.get();
404404
debug_assert_eq!(prev_value, 0, "No prior strong references should exist");
@@ -804,7 +804,7 @@ impl<T: ?Sized> Rc<T> {
804804
// SAFETY: This cannot go through Deref::deref or Rc::inner because
805805
// this is required to retain raw/mut provenance such that e.g. `get_mut` can
806806
// write through the pointer after the Rc is recovered through `from_raw`.
807-
unsafe { &raw const (*ptr).value }
807+
unsafe { ptr::addr_of_mut!((*ptr).value) }
808808
}
809809

810810
/// Constructs an `Rc<T>` from a raw pointer.
@@ -1917,7 +1917,7 @@ impl<T: ?Sized> Weak<T> {
19171917
// SAFETY: if is_dangling returns false, then the pointer is dereferencable.
19181918
// The payload may be dropped at this point, and we have to maintain provenance,
19191919
// so use raw pointer manipulation.
1920-
unsafe { &raw const (*ptr).value }
1920+
unsafe { ptr::addr_of_mut!((*ptr).value) }
19211921
}
19221922
}
19231923

library/alloc/src/sync.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ impl<T> Arc<T> {
384384
// reference into a strong reference.
385385
unsafe {
386386
let inner = init_ptr.as_ptr();
387-
ptr::write(&raw mut (*inner).data, data);
387+
ptr::write(ptr::addr_of_mut!((*inner).data), data);
388388

389389
// The above write to the data field must be visible to any threads which
390390
// observe a non-zero strong count. Therefore we need at least "Release" ordering
@@ -800,7 +800,7 @@ impl<T: ?Sized> Arc<T> {
800800
// SAFETY: This cannot go through Deref::deref or RcBoxPtr::inner because
801801
// this is required to retain raw/mut provenance such that e.g. `get_mut` can
802802
// write through the pointer after the Rc is recovered through `from_raw`.
803-
unsafe { &raw const (*ptr).data }
803+
unsafe { ptr::addr_of_mut!((*ptr).data) }
804804
}
805805

806806
/// Constructs an `Arc<T>` from a raw pointer.
@@ -1677,7 +1677,7 @@ impl<T: ?Sized> Weak<T> {
16771677
// SAFETY: if is_dangling returns false, then the pointer is dereferencable.
16781678
// The payload may be dropped at this point, and we have to maintain provenance,
16791679
// so use raw pointer manipulation.
1680-
unsafe { &raw mut (*ptr).data }
1680+
unsafe { ptr::addr_of_mut!((*ptr).data) }
16811681
}
16821682
}
16831683

library/alloc/src/vec/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2211,7 +2211,7 @@ impl<T, A: Allocator> Vec<T, A> {
22112211
/// This is optimal if:
22122212
///
22132213
/// * The tail (elements in the vector after `range`) is empty,
2214-
/// * or `replace_with` yields fewer elements than `range`’s length
2214+
/// * or `replace_with` yields fewer or equal elements than `range`’s length
22152215
/// * or the lower bound of its `size_hint()` is exact.
22162216
///
22172217
/// Otherwise, a temporary vector is allocated and the tail is moved twice.

library/core/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@
126126
#![feature(auto_traits)]
127127
#![feature(or_patterns)]
128128
#![feature(prelude_import)]
129-
#![feature(raw_ref_macros)]
130129
#![feature(repr_simd, platform_intrinsics)]
131130
#![feature(rustc_attrs)]
132131
#![feature(simd_ffi)]
@@ -254,6 +253,8 @@ pub mod panicking;
254253
pub mod pin;
255254
pub mod raw;
256255
pub mod result;
256+
#[unstable(feature = "async_stream", issue = "79024")]
257+
pub mod stream;
257258
pub mod sync;
258259

259260
pub mod fmt;

library/core/src/num/dec2flt/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ fn bound_intermediate_digits(decimal: &Decimal<'_>, e: i64) -> u64 {
332332
// It tries to find a positive number k such that `f << k / 10^e` is an in-range
333333
// significand. This will result in about `2^53 * f * 10^e` < `10^17 * f * 10^e`.
334334
// One input that triggers this is 0.33...33 (375 x 3).
335-
f_len + (e.abs() as u64) + 17
335+
f_len + e.unsigned_abs() + 17
336336
}
337337
}
338338

library/core/src/num/int_macros.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1158,12 +1158,12 @@ macro_rules! int_impl {
11581158
/// Basic usage:
11591159
///
11601160
/// ```
1161-
/// #![feature(unsigned_abs)]
11621161
#[doc = concat!("assert_eq!(100", stringify!($SelfT), ".unsigned_abs(), 100", stringify!($UnsignedT), ");")]
11631162
#[doc = concat!("assert_eq!((-100", stringify!($SelfT), ").unsigned_abs(), 100", stringify!($UnsignedT), ");")]
11641163
/// assert_eq!((-128i8).unsigned_abs(), 128u8);
11651164
/// ```
1166-
#[unstable(feature = "unsigned_abs", issue = "74913")]
1165+
#[stable(feature = "unsigned_abs", since = "1.51.0")]
1166+
#[rustc_const_stable(feature = "unsigned_abs", since = "1.51.0")]
11671167
#[inline]
11681168
pub const fn unsigned_abs(self) -> $UnsignedT {
11691169
self.wrapping_abs() as $UnsignedT

0 commit comments

Comments
 (0)