Skip to content

Commit c5799b2

Browse files
committedSep 3, 2021
Auto merge of #88618 - m-ou-se:rollup-6tss5z6, r=m-ou-se
Rollup of 7 pull requests Successful merges: - #88202 (Add an example for deriving PartialOrd on enums) - #88483 (Fix LLVM libunwind build for non-musl targets) - #88507 (Add test case for using `slice::fill` with MaybeUninit) - #88557 (small const generics cleanup) - #88579 (remove redundant / misplaced sentence from docs) - #88610 (Update outdated docs of array::IntoIter::new.) - #88613 (Update primitive docs for rust 2021.) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents e4e4179 + 2ce74b0 commit c5799b2

File tree

8 files changed

+64
-56
lines changed

8 files changed

+64
-56
lines changed
 

‎compiler/rustc_trait_selection/src/traits/object_safety.rs

+5-30
Original file line numberDiff line numberDiff line change
@@ -820,10 +820,10 @@ fn contains_illegal_self_type_reference<'tcx, T: TypeFoldable<'tcx>>(
820820
}
821821
}
822822

823-
fn visit_const(&mut self, ct: &ty::Const<'tcx>) -> ControlFlow<Self::BreakTy> {
824-
// First check if the type of this constant references `Self`.
825-
self.visit_ty(ct.ty)?;
826-
823+
fn visit_unevaluated_const(
824+
&mut self,
825+
uv: ty::Unevaluated<'tcx>,
826+
) -> ControlFlow<Self::BreakTy> {
827827
// Constants can only influence object safety if they reference `Self`.
828828
// This is only possible for unevaluated constants, so we walk these here.
829829
//
@@ -837,7 +837,7 @@ fn contains_illegal_self_type_reference<'tcx, T: TypeFoldable<'tcx>>(
837837
// This shouldn't really matter though as we can't really use any
838838
// constants which are not considered const evaluatable.
839839
use rustc_middle::mir::abstract_const::Node;
840-
if let Ok(Some(ct)) = AbstractConst::from_const(self.tcx, ct) {
840+
if let Ok(Some(ct)) = AbstractConst::new(self.tcx, uv.shrink()) {
841841
const_evaluatable::walk_abstract_const(self.tcx, ct, |node| match node.root() {
842842
Node::Leaf(leaf) => {
843843
let leaf = leaf.subst(self.tcx, ct.substs);
@@ -852,31 +852,6 @@ fn contains_illegal_self_type_reference<'tcx, T: TypeFoldable<'tcx>>(
852852
ControlFlow::CONTINUE
853853
}
854854
}
855-
856-
fn visit_predicate(&mut self, pred: ty::Predicate<'tcx>) -> ControlFlow<Self::BreakTy> {
857-
if let ty::PredicateKind::ConstEvaluatable(ct) = pred.kind().skip_binder() {
858-
// FIXME(generic_const_exprs): We should probably deduplicate the logic for
859-
// `AbstractConst`s here, it might make sense to change `ConstEvaluatable` to
860-
// take a `ty::Const` instead.
861-
use rustc_middle::mir::abstract_const::Node;
862-
if let Ok(Some(ct)) = AbstractConst::new(self.tcx, ct) {
863-
const_evaluatable::walk_abstract_const(self.tcx, ct, |node| match node.root() {
864-
Node::Leaf(leaf) => {
865-
let leaf = leaf.subst(self.tcx, ct.substs);
866-
self.visit_const(leaf)
867-
}
868-
Node::Cast(_, _, ty) => self.visit_ty(ty),
869-
Node::Binop(..) | Node::UnaryOp(..) | Node::FunctionCall(_, _) => {
870-
ControlFlow::CONTINUE
871-
}
872-
})
873-
} else {
874-
ControlFlow::CONTINUE
875-
}
876-
} else {
877-
pred.super_visit_with(self)
878-
}
879-
}
880855
}
881856

882857
value

‎compiler/rustc_typeck/src/outlives/implicit_infer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ fn insert_required_predicates_to_be_wf<'tcx>(
120120
// Luckily the only types contained in default substs are type
121121
// parameters which don't matter here.
122122
//
123-
// FIXME(const_generics): Once more complex const parameter types
123+
// FIXME(adt_const_params): Once complex const parameter types
124124
// are allowed, this might be incorrect. I think that we will still be
125125
// fine, as all outlives relations of the const param types should also
126126
// be part of the adt containing it, but we should still both update the

‎library/core/src/array/iter.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl<T, const N: usize> IntoIter<T, N> {
3737
/// Creates a new iterator over the given `array`.
3838
///
3939
/// *Note*: this method might be deprecated in the future,
40-
/// after [`IntoIterator` is implemented for arrays][array-into-iter].
40+
/// since [`IntoIterator`] is now implemented for arrays.
4141
///
4242
/// # Examples
4343
///
@@ -48,8 +48,13 @@ impl<T, const N: usize> IntoIter<T, N> {
4848
/// // The type of `value` is an `i32` here, instead of `&i32`
4949
/// let _: i32 = value;
5050
/// }
51+
///
52+
/// // Since Rust 1.53, arrays implement IntoIterator directly:
53+
/// for value in [1, 2, 3, 4, 5] {
54+
/// // The type of `value` is an `i32` here, instead of `&i32`
55+
/// let _: i32 = value;
56+
/// }
5157
/// ```
52-
/// [array-into-iter]: https://github.com/rust-lang/rust/pull/65819
5358
#[stable(feature = "array_value_iter", since = "1.51.0")]
5459
pub fn new(array: [T; N]) -> Self {
5560
// SAFETY: The transmute here is actually safe. The docs of `MaybeUninit`

‎library/core/src/cmp.rs

+12
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,18 @@ impl<T: Clone> Clone for Reverse<T> {
660660
/// This trait can be used with `#[derive]`. When `derive`d on structs, it will produce a
661661
/// [lexicographic](https://en.wikipedia.org/wiki/Lexicographic_order) ordering based on the top-to-bottom declaration order of the struct's members.
662662
/// When `derive`d on enums, variants are ordered by their top-to-bottom discriminant order.
663+
/// This means variants at the top are less than variants at the bottom.
664+
/// Here's an example:
665+
///
666+
/// ```
667+
/// #[derive(PartialEq, PartialOrd)]
668+
/// enum Size {
669+
/// Small,
670+
/// Large,
671+
/// }
672+
///
673+
/// assert!(Size::Small < Size::Large);
674+
/// ```
663675
///
664676
/// ## Lexicographical comparison
665677
///

‎library/core/src/ptr/mod.rs

-4
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,6 @@ mod mut_ptr;
182182
/// // Ensure that the last item was dropped.
183183
/// assert!(weak.upgrade().is_none());
184184
/// ```
185-
///
186-
/// Notice that the compiler performs this copy automatically when dropping packed structs,
187-
/// i.e., you do not usually have to worry about such issues unless you call `drop_in_place`
188-
/// manually.
189185
#[stable(feature = "drop_in_place", since = "1.8.0")]
190186
#[lang = "drop_in_place"]
191187
#[allow(unconditional_recursion)]

‎library/core/tests/slice.rs

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use core::cell::Cell;
22
use core::cmp::Ordering;
3+
use core::mem::MaybeUninit;
34
use core::result::Result::{Err, Ok};
45

56
#[test]
@@ -2144,3 +2145,10 @@ fn test_slice_run_destructors() {
21442145

21452146
assert_eq!(x.get(), 1);
21462147
}
2148+
2149+
#[test]
2150+
fn test_slice_fill_with_uninit() {
2151+
// This should not UB. See #87891
2152+
let mut a = [MaybeUninit::<u8>::uninit(); 10];
2153+
a.fill(MaybeUninit::uninit());
2154+
}

‎library/std/src/primitive_docs.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,8 @@ mod prim_pointer {}
581581
/// might be made consistent to the behavior of later editions.
582582
///
583583
/// ```rust,edition2018
584+
/// // Rust 2015 and 2018:
585+
///
584586
/// # #![allow(array_into_iter)] // override our `deny(warnings)`
585587
/// let array: [i32; 3] = [0; 3];
586588
///
@@ -604,11 +606,13 @@ mod prim_pointer {}
604606
/// }
605607
/// ```
606608
///
607-
/// Starting in the 2021 edition, `array.into_iter()` will use `IntoIterator` normally to iterate
609+
/// Starting in the 2021 edition, `array.into_iter()` uses `IntoIterator` normally to iterate
608610
/// by value, and `iter()` should be used to iterate by reference like previous editions.
609611
///
610-
/// ```rust,edition2021,ignore
611-
/// # // FIXME: ignored because 2021 testing is still unstable
612+
#[cfg_attr(bootstrap, doc = "```rust,edition2021,ignore")]
613+
#[cfg_attr(not(bootstrap), doc = "```rust,edition2021")]
614+
/// // Rust 2021:
615+
///
612616
/// let array: [i32; 3] = [0; 3];
613617
///
614618
/// // This iterates by reference:
@@ -631,12 +635,12 @@ mod prim_pointer {}
631635
/// avoid the `into_iter` syntax on those editions. If an edition update is not
632636
/// viable/desired, there are multiple alternatives:
633637
/// * use `iter`, equivalent to the old behavior, creating references
634-
/// * use [`array::IntoIter`], equivalent to the post-2021 behavior (Rust 1.51+)
638+
/// * use [`IntoIterator::into_iter`], equivalent to the post-2021 behavior (Rust 1.53+)
635639
/// * replace `for ... in array.into_iter() {` with `for ... in array {`,
636640
/// equivalent to the post-2021 behavior (Rust 1.53+)
637641
///
638642
/// ```rust,edition2018
639-
/// use std::array::IntoIter;
643+
/// // Rust 2015 and 2018:
640644
///
641645
/// let array: [i32; 3] = [0; 3];
642646
///
@@ -647,7 +651,7 @@ mod prim_pointer {}
647651
/// }
648652
///
649653
/// // This iterates by value:
650-
/// for item in IntoIter::new(array) {
654+
/// for item in IntoIterator::into_iter(array) {
651655
/// let x: i32 = item;
652656
/// println!("{}", x);
653657
/// }
@@ -660,7 +664,7 @@ mod prim_pointer {}
660664
///
661665
/// // IntoIter can also start a chain.
662666
/// // This iterates by value:
663-
/// for item in IntoIter::new(array).enumerate() {
667+
/// for item in IntoIterator::into_iter(array).enumerate() {
664668
/// let (i, x): (usize, i32) = item;
665669
/// println!("array[{}] = {}", i, x);
666670
/// }

‎src/bootstrap/compile.rs

+20-12
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,14 @@ fn copy_and_stamp(
142142
target_deps.push((target, dependency_type));
143143
}
144144

145+
fn copy_llvm_libunwind(builder: &Builder<'_>, target: TargetSelection, libdir: &Path) -> PathBuf {
146+
let libunwind_path = builder.ensure(native::Libunwind { target });
147+
let libunwind_source = libunwind_path.join("libunwind.a");
148+
let libunwind_target = libdir.join("libunwind.a");
149+
builder.copy(&libunwind_source, &libunwind_target);
150+
libunwind_target
151+
}
152+
145153
/// Copies third party objects needed by various targets.
146154
fn copy_third_party_objects(
147155
builder: &Builder<'_>,
@@ -167,6 +175,15 @@ fn copy_third_party_objects(
167175
);
168176
}
169177

178+
if target == "x86_64-fortanix-unknown-sgx"
179+
|| builder.config.llvm_libunwind == LlvmLibunwind::InTree
180+
&& (target.contains("linux") || target.contains("fuchsia"))
181+
{
182+
let libunwind_path =
183+
copy_llvm_libunwind(builder, target, &builder.sysroot_libdir(*compiler, target));
184+
target_deps.push((libunwind_path, DependencyType::Target));
185+
}
186+
170187
target_deps
171188
}
172189

@@ -208,6 +225,9 @@ fn copy_self_contained_objects(
208225
builder.copy(&src, &target);
209226
target_deps.push((target, DependencyType::TargetSelfContained));
210227
}
228+
229+
let libunwind_path = copy_llvm_libunwind(builder, target, &libdir_self_contained);
230+
target_deps.push((libunwind_path, DependencyType::TargetSelfContained));
211231
} else if target.ends_with("-wasi") {
212232
let srcdir = builder
213233
.wasi_root(target)
@@ -234,18 +254,6 @@ fn copy_self_contained_objects(
234254
}
235255
}
236256

237-
if target.contains("musl")
238-
|| target.contains("x86_64-fortanix-unknown-sgx")
239-
|| builder.config.llvm_libunwind == LlvmLibunwind::InTree
240-
&& (target.contains("linux") || target.contains("fuchsia"))
241-
{
242-
let libunwind_path = builder.ensure(native::Libunwind { target });
243-
let libunwind_source = libunwind_path.join("libunwind.a");
244-
let libunwind_target = libdir_self_contained.join("libunwind.a");
245-
builder.copy(&libunwind_source, &libunwind_target);
246-
target_deps.push((libunwind_target, DependencyType::TargetSelfContained));
247-
}
248-
249257
target_deps
250258
}
251259

0 commit comments

Comments
 (0)
Please sign in to comment.