Skip to content

Commit

Permalink
Auto merge of rust-lang#89608 - Manishearth:rollup-m7kd76f, r=Manishe…
Browse files Browse the repository at this point in the history
…arth

Rollup of 12 pull requests

Successful merges:

 - rust-lang#87601 (Add functions to add unsigned and signed integers)
 - rust-lang#88523 (Expand documentation for `FpCategory`.)
 - rust-lang#89050 (refactor: VecDeques Drain fields to private)
 - rust-lang#89245 (refactor: make VecDeque's IterMut fields module-private, not just crate-private)
 - rust-lang#89324 (Rename `std::thread::available_conccurrency` to `std::thread::available_parallelism`)
 - rust-lang#89329 (print-type-sizes: skip field printing for primitives)
 - rust-lang#89501 (Note specific regions involved in 'borrowed data escapes' error)
 - rust-lang#89506 (librustdoc: Use correct heading levels.)
 - rust-lang#89528 (Fix suggestion to borrow when casting from pointer to reference)
 - rust-lang#89531 (library std, libc dependency update)
 - rust-lang#89588 (Add a test for generic_const_exprs)
 - rust-lang#89591 (fix: alloc-optimisation is only for rust llvm)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Oct 6, 2021
2 parents d480cef + f31c805 commit 0eabf25
Show file tree
Hide file tree
Showing 69 changed files with 984 additions and 249 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1879,9 +1879,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"

[[package]]
name = "libc"
version = "0.2.99"
version = "0.2.103"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a7f823d141fe0a24df1e23b4af4e3c7ba9e5966ec514ea068c93024aa7deb765"
checksum = "dd8f7255a17a627354f321ef0055d63b898c6fb27eff628af4d1b66b7331edf6"
dependencies = [
"rustc-std-workspace-core",
]
Expand Down
21 changes: 21 additions & 0 deletions compiler/rustc_borrowck/src/diagnostics/region_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,27 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
diag.span_label(*span, format!("`{}` escapes the {} body here", fr_name, escapes_from));
}

// Only show an extra note if we can find an 'error region' for both of the region
// variables. This avoids showing a noisy note that just mentions 'synthetic' regions
// that don't help the user understand the error.
if self.to_error_region(errci.fr).is_some()
&& self.to_error_region(errci.outlived_fr).is_some()
{
let fr_region_name = self.give_region_a_name(errci.fr).unwrap();
fr_region_name.highlight_region_name(&mut diag);
let outlived_fr_region_name = self.give_region_a_name(errci.outlived_fr).unwrap();
outlived_fr_region_name.highlight_region_name(&mut diag);

diag.span_label(
*span,
format!(
"{}requires that `{}` must outlive `{}`",
category.description(),
fr_region_name,
outlived_fr_region_name,
),
);
}
diag
}

Expand Down
7 changes: 5 additions & 2 deletions compiler/rustc_middle/src/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1826,8 +1826,11 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {

match layout.variants {
Variants::Single { index } => {
debug!("print-type-size `{:#?}` variant {}", layout, adt_def.variants[index].ident);
if !adt_def.variants.is_empty() {
if !adt_def.variants.is_empty() && layout.fields != FieldsShape::Primitive {
debug!(
"print-type-size `{:#?}` variant {}",
layout, adt_def.variants[index].ident
);
let variant_def = &adt_def.variants[index];
let fields: Vec<_> = variant_def.fields.iter().map(|f| f.ident.name).collect();
record(
Expand Down
44 changes: 36 additions & 8 deletions compiler/rustc_typeck/src/check/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
);
let mut sugg = None;
let mut sugg_mutref = false;
if let ty::Ref(reg, _, mutbl) = *self.cast_ty.kind() {
if let ty::Ref(reg, cast_ty, mutbl) = *self.cast_ty.kind() {
if let ty::RawPtr(TypeAndMut { ty: expr_ty, .. }) = *self.expr_ty.kind() {
if fcx
.try_coerce(
Expand All @@ -366,7 +366,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
)
.is_ok()
{
sugg = Some(format!("&{}*", mutbl.prefix_str()));
sugg = Some((format!("&{}*", mutbl.prefix_str()), cast_ty == expr_ty));
}
} else if let ty::Ref(expr_reg, expr_ty, expr_mutbl) = *self.expr_ty.kind() {
if expr_mutbl == Mutability::Not
Expand Down Expand Up @@ -400,7 +400,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
)
.is_ok()
{
sugg = Some(format!("&{}", mutbl.prefix_str()));
sugg = Some((format!("&{}", mutbl.prefix_str()), false));
}
} else if let ty::RawPtr(TypeAndMut { mutbl, .. }) = *self.cast_ty.kind() {
if fcx
Expand All @@ -416,19 +416,47 @@ impl<'a, 'tcx> CastCheck<'tcx> {
)
.is_ok()
{
sugg = Some(format!("&{}", mutbl.prefix_str()));
sugg = Some((format!("&{}", mutbl.prefix_str()), false));
}
}
if sugg_mutref {
err.span_label(self.span, "invalid cast");
err.span_note(self.expr.span, "this reference is immutable");
err.span_note(self.cast_span, "trying to cast to a mutable reference type");
} else if let Some(sugg) = sugg {
} else if let Some((sugg, remove_cast)) = sugg {
err.span_label(self.span, "invalid cast");
err.span_suggestion_verbose(
self.expr.span.shrink_to_lo(),

let has_parens = fcx
.tcx
.sess
.source_map()
.span_to_snippet(self.expr.span)
.map_or(false, |snip| snip.starts_with("("));

// Very crude check to see whether the expression must be wrapped
// in parentheses for the suggestion to work (issue #89497).
// Can/should be extended in the future.
let needs_parens = !has_parens
&& match self.expr.kind {
hir::ExprKind::Cast(..) => true,
_ => false,
};

let mut suggestion = vec![(self.expr.span.shrink_to_lo(), sugg)];
if needs_parens {
suggestion[0].1 += "(";
suggestion.push((self.expr.span.shrink_to_hi(), ")".to_string()));
}
if remove_cast {
suggestion.push((
self.expr.span.shrink_to_hi().to(self.cast_span),
String::new(),
));
}

err.multipart_suggestion_verbose(
"consider borrowing the value",
sugg,
suggestion,
Applicability::MachineApplicable,
);
} else if !matches!(
Expand Down
19 changes: 15 additions & 4 deletions library/alloc/src/collections/vec_deque/drain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,21 @@ pub struct Drain<
T: 'a,
#[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global,
> {
pub(crate) after_tail: usize,
pub(crate) after_head: usize,
pub(crate) iter: Iter<'a, T>,
pub(crate) deque: NonNull<VecDeque<T, A>>,
after_tail: usize,
after_head: usize,
iter: Iter<'a, T>,
deque: NonNull<VecDeque<T, A>>,
}

impl<'a, T, A: Allocator> Drain<'a, T, A> {
pub(super) unsafe fn new(
after_tail: usize,
after_head: usize,
iter: Iter<'a, T>,
deque: NonNull<VecDeque<T, A>>,
) -> Self {
Drain { after_tail, after_head, iter, deque }
}
}

#[stable(feature = "collection_debug", since = "1.17.0")]
Expand Down
19 changes: 15 additions & 4 deletions library/alloc/src/collections/vec_deque/iter_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,21 @@ use super::{count, wrap_index, RingSlices};
#[stable(feature = "rust1", since = "1.0.0")]
pub struct IterMut<'a, T: 'a> {
// Internal safety invariant: the entire slice is dereferencable.
pub(crate) ring: *mut [T],
pub(crate) tail: usize,
pub(crate) head: usize,
pub(crate) phantom: PhantomData<&'a mut [T]>,
ring: *mut [T],
tail: usize,
head: usize,
phantom: PhantomData<&'a mut [T]>,
}

impl<'a, T> IterMut<'a, T> {
pub(super) unsafe fn new(
ring: *mut [T],
tail: usize,
head: usize,
phantom: PhantomData<&'a mut [T]>,
) -> Self {
IterMut { ring, tail, head, phantom }
}
}

// SAFETY: we do nothing thread-local and there is no interior mutability,
Expand Down
42 changes: 17 additions & 25 deletions library/alloc/src/collections/vec_deque/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1000,12 +1000,9 @@ impl<T, A: Allocator> VecDeque<T, A> {
pub fn iter_mut(&mut self) -> IterMut<'_, T> {
// SAFETY: The internal `IterMut` safety invariant is established because the
// `ring` we create is a dereferencable slice for lifetime '_.
IterMut {
tail: self.tail,
head: self.head,
ring: ptr::slice_from_raw_parts_mut(self.ptr(), self.cap()),
phantom: PhantomData,
}
let ring = ptr::slice_from_raw_parts_mut(self.ptr(), self.cap());

unsafe { IterMut::new(ring, self.tail, self.head, PhantomData) }
}

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

// SAFETY: The internal `IterMut` safety invariant is established because the
// `ring` we create is a dereferencable slice for lifetime '_.
IterMut {
tail,
head,
ring: ptr::slice_from_raw_parts_mut(self.ptr(), self.cap()),
phantom: PhantomData,
}
let ring = ptr::slice_from_raw_parts_mut(self.ptr(), self.cap());

unsafe { IterMut::new(ring, tail, head, PhantomData) }
}

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

Drain {
deque: NonNull::from(&mut *self),
after_tail: drain_head,
after_head: head,
iter: Iter {
tail: drain_tail,
head: drain_head,
// Crucially, we only create shared references from `self` here and read from
// it. We do not write to `self` nor reborrow to a mutable reference.
// Hence the raw pointer we created above, for `deque`, remains valid.
ring: unsafe { self.buffer_as_slice() },
},
}
let deque = NonNull::from(&mut *self);
let iter = Iter {
tail: drain_tail,
head: drain_head,
// Crucially, we only create shared references from `self` here and read from
// it. We do not write to `self` nor reborrow to a mutable reference.
// Hence the raw pointer we created above, for `deque`, remains valid.
ring: unsafe { self.buffer_as_slice() },
};

unsafe { Drain::new(drain_head, head, iter, deque) }
}

/// Clears the `VecDeque`, removing all values.
Expand Down
1 change: 1 addition & 0 deletions library/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
#![feature(link_llvm_intrinsics)]
#![feature(llvm_asm)]
#![feature(min_specialization)]
#![feature(mixed_integer_ops)]
#![cfg_attr(not(bootstrap), feature(must_not_suspend))]
#![feature(negative_impls)]
#![feature(never_type)]
Expand Down
Loading

0 comments on commit 0eabf25

Please sign in to comment.