Skip to content

Commit

Permalink
Auto merge of rust-lang#89386 - ehuss:rollup-idf4dmj, r=ehuss
Browse files Browse the repository at this point in the history
Rollup of 13 pull requests

Successful merges:

 - rust-lang#87428 (Fix union keyword highlighting in rustdoc HTML sources)
 - rust-lang#88412 (Remove ignore-tidy-undocumented-unsafe from core::slice::sort)
 - rust-lang#89098 (Fix generics where bounds order)
 - rust-lang#89232 (Improve help for recursion limit errors)
 - rust-lang#89294 (:arrow_up: rust-analyzer)
 - rust-lang#89297 (Remove Never variant from clean::Type enum)
 - rust-lang#89311 (Add unit assignment to MIR for `asm!()`)
 - rust-lang#89313 (PassWrapper: handle function rename from upstream D36850)
 - rust-lang#89315 (Clarify that `CString::from_vec_unchecked` appends 0 byte.)
 - rust-lang#89335 (Optimize is_sorted for Range and RangeInclusive)
 - rust-lang#89366 (rustdoc: Remove lazy_static dependency)
 - rust-lang#89377 (Update cargo)
 - rust-lang#89378 (Update books)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Sep 30, 2021
2 parents 4aa7879 + 20c9530 commit 30acf6d
Show file tree
Hide file tree
Showing 52 changed files with 262 additions and 69 deletions.
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
2 changes: 1 addition & 1 deletion src/doc/book
Submodule book updated 76 files
+4 −4 .github/workflows/main.yml
+1 −5 listings/ch02-guessing-game-tutorial/listing-02-04/output.txt
+1 −2 listings/ch02-guessing-game-tutorial/no-listing-02-without-expect/output.txt
+1 −5 listings/ch03-common-programming-concepts/no-listing-01-variables-are-immutable/output.txt
+1 −5 listings/ch03-common-programming-concepts/no-listing-05-mut-cant-change-types/output.txt
+2 −5 listings/ch03-common-programming-concepts/no-listing-19-statements-vs-expressions/output.txt
+0 −2 listings/ch03-common-programming-concepts/no-listing-20-blocks-are-expressions/src/main.rs
+1 −5 listings/ch03-common-programming-concepts/no-listing-23-statements-dont-return-values/output.txt
+1 −5 listings/ch03-common-programming-concepts/no-listing-28-if-condition-must-be-bool/output.txt
+1 −5 listings/ch03-common-programming-concepts/no-listing-31-arms-must-return-same-type/output.txt
+1 −5 listings/ch03-common-programming-concepts/output-only-01-no-type-annotations/output.txt
+1 −5 listings/ch04-understanding-ownership/listing-04-06/output.txt
+1 −5 listings/ch04-understanding-ownership/no-listing-04-cant-use-after-move/output.txt
+1 −5 listings/ch04-understanding-ownership/no-listing-10-multiple-mut-not-allowed/output.txt
+1 −5 listings/ch04-understanding-ownership/no-listing-12-immutable-and-mutable-not-allowed/output.txt
+1 −5 listings/ch04-understanding-ownership/no-listing-14-dangling-reference/output.txt
+1 −5 listings/ch04-understanding-ownership/no-listing-19-slice-error/output.txt
+1 −6 listings/ch05-using-structs-to-structure-related-data/listing-05-11/output.txt
+10 −12 listings/ch05-using-structs-to-structure-related-data/no-listing-02-reference-in-struct/output.txt
+2 −7 listings/ch05-using-structs-to-structure-related-data/output-only-01-debug/output.txt
+1 −5 listings/ch06-enums-and-pattern-matching/no-listing-07-cant-use-option-directly/output.txt
+1 −5 listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/output.txt
+1 −5 listings/ch07-managing-growing-projects/listing-07-03/output.txt
+1 −5 listings/ch07-managing-growing-projects/listing-07-05/output.txt
+1 −5 listings/ch08-common-collections/listing-08-07/output.txt
+1 −5 listings/ch08-common-collections/listing-08-19/output.txt
+1 −5 listings/ch09-error-handling/no-listing-02-ask-compiler-for-type/output.txt
+11 −15 listings/ch09-error-handling/no-listing-06-question-mark-in-main/output.txt
+1 −5 listings/ch10-generic-types-traits-and-lifetimes/listing-10-05/output.txt
+1 −5 listings/ch10-generic-types-traits-and-lifetimes/listing-10-07/output.txt
+1 −5 listings/ch10-generic-types-traits-and-lifetimes/listing-10-17/output.txt
+1 −5 listings/ch10-generic-types-traits-and-lifetimes/listing-10-21/output.txt
+1 −5 listings/ch10-generic-types-traits-and-lifetimes/listing-10-24/output.txt
+1 −5 listings/ch10-generic-types-traits-and-lifetimes/no-listing-07-fixing-listing-10-05/output.txt
+1 −5 listings/ch10-generic-types-traits-and-lifetimes/no-listing-09-unrelated-lifetime/output.txt
+1 −1 listings/ch11-writing-automated-tests/no-listing-11-ignore-a-test/output.txt
+1 −2 listings/ch12-an-io-project/listing-12-12/output.txt
+1 −5 listings/ch12-an-io-project/output-only-02-missing-lifetimes/output.txt
+1 −5 listings/ch13-functional-features/listing-13-08/output.txt
+1 −2 listings/ch13-functional-features/listing-13-17/output.txt
+1 −5 listings/ch13-functional-features/no-listing-02-functions-cant-capture/output.txt
+1 −5 listings/ch13-functional-features/no-listing-03-move-closures/output.txt
+1 −5 listings/ch15-smart-pointers/listing-15-03/output.txt
+1 −5 listings/ch15-smart-pointers/listing-15-09/output.txt
+1 −5 listings/ch15-smart-pointers/listing-15-15/output.txt
+1 −5 listings/ch15-smart-pointers/listing-15-17/output.txt
+1 −5 listings/ch15-smart-pointers/listing-15-21/output.txt
+1 −5 listings/ch15-smart-pointers/no-listing-01-cant-borrow-immutable-as-mutable/output.txt
+1 −5 listings/ch15-smart-pointers/output-only-01-comparing-to-reference/output.txt
+1 −5 listings/ch16-fearless-concurrency/listing-16-03/output.txt
+1 −5 listings/ch16-fearless-concurrency/listing-16-09/output.txt
+1 −5 listings/ch16-fearless-concurrency/listing-16-13/output.txt
+1 −5 listings/ch16-fearless-concurrency/listing-16-14/output.txt
+1 −5 listings/ch16-fearless-concurrency/output-only-01-move-drop/output.txt
+1 −5 listings/ch17-oop/listing-17-10/output.txt
+3 −7 listings/ch17-oop/no-listing-01-trait-object-of-clone/output.txt
+1 −5 listings/ch18-patterns-and-matching/listing-18-05/output.txt
+1 −5 listings/ch18-patterns-and-matching/listing-18-08/output.txt
+1 −2 listings/ch18-patterns-and-matching/listing-18-10/output.txt
+1 −5 listings/ch18-patterns-and-matching/listing-18-25/output.txt
+1 −5 listings/ch19-advanced-features/listing-19-05/output.txt
+6 −8 listings/ch19-advanced-features/listing-19-20/output.txt
+1 −5 listings/ch19-advanced-features/no-listing-02-impl-outlineprint-for-point/output.txt
+1 −5 listings/ch19-advanced-features/no-listing-18-returns-closure/output.txt
+1 −5 listings/ch19-advanced-features/output-only-01-missing-unsafe/output.txt
+1 −5 listings/ch20-web-server/listing-20-12/output.txt
+1 −5 listings/ch20-web-server/listing-20-17/output.txt
+1 −5 listings/ch20-web-server/listing-20-22/output.txt
+1 −5 listings/ch20-web-server/no-listing-01-define-threadpool-struct/output.txt
+1 −5 listings/ch20-web-server/no-listing-02-impl-threadpool-new/output.txt
+1 −5 listings/ch20-web-server/no-listing-04-update-worker-definition/output.txt
+1 −1 rust-toolchain
+1 −1 src/appendix-02-operators.md
+1 −1 src/ch17-01-what-is-oo.md
+1 −1 src/title-page.md
+3 −0 tools/update-rustc.sh
2 changes: 1 addition & 1 deletion src/doc/nomicon
Submodule nomicon updated 1 files
+2 −2 src/lifetimes.md
2 changes: 1 addition & 1 deletion src/doc/reference
2 changes: 1 addition & 1 deletion src/doc/rust-by-example
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

0 comments on commit 30acf6d

Please sign in to comment.