Skip to content

Commit 74bd074

Browse files
committed
Auto merge of rust-lang#70747 - Centril:rollup-2vx9bve, r=Centril
Rollup of 9 pull requests Successful merges: - rust-lang#69860 (Use associated numeric consts in documentation) - rust-lang#70576 (Update the description of the ticket to point at RFC 1721) - rust-lang#70597 (Fix double-free and undefined behaviour in libstd::syn::unix::Thread::new) - rust-lang#70640 (Hide `task_context` when lowering body) - rust-lang#70641 (Remove duplicated code in trait selection) - rust-lang#70707 (Remove unused graphviz emitter) - rust-lang#70720 (Place TLS initializers with relocations in .tdata) - rust-lang#70735 (Clean up E0502 explanation) - rust-lang#70741 (Add test for rust-lang#59023) Failed merges: r? @ghost
2 parents f6fe99c + 4c41ea3 commit 74bd074

File tree

41 files changed

+283
-709
lines changed

Some content is hidden

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

41 files changed

+283
-709
lines changed

src/liballoc/slice.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ impl<T> [T] {
432432
///
433433
/// ```should_panic
434434
/// // this will panic at runtime
435-
/// b"0123456789abcdef".repeat(usize::max_value());
435+
/// b"0123456789abcdef".repeat(usize::MAX);
436436
/// ```
437437
#[stable(feature = "repeat_generic_slice", since = "1.40.0")]
438438
pub fn repeat(&self, n: usize) -> Vec<T>

src/liballoc/str.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ impl str {
499499
///
500500
/// ```should_panic
501501
/// // this will panic at runtime
502-
/// "0123456789abcdef".repeat(usize::max_value());
502+
/// "0123456789abcdef".repeat(usize::MAX);
503503
/// ```
504504
#[stable(feature = "repeat_str", since = "1.16.0")]
505505
pub fn repeat(&self, n: usize) -> String {

src/libcore/cmp.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,7 @@ pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> {
817817
/// When comparison is impossible:
818818
///
819819
/// ```
820-
/// let result = std::f64::NAN.partial_cmp(&1.0);
820+
/// let result = f64::NAN.partial_cmp(&1.0);
821821
/// assert_eq!(result, None);
822822
/// ```
823823
#[must_use]

src/libcore/fmt/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,7 @@ pub trait LowerHex {
852852
/// }
853853
/// }
854854
///
855-
/// let l = Length(i32::max_value());
855+
/// let l = Length(i32::MAX);
856856
///
857857
/// assert_eq!(format!("l as hex is: {:X}", l), "l as hex is: 7FFFFFFF");
858858
///

src/libcore/hint.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ use crate::intrinsics;
4343
///
4444
/// assert_eq!(div_1(7, 0), 7);
4545
/// assert_eq!(div_1(9, 1), 4);
46-
/// assert_eq!(div_1(11, std::u32::MAX), 0);
46+
/// assert_eq!(div_1(11, u32::MAX), 0);
4747
/// ```
4848
#[inline]
4949
#[stable(feature = "unreachable", since = "1.27.0")]

src/libcore/intrinsics.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1739,19 +1739,19 @@ extern "rust-intrinsic" {
17391739
pub fn mul_with_overflow<T: Copy>(x: T, y: T) -> (T, bool);
17401740

17411741
/// Performs an exact division, resulting in undefined behavior where
1742-
/// `x % y != 0` or `y == 0` or `x == T::min_value() && y == -1`
1742+
/// `x % y != 0` or `y == 0` or `x == T::MIN && y == -1`
17431743
pub fn exact_div<T: Copy>(x: T, y: T) -> T;
17441744

17451745
/// Performs an unchecked division, resulting in undefined behavior
1746-
/// where y = 0 or x = `T::min_value()` and y = -1
1746+
/// where y = 0 or x = `T::MIN` and y = -1
17471747
///
17481748
/// The stabilized versions of this intrinsic are available on the integer
17491749
/// primitives via the `checked_div` method. For example,
17501750
/// [`std::u32::checked_div`](../../std/primitive.u32.html#method.checked_div)
17511751
#[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")]
17521752
pub fn unchecked_div<T: Copy>(x: T, y: T) -> T;
17531753
/// Returns the remainder of an unchecked division, resulting in
1754-
/// undefined behavior where y = 0 or x = `T::min_value()` and y = -1
1754+
/// undefined behavior where y = 0 or x = `T::MIN` and y = -1
17551755
///
17561756
/// The stabilized versions of this intrinsic are available on the integer
17571757
/// primitives via the `checked_rem` method. For example,
@@ -1777,17 +1777,17 @@ extern "rust-intrinsic" {
17771777
pub fn unchecked_shr<T: Copy>(x: T, y: T) -> T;
17781778

17791779
/// Returns the result of an unchecked addition, resulting in
1780-
/// undefined behavior when `x + y > T::max_value()` or `x + y < T::min_value()`.
1780+
/// undefined behavior when `x + y > T::MAX` or `x + y < T::MIN`.
17811781
#[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")]
17821782
pub fn unchecked_add<T: Copy>(x: T, y: T) -> T;
17831783

17841784
/// Returns the result of an unchecked subtraction, resulting in
1785-
/// undefined behavior when `x - y > T::max_value()` or `x - y < T::min_value()`.
1785+
/// undefined behavior when `x - y > T::MAX` or `x - y < T::MIN`.
17861786
#[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")]
17871787
pub fn unchecked_sub<T: Copy>(x: T, y: T) -> T;
17881788

17891789
/// Returns the result of an unchecked multiplication, resulting in
1790-
/// undefined behavior when `x * y > T::max_value()` or `x * y < T::min_value()`.
1790+
/// undefined behavior when `x * y > T::MAX` or `x * y < T::MIN`.
17911791
#[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")]
17921792
pub fn unchecked_mul<T: Copy>(x: T, y: T) -> T;
17931793

src/libcore/iter/traits/iterator.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ pub trait Iterator {
198198
/// // and the maximum possible lower bound
199199
/// let iter = 0..;
200200
///
201-
/// assert_eq!((usize::max_value(), None), iter.size_hint());
201+
/// assert_eq!((usize::MAX, None), iter.size_hint());
202202
/// ```
203203
#[inline]
204204
#[stable(feature = "rust1", since = "1.0.0")]
@@ -2920,7 +2920,7 @@ pub trait Iterator {
29202920
/// assert_eq!([1.].iter().partial_cmp([1., 2.].iter()), Some(Ordering::Less));
29212921
/// assert_eq!([1., 2.].iter().partial_cmp([1.].iter()), Some(Ordering::Greater));
29222922
///
2923-
/// assert_eq!([std::f64::NAN].iter().partial_cmp([1.].iter()), None);
2923+
/// assert_eq!([f64::NAN].iter().partial_cmp([1.].iter()), None);
29242924
/// ```
29252925
#[stable(feature = "iter_order", since = "1.5.0")]
29262926
fn partial_cmp<I>(self, other: I) -> Option<Ordering>
@@ -3170,7 +3170,7 @@ pub trait Iterator {
31703170
/// assert!(![1, 3, 2, 4].iter().is_sorted());
31713171
/// assert!([0].iter().is_sorted());
31723172
/// assert!(std::iter::empty::<i32>().is_sorted());
3173-
/// assert!(![0.0, 1.0, std::f32::NAN].iter().is_sorted());
3173+
/// assert!(![0.0, 1.0, f32::NAN].iter().is_sorted());
31743174
/// ```
31753175
#[inline]
31763176
#[unstable(feature = "is_sorted", reason = "new API", issue = "53485")]
@@ -3197,7 +3197,7 @@ pub trait Iterator {
31973197
/// assert!(![1, 3, 2, 4].iter().is_sorted_by(|a, b| a.partial_cmp(b)));
31983198
/// assert!([0].iter().is_sorted_by(|a, b| a.partial_cmp(b)));
31993199
/// assert!(std::iter::empty::<i32>().is_sorted_by(|a, b| a.partial_cmp(b)));
3200-
/// assert!(![0.0, 1.0, std::f32::NAN].iter().is_sorted_by(|a, b| a.partial_cmp(b)));
3200+
/// assert!(![0.0, 1.0, f32::NAN].iter().is_sorted_by(|a, b| a.partial_cmp(b)));
32013201
/// ```
32023202
///
32033203
/// [`is_sorted`]: trait.Iterator.html#method.is_sorted

src/libcore/num/f32.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ impl f32 {
470470
///
471471
/// let value = -128.9_f32;
472472
/// let rounded = unsafe { value.to_int_unchecked::<i8>() };
473-
/// assert_eq!(rounded, std::i8::MIN);
473+
/// assert_eq!(rounded, i8::MIN);
474474
/// ```
475475
///
476476
/// # Safety

src/libcore/num/f64.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ impl f64 {
484484
///
485485
/// let value = -128.9_f32;
486486
/// let rounded = unsafe { value.to_int_unchecked::<i8>() };
487-
/// assert_eq!(rounded, std::i8::MIN);
487+
/// assert_eq!(rounded, i8::MIN);
488488
/// ```
489489
///
490490
/// # Safety

src/libcore/num/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ NonZeroI8 NonZeroI16 NonZeroI32 NonZeroI64 NonZeroI128 NonZeroIsize }
174174
/// let zero = Wrapping(0u32);
175175
/// let one = Wrapping(1u32);
176176
///
177-
/// assert_eq!(std::u32::MAX, (zero - one).0);
177+
/// assert_eq!(u32::MAX, (zero - one).0);
178178
/// ```
179179
#[stable(feature = "rust1", since = "1.0.0")]
180180
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Default, Hash)]

src/libcore/ops/range.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,9 @@ impl<Idx: PartialOrd<Idx>> Range<Idx> {
139139
/// ```
140140
/// #![feature(range_is_empty)]
141141
///
142-
/// use std::f32::NAN;
143142
/// assert!(!(3.0..5.0).is_empty());
144-
/// assert!( (3.0..NAN).is_empty());
145-
/// assert!( (NAN..5.0).is_empty());
143+
/// assert!( (3.0..f32::NAN).is_empty());
144+
/// assert!( (f32::NAN..5.0).is_empty());
146145
/// ```
147146
#[unstable(feature = "range_is_empty", reason = "recently added", issue = "48111")]
148147
pub fn is_empty(&self) -> bool {
@@ -496,10 +495,9 @@ impl<Idx: PartialOrd<Idx>> RangeInclusive<Idx> {
496495
/// ```
497496
/// #![feature(range_is_empty)]
498497
///
499-
/// use std::f32::NAN;
500498
/// assert!(!(3.0..=5.0).is_empty());
501-
/// assert!( (3.0..=NAN).is_empty());
502-
/// assert!( (NAN..=5.0).is_empty());
499+
/// assert!( (3.0..=f32::NAN).is_empty());
500+
/// assert!( (f32::NAN..=5.0).is_empty());
503501
/// ```
504502
///
505503
/// This method returns `true` after iteration has finished:

src/libcore/ptr/const_ptr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -659,8 +659,8 @@ impl<T: ?Sized> *const T {
659659
/// `align`.
660660
///
661661
/// If it is not possible to align the pointer, the implementation returns
662-
/// `usize::max_value()`. It is permissible for the implementation to *always*
663-
/// return `usize::max_value()`. Only your algorithm's performance can depend
662+
/// `usize::MAX`. It is permissible for the implementation to *always*
663+
/// return `usize::MAX`. Only your algorithm's performance can depend
664664
/// on getting a usable offset here, not its correctness.
665665
///
666666
/// The offset is expressed in number of `T` elements, and not bytes. The value returned can be

src/libcore/ptr/mut_ptr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -847,8 +847,8 @@ impl<T: ?Sized> *mut T {
847847
/// `align`.
848848
///
849849
/// If it is not possible to align the pointer, the implementation returns
850-
/// `usize::max_value()`. It is permissible for the implementation to *always*
851-
/// return `usize::max_value()`. Only your algorithm's performance can depend
850+
/// `usize::MAX`. It is permissible for the implementation to *always*
851+
/// return `usize::MAX`. Only your algorithm's performance can depend
852852
/// on getting a usable offset here, not its correctness.
853853
///
854854
/// The offset is expressed in number of `T` elements, and not bytes. The value returned can be

src/libcore/slice/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2588,7 +2588,7 @@ impl<T> [T] {
25882588
/// assert!(![1, 3, 2, 4].is_sorted());
25892589
/// assert!([0].is_sorted());
25902590
/// assert!(empty.is_sorted());
2591-
/// assert!(![0.0, 1.0, std::f32::NAN].is_sorted());
2591+
/// assert!(![0.0, 1.0, f32::NAN].is_sorted());
25922592
/// ```
25932593
#[inline]
25942594
#[unstable(feature = "is_sorted", reason = "new API", issue = "53485")]

src/libcore/time.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ impl Duration {
389389
/// use std::time::Duration;
390390
///
391391
/// assert_eq!(Duration::new(0, 0).checked_add(Duration::new(0, 1)), Some(Duration::new(0, 1)));
392-
/// assert_eq!(Duration::new(1, 0).checked_add(Duration::new(std::u64::MAX, 0)), None);
392+
/// assert_eq!(Duration::new(1, 0).checked_add(Duration::new(u64::MAX, 0)), None);
393393
/// ```
394394
#[stable(feature = "duration_checked_ops", since = "1.16.0")]
395395
#[inline]
@@ -460,7 +460,7 @@ impl Duration {
460460
/// use std::time::Duration;
461461
///
462462
/// assert_eq!(Duration::new(0, 500_000_001).checked_mul(2), Some(Duration::new(1, 2)));
463-
/// assert_eq!(Duration::new(std::u64::MAX - 1, 0).checked_mul(2), None);
463+
/// assert_eq!(Duration::new(u64::MAX - 1, 0).checked_mul(2), None);
464464
/// ```
465465
#[stable(feature = "duration_checked_ops", since = "1.16.0")]
466466
#[inline]

src/librustc_ast_lowering/item.rs

+2
Original file line numberDiff line numberDiff line change
@@ -972,8 +972,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
972972
f: impl FnOnce(&mut Self) -> (&'hir [hir::Param<'hir>], hir::Expr<'hir>),
973973
) -> hir::BodyId {
974974
let prev_gen_kind = self.generator_kind.take();
975+
let task_context = self.task_context.take();
975976
let (parameters, result) = f(self);
976977
let body_id = self.record_body(parameters, result);
978+
self.task_context = task_context;
977979
self.generator_kind = prev_gen_kind;
978980
body_id
979981
}

src/librustc_codegen_llvm/consts.rs

+13-16
Original file line numberDiff line numberDiff line change
@@ -436,24 +436,21 @@ impl StaticMethods for CodegenCx<'ll, 'tcx> {
436436
//
437437
// We could remove this hack whenever we decide to drop macOS 10.10 support.
438438
if self.tcx.sess.target.target.options.is_like_osx {
439-
assert_eq!(alloc.relocations().len(), 0);
440-
441-
let is_zeroed = {
442-
// Treats undefined bytes as if they were defined with the byte value that
443-
// happens to be currently assigned in mir. This is valid since reading
444-
// undef bytes may yield arbitrary values.
445-
//
446-
// FIXME: ignore undef bytes even with representation `!= 0`.
447-
//
448-
// The `inspect` method is okay here because we checked relocations, and
449-
// because we are doing this access to inspect the final interpreter state
450-
// (not as part of the interpreter execution).
451-
alloc
439+
// The `inspect` method is okay here because we checked relocations, and
440+
// because we are doing this access to inspect the final interpreter state
441+
// (not as part of the interpreter execution).
442+
//
443+
// FIXME: This check requires that the (arbitrary) value of undefined bytes
444+
// happens to be zero. Instead, we should only check the value of defined bytes
445+
// and set all undefined bytes to zero if this allocation is headed for the
446+
// BSS.
447+
let all_bytes_are_zero = alloc.relocations().is_empty()
448+
&& alloc
452449
.inspect_with_undef_and_ptr_outside_interpreter(0..alloc.len())
453450
.iter()
454-
.all(|b| *b == 0)
455-
};
456-
let sect_name = if is_zeroed {
451+
.all(|&byte| byte == 0);
452+
453+
let sect_name = if all_bytes_are_zero {
457454
CStr::from_bytes_with_nul_unchecked(b"__DATA,__thread_bss\0")
458455
} else {
459456
CStr::from_bytes_with_nul_unchecked(b"__DATA,__thread_data\0")

src/librustc_error_codes/error_codes/E0502.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
This error indicates that you are trying to borrow a variable as mutable when it
2-
has already been borrowed as immutable.
1+
A variable already borrowed as immutable was borrowed as mutable.
32

43
Erroneous code example:
54

src/librustc_infer/traits/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ mod engine;
66
pub mod error_reporting;
77
mod project;
88
mod structural_impls;
9-
mod util;
9+
pub mod util;
1010

1111
use rustc_hir as hir;
1212
use rustc_middle::ty::error::{ExpectedFound, TypeError};

src/librustc_infer/traits/util.rs

+78-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ use smallvec::smallvec;
22

33
use rustc_data_structures::fx::FxHashSet;
44
use rustc_middle::ty::outlives::Component;
5-
use rustc_middle::ty::{self, ToPolyTraitRef, TyCtxt};
5+
use rustc_middle::ty::{self, ToPolyTraitRef, ToPredicate, TyCtxt, WithConstness};
66

7-
fn anonymize_predicate<'tcx>(tcx: TyCtxt<'tcx>, pred: &ty::Predicate<'tcx>) -> ty::Predicate<'tcx> {
7+
pub fn anonymize_predicate<'tcx>(
8+
tcx: TyCtxt<'tcx>,
9+
pred: &ty::Predicate<'tcx>,
10+
) -> ty::Predicate<'tcx> {
811
match *pred {
912
ty::Predicate::Trait(ref data, constness) => {
1013
ty::Predicate::Trait(tcx.anonymize_late_bound_regions(data), constness)
@@ -88,6 +91,21 @@ pub struct Elaborator<'tcx> {
8891
visited: PredicateSet<'tcx>,
8992
}
9093

94+
pub fn elaborate_trait_ref<'tcx>(
95+
tcx: TyCtxt<'tcx>,
96+
trait_ref: ty::PolyTraitRef<'tcx>,
97+
) -> Elaborator<'tcx> {
98+
elaborate_predicates(tcx, vec![trait_ref.without_const().to_predicate()])
99+
}
100+
101+
pub fn elaborate_trait_refs<'tcx>(
102+
tcx: TyCtxt<'tcx>,
103+
trait_refs: impl Iterator<Item = ty::PolyTraitRef<'tcx>>,
104+
) -> Elaborator<'tcx> {
105+
let predicates = trait_refs.map(|trait_ref| trait_ref.without_const().to_predicate()).collect();
106+
elaborate_predicates(tcx, predicates)
107+
}
108+
91109
pub fn elaborate_predicates<'tcx>(
92110
tcx: TyCtxt<'tcx>,
93111
mut predicates: Vec<ty::Predicate<'tcx>>,
@@ -98,6 +116,10 @@ pub fn elaborate_predicates<'tcx>(
98116
}
99117

100118
impl Elaborator<'tcx> {
119+
pub fn filter_to_traits(self) -> FilterToTraits<Self> {
120+
FilterToTraits::new(self)
121+
}
122+
101123
fn elaborate(&mut self, predicate: &ty::Predicate<'tcx>) {
102124
let tcx = self.visited.tcx;
103125
match *predicate {
@@ -223,3 +245,57 @@ impl Iterator for Elaborator<'tcx> {
223245
}
224246
}
225247
}
248+
249+
///////////////////////////////////////////////////////////////////////////
250+
// Supertrait iterator
251+
///////////////////////////////////////////////////////////////////////////
252+
253+
pub type Supertraits<'tcx> = FilterToTraits<Elaborator<'tcx>>;
254+
255+
pub fn supertraits<'tcx>(
256+
tcx: TyCtxt<'tcx>,
257+
trait_ref: ty::PolyTraitRef<'tcx>,
258+
) -> Supertraits<'tcx> {
259+
elaborate_trait_ref(tcx, trait_ref).filter_to_traits()
260+
}
261+
262+
pub fn transitive_bounds<'tcx>(
263+
tcx: TyCtxt<'tcx>,
264+
bounds: impl Iterator<Item = ty::PolyTraitRef<'tcx>>,
265+
) -> Supertraits<'tcx> {
266+
elaborate_trait_refs(tcx, bounds).filter_to_traits()
267+
}
268+
269+
///////////////////////////////////////////////////////////////////////////
270+
// Other
271+
///////////////////////////////////////////////////////////////////////////
272+
273+
/// A filter around an iterator of predicates that makes it yield up
274+
/// just trait references.
275+
pub struct FilterToTraits<I> {
276+
base_iterator: I,
277+
}
278+
279+
impl<I> FilterToTraits<I> {
280+
fn new(base: I) -> FilterToTraits<I> {
281+
FilterToTraits { base_iterator: base }
282+
}
283+
}
284+
285+
impl<'tcx, I: Iterator<Item = ty::Predicate<'tcx>>> Iterator for FilterToTraits<I> {
286+
type Item = ty::PolyTraitRef<'tcx>;
287+
288+
fn next(&mut self) -> Option<ty::PolyTraitRef<'tcx>> {
289+
while let Some(pred) = self.base_iterator.next() {
290+
if let ty::Predicate::Trait(data, _) = pred {
291+
return Some(data.to_poly_trait_ref());
292+
}
293+
}
294+
None
295+
}
296+
297+
fn size_hint(&self) -> (usize, Option<usize>) {
298+
let (_, upper) = self.base_iterator.size_hint();
299+
(0, upper)
300+
}
301+
}

0 commit comments

Comments
 (0)