Skip to content

Commit 30acf6d

Browse files
committed
Auto merge of #89386 - ehuss:rollup-idf4dmj, r=ehuss
Rollup of 13 pull requests Successful merges: - #87428 (Fix union keyword highlighting in rustdoc HTML sources) - #88412 (Remove ignore-tidy-undocumented-unsafe from core::slice::sort) - #89098 (Fix generics where bounds order) - #89232 (Improve help for recursion limit errors) - #89294 (:arrow_up: rust-analyzer) - #89297 (Remove Never variant from clean::Type enum) - #89311 (Add unit assignment to MIR for `asm!()`) - #89313 (PassWrapper: handle function rename from upstream D36850) - #89315 (Clarify that `CString::from_vec_unchecked` appends 0 byte.) - #89335 (Optimize is_sorted for Range and RangeInclusive) - #89366 (rustdoc: Remove lazy_static dependency) - #89377 (Update cargo) - #89378 (Update books) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 4aa7879 + 20c9530 commit 30acf6d

Some content is hidden

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

52 files changed

+262
-69
lines changed

compiler/rustc_expand/src/expand.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -633,14 +633,18 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
633633

634634
fn error_recursion_limit_reached(&mut self) {
635635
let expn_data = self.cx.current_expansion.id.expn_data();
636-
let suggested_limit = self.cx.ecfg.recursion_limit * 2;
636+
let suggested_limit = match self.cx.ecfg.recursion_limit {
637+
Limit(0) => Limit(2),
638+
limit => limit * 2,
639+
};
637640
self.cx
638641
.struct_span_err(
639642
expn_data.call_site,
640643
&format!("recursion limit reached while expanding `{}`", expn_data.kind.descr()),
641644
)
642645
.help(&format!(
643-
"consider adding a `#![recursion_limit=\"{}\"]` attribute to your crate (`{}`)",
646+
"consider increasing the recursion limit by adding a \
647+
`#![recursion_limit = \"{}\"]` attribute to your crate (`{}`)",
644648
suggested_limit, self.cx.ecfg.crate_name,
645649
))
646650
.emit();

compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -1572,7 +1572,11 @@ extern "C" bool
15721572
LLVMRustPrepareThinLTOResolveWeak(const LLVMRustThinLTOData *Data, LLVMModuleRef M) {
15731573
Module &Mod = *unwrap(M);
15741574
const auto &DefinedGlobals = Data->ModuleToDefinedGVSummaries.lookup(Mod.getModuleIdentifier());
1575+
#if LLVM_VERSION_GE(14, 0)
1576+
thinLTOFinalizeInModule(Mod, DefinedGlobals, /*PropagateAttrs=*/true);
1577+
#else
15751578
thinLTOResolvePrevailingInModule(Mod, DefinedGlobals);
1579+
#endif
15761580
return true;
15771581
}
15781582

compiler/rustc_mir_build/src/build/expr/into.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -449,8 +449,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
449449
})
450450
.collect();
451451

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

456+
let destination_block = this.cfg.start_new_block();
454457
this.cfg.terminate(
455458
block,
456459
source_info,
@@ -462,11 +465,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
462465
destination: if options.contains(InlineAsmOptions::NORETURN) {
463466
None
464467
} else {
465-
Some(destination)
468+
Some(destination_block)
466469
},
467470
},
468471
);
469-
destination.unit()
472+
destination_block.unit()
470473
}
471474

472475
// These cases don't actually need a destination

compiler/rustc_trait_selection/src/autoderef.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_hir as hir;
55
use rustc_infer::infer::InferCtxt;
66
use rustc_middle::ty::{self, TraitRef, Ty, TyCtxt, WithConstness};
77
use rustc_middle::ty::{ToPredicate, TypeFoldable};
8-
use rustc_session::DiagnosticMessageId;
8+
use rustc_session::{DiagnosticMessageId, Limit};
99
use rustc_span::def_id::LOCAL_CRATE;
1010
use rustc_span::Span;
1111

@@ -217,7 +217,10 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> {
217217

218218
pub fn report_autoderef_recursion_limit_error<'tcx>(tcx: TyCtxt<'tcx>, span: Span, ty: Ty<'tcx>) {
219219
// We've reached the recursion limit, error gracefully.
220-
let suggested_limit = tcx.recursion_limit() * 2;
220+
let suggested_limit = match tcx.recursion_limit() {
221+
Limit(0) => Limit(2),
222+
limit => limit * 2,
223+
};
221224
let msg = format!("reached the recursion limit while auto-dereferencing `{:?}`", ty);
222225
let error_id = (DiagnosticMessageId::ErrorId(55), Some(span), msg);
223226
let fresh = tcx.sess.one_time_diagnostics.borrow_mut().insert(error_id);
@@ -231,7 +234,8 @@ pub fn report_autoderef_recursion_limit_error<'tcx>(tcx: TyCtxt<'tcx>, span: Spa
231234
)
232235
.span_label(span, "deref recursion limit reached")
233236
.help(&format!(
234-
"consider adding a `#![recursion_limit=\"{}\"]` attribute to your crate (`{}`)",
237+
"consider increasing the recursion limit by adding a \
238+
`#![recursion_limit = \"{}\"]` attribute to your crate (`{}`)",
235239
suggested_limit,
236240
tcx.crate_name(LOCAL_CRATE),
237241
))

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use rustc_middle::ty::{
2222
Infer, InferTy, ToPredicate, Ty, TyCtxt, TypeFoldable, WithConstness,
2323
};
2424
use rustc_middle::ty::{TypeAndMut, TypeckResults};
25+
use rustc_session::Limit;
2526
use rustc_span::def_id::LOCAL_CRATE;
2627
use rustc_span::symbol::{kw, sym, Ident, Symbol};
2728
use rustc_span::{BytePos, DesugaringKind, ExpnKind, ForLoopLoc, MultiSpan, Span, DUMMY_SP};
@@ -2426,10 +2427,13 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
24262427
}
24272428

24282429
fn suggest_new_overflow_limit(&self, err: &mut DiagnosticBuilder<'_>) {
2429-
let current_limit = self.tcx.recursion_limit();
2430-
let suggested_limit = current_limit * 2;
2430+
let suggested_limit = match self.tcx.recursion_limit() {
2431+
Limit(0) => Limit(2),
2432+
limit => limit * 2,
2433+
};
24312434
err.help(&format!(
2432-
"consider adding a `#![recursion_limit=\"{}\"]` attribute to your crate (`{}`)",
2435+
"consider increasing the recursion limit by adding a \
2436+
`#![recursion_limit = \"{}\"]` attribute to your crate (`{}`)",
24332437
suggested_limit,
24342438
self.tcx.crate_name(LOCAL_CRATE),
24352439
));

library/core/src/iter/range.rs

+10
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,11 @@ impl<A: Step> Iterator for ops::Range<A> {
672672
self.next_back()
673673
}
674674

675+
#[inline]
676+
fn is_sorted(self) -> bool {
677+
true
678+
}
679+
675680
#[inline]
676681
#[doc(hidden)]
677682
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> Self::Item
@@ -1095,6 +1100,11 @@ impl<A: Step> Iterator for ops::RangeInclusive<A> {
10951100
fn max(mut self) -> Option<A> {
10961101
self.next_back()
10971102
}
1103+
1104+
#[inline]
1105+
fn is_sorted(self) -> bool {
1106+
true
1107+
}
10981108
}
10991109

11001110
#[stable(feature = "inclusive_range", since = "1.26.0")]

library/core/src/slice/sort.rs

+23-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
//! Unstable sorting is compatible with libcore because it doesn't allocate memory, unlike our
77
//! stable sorting implementation.
88
9-
// ignore-tidy-undocumented-unsafe
10-
119
use crate::cmp;
1210
use crate::mem::{self, MaybeUninit};
1311
use crate::ptr;
@@ -291,6 +289,9 @@ where
291289
} else if start_r < end_r {
292290
block_l = rem;
293291
} else {
292+
// There were the same number of elements to switch on both blocks during the last
293+
// iteration, so there are no remaining elements on either block. Cover the remaining
294+
// items with roughly equally-sized blocks.
294295
block_l = rem / 2;
295296
block_r = rem - block_l;
296297
}
@@ -437,6 +438,17 @@ where
437438
// Move its remaining out-of-order elements to the far right.
438439
debug_assert_eq!(width(l, r), block_l);
439440
while start_l < end_l {
441+
// remaining-elements-safety
442+
// SAFETY: while the loop condition holds there are still elements in `offsets_l`, so it
443+
// is safe to point `end_l` to the previous element.
444+
//
445+
// The `ptr::swap` is safe if both its arguments are valid for reads and writes:
446+
// - Per the debug assert above, the distance between `l` and `r` is `block_l`
447+
// elements, so there can be at most `block_l` remaining offsets between `start_l`
448+
// and `end_l`. This means `r` will be moved at most `block_l` steps back, which
449+
// makes the `r.offset` calls valid (at that point `l == r`).
450+
// - `offsets_l` contains valid offsets into `v` collected during the partitioning of
451+
// the last block, so the `l.offset` calls are valid.
440452
unsafe {
441453
end_l = end_l.offset(-1);
442454
ptr::swap(l.offset(*end_l as isize), r.offset(-1));
@@ -449,6 +461,7 @@ where
449461
// Move its remaining out-of-order elements to the far left.
450462
debug_assert_eq!(width(l, r), block_r);
451463
while start_r < end_r {
464+
// SAFETY: See the reasoning in [remaining-elements-safety].
452465
unsafe {
453466
end_r = end_r.offset(-1);
454467
ptr::swap(l, r.offset(-(*end_r as isize) - 1));
@@ -481,6 +494,8 @@ where
481494

482495
// Read the pivot into a stack-allocated variable for efficiency. If a following comparison
483496
// operation panics, the pivot will be automatically written back into the slice.
497+
498+
// SAFETY: `pivot` is a reference to the first element of `v`, so `ptr::read` is safe.
484499
let mut tmp = mem::ManuallyDrop::new(unsafe { ptr::read(pivot) });
485500
let _pivot_guard = CopyOnDrop { src: &mut *tmp, dest: pivot };
486501
let pivot = &*tmp;
@@ -646,6 +661,12 @@ where
646661

647662
if len >= 8 {
648663
// Swaps indices so that `v[a] <= v[b]`.
664+
// SAFETY: `len >= 8` so there are at least two elements in the neighborhoods of
665+
// `a`, `b` and `c`. This means the three calls to `sort_adjacent` result in
666+
// corresponding calls to `sort3` with valid 3-item neighborhoods around each
667+
// pointer, which in turn means the calls to `sort2` are done with valid
668+
// references. Thus the `v.get_unchecked` calls are safe, as is the `ptr::swap`
669+
// call.
649670
let mut sort2 = |a: &mut usize, b: &mut usize| unsafe {
650671
if is_less(v.get_unchecked(*b), v.get_unchecked(*a)) {
651672
ptr::swap(a, b);

library/std/src/ffi/c_str.rs

+2
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,8 @@ impl CString {
409409
/// Creates a C-compatible string by consuming a byte vector,
410410
/// without checking for interior 0 bytes.
411411
///
412+
/// Trailing 0 byte will be appended by this function.
413+
///
412414
/// This method is equivalent to [`CString::new`] except that no runtime
413415
/// assertion is made that `v` contains no 0 bytes, and it requires an
414416
/// actual byte vector, not anything that can be converted to one with Into.

src/doc/book

Submodule book updated 76 files

src/doc/nomicon

src/librustdoc/clean/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1313,7 +1313,7 @@ impl Clean<Type> for hir::Ty<'_> {
13131313
use rustc_hir::*;
13141314

13151315
match self.kind {
1316-
TyKind::Never => Never,
1316+
TyKind::Never => Primitive(PrimitiveType::Never),
13171317
TyKind::Ptr(ref m) => RawPointer(m.mutbl, box m.ty.clean(cx)),
13181318
TyKind::Rptr(ref l, ref m) => {
13191319
// There are two times a `Fresh` lifetime can be created:
@@ -1402,7 +1402,7 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
14021402
trace!("cleaning type: {:?}", self);
14031403
let ty = normalize(cx, self).unwrap_or(self);
14041404
match *ty.kind() {
1405-
ty::Never => Never,
1405+
ty::Never => Primitive(PrimitiveType::Never),
14061406
ty::Bool => Primitive(PrimitiveType::Bool),
14071407
ty::Char => Primitive(PrimitiveType::Char),
14081408
ty::Int(int_ty) => Primitive(int_ty.into()),

src/librustdoc/clean/simplify.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
//! This module attempts to reconstruct the original where and/or parameter
1212
//! bounds by special casing scenarios such as these. Fun!
1313
14-
use std::collections::BTreeMap;
15-
14+
use rustc_data_structures::fx::FxIndexMap;
1615
use rustc_hir::def_id::DefId;
1716
use rustc_middle::ty;
1817
use rustc_span::Symbol;
@@ -23,8 +22,11 @@ use crate::clean::WherePredicate as WP;
2322
use crate::core::DocContext;
2423

2524
crate fn where_clauses(cx: &DocContext<'_>, clauses: Vec<WP>) -> Vec<WP> {
26-
// First, partition the where clause into its separate components
27-
let mut params: BTreeMap<_, (Vec<_>, Vec<_>)> = BTreeMap::new();
25+
// First, partition the where clause into its separate components.
26+
//
27+
// We use `FxIndexMap` so that the insertion order is preserved to prevent messing up to
28+
// the order of the generated bounds.
29+
let mut params: FxIndexMap<Symbol, (Vec<_>, Vec<_>)> = FxIndexMap::default();
2830
let mut lifetimes = Vec::new();
2931
let mut equalities = Vec::new();
3032
let mut tybounds = Vec::new();

src/librustdoc/clean/types.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1396,7 +1396,6 @@ crate enum Type {
13961396
Slice(Box<Type>),
13971397
/// The `String` field is about the size or the constant representing the array's length.
13981398
Array(Box<Type>, String),
1399-
Never,
14001399
RawPointer(Mutability, Box<Type>),
14011400
BorrowedRef {
14021401
lifetime: Option<Lifetime>,
@@ -1462,7 +1461,6 @@ impl Type {
14621461
}
14631462
RawPointer(..) => Some(PrimitiveType::RawPointer),
14641463
BareFunction(..) => Some(PrimitiveType::Fn),
1465-
Never => Some(PrimitiveType::Never),
14661464
_ => None,
14671465
}
14681466
}
@@ -1550,7 +1548,6 @@ impl Type {
15501548
}
15511549
}
15521550
BareFunction(..) => PrimitiveType::Fn,
1553-
Never => PrimitiveType::Never,
15541551
Slice(..) => PrimitiveType::Slice,
15551552
Array(..) => PrimitiveType::Array,
15561553
RawPointer(..) => PrimitiveType::RawPointer,

src/librustdoc/core.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use rustc_span::symbol::sym;
2525
use rustc_span::Span;
2626

2727
use std::cell::RefCell;
28+
use std::lazy::SyncLazy;
2829
use std::mem;
2930
use std::rc::Rc;
3031

@@ -271,9 +272,8 @@ crate fn create_config(
271272
providers.typeck_item_bodies = |_, _| {};
272273
// hack so that `used_trait_imports` won't try to call typeck
273274
providers.used_trait_imports = |_, _| {
274-
lazy_static! {
275-
static ref EMPTY_SET: FxHashSet<LocalDefId> = FxHashSet::default();
276-
}
275+
static EMPTY_SET: SyncLazy<FxHashSet<LocalDefId>> =
276+
SyncLazy::new(FxHashSet::default);
277277
&EMPTY_SET
278278
};
279279
// In case typeck does end up being called, don't ICE in case there were name resolution errors

src/librustdoc/html/format.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,9 @@ fn fmt_type<'cx>(
761761
fmt::Display::fmt(&tybounds(bounds, lt, cx), f)
762762
}
763763
clean::Infer => write!(f, "_"),
764+
clean::Primitive(clean::PrimitiveType::Never) => {
765+
primitive_link(f, PrimitiveType::Never, "!", cx)
766+
}
764767
clean::Primitive(prim) => primitive_link(f, prim, &*prim.as_sym().as_str(), cx),
765768
clean::BareFunction(ref decl) => {
766769
if f.alternate() {
@@ -819,7 +822,6 @@ fn fmt_type<'cx>(
819822
primitive_link(f, PrimitiveType::Array, &format!("; {}]", Escape(n)), cx)
820823
}
821824
}
822-
clean::Never => primitive_link(f, PrimitiveType::Never, "!", cx),
823825
clean::RawPointer(m, ref t) => {
824826
let m = match m {
825827
hir::Mutability::Mut => "mut",

0 commit comments

Comments
 (0)