Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 12 pull requests #89608

Merged
merged 38 commits into from
Oct 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
18df8d6
Expand documentation for `FpCategory`.
kpreid Aug 31, 2021
25b6f9b
print-type-sizes: skip field printing for primitives
tmiasko Sep 28, 2021
6cc91cb
Rename `std::thread::available_onccurrency` to `std::thread::availabl…
yoshuawuyts Sep 28, 2021
fe11483
Add functions to add unsigned and signed integers
a1phyr Jul 29, 2021
ab9f8a0
Apply suggestion for `overflowing_add_signed`
a1phyr Jul 30, 2021
b5dd522
Fix doc test
a1phyr Aug 7, 2021
9faf621
Add methods to add/sub `uX` to/from `iX`
a1phyr Aug 7, 2021
70e55a8
Apply suggestions
a1phyr Oct 3, 2021
4846fd9
Revert suggested use of `unwrap_or`
a1phyr Oct 3, 2021
a8a40ea
librustdoc: Use correct heading levels.
Oct 1, 2021
03fbc16
Add doc aliases to `std::thread::available_parallelism`
yoshuawuyts Oct 4, 2021
47edde1
Optimize `saturating_add_signed`
a1phyr Oct 4, 2021
388bcc1
Fix suggestion to borrow when casting from pointer to reference
FabianWolff Oct 4, 2021
4a6aa6e
Fix heading for methods on trait impls.
Oct 5, 2021
6518a0a
Change `Markdown(...)` to `Markdown { ... }`
Oct 5, 2021
13558ee
No need to default offset since we always override it.
Oct 5, 2021
f1425c7
heading_level: u32 -> heading_offset: HeadingOffset
Oct 5, 2021
08a4f24
Add tests for ensuring docblock headings.
Oct 5, 2021
c79447e
library std, libc dependency update
devnexen Oct 4, 2021
b2e4e59
refactor: VecDeques Drain fields to private
DeveloperC286 Sep 17, 2021
5af61cb
refactor: VecDeques IterMut fields to private
DeveloperC286 Sep 25, 2021
3c974ad
Note specific regions involved in 'borrowed data escapes' error
Aaron1011 Oct 3, 2021
edfd6d5
test
BoxyUwU Oct 6, 2021
b386959
fix: alloc-optimisation is only for rust llvm
infinity0 Oct 6, 2021
742d8be
Restore h1 styles, which got accidentally removed.
Oct 6, 2021
1f86a8e
Revert the rustc_error_codes changes.
Oct 6, 2021
3209582
Rollup merge of #87601 - a1phyr:feature_uint_add_signed, r=kennytm
Manishearth Oct 6, 2021
1e3b5d6
Rollup merge of #88523 - kpreid:category, r=yaahc
Manishearth Oct 6, 2021
91e3b51
Rollup merge of #89050 - DeveloperC286:drain_fields_to_private, r=jos…
Manishearth Oct 6, 2021
14da7fc
Rollup merge of #89245 - DeveloperC286:iter_mut_fields_to_private, r=…
Manishearth Oct 6, 2021
b4615b5
Rollup merge of #89324 - yoshuawuyts:hardware-parallelism, r=m-ou-se
Manishearth Oct 6, 2021
b87a9a8
Rollup merge of #89329 - tmiasko:print-type-sizes-no-fields, r=jackh726
Manishearth Oct 6, 2021
b015940
Rollup merge of #89501 - Aaron1011:escaping-name-regions, r=davidtwco
Manishearth Oct 6, 2021
7d6feb4
Rollup merge of #89506 - yaymukund:docblock-headings, r=GuillaumeGomez
Manishearth Oct 6, 2021
f5bfa34
Rollup merge of #89528 - FabianWolff:issue-89497, r=jackh726
Manishearth Oct 6, 2021
79a1fc8
Rollup merge of #89531 - devnexen:stack_overflow_bsd_libc_upd, r=dtolnay
Manishearth Oct 6, 2021
eb7da35
Rollup merge of #89588 - BoxyUwU:add_a_test_uwu, r=lcnr
Manishearth Oct 6, 2021
f31c805
Rollup merge of #89591 - infinity0:master, r=Amanieu
Manishearth Oct 6, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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