Skip to content

Commit

Permalink
Auto merge of #55433 - kennytm:rollup, r=kennytm
Browse files Browse the repository at this point in the history
Rollup of 11 pull requests

Successful merges:

 - #55148 (Implement FromStr for PathBuf)
 - #55185 (path suggestions in Rust 2018 should point out the change in semantics)
 - #55191 (Fix sub-variant doc display)
 - #55199 (Impl items have generics)
 - #55244 (Don't rerun MIR passes when inlining)
 - #55252 (Add MaybeUninit::new)
 - #55257 (Allow extern statics with an extern type)
 - #55389 (Remove unnecessary mut in iterator.find_map documentation example, R…)
 - #55406 (Update string.rs)
 - #55412 (Fix an ICE in the min_const_fn analysis)
 - #55421 (Add ManuallyDrop::take)
  • Loading branch information
bors committed Oct 28, 2018
2 parents 4f5cfa6 + db4e77c commit d492c67
Show file tree
Hide file tree
Showing 37 changed files with 386 additions and 171 deletions.
2 changes: 1 addition & 1 deletion src/liballoc/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ impl String {
///
/// // These are all done without reallocating...
/// let cap = s.capacity();
/// for i in 0..10 {
/// for _ in 0..10 {
/// s.push('a');
/// }
///
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/iter/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1857,7 +1857,7 @@ pub trait Iterator {
/// ```
/// let a = ["lol", "NaN", "2", "5"];
///
/// let mut first_number = a.iter().find_map(|s| s.parse().ok());
/// let first_number = a.iter().find_map(|s| s.parse().ok());
///
/// assert_eq!(first_number, Some(2));
/// ```
Expand Down
1 change: 1 addition & 0 deletions src/libcore/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
#![feature(const_fn)]
#![feature(const_int_ops)]
#![feature(const_fn_union)]
#![feature(const_manually_drop_new)]
#![feature(custom_attribute)]
#![feature(doc_cfg)]
#![feature(doc_spotlight)]
Expand Down
29 changes: 29 additions & 0 deletions src/libcore/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,26 @@ impl<T> ManuallyDrop<T> {
pub fn into_inner(slot: ManuallyDrop<T>) -> T {
slot.value
}

/// Takes the contained value out.
///
/// This method is primarily intended for moving out values in drop.
/// Instead of using [`ManuallyDrop::drop`] to manually drop the value,
/// you can use this method to take the value and use it however desired.
/// `Drop` will be invoked on the returned value following normal end-of-scope rules.
///
/// If you have ownership of the container, you can use [`ManuallyDrop::into_inner`] instead.
///
/// # Safety
///
/// This function semantically moves out the contained value without preventing further usage.
/// It is up to the user of this method to ensure that this container is not used again.
#[must_use = "if you don't need the value, you can use `ManuallyDrop::drop` instead"]
#[unstable(feature = "manually_drop_take", issue = "55422")]
#[inline]
pub unsafe fn take(slot: &mut ManuallyDrop<T>) -> T {
ManuallyDrop::into_inner(ptr::read(slot))
}
}

impl<T: ?Sized> ManuallyDrop<T> {
Expand Down Expand Up @@ -1021,6 +1041,15 @@ pub union MaybeUninit<T> {
}

impl<T> MaybeUninit<T> {
/// Create a new `MaybeUninit` initialized with the given value.
///
/// Note that dropping a `MaybeUninit` will never call `T`'s drop code.
/// It is your responsibility to make sure `T` gets dropped if it got initialized.
#[unstable(feature = "maybe_uninit", issue = "53491")]
pub const fn new(val: T) -> MaybeUninit<T> {
MaybeUninit { value: ManuallyDrop::new(val) }
}

/// Create a new `MaybeUninit` in an uninitialized state.
///
/// Note that dropping a `MaybeUninit` will never call `T`'s drop code.
Expand Down
36 changes: 36 additions & 0 deletions src/librustc/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,38 @@ impl<'tcx> HasLocalDecls<'tcx> for Mir<'tcx> {
}
}

/// The various "big phases" that MIR goes through.
///
/// Warning: ordering of variants is significant
#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub enum MirPhase {
Build = 0,
Const = 1,
Validated = 2,
Optimized = 3,
}

impl MirPhase {
/// Gets the index of the current MirPhase within the set of all MirPhases.
pub fn phase_index(&self) -> usize {
*self as usize
}
}

/// Lowered representation of a single function.
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
pub struct Mir<'tcx> {
/// List of basic blocks. References to basic block use a newtyped index type `BasicBlock`
/// that indexes into this vector.
basic_blocks: IndexVec<BasicBlock, BasicBlockData<'tcx>>,

/// Records how far through the "desugaring and optimization" process this particular
/// MIR has traversed. This is particularly useful when inlining, since in that context
/// we instantiate the promoted constants and add them to our promoted vector -- but those
/// promoted items have already been optimized, whereas ours have not. This field allows
/// us to see the difference and forego optimization on the inlined promoted items.
pub phase: MirPhase,

/// List of source scopes; these are referenced by statements
/// and used for debuginfo. Indexed by a `SourceScope`.
pub source_scopes: IndexVec<SourceScope, SourceScopeData>,
Expand Down Expand Up @@ -151,6 +176,7 @@ impl<'tcx> Mir<'tcx> {
);

Mir {
phase: MirPhase::Build,
basic_blocks,
source_scopes,
source_scope_local_data,
Expand Down Expand Up @@ -368,6 +394,7 @@ pub enum Safety {
}

impl_stable_hash_for!(struct Mir<'tcx> {
phase,
basic_blocks,
source_scopes,
source_scope_local_data,
Expand Down Expand Up @@ -616,6 +643,13 @@ impl_stable_hash_for!(enum self::ImplicitSelfKind {
None
});

impl_stable_hash_for!(enum self::MirPhase {
Build,
Const,
Validated,
Optimized,
});

mod binding_form_impl {
use ich::StableHashingContext;
use rustc_data_structures::stable_hasher::{HashStable, StableHasher, StableHasherResult};
Expand Down Expand Up @@ -2905,6 +2939,7 @@ pub enum ClosureOutlivesSubject<'tcx> {

CloneTypeFoldableAndLiftImpls! {
BlockTailInfo,
MirPhase,
Mutability,
SourceInfo,
UpvarDecl,
Expand All @@ -2917,6 +2952,7 @@ CloneTypeFoldableAndLiftImpls! {

BraceStructTypeFoldableImpl! {
impl<'tcx> TypeFoldable<'tcx> for Mir<'tcx> {
phase,
basic_blocks,
source_scopes,
source_scope_local_data,
Expand Down
14 changes: 3 additions & 11 deletions src/librustc/util/ppaux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,25 +251,17 @@ impl PrintContext {
fn parameterized<F: fmt::Write>(&mut self,
f: &mut F,
substs: &subst::Substs<'_>,
mut did: DefId,
did: DefId,
projections: &[ty::ProjectionPredicate<'_>])
-> fmt::Result {
let key = ty::tls::with(|tcx| tcx.def_key(did));
let mut item_name = if let Some(name) = key.disambiguated_data.data.get_opt_name() {
Some(name)
} else {
did.index = key.parent.unwrap_or_else(
|| bug!("finding type for {:?}, encountered def-id {:?} with no parent",
did, did));
self.parameterized(f, substs, did, projections)?;
return write!(f, "::{}", key.disambiguated_data.data.as_interned_str());
};

let verbose = self.is_verbose;
let mut num_supplied_defaults = 0;
let mut has_self = false;
let mut own_counts: GenericParamCount = Default::default();
let mut is_value_path = false;
let mut item_name = Some(key.disambiguated_data.data.as_interned_str());
let fn_trait_kind = ty::tls::with(|tcx| {
// Unfortunately, some kinds of items (e.g., closures) don't have
// generics. So walk back up the find the closest parent that DOES
Expand All @@ -282,6 +274,7 @@ impl PrintContext {
DefPathData::AssocTypeInImpl(_) |
DefPathData::AssocExistentialInImpl(_) |
DefPathData::Trait(_) |
DefPathData::Impl |
DefPathData::TypeNs(_) => {
break;
}
Expand All @@ -292,7 +285,6 @@ impl PrintContext {
}
DefPathData::CrateRoot |
DefPathData::Misc |
DefPathData::Impl |
DefPathData::Module(_) |
DefPathData::MacroDef(_) |
DefPathData::ClosureExpr |
Expand Down
7 changes: 7 additions & 0 deletions src/librustc_mir/const_eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,13 @@ pub fn const_eval_raw_provider<'a, 'tcx>(
other => return other,
}
}
// the first trace is for replicating an ice
// There's no tracking issue, but the next two lines concatenated link to the discussion on
// zulip. It's not really possible to test this, because it doesn't show up in diagnostics
// or MIR.
// https://rust-lang.zulipchat.com/#narrow/stream/146212-t-compiler.2Fconst-eval/
// subject/anon_const_instance_printing/near/135980032
trace!("const eval: {}", key.value.instance);
trace!("const eval: {:?}", key);

let cid = key.value;
Expand Down
1 change: 0 additions & 1 deletion src/librustc_mir/dataflow/impls/borrows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ impl<'a, 'gcx, 'tcx> Borrows<'a, 'gcx, 'tcx> {
}

crate fn borrows(&self) -> &IndexVec<BorrowIndex, BorrowData<'tcx>> { &self.borrow_set.borrows }
pub fn scope_tree(&self) -> &Lrc<region::ScopeTree> { &self.scope_tree }

pub fn location(&self, idx: BorrowIndex) -> &Location {
&self.borrow_set.borrows[idx].reserve_location
Expand Down
14 changes: 0 additions & 14 deletions src/librustc_mir/dataflow/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -724,20 +724,6 @@ impl<'a, 'tcx, D> DataflowAnalysis<'a, 'tcx, D> where D: BitDenotation
}
}
}

pub fn new_from_sets(mir: &'a Mir<'tcx>,
dead_unwinds: &'a BitSet<mir::BasicBlock>,
sets: AllSets<D::Idx>,
denotation: D) -> Self {
DataflowAnalysis {
mir,
dead_unwinds,
flow_state: DataflowState {
sets: sets,
operator: denotation,
}
}
}
}

impl<'a, 'tcx: 'a, D> DataflowAnalysis<'a, 'tcx, D> where D: BitDenotation
Expand Down
Loading

0 comments on commit d492c67

Please sign in to comment.