Skip to content

Commit 41e74a2

Browse files
committed
Auto merge of #42276 - Mark-Simulacrum:rollup, r=Mark-Simulacrum
Rollup of 6 pull requests - Successful merges: #42207, #42217, #42249, #42251, #42260, #42266 - Failed merges:
2 parents 5d2512e + 1128fab commit 41e74a2

Some content is hidden

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

44 files changed

+155
-1235
lines changed

src/libcollections/binary_heap.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,11 @@
4343
//! // instead of a max-heap.
4444
//! impl Ord for State {
4545
//! fn cmp(&self, other: &State) -> Ordering {
46-
//! // Notice that the we flip the ordering here
46+
//! // Notice that the we flip the ordering on costs.
47+
//! // In case of a tie we compare positions - this step is necessary
48+
//! // to make implementations of `PartialEq` and `Ord` consistent.
4749
//! other.cost.cmp(&self.cost)
50+
//! .then_with(|| self.position.cmp(&other.position))
4851
//! }
4952
//! }
5053
//!

src/libcore/cmp.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ use self::Ordering::*;
6767
/// the rule that `eq` is a strict inverse of `ne`; that is, `!(a == b)` if and
6868
/// only if `a != b`.
6969
///
70+
/// Implementations of `PartialEq`, `PartialOrd`, and `Ord` *must* agree with
71+
/// each other. It's easy to accidentally make them disagree by deriving some
72+
/// of the traits and manually implementing others.
73+
///
7074
/// An example implementation for a domain in which two books are considered
7175
/// the same book if their ISBN matches, even if the formats differ:
7276
///
@@ -386,6 +390,10 @@ impl<T: Ord> Ord for Reverse<T> {
386390
/// Then you must define an implementation for `cmp()`. You may find it useful to use
387391
/// `cmp()` on your type's fields.
388392
///
393+
/// Implementations of `PartialEq`, `PartialOrd`, and `Ord` *must* agree with each other. It's
394+
/// easy to accidentally make them disagree by deriving some of the traits and manually
395+
/// implementing others.
396+
///
389397
/// Here's an example where you want to sort people by height only, disregarding `id`
390398
/// and `name`:
391399
///
@@ -474,15 +482,19 @@ impl PartialOrd for Ordering {
474482
///
475483
/// ## How can I implement `PartialOrd`?
476484
///
477-
/// PartialOrd only requires implementation of the `partial_cmp` method, with the others generated
478-
/// from default implementations.
485+
/// `PartialOrd` only requires implementation of the `partial_cmp` method, with the others
486+
/// generated from default implementations.
479487
///
480488
/// However it remains possible to implement the others separately for types which do not have a
481489
/// total order. For example, for floating point numbers, `NaN < 0 == false` and `NaN >= 0 ==
482490
/// false` (cf. IEEE 754-2008 section 5.11).
483491
///
484492
/// `PartialOrd` requires your type to be `PartialEq`.
485493
///
494+
/// Implementations of `PartialEq`, `PartialOrd`, and `Ord` *must* agree with each other. It's
495+
/// easy to accidentally make them disagree by deriving some of the traits and manually
496+
/// implementing others.
497+
///
486498
/// If your type is `Ord`, you can implement `partial_cmp()` by using `cmp()`:
487499
///
488500
/// ```

src/librustc/ty/context.rs

+1-29
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ use ty::layout::{Layout, TargetDataLayout};
4040
use ty::inhabitedness::DefIdForest;
4141
use ty::maps;
4242
use ty::steal::Steal;
43-
use util::nodemap::{NodeMap, NodeSet, DefIdMap, DefIdSet};
43+
use util::nodemap::{NodeMap, NodeSet, DefIdSet};
4444
use util::nodemap::{FxHashMap, FxHashSet};
4545
use rustc_data_structures::accumulate_vec::AccumulateVec;
4646

@@ -499,33 +499,6 @@ pub struct GlobalCtxt<'tcx> {
499499
/// Maps Expr NodeId's to `true` iff `&expr` can have 'static lifetime.
500500
pub rvalue_promotable_to_static: RefCell<NodeMap<bool>>,
501501

502-
/// Maps Fn items to a collection of fragment infos.
503-
///
504-
/// The main goal is to identify data (each of which may be moved
505-
/// or assigned) whose subparts are not moved nor assigned
506-
/// (i.e. their state is *unfragmented*) and corresponding ast
507-
/// nodes where the path to that data is moved or assigned.
508-
///
509-
/// In the long term, unfragmented values will have their
510-
/// destructor entirely driven by a single stack-local drop-flag,
511-
/// and their parents, the collections of the unfragmented values
512-
/// (or more simply, "fragmented values"), are mapped to the
513-
/// corresponding collections of stack-local drop-flags.
514-
///
515-
/// (However, in the short term that is not the case; e.g. some
516-
/// unfragmented paths still need to be zeroed, namely when they
517-
/// reference parent data from an outer scope that was not
518-
/// entirely moved, and therefore that needs to be zeroed so that
519-
/// we do not get double-drop when we hit the end of the parent
520-
/// scope.)
521-
///
522-
/// Also: currently the table solely holds keys for node-ids of
523-
/// unfragmented values (see `FragmentInfo` enum definition), but
524-
/// longer-term we will need to also store mappings from
525-
/// fragmented data to the set of unfragmented pieces that
526-
/// constitute it.
527-
pub fragment_infos: RefCell<DefIdMap<Vec<ty::FragmentInfo>>>,
528-
529502
/// The definite name of the current crate after taking into account
530503
/// attributes, commandline parameters, etc.
531504
pub crate_name: Symbol,
@@ -730,7 +703,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
730703
selection_cache: traits::SelectionCache::new(),
731704
evaluation_cache: traits::EvaluationCache::new(),
732705
rvalue_promotable_to_static: RefCell::new(NodeMap()),
733-
fragment_infos: RefCell::new(DefIdMap()),
734706
crate_name: Symbol::intern(crate_name),
735707
data_layout: data_layout,
736708
layout_cache: RefCell::new(FxHashMap()),

src/librustc/ty/mod.rs

-11
Original file line numberDiff line numberDiff line change
@@ -444,17 +444,6 @@ pub struct CReaderCacheKey {
444444
pub pos: usize,
445445
}
446446

447-
/// Describes the fragment-state associated with a NodeId.
448-
///
449-
/// Currently only unfragmented paths have entries in the table,
450-
/// but longer-term this enum is expected to expand to also
451-
/// include data for fragmented paths.
452-
#[derive(Copy, Clone, Debug)]
453-
pub enum FragmentInfo {
454-
Moved { var: NodeId, move_expr: NodeId },
455-
Assigned { var: NodeId, assign_expr: NodeId, assignee_id: NodeId },
456-
}
457-
458447
// Flags that we track on types. These flags are propagated upwards
459448
// through the type during type construction, so that we can quickly
460449
// check whether the type has various kinds of types in it without

src/librustc/ty/util.rs

+23-7
Original file line numberDiff line numberDiff line change
@@ -266,13 +266,29 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
266266
/// if not a structure at all. Corresponds to the only possible unsized
267267
/// field, and its type can be used to determine unsizing strategy.
268268
pub fn struct_tail(self, mut ty: Ty<'tcx>) -> Ty<'tcx> {
269-
while let TyAdt(def, substs) = ty.sty {
270-
if !def.is_struct() {
271-
break;
272-
}
273-
match def.struct_variant().fields.last() {
274-
Some(f) => ty = f.ty(self, substs),
275-
None => break,
269+
loop {
270+
match ty.sty {
271+
ty::TyAdt(def, substs) => {
272+
if !def.is_struct() {
273+
break;
274+
}
275+
match def.struct_variant().fields.last() {
276+
Some(f) => ty = f.ty(self, substs),
277+
None => break,
278+
}
279+
}
280+
281+
ty::TyTuple(tys, _) => {
282+
if let Some((&last_ty, _)) = tys.split_last() {
283+
ty = last_ty;
284+
} else {
285+
break;
286+
}
287+
}
288+
289+
_ => {
290+
break;
291+
}
276292
}
277293
}
278294
ty

0 commit comments

Comments
 (0)