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 10 pull requests #89373

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
47c5056
Fix highlighting for union keyword
GuillaumeGomez Jul 24, 2021
ee38116
Add test for union keyword highlighting
GuillaumeGomez Jul 24, 2021
18fb97e
Remove ignore-tidy-undocumented-unsafe from core::slice::sort
mdsn Aug 25, 2021
b226d17
Fix generics where bounds order
GuillaumeGomez Sep 19, 2021
12c3f50
PassWrapper: handle function rename from upstream D36850
durin42 Sep 27, 2021
cd0873b
Add unit assignment to MIR for `asm!()`
FabianWolff Sep 27, 2021
dd0b5f4
Clarify that `CString::from_vec_unchecked` appends 0 byte.
et342 Sep 28, 2021
830ecbd
Optimize is_sorted for Range and RangeInclusive
mbrubeck Sep 28, 2021
d2613fb
Improve help for recursion limit errors
rossmacarthur Sep 28, 2021
a0f4e78
Remove lazy_static dependency
GuillaumeGomez Sep 29, 2021
bdd3471
Remove Never variant from clean::Type enum
GuillaumeGomez Sep 27, 2021
8dfbfe8
Rollup merge of #87428 - GuillaumeGomez:union-highlighting, r=notriddle
GuillaumeGomez Sep 29, 2021
024664d
Rollup merge of #88412 - mdsn:slice-sort-safety, r=dtolnay
GuillaumeGomez Sep 29, 2021
905b9eb
Rollup merge of #89098 - GuillaumeGomez:where-bounds-order, r=camelid
GuillaumeGomez Sep 29, 2021
d21761a
Rollup merge of #89232 - rossmacarthur:fix-76424, r=wesleywiser
GuillaumeGomez Sep 29, 2021
18fd2db
Rollup merge of #89297 - GuillaumeGomez:remove-never-from-type-enum, …
GuillaumeGomez Sep 29, 2021
38ba95d
Rollup merge of #89311 - FabianWolff:issue-89305, r=oli-obk
GuillaumeGomez Sep 29, 2021
05038de
Rollup merge of #89313 - durin42:llvm-14-thinLTOResolvePrevailingInMo…
GuillaumeGomez Sep 29, 2021
164477d
Rollup merge of #89315 - et342:cstr_from_vec_unchecked_doc, r=yaahc
GuillaumeGomez Sep 29, 2021
dc9bf70
Rollup merge of #89335 - mbrubeck:range-is-sorted, r=cuviper
GuillaumeGomez Sep 29, 2021
0d81368
Rollup merge of #89366 - GuillaumeGomez:remove-lazy-static, r=jyn514
GuillaumeGomez Sep 29, 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
8 changes: 6 additions & 2 deletions compiler/rustc_expand/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -633,14 +633,18 @@ impl<'a, 'b> MacroExpander<'a, 'b> {

fn error_recursion_limit_reached(&mut self) {
let expn_data = self.cx.current_expansion.id.expn_data();
let suggested_limit = self.cx.ecfg.recursion_limit * 2;
let suggested_limit = match self.cx.ecfg.recursion_limit {
Limit(0) => Limit(2),
limit => limit * 2,
};
self.cx
.struct_span_err(
expn_data.call_site,
&format!("recursion limit reached while expanding `{}`", expn_data.kind.descr()),
)
.help(&format!(
"consider adding a `#![recursion_limit=\"{}\"]` attribute to your crate (`{}`)",
"consider increasing the recursion limit by adding a \
`#![recursion_limit = \"{}\"]` attribute to your crate (`{}`)",
suggested_limit, self.cx.ecfg.crate_name,
))
.emit();
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1572,7 +1572,11 @@ extern "C" bool
LLVMRustPrepareThinLTOResolveWeak(const LLVMRustThinLTOData *Data, LLVMModuleRef M) {
Module &Mod = *unwrap(M);
const auto &DefinedGlobals = Data->ModuleToDefinedGVSummaries.lookup(Mod.getModuleIdentifier());
#if LLVM_VERSION_GE(14, 0)
thinLTOFinalizeInModule(Mod, DefinedGlobals, /*PropagateAttrs=*/true);
#else
thinLTOResolvePrevailingInModule(Mod, DefinedGlobals);
#endif
return true;
}

Expand Down
9 changes: 6 additions & 3 deletions compiler/rustc_mir_build/src/build/expr/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,8 +449,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
})
.collect();

let destination = this.cfg.start_new_block();
if !options.contains(InlineAsmOptions::NORETURN) {
this.cfg.push_assign_unit(block, source_info, destination, this.tcx);
}

let destination_block = this.cfg.start_new_block();
this.cfg.terminate(
block,
source_info,
Expand All @@ -462,11 +465,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
destination: if options.contains(InlineAsmOptions::NORETURN) {
None
} else {
Some(destination)
Some(destination_block)
},
},
);
destination.unit()
destination_block.unit()
}

// These cases don't actually need a destination
Expand Down
10 changes: 7 additions & 3 deletions compiler/rustc_trait_selection/src/autoderef.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use rustc_hir as hir;
use rustc_infer::infer::InferCtxt;
use rustc_middle::ty::{self, TraitRef, Ty, TyCtxt, WithConstness};
use rustc_middle::ty::{ToPredicate, TypeFoldable};
use rustc_session::DiagnosticMessageId;
use rustc_session::{DiagnosticMessageId, Limit};
use rustc_span::def_id::LOCAL_CRATE;
use rustc_span::Span;

Expand Down Expand Up @@ -217,7 +217,10 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> {

pub fn report_autoderef_recursion_limit_error<'tcx>(tcx: TyCtxt<'tcx>, span: Span, ty: Ty<'tcx>) {
// We've reached the recursion limit, error gracefully.
let suggested_limit = tcx.recursion_limit() * 2;
let suggested_limit = match tcx.recursion_limit() {
Limit(0) => Limit(2),
limit => limit * 2,
};
let msg = format!("reached the recursion limit while auto-dereferencing `{:?}`", ty);
let error_id = (DiagnosticMessageId::ErrorId(55), Some(span), msg);
let fresh = tcx.sess.one_time_diagnostics.borrow_mut().insert(error_id);
Expand All @@ -231,7 +234,8 @@ pub fn report_autoderef_recursion_limit_error<'tcx>(tcx: TyCtxt<'tcx>, span: Spa
)
.span_label(span, "deref recursion limit reached")
.help(&format!(
"consider adding a `#![recursion_limit=\"{}\"]` attribute to your crate (`{}`)",
"consider increasing the recursion limit by adding a \
`#![recursion_limit = \"{}\"]` attribute to your crate (`{}`)",
suggested_limit,
tcx.crate_name(LOCAL_CRATE),
))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use rustc_middle::ty::{
Infer, InferTy, ToPredicate, Ty, TyCtxt, TypeFoldable, WithConstness,
};
use rustc_middle::ty::{TypeAndMut, TypeckResults};
use rustc_session::Limit;
use rustc_span::def_id::LOCAL_CRATE;
use rustc_span::symbol::{kw, sym, Ident, Symbol};
use rustc_span::{BytePos, DesugaringKind, ExpnKind, ForLoopLoc, MultiSpan, Span, DUMMY_SP};
Expand Down Expand Up @@ -2426,10 +2427,13 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
}

fn suggest_new_overflow_limit(&self, err: &mut DiagnosticBuilder<'_>) {
let current_limit = self.tcx.recursion_limit();
let suggested_limit = current_limit * 2;
let suggested_limit = match self.tcx.recursion_limit() {
Limit(0) => Limit(2),
limit => limit * 2,
};
err.help(&format!(
"consider adding a `#![recursion_limit=\"{}\"]` attribute to your crate (`{}`)",
"consider increasing the recursion limit by adding a \
`#![recursion_limit = \"{}\"]` attribute to your crate (`{}`)",
suggested_limit,
self.tcx.crate_name(LOCAL_CRATE),
));
Expand Down
10 changes: 10 additions & 0 deletions library/core/src/iter/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,11 @@ impl<A: Step> Iterator for ops::Range<A> {
self.next_back()
}

#[inline]
fn is_sorted(self) -> bool {
true
}

#[inline]
#[doc(hidden)]
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> Self::Item
Expand Down Expand Up @@ -1095,6 +1100,11 @@ impl<A: Step> Iterator for ops::RangeInclusive<A> {
fn max(mut self) -> Option<A> {
self.next_back()
}

#[inline]
fn is_sorted(self) -> bool {
true
}
}

#[stable(feature = "inclusive_range", since = "1.26.0")]
Expand Down
25 changes: 23 additions & 2 deletions library/core/src/slice/sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
//! Unstable sorting is compatible with libcore because it doesn't allocate memory, unlike our
//! stable sorting implementation.

// ignore-tidy-undocumented-unsafe

use crate::cmp;
use crate::mem::{self, MaybeUninit};
use crate::ptr;
Expand Down Expand Up @@ -291,6 +289,9 @@ where
} else if start_r < end_r {
block_l = rem;
} else {
// There were the same number of elements to switch on both blocks during the last
// iteration, so there are no remaining elements on either block. Cover the remaining
// items with roughly equally-sized blocks.
block_l = rem / 2;
block_r = rem - block_l;
}
Expand Down Expand Up @@ -437,6 +438,17 @@ where
// Move its remaining out-of-order elements to the far right.
debug_assert_eq!(width(l, r), block_l);
while start_l < end_l {
// remaining-elements-safety
// SAFETY: while the loop condition holds there are still elements in `offsets_l`, so it
// is safe to point `end_l` to the previous element.
//
// The `ptr::swap` is safe if both its arguments are valid for reads and writes:
// - Per the debug assert above, the distance between `l` and `r` is `block_l`
// elements, so there can be at most `block_l` remaining offsets between `start_l`
// and `end_l`. This means `r` will be moved at most `block_l` steps back, which
// makes the `r.offset` calls valid (at that point `l == r`).
// - `offsets_l` contains valid offsets into `v` collected during the partitioning of
// the last block, so the `l.offset` calls are valid.
unsafe {
end_l = end_l.offset(-1);
ptr::swap(l.offset(*end_l as isize), r.offset(-1));
Expand All @@ -449,6 +461,7 @@ where
// Move its remaining out-of-order elements to the far left.
debug_assert_eq!(width(l, r), block_r);
while start_r < end_r {
// SAFETY: See the reasoning in [remaining-elements-safety].
unsafe {
end_r = end_r.offset(-1);
ptr::swap(l, r.offset(-(*end_r as isize) - 1));
Expand Down Expand Up @@ -481,6 +494,8 @@ where

// Read the pivot into a stack-allocated variable for efficiency. If a following comparison
// operation panics, the pivot will be automatically written back into the slice.

// SAFETY: `pivot` is a reference to the first element of `v`, so `ptr::read` is safe.
let mut tmp = mem::ManuallyDrop::new(unsafe { ptr::read(pivot) });
let _pivot_guard = CopyOnDrop { src: &mut *tmp, dest: pivot };
let pivot = &*tmp;
Expand Down Expand Up @@ -646,6 +661,12 @@ where

if len >= 8 {
// Swaps indices so that `v[a] <= v[b]`.
// SAFETY: `len >= 8` so there are at least two elements in the neighborhoods of
// `a`, `b` and `c`. This means the three calls to `sort_adjacent` result in
// corresponding calls to `sort3` with valid 3-item neighborhoods around each
// pointer, which in turn means the calls to `sort2` are done with valid
// references. Thus the `v.get_unchecked` calls are safe, as is the `ptr::swap`
// call.
let mut sort2 = |a: &mut usize, b: &mut usize| unsafe {
if is_less(v.get_unchecked(*b), v.get_unchecked(*a)) {
ptr::swap(a, b);
Expand Down
2 changes: 2 additions & 0 deletions library/std/src/ffi/c_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,8 @@ impl CString {
/// Creates a C-compatible string by consuming a byte vector,
/// without checking for interior 0 bytes.
///
/// Trailing 0 byte will be appended by this function.
///
/// This method is equivalent to [`CString::new`] except that no runtime
/// assertion is made that `v` contains no 0 bytes, and it requires an
/// actual byte vector, not anything that can be converted to one with Into.
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1313,7 +1313,7 @@ impl Clean<Type> for hir::Ty<'_> {
use rustc_hir::*;

match self.kind {
TyKind::Never => Never,
TyKind::Never => Primitive(PrimitiveType::Never),
TyKind::Ptr(ref m) => RawPointer(m.mutbl, box m.ty.clean(cx)),
TyKind::Rptr(ref l, ref m) => {
// There are two times a `Fresh` lifetime can be created:
Expand Down Expand Up @@ -1402,7 +1402,7 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
trace!("cleaning type: {:?}", self);
let ty = normalize(cx, self).unwrap_or(self);
match *ty.kind() {
ty::Never => Never,
ty::Never => Primitive(PrimitiveType::Never),
ty::Bool => Primitive(PrimitiveType::Bool),
ty::Char => Primitive(PrimitiveType::Char),
ty::Int(int_ty) => Primitive(int_ty.into()),
Expand Down
10 changes: 6 additions & 4 deletions src/librustdoc/clean/simplify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
//! This module attempts to reconstruct the original where and/or parameter
//! bounds by special casing scenarios such as these. Fun!

use std::collections::BTreeMap;

use rustc_data_structures::fx::FxIndexMap;
use rustc_hir::def_id::DefId;
use rustc_middle::ty;
use rustc_span::Symbol;
Expand All @@ -23,8 +22,11 @@ use crate::clean::WherePredicate as WP;
use crate::core::DocContext;

crate fn where_clauses(cx: &DocContext<'_>, clauses: Vec<WP>) -> Vec<WP> {
// First, partition the where clause into its separate components
let mut params: BTreeMap<_, (Vec<_>, Vec<_>)> = BTreeMap::new();
// First, partition the where clause into its separate components.
//
// We use `FxIndexMap` so that the insertion order is preserved to prevent messing up to
// the order of the generated bounds.
let mut params: FxIndexMap<Symbol, (Vec<_>, Vec<_>)> = FxIndexMap::default();
let mut lifetimes = Vec::new();
let mut equalities = Vec::new();
let mut tybounds = Vec::new();
Expand Down
3 changes: 0 additions & 3 deletions src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1396,7 +1396,6 @@ crate enum Type {
Slice(Box<Type>),
/// The `String` field is about the size or the constant representing the array's length.
Array(Box<Type>, String),
Never,
RawPointer(Mutability, Box<Type>),
BorrowedRef {
lifetime: Option<Lifetime>,
Expand Down Expand Up @@ -1462,7 +1461,6 @@ impl Type {
}
RawPointer(..) => Some(PrimitiveType::RawPointer),
BareFunction(..) => Some(PrimitiveType::Fn),
Never => Some(PrimitiveType::Never),
_ => None,
}
}
Expand Down Expand Up @@ -1550,7 +1548,6 @@ impl Type {
}
}
BareFunction(..) => PrimitiveType::Fn,
Never => PrimitiveType::Never,
Slice(..) => PrimitiveType::Slice,
Array(..) => PrimitiveType::Array,
RawPointer(..) => PrimitiveType::RawPointer,
Expand Down
6 changes: 3 additions & 3 deletions src/librustdoc/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use rustc_span::symbol::sym;
use rustc_span::Span;

use std::cell::RefCell;
use std::lazy::SyncLazy;
use std::mem;
use std::rc::Rc;

Expand Down Expand Up @@ -271,9 +272,8 @@ crate fn create_config(
providers.typeck_item_bodies = |_, _| {};
// hack so that `used_trait_imports` won't try to call typeck
providers.used_trait_imports = |_, _| {
lazy_static! {
static ref EMPTY_SET: FxHashSet<LocalDefId> = FxHashSet::default();
}
static EMPTY_SET: SyncLazy<FxHashSet<LocalDefId>> =
SyncLazy::new(FxHashSet::default);
&EMPTY_SET
};
// In case typeck does end up being called, don't ICE in case there were name resolution errors
Expand Down
4 changes: 3 additions & 1 deletion src/librustdoc/html/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,9 @@ fn fmt_type<'cx>(
fmt::Display::fmt(&tybounds(bounds, lt, cx), f)
}
clean::Infer => write!(f, "_"),
clean::Primitive(clean::PrimitiveType::Never) => {
primitive_link(f, PrimitiveType::Never, "!", cx)
}
clean::Primitive(prim) => primitive_link(f, prim, &*prim.as_sym().as_str(), cx),
clean::BareFunction(ref decl) => {
if f.alternate() {
Expand Down Expand Up @@ -819,7 +822,6 @@ fn fmt_type<'cx>(
primitive_link(f, PrimitiveType::Array, &format!("; {}]", Escape(n)), cx)
}
}
clean::Never => primitive_link(f, PrimitiveType::Never, "!", cx),
clean::RawPointer(m, ref t) => {
let m = match m {
hir::Mutability::Mut => "mut",
Expand Down
Loading