Skip to content

Commit ca3766e

Browse files
committed
Auto merge of #64456 - Centril:rollup-ytqdwaq, r=Centril
Rollup of 17 pull requests Successful merges: - #63846 (Added table containing the system calls used by Instant and SystemTime.) - #64116 (Fix minor typo in docs.) - #64203 (A few cosmetic improvements to code & comments in liballoc and libcore) - #64302 (Shrink `ObligationCauseCode`) - #64372 (use randSecure and randABytes) - #64374 (Box `DiagnosticBuilder`.) - #64375 (Fast path for vec.clear/truncate ) - #64378 (Fix inconsistent link formatting.) - #64384 (Trim rustc-workspace-hack) - #64393 ( declare EnvKey before use to fix build error) - #64420 (Inline `mark_neighbours_as_waiting_from`.) - #64422 (Remove raw string literal quotes from error index descriptions) - #64423 (Add self to .mailmap) - #64425 (typo fix) - #64431 (fn ptr is structural match) - #64435 (codegen: use "_N" (like for other locals) instead of "argN", for argument names.) - #64439 (fix #64430, confusing `owned_box` error message in no_std build) Failed merges: r? @ghost
2 parents 4576668 + 1c7959b commit ca3766e

Some content is hidden

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

63 files changed

+663
-382
lines changed

.mailmap

+1
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ Neil Pankey <[email protected]> <[email protected]>
184184
Nick Platt <[email protected]>
185185
Nicole Mazzuca <[email protected]>
186186
187+
187188
188189
189190

Cargo.lock

-4
Original file line numberDiff line numberDiff line change
@@ -3256,13 +3256,9 @@ version = "1.0.0"
32563256
dependencies = [
32573257
"byteorder",
32583258
"crossbeam-utils 0.6.5",
3259-
"parking_lot 0.7.1",
3260-
"rand 0.6.1",
3261-
"scopeguard 0.3.3",
32623259
"serde",
32633260
"serde_json",
32643261
"smallvec",
3265-
"syn 0.15.35",
32663262
"winapi 0.3.6",
32673263
]
32683264

src/liballoc/collections/linked_list/tests.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ fn test_append() {
102102
assert_eq!(m.pop_front(), Some(elt))
103103
}
104104
assert_eq!(n.len(), 0);
105-
// let's make sure it's working properly, since we
106-
// did some direct changes to private members
105+
// Let's make sure it's working properly, since we
106+
// did some direct changes to private members.
107107
n.push_back(3);
108108
assert_eq!(n.len(), 1);
109109
assert_eq!(n.pop_front(), Some(3));

src/liballoc/raw_vec.rs

+74-76
Large diffs are not rendered by default.

src/liballoc/raw_vec/tests.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ fn allocator_param() {
55
use crate::alloc::AllocErr;
66

77
// Writing a test of integration between third-party
8-
// allocators and RawVec is a little tricky because the RawVec
8+
// allocators and `RawVec` is a little tricky because the `RawVec`
99
// API does not expose fallible allocation methods, so we
1010
// cannot check what happens when allocator is exhausted
1111
// (beyond detecting a panic).
1212
//
13-
// Instead, this just checks that the RawVec methods do at
13+
// Instead, this just checks that the `RawVec` methods do at
1414
// least go through the Allocator API when it reserves
1515
// storage.
1616

@@ -44,7 +44,7 @@ fn allocator_param() {
4444
fn reserve_does_not_overallocate() {
4545
{
4646
let mut v: RawVec<u32> = RawVec::new();
47-
// First `reserve` allocates like `reserve_exact`
47+
// First, `reserve` allocates like `reserve_exact`.
4848
v.reserve(0, 9);
4949
assert_eq!(9, v.capacity());
5050
}

src/liballoc/rc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ impl<T: ?Sized> Rc<T> {
567567
/// let x = Rc::from_raw(x_ptr);
568568
/// assert_eq!(&*x, "hello");
569569
///
570-
/// // Further calls to `Rc::from_raw(x_ptr)` would be memory unsafe.
570+
/// // Further calls to `Rc::from_raw(x_ptr)` would be memory-unsafe.
571571
/// }
572572
///
573573
/// // The memory was freed when `x` went out of scope above, so `x_ptr` is now dangling!

src/liballoc/sync.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ impl<T: ?Sized> Arc<T> {
547547
/// let x = Arc::from_raw(x_ptr);
548548
/// assert_eq!(&*x, "hello");
549549
///
550-
/// // Further calls to `Arc::from_raw(x_ptr)` would be memory unsafe.
550+
/// // Further calls to `Arc::from_raw(x_ptr)` would be memory-unsafe.
551551
/// }
552552
///
553553
/// // The memory was freed when `x` went out of scope above, so `x_ptr` is now dangling!

src/liballoc/vec.rs

+17-13
Original file line numberDiff line numberDiff line change
@@ -685,21 +685,25 @@ impl<T> Vec<T> {
685685
/// [`drain`]: #method.drain
686686
#[stable(feature = "rust1", since = "1.0.0")]
687687
pub fn truncate(&mut self, len: usize) {
688-
let current_len = self.len;
689-
unsafe {
690-
let mut ptr = self.as_mut_ptr().add(self.len);
691-
// Set the final length at the end, keeping in mind that
692-
// dropping an element might panic. Works around a missed
693-
// optimization, as seen in the following issue:
694-
// https://github.com/rust-lang/rust/issues/51802
695-
let mut local_len = SetLenOnDrop::new(&mut self.len);
688+
if mem::needs_drop::<T>() {
689+
let current_len = self.len;
690+
unsafe {
691+
let mut ptr = self.as_mut_ptr().add(self.len);
692+
// Set the final length at the end, keeping in mind that
693+
// dropping an element might panic. Works around a missed
694+
// optimization, as seen in the following issue:
695+
// https://github.com/rust-lang/rust/issues/51802
696+
let mut local_len = SetLenOnDrop::new(&mut self.len);
696697

697-
// drop any extra elements
698-
for _ in len..current_len {
699-
local_len.decrement_len(1);
700-
ptr = ptr.offset(-1);
701-
ptr::drop_in_place(ptr);
698+
// drop any extra elements
699+
for _ in len..current_len {
700+
local_len.decrement_len(1);
701+
ptr = ptr.offset(-1);
702+
ptr::drop_in_place(ptr);
703+
}
702704
}
705+
} else if len <= self.len {
706+
self.len = len;
703707
}
704708
}
705709

src/libcore/any.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,13 @@ impl dyn Any {
153153
#[stable(feature = "rust1", since = "1.0.0")]
154154
#[inline]
155155
pub fn is<T: Any>(&self) -> bool {
156-
// Get TypeId of the type this function is instantiated with
156+
// Get `TypeId` of the type this function is instantiated with.
157157
let t = TypeId::of::<T>();
158158

159-
// Get TypeId of the type in the trait object
159+
// Get `TypeId` of the type in the trait object.
160160
let concrete = self.type_id();
161161

162-
// Compare both TypeIds on equality
162+
// Compare both `TypeId`s on equality.
163163
t == concrete
164164
}
165165

src/libcore/marker.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -602,10 +602,10 @@ unsafe impl<T: ?Sized> Freeze for *mut T {}
602602
unsafe impl<T: ?Sized> Freeze for &T {}
603603
unsafe impl<T: ?Sized> Freeze for &mut T {}
604604

605-
/// Types which can be safely moved after being pinned.
605+
/// Types that can be safely moved after being pinned.
606606
///
607607
/// Since Rust itself has no notion of immovable types, and considers moves
608-
/// (e.g. through assignment or [`mem::replace`]) to always be safe,
608+
/// (e.g., through assignment or [`mem::replace`]) to always be safe,
609609
/// this trait cannot prevent types from moving by itself.
610610
///
611611
/// Instead it is used to prevent moves through the type system,

src/libcore/ptr/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1042,7 +1042,7 @@ impl<T: ?Sized> *const T {
10421042
(self as *const u8) == null()
10431043
}
10441044

1045-
/// Cast to a pointer to a different type
1045+
/// Casts to a pointer of another type.
10461046
#[stable(feature = "ptr_cast", since = "1.38.0")]
10471047
#[inline]
10481048
pub const fn cast<U>(self) -> *const U {
@@ -1726,7 +1726,7 @@ impl<T: ?Sized> *mut T {
17261726
(self as *mut u8) == null_mut()
17271727
}
17281728

1729-
/// Cast to a pointer to a different type
1729+
/// Casts to a pointer of another type.
17301730
#[stable(feature = "ptr_cast", since = "1.38.0")]
17311731
#[inline]
17321732
pub const fn cast<U>(self) -> *mut U {

src/libcore/ptr/non_null.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ impl<T: ?Sized> NonNull<T> {
125125
&mut *self.as_ptr()
126126
}
127127

128-
/// Cast to a pointer of another type
128+
/// Casts to a pointer of another type.
129129
#[stable(feature = "nonnull_cast", since = "1.27.0")]
130130
#[inline]
131131
pub const fn cast<U>(self) -> NonNull<U> {

src/librustc/hir/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ pub enum ParamName {
190190
Fresh(usize),
191191

192192
/// Indicates an illegal name was given and an error has been
193-
/// repored (so we should squelch other derived errors). Occurs
193+
/// reported (so we should squelch other derived errors). Occurs
194194
/// when, e.g., `'_` is used in the wrong place.
195195
Error,
196196
}

src/librustc/infer/error_reporting/mod.rs

+15-12
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ use crate::hir::def_id::DefId;
5555
use crate::hir::Node;
5656
use crate::infer::opaque_types;
5757
use crate::middle::region;
58-
use crate::traits::{ObligationCause, ObligationCauseCode};
58+
use crate::traits::{IfExpressionCause, MatchExpressionArmCause, ObligationCause};
59+
use crate::traits::{ObligationCauseCode};
5960
use crate::ty::error::TypeError;
6061
use crate::ty::{self, subst::{Subst, SubstsRef}, Region, Ty, TyCtxt, TypeFoldable};
6162
use errors::{Applicability, DiagnosticBuilder, DiagnosticStyledString};
@@ -624,13 +625,13 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
624625
}
625626
}
626627
}
627-
ObligationCauseCode::MatchExpressionArm {
628+
ObligationCauseCode::MatchExpressionArm(box MatchExpressionArmCause {
628629
source,
629630
ref prior_arms,
630631
last_ty,
631632
discrim_hir_id,
632633
..
633-
} => match source {
634+
}) => match source {
634635
hir::MatchSource::IfLetDesugar { .. } => {
635636
let msg = "`if let` arms have incompatible types";
636637
err.span_label(cause.span, msg);
@@ -681,7 +682,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
681682
}
682683
}
683684
},
684-
ObligationCauseCode::IfExpression { then, outer, semicolon } => {
685+
ObligationCauseCode::IfExpression(box IfExpressionCause { then, outer, semicolon }) => {
685686
err.span_label(then, "expected because of this");
686687
outer.map(|sp| err.span_label(sp, "if and else have incompatible types"));
687688
if let Some(sp) = semicolon {
@@ -1622,13 +1623,15 @@ impl<'tcx> ObligationCause<'tcx> {
16221623
use crate::traits::ObligationCauseCode::*;
16231624
match self.code {
16241625
CompareImplMethodObligation { .. } => Error0308("method not compatible with trait"),
1625-
MatchExpressionArm { source, .. } => Error0308(match source {
1626-
hir::MatchSource::IfLetDesugar { .. } => "`if let` arms have incompatible types",
1627-
hir::MatchSource::TryDesugar => {
1628-
"try expression alternatives have incompatible types"
1629-
}
1630-
_ => "match arms have incompatible types",
1631-
}),
1626+
MatchExpressionArm(box MatchExpressionArmCause { source, .. }) =>
1627+
Error0308(match source {
1628+
hir::MatchSource::IfLetDesugar { .. } =>
1629+
"`if let` arms have incompatible types",
1630+
hir::MatchSource::TryDesugar => {
1631+
"try expression alternatives have incompatible types"
1632+
}
1633+
_ => "match arms have incompatible types",
1634+
}),
16321635
IfExpression { .. } => Error0308("if and else have incompatible types"),
16331636
IfExpressionWithNoElse => Error0317("if may be missing an else clause"),
16341637
MainFunctionType => Error0580("main function has wrong type"),
@@ -1656,7 +1659,7 @@ impl<'tcx> ObligationCause<'tcx> {
16561659
match self.code {
16571660
CompareImplMethodObligation { .. } => "method type is compatible with trait",
16581661
ExprAssignable => "expression is assignable",
1659-
MatchExpressionArm { source, .. } => match source {
1662+
MatchExpressionArm(box MatchExpressionArmCause { source, .. }) => match source {
16601663
hir::MatchSource::IfLetDesugar { .. } => "`if let` arms have compatible types",
16611664
_ => "match arms have compatible types",
16621665
},

src/librustc/mir/interpret/value.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ pub struct RawConst<'tcx> {
1717
pub ty: Ty<'tcx>,
1818
}
1919

20-
/// Represents a constant value in Rust. `Scalar` and `ScalarPair` are optimizations that
21-
/// match the `LocalState` optimizations for easy conversions between `Value` and `ConstValue`.
20+
/// Represents a constant value in Rust. `Scalar` and `Slice` are optimizations for
21+
/// array length computations, enum discriminants and the pattern matching logic.
2222
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord,
2323
RustcEncodable, RustcDecodable, Hash, HashStable)]
2424
pub enum ConstValue<'tcx> {

src/librustc/traits/fulfill.rs

+4
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ pub struct PendingPredicateObligation<'tcx> {
6868
pub stalled_on: Vec<Ty<'tcx>>,
6969
}
7070

71+
// `PendingPredicateObligation` is used a lot. Make sure it doesn't unintentionally get bigger.
72+
#[cfg(target_arch = "x86_64")]
73+
static_assert_size!(PendingPredicateObligation<'_>, 136);
74+
7175
impl<'a, 'tcx> FulfillmentContext<'tcx> {
7276
/// Creates a new fulfillment context.
7377
pub fn new() -> FulfillmentContext<'tcx> {

src/librustc/traits/mod.rs

+28-13
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ pub struct Obligation<'tcx, T> {
123123
pub type PredicateObligation<'tcx> = Obligation<'tcx, ty::Predicate<'tcx>>;
124124
pub type TraitObligation<'tcx> = Obligation<'tcx, ty::PolyTraitPredicate<'tcx>>;
125125

126+
// `PredicateObligation` is used a lot. Make sure it doesn't unintentionally get bigger.
127+
#[cfg(target_arch = "x86_64")]
128+
static_assert_size!(PredicateObligation<'_>, 112);
129+
126130
/// The reason why we incurred this obligation; used for error reporting.
127131
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
128132
pub struct ObligationCause<'tcx> {
@@ -147,7 +151,8 @@ impl<'tcx> ObligationCause<'tcx> {
147151
ObligationCauseCode::StartFunctionType => {
148152
tcx.sess.source_map().def_span(self.span)
149153
}
150-
ObligationCauseCode::MatchExpressionArm { arm_span, .. } => arm_span,
154+
ObligationCauseCode::MatchExpressionArm(
155+
box MatchExpressionArmCause { arm_span, .. }) => arm_span,
151156
_ => self.span,
152157
}
153158
}
@@ -223,23 +228,13 @@ pub enum ObligationCauseCode<'tcx> {
223228
ExprAssignable,
224229

225230
/// Computing common supertype in the arms of a match expression
226-
MatchExpressionArm {
227-
arm_span: Span,
228-
source: hir::MatchSource,
229-
prior_arms: Vec<Span>,
230-
last_ty: Ty<'tcx>,
231-
discrim_hir_id: hir::HirId,
232-
},
231+
MatchExpressionArm(Box<MatchExpressionArmCause<'tcx>>),
233232

234233
/// Computing common supertype in the pattern guard for the arms of a match expression
235234
MatchExpressionArmPattern { span: Span, ty: Ty<'tcx> },
236235

237236
/// Computing common supertype in an if expression
238-
IfExpression {
239-
then: Span,
240-
outer: Option<Span>,
241-
semicolon: Option<Span>,
242-
},
237+
IfExpression(Box<IfExpressionCause>),
243238

244239
/// Computing common supertype of an if expression with no else counter-part
245240
IfExpressionWithNoElse,
@@ -269,6 +264,26 @@ pub enum ObligationCauseCode<'tcx> {
269264
TrivialBound,
270265
}
271266

267+
// `ObligationCauseCode` is used a lot. Make sure it doesn't unintentionally get bigger.
268+
#[cfg(target_arch = "x86_64")]
269+
static_assert_size!(ObligationCauseCode<'_>, 32);
270+
271+
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
272+
pub struct MatchExpressionArmCause<'tcx> {
273+
pub arm_span: Span,
274+
pub source: hir::MatchSource,
275+
pub prior_arms: Vec<Span>,
276+
pub last_ty: Ty<'tcx>,
277+
pub discrim_hir_id: hir::HirId,
278+
}
279+
280+
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
281+
pub struct IfExpressionCause {
282+
pub then: Span,
283+
pub outer: Option<Span>,
284+
pub semicolon: Option<Span>,
285+
}
286+
272287
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
273288
pub struct DerivedObligationCause<'tcx> {
274289
/// The trait reference of the parent obligation that led to the

src/librustc/traits/structural_impls.rs

+11-9
Original file line numberDiff line numberDiff line change
@@ -508,31 +508,33 @@ impl<'a, 'tcx> Lift<'tcx> for traits::ObligationCauseCode<'a> {
508508
trait_item_def_id,
509509
}),
510510
super::ExprAssignable => Some(super::ExprAssignable),
511-
super::MatchExpressionArm {
511+
super::MatchExpressionArm(box super::MatchExpressionArmCause {
512512
arm_span,
513513
source,
514514
ref prior_arms,
515515
last_ty,
516516
discrim_hir_id,
517-
} => {
517+
}) => {
518518
tcx.lift(&last_ty).map(|last_ty| {
519-
super::MatchExpressionArm {
519+
super::MatchExpressionArm(box super::MatchExpressionArmCause {
520520
arm_span,
521521
source,
522522
prior_arms: prior_arms.clone(),
523523
last_ty,
524524
discrim_hir_id,
525-
}
525+
})
526526
})
527527
}
528528
super::MatchExpressionArmPattern { span, ty } => {
529529
tcx.lift(&ty).map(|ty| super::MatchExpressionArmPattern { span, ty })
530530
}
531-
super::IfExpression { then, outer, semicolon } => Some(super::IfExpression {
532-
then,
533-
outer,
534-
semicolon,
535-
}),
531+
super::IfExpression(box super::IfExpressionCause { then, outer, semicolon }) => {
532+
Some(super::IfExpression(box super::IfExpressionCause {
533+
then,
534+
outer,
535+
semicolon,
536+
}))
537+
}
536538
super::IfExpressionWithNoElse => Some(super::IfExpressionWithNoElse),
537539
super::MainFunctionType => Some(super::MainFunctionType),
538540
super::StartFunctionType => Some(super::StartFunctionType),

src/librustc/ty/context.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2396,9 +2396,9 @@ impl<'tcx> TyCtxt<'tcx> {
23962396
}
23972397

23982398
#[inline]
2399-
pub fn mk_lang_item(self, ty: Ty<'tcx>, item: lang_items::LangItem) -> Ty<'tcx> {
2400-
let def_id = self.require_lang_item(item, None);
2401-
self.mk_generic_adt(def_id, ty)
2399+
pub fn mk_lang_item(self, ty: Ty<'tcx>, item: lang_items::LangItem) -> Option<Ty<'tcx>> {
2400+
let def_id = self.lang_items().require(item).ok()?;
2401+
Some(self.mk_generic_adt(def_id, ty))
24022402
}
24032403

24042404
#[inline]

0 commit comments

Comments
 (0)