Skip to content

Commit d492c67

Browse files
committed
Auto merge of #55433 - kennytm:rollup, r=kennytm
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)
2 parents 4f5cfa6 + db4e77c commit d492c67

37 files changed

+386
-171
lines changed

src/liballoc/string.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ impl String {
413413
///
414414
/// // These are all done without reallocating...
415415
/// let cap = s.capacity();
416-
/// for i in 0..10 {
416+
/// for _ in 0..10 {
417417
/// s.push('a');
418418
/// }
419419
///

src/libcore/iter/iterator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1857,7 +1857,7 @@ pub trait Iterator {
18571857
/// ```
18581858
/// let a = ["lol", "NaN", "2", "5"];
18591859
///
1860-
/// let mut first_number = a.iter().find_map(|s| s.parse().ok());
1860+
/// let first_number = a.iter().find_map(|s| s.parse().ok());
18611861
///
18621862
/// assert_eq!(first_number, Some(2));
18631863
/// ```

src/libcore/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
#![feature(const_fn)]
8383
#![feature(const_int_ops)]
8484
#![feature(const_fn_union)]
85+
#![feature(const_manually_drop_new)]
8586
#![feature(custom_attribute)]
8687
#![feature(doc_cfg)]
8788
#![feature(doc_spotlight)]

src/libcore/mem.rs

+29
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,26 @@ impl<T> ManuallyDrop<T> {
973973
pub fn into_inner(slot: ManuallyDrop<T>) -> T {
974974
slot.value
975975
}
976+
977+
/// Takes the contained value out.
978+
///
979+
/// This method is primarily intended for moving out values in drop.
980+
/// Instead of using [`ManuallyDrop::drop`] to manually drop the value,
981+
/// you can use this method to take the value and use it however desired.
982+
/// `Drop` will be invoked on the returned value following normal end-of-scope rules.
983+
///
984+
/// If you have ownership of the container, you can use [`ManuallyDrop::into_inner`] instead.
985+
///
986+
/// # Safety
987+
///
988+
/// This function semantically moves out the contained value without preventing further usage.
989+
/// It is up to the user of this method to ensure that this container is not used again.
990+
#[must_use = "if you don't need the value, you can use `ManuallyDrop::drop` instead"]
991+
#[unstable(feature = "manually_drop_take", issue = "55422")]
992+
#[inline]
993+
pub unsafe fn take(slot: &mut ManuallyDrop<T>) -> T {
994+
ManuallyDrop::into_inner(ptr::read(slot))
995+
}
976996
}
977997

978998
impl<T: ?Sized> ManuallyDrop<T> {
@@ -1021,6 +1041,15 @@ pub union MaybeUninit<T> {
10211041
}
10221042

10231043
impl<T> MaybeUninit<T> {
1044+
/// Create a new `MaybeUninit` initialized with the given value.
1045+
///
1046+
/// Note that dropping a `MaybeUninit` will never call `T`'s drop code.
1047+
/// It is your responsibility to make sure `T` gets dropped if it got initialized.
1048+
#[unstable(feature = "maybe_uninit", issue = "53491")]
1049+
pub const fn new(val: T) -> MaybeUninit<T> {
1050+
MaybeUninit { value: ManuallyDrop::new(val) }
1051+
}
1052+
10241053
/// Create a new `MaybeUninit` in an uninitialized state.
10251054
///
10261055
/// Note that dropping a `MaybeUninit` will never call `T`'s drop code.

src/librustc/mir/mod.rs

+36
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,38 @@ impl<'tcx> HasLocalDecls<'tcx> for Mir<'tcx> {
6969
}
7070
}
7171

72+
/// The various "big phases" that MIR goes through.
73+
///
74+
/// Warning: ordering of variants is significant
75+
#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug, PartialEq, Eq, PartialOrd, Ord)]
76+
pub enum MirPhase {
77+
Build = 0,
78+
Const = 1,
79+
Validated = 2,
80+
Optimized = 3,
81+
}
82+
83+
impl MirPhase {
84+
/// Gets the index of the current MirPhase within the set of all MirPhases.
85+
pub fn phase_index(&self) -> usize {
86+
*self as usize
87+
}
88+
}
89+
7290
/// Lowered representation of a single function.
7391
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
7492
pub struct Mir<'tcx> {
7593
/// List of basic blocks. References to basic block use a newtyped index type `BasicBlock`
7694
/// that indexes into this vector.
7795
basic_blocks: IndexVec<BasicBlock, BasicBlockData<'tcx>>,
7896

97+
/// Records how far through the "desugaring and optimization" process this particular
98+
/// MIR has traversed. This is particularly useful when inlining, since in that context
99+
/// we instantiate the promoted constants and add them to our promoted vector -- but those
100+
/// promoted items have already been optimized, whereas ours have not. This field allows
101+
/// us to see the difference and forego optimization on the inlined promoted items.
102+
pub phase: MirPhase,
103+
79104
/// List of source scopes; these are referenced by statements
80105
/// and used for debuginfo. Indexed by a `SourceScope`.
81106
pub source_scopes: IndexVec<SourceScope, SourceScopeData>,
@@ -151,6 +176,7 @@ impl<'tcx> Mir<'tcx> {
151176
);
152177

153178
Mir {
179+
phase: MirPhase::Build,
154180
basic_blocks,
155181
source_scopes,
156182
source_scope_local_data,
@@ -368,6 +394,7 @@ pub enum Safety {
368394
}
369395

370396
impl_stable_hash_for!(struct Mir<'tcx> {
397+
phase,
371398
basic_blocks,
372399
source_scopes,
373400
source_scope_local_data,
@@ -616,6 +643,13 @@ impl_stable_hash_for!(enum self::ImplicitSelfKind {
616643
None
617644
});
618645

646+
impl_stable_hash_for!(enum self::MirPhase {
647+
Build,
648+
Const,
649+
Validated,
650+
Optimized,
651+
});
652+
619653
mod binding_form_impl {
620654
use ich::StableHashingContext;
621655
use rustc_data_structures::stable_hasher::{HashStable, StableHasher, StableHasherResult};
@@ -2905,6 +2939,7 @@ pub enum ClosureOutlivesSubject<'tcx> {
29052939

29062940
CloneTypeFoldableAndLiftImpls! {
29072941
BlockTailInfo,
2942+
MirPhase,
29082943
Mutability,
29092944
SourceInfo,
29102945
UpvarDecl,
@@ -2917,6 +2952,7 @@ CloneTypeFoldableAndLiftImpls! {
29172952

29182953
BraceStructTypeFoldableImpl! {
29192954
impl<'tcx> TypeFoldable<'tcx> for Mir<'tcx> {
2955+
phase,
29202956
basic_blocks,
29212957
source_scopes,
29222958
source_scope_local_data,

src/librustc/util/ppaux.rs

+3-11
Original file line numberDiff line numberDiff line change
@@ -251,25 +251,17 @@ impl PrintContext {
251251
fn parameterized<F: fmt::Write>(&mut self,
252252
f: &mut F,
253253
substs: &subst::Substs<'_>,
254-
mut did: DefId,
254+
did: DefId,
255255
projections: &[ty::ProjectionPredicate<'_>])
256256
-> fmt::Result {
257257
let key = ty::tls::with(|tcx| tcx.def_key(did));
258-
let mut item_name = if let Some(name) = key.disambiguated_data.data.get_opt_name() {
259-
Some(name)
260-
} else {
261-
did.index = key.parent.unwrap_or_else(
262-
|| bug!("finding type for {:?}, encountered def-id {:?} with no parent",
263-
did, did));
264-
self.parameterized(f, substs, did, projections)?;
265-
return write!(f, "::{}", key.disambiguated_data.data.as_interned_str());
266-
};
267258

268259
let verbose = self.is_verbose;
269260
let mut num_supplied_defaults = 0;
270261
let mut has_self = false;
271262
let mut own_counts: GenericParamCount = Default::default();
272263
let mut is_value_path = false;
264+
let mut item_name = Some(key.disambiguated_data.data.as_interned_str());
273265
let fn_trait_kind = ty::tls::with(|tcx| {
274266
// Unfortunately, some kinds of items (e.g., closures) don't have
275267
// generics. So walk back up the find the closest parent that DOES
@@ -282,6 +274,7 @@ impl PrintContext {
282274
DefPathData::AssocTypeInImpl(_) |
283275
DefPathData::AssocExistentialInImpl(_) |
284276
DefPathData::Trait(_) |
277+
DefPathData::Impl |
285278
DefPathData::TypeNs(_) => {
286279
break;
287280
}
@@ -292,7 +285,6 @@ impl PrintContext {
292285
}
293286
DefPathData::CrateRoot |
294287
DefPathData::Misc |
295-
DefPathData::Impl |
296288
DefPathData::Module(_) |
297289
DefPathData::MacroDef(_) |
298290
DefPathData::ClosureExpr |

src/librustc_mir/const_eval.rs

+7
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,13 @@ pub fn const_eval_raw_provider<'a, 'tcx>(
612612
other => return other,
613613
}
614614
}
615+
// the first trace is for replicating an ice
616+
// There's no tracking issue, but the next two lines concatenated link to the discussion on
617+
// zulip. It's not really possible to test this, because it doesn't show up in diagnostics
618+
// or MIR.
619+
// https://rust-lang.zulipchat.com/#narrow/stream/146212-t-compiler.2Fconst-eval/
620+
// subject/anon_const_instance_printing/near/135980032
621+
trace!("const eval: {}", key.value.instance);
615622
trace!("const eval: {:?}", key);
616623

617624
let cid = key.value;

src/librustc_mir/dataflow/impls/borrows.rs

-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ impl<'a, 'gcx, 'tcx> Borrows<'a, 'gcx, 'tcx> {
184184
}
185185

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

189188
pub fn location(&self, idx: BorrowIndex) -> &Location {
190189
&self.borrow_set.borrows[idx].reserve_location

src/librustc_mir/dataflow/mod.rs

-14
Original file line numberDiff line numberDiff line change
@@ -724,20 +724,6 @@ impl<'a, 'tcx, D> DataflowAnalysis<'a, 'tcx, D> where D: BitDenotation
724724
}
725725
}
726726
}
727-
728-
pub fn new_from_sets(mir: &'a Mir<'tcx>,
729-
dead_unwinds: &'a BitSet<mir::BasicBlock>,
730-
sets: AllSets<D::Idx>,
731-
denotation: D) -> Self {
732-
DataflowAnalysis {
733-
mir,
734-
dead_unwinds,
735-
flow_state: DataflowState {
736-
sets: sets,
737-
operator: denotation,
738-
}
739-
}
740-
}
741727
}
742728

743729
impl<'a, 'tcx: 'a, D> DataflowAnalysis<'a, 'tcx, D> where D: BitDenotation

0 commit comments

Comments
 (0)