Skip to content

Commit 0eabf25

Browse files
committed
Auto merge of #89608 - Manishearth:rollup-m7kd76f, r=Manishearth
Rollup of 12 pull requests Successful merges: - #87601 (Add functions to add unsigned and signed integers) - #88523 (Expand documentation for `FpCategory`.) - #89050 (refactor: VecDeques Drain fields to private) - #89245 (refactor: make VecDeque's IterMut fields module-private, not just crate-private) - #89324 (Rename `std::thread::available_conccurrency` to `std::thread::available_parallelism`) - #89329 (print-type-sizes: skip field printing for primitives) - #89501 (Note specific regions involved in 'borrowed data escapes' error) - #89506 (librustdoc: Use correct heading levels.) - #89528 (Fix suggestion to borrow when casting from pointer to reference) - #89531 (library std, libc dependency update) - #89588 (Add a test for generic_const_exprs) - #89591 (fix: alloc-optimisation is only for rust llvm) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents d480cef + f31c805 commit 0eabf25

File tree

69 files changed

+984
-249
lines changed

Some content is hidden

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

69 files changed

+984
-249
lines changed

Cargo.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -1879,9 +1879,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
18791879

18801880
[[package]]
18811881
name = "libc"
1882-
version = "0.2.99"
1882+
version = "0.2.103"
18831883
source = "registry+https://github.com/rust-lang/crates.io-index"
1884-
checksum = "a7f823d141fe0a24df1e23b4af4e3c7ba9e5966ec514ea068c93024aa7deb765"
1884+
checksum = "dd8f7255a17a627354f321ef0055d63b898c6fb27eff628af4d1b66b7331edf6"
18851885
dependencies = [
18861886
"rustc-std-workspace-core",
18871887
]

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

+21
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,27 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
498498
diag.span_label(*span, format!("`{}` escapes the {} body here", fr_name, escapes_from));
499499
}
500500

501+
// Only show an extra note if we can find an 'error region' for both of the region
502+
// variables. This avoids showing a noisy note that just mentions 'synthetic' regions
503+
// that don't help the user understand the error.
504+
if self.to_error_region(errci.fr).is_some()
505+
&& self.to_error_region(errci.outlived_fr).is_some()
506+
{
507+
let fr_region_name = self.give_region_a_name(errci.fr).unwrap();
508+
fr_region_name.highlight_region_name(&mut diag);
509+
let outlived_fr_region_name = self.give_region_a_name(errci.outlived_fr).unwrap();
510+
outlived_fr_region_name.highlight_region_name(&mut diag);
511+
512+
diag.span_label(
513+
*span,
514+
format!(
515+
"{}requires that `{}` must outlive `{}`",
516+
category.description(),
517+
fr_region_name,
518+
outlived_fr_region_name,
519+
),
520+
);
521+
}
501522
diag
502523
}
503524

compiler/rustc_middle/src/ty/layout.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1826,8 +1826,11 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
18261826

18271827
match layout.variants {
18281828
Variants::Single { index } => {
1829-
debug!("print-type-size `{:#?}` variant {}", layout, adt_def.variants[index].ident);
1830-
if !adt_def.variants.is_empty() {
1829+
if !adt_def.variants.is_empty() && layout.fields != FieldsShape::Primitive {
1830+
debug!(
1831+
"print-type-size `{:#?}` variant {}",
1832+
layout, adt_def.variants[index].ident
1833+
);
18311834
let variant_def = &adt_def.variants[index];
18321835
let fields: Vec<_> = variant_def.fields.iter().map(|f| f.ident.name).collect();
18331836
record(

compiler/rustc_typeck/src/check/cast.rs

+36-8
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
351351
);
352352
let mut sugg = None;
353353
let mut sugg_mutref = false;
354-
if let ty::Ref(reg, _, mutbl) = *self.cast_ty.kind() {
354+
if let ty::Ref(reg, cast_ty, mutbl) = *self.cast_ty.kind() {
355355
if let ty::RawPtr(TypeAndMut { ty: expr_ty, .. }) = *self.expr_ty.kind() {
356356
if fcx
357357
.try_coerce(
@@ -366,7 +366,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
366366
)
367367
.is_ok()
368368
{
369-
sugg = Some(format!("&{}*", mutbl.prefix_str()));
369+
sugg = Some((format!("&{}*", mutbl.prefix_str()), cast_ty == expr_ty));
370370
}
371371
} else if let ty::Ref(expr_reg, expr_ty, expr_mutbl) = *self.expr_ty.kind() {
372372
if expr_mutbl == Mutability::Not
@@ -400,7 +400,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
400400
)
401401
.is_ok()
402402
{
403-
sugg = Some(format!("&{}", mutbl.prefix_str()));
403+
sugg = Some((format!("&{}", mutbl.prefix_str()), false));
404404
}
405405
} else if let ty::RawPtr(TypeAndMut { mutbl, .. }) = *self.cast_ty.kind() {
406406
if fcx
@@ -416,19 +416,47 @@ impl<'a, 'tcx> CastCheck<'tcx> {
416416
)
417417
.is_ok()
418418
{
419-
sugg = Some(format!("&{}", mutbl.prefix_str()));
419+
sugg = Some((format!("&{}", mutbl.prefix_str()), false));
420420
}
421421
}
422422
if sugg_mutref {
423423
err.span_label(self.span, "invalid cast");
424424
err.span_note(self.expr.span, "this reference is immutable");
425425
err.span_note(self.cast_span, "trying to cast to a mutable reference type");
426-
} else if let Some(sugg) = sugg {
426+
} else if let Some((sugg, remove_cast)) = sugg {
427427
err.span_label(self.span, "invalid cast");
428-
err.span_suggestion_verbose(
429-
self.expr.span.shrink_to_lo(),
428+
429+
let has_parens = fcx
430+
.tcx
431+
.sess
432+
.source_map()
433+
.span_to_snippet(self.expr.span)
434+
.map_or(false, |snip| snip.starts_with("("));
435+
436+
// Very crude check to see whether the expression must be wrapped
437+
// in parentheses for the suggestion to work (issue #89497).
438+
// Can/should be extended in the future.
439+
let needs_parens = !has_parens
440+
&& match self.expr.kind {
441+
hir::ExprKind::Cast(..) => true,
442+
_ => false,
443+
};
444+
445+
let mut suggestion = vec![(self.expr.span.shrink_to_lo(), sugg)];
446+
if needs_parens {
447+
suggestion[0].1 += "(";
448+
suggestion.push((self.expr.span.shrink_to_hi(), ")".to_string()));
449+
}
450+
if remove_cast {
451+
suggestion.push((
452+
self.expr.span.shrink_to_hi().to(self.cast_span),
453+
String::new(),
454+
));
455+
}
456+
457+
err.multipart_suggestion_verbose(
430458
"consider borrowing the value",
431-
sugg,
459+
suggestion,
432460
Applicability::MachineApplicable,
433461
);
434462
} else if !matches!(

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

+15-4
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,21 @@ pub struct Drain<
1818
T: 'a,
1919
#[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global,
2020
> {
21-
pub(crate) after_tail: usize,
22-
pub(crate) after_head: usize,
23-
pub(crate) iter: Iter<'a, T>,
24-
pub(crate) deque: NonNull<VecDeque<T, A>>,
21+
after_tail: usize,
22+
after_head: usize,
23+
iter: Iter<'a, T>,
24+
deque: NonNull<VecDeque<T, A>>,
25+
}
26+
27+
impl<'a, T, A: Allocator> Drain<'a, T, A> {
28+
pub(super) unsafe fn new(
29+
after_tail: usize,
30+
after_head: usize,
31+
iter: Iter<'a, T>,
32+
deque: NonNull<VecDeque<T, A>>,
33+
) -> Self {
34+
Drain { after_tail, after_head, iter, deque }
35+
}
2536
}
2637

2738
#[stable(feature = "collection_debug", since = "1.17.0")]

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

+15-4
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,21 @@ use super::{count, wrap_index, RingSlices};
1313
#[stable(feature = "rust1", since = "1.0.0")]
1414
pub struct IterMut<'a, T: 'a> {
1515
// Internal safety invariant: the entire slice is dereferencable.
16-
pub(crate) ring: *mut [T],
17-
pub(crate) tail: usize,
18-
pub(crate) head: usize,
19-
pub(crate) phantom: PhantomData<&'a mut [T]>,
16+
ring: *mut [T],
17+
tail: usize,
18+
head: usize,
19+
phantom: PhantomData<&'a mut [T]>,
20+
}
21+
22+
impl<'a, T> IterMut<'a, T> {
23+
pub(super) unsafe fn new(
24+
ring: *mut [T],
25+
tail: usize,
26+
head: usize,
27+
phantom: PhantomData<&'a mut [T]>,
28+
) -> Self {
29+
IterMut { ring, tail, head, phantom }
30+
}
2031
}
2132

2233
// SAFETY: we do nothing thread-local and there is no interior mutability,

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

+17-25
Original file line numberDiff line numberDiff line change
@@ -1000,12 +1000,9 @@ impl<T, A: Allocator> VecDeque<T, A> {
10001000
pub fn iter_mut(&mut self) -> IterMut<'_, T> {
10011001
// SAFETY: The internal `IterMut` safety invariant is established because the
10021002
// `ring` we create is a dereferencable slice for lifetime '_.
1003-
IterMut {
1004-
tail: self.tail,
1005-
head: self.head,
1006-
ring: ptr::slice_from_raw_parts_mut(self.ptr(), self.cap()),
1007-
phantom: PhantomData,
1008-
}
1003+
let ring = ptr::slice_from_raw_parts_mut(self.ptr(), self.cap());
1004+
1005+
unsafe { IterMut::new(ring, self.tail, self.head, PhantomData) }
10091006
}
10101007

10111008
/// Returns a pair of slices which contain, in order, the contents of the
@@ -1192,12 +1189,9 @@ impl<T, A: Allocator> VecDeque<T, A> {
11921189

11931190
// SAFETY: The internal `IterMut` safety invariant is established because the
11941191
// `ring` we create is a dereferencable slice for lifetime '_.
1195-
IterMut {
1196-
tail,
1197-
head,
1198-
ring: ptr::slice_from_raw_parts_mut(self.ptr(), self.cap()),
1199-
phantom: PhantomData,
1200-
}
1192+
let ring = ptr::slice_from_raw_parts_mut(self.ptr(), self.cap());
1193+
1194+
unsafe { IterMut::new(ring, tail, head, PhantomData) }
12011195
}
12021196

12031197
/// Creates a draining iterator that removes the specified range in the
@@ -1269,19 +1263,17 @@ impl<T, A: Allocator> VecDeque<T, A> {
12691263
// the drain is complete and the Drain destructor is run.
12701264
self.head = drain_tail;
12711265

1272-
Drain {
1273-
deque: NonNull::from(&mut *self),
1274-
after_tail: drain_head,
1275-
after_head: head,
1276-
iter: Iter {
1277-
tail: drain_tail,
1278-
head: drain_head,
1279-
// Crucially, we only create shared references from `self` here and read from
1280-
// it. We do not write to `self` nor reborrow to a mutable reference.
1281-
// Hence the raw pointer we created above, for `deque`, remains valid.
1282-
ring: unsafe { self.buffer_as_slice() },
1283-
},
1284-
}
1266+
let deque = NonNull::from(&mut *self);
1267+
let iter = Iter {
1268+
tail: drain_tail,
1269+
head: drain_head,
1270+
// Crucially, we only create shared references from `self` here and read from
1271+
// it. We do not write to `self` nor reborrow to a mutable reference.
1272+
// Hence the raw pointer we created above, for `deque`, remains valid.
1273+
ring: unsafe { self.buffer_as_slice() },
1274+
};
1275+
1276+
unsafe { Drain::new(drain_head, head, iter, deque) }
12851277
}
12861278

12871279
/// Clears the `VecDeque`, removing all values.

library/core/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@
142142
#![feature(link_llvm_intrinsics)]
143143
#![feature(llvm_asm)]
144144
#![feature(min_specialization)]
145+
#![feature(mixed_integer_ops)]
145146
#![cfg_attr(not(bootstrap), feature(must_not_suspend))]
146147
#![feature(negative_impls)]
147148
#![feature(never_type)]

0 commit comments

Comments
 (0)