Skip to content

Commit 8216b99

Browse files
authored
Unrolled build for rust-lang#137501
Rollup merge of rust-lang#137501 - nnethercote:mv-impls-out-of-syntax, r=compiler-errors Move `impl` blocks out of `rustc_middle/src/mir/syntax.rs` Best reviewed one commit at a time.
2 parents f43e549 + 4183c08 commit 8216b99

File tree

6 files changed

+110
-116
lines changed

6 files changed

+110
-116
lines changed

compiler/rustc_middle/src/mir/mod.rs

+11
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,17 @@ impl<'tcx> HasLocalDecls<'tcx> for Body<'tcx> {
9696
}
9797

9898
impl MirPhase {
99+
pub fn name(&self) -> &'static str {
100+
match *self {
101+
MirPhase::Built => "built",
102+
MirPhase::Analysis(AnalysisPhase::Initial) => "analysis",
103+
MirPhase::Analysis(AnalysisPhase::PostCleanup) => "analysis-post-cleanup",
104+
MirPhase::Runtime(RuntimePhase::Initial) => "runtime",
105+
MirPhase::Runtime(RuntimePhase::PostCleanup) => "runtime-post-cleanup",
106+
MirPhase::Runtime(RuntimePhase::Optimized) => "runtime-optimized",
107+
}
108+
}
109+
99110
/// Gets the (dialect, phase) index of the current `MirPhase`. Both numbers
100111
/// are 1-indexed.
101112
pub fn index(&self) -> (usize, usize) {

compiler/rustc_middle/src/mir/statement.rs

+57
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,26 @@ impl Statement<'_> {
2525
}
2626

2727
impl<'tcx> StatementKind<'tcx> {
28+
/// Returns a simple string representation of a `StatementKind` variant, independent of any
29+
/// values it might hold (e.g. `StatementKind::Assign` always returns `"Assign"`).
30+
pub const fn name(&self) -> &'static str {
31+
match self {
32+
StatementKind::Assign(..) => "Assign",
33+
StatementKind::FakeRead(..) => "FakeRead",
34+
StatementKind::SetDiscriminant { .. } => "SetDiscriminant",
35+
StatementKind::Deinit(..) => "Deinit",
36+
StatementKind::StorageLive(..) => "StorageLive",
37+
StatementKind::StorageDead(..) => "StorageDead",
38+
StatementKind::Retag(..) => "Retag",
39+
StatementKind::PlaceMention(..) => "PlaceMention",
40+
StatementKind::AscribeUserType(..) => "AscribeUserType",
41+
StatementKind::Coverage(..) => "Coverage",
42+
StatementKind::Intrinsic(..) => "Intrinsic",
43+
StatementKind::ConstEvalCounter => "ConstEvalCounter",
44+
StatementKind::Nop => "Nop",
45+
StatementKind::BackwardIncompatibleDropHint { .. } => "BackwardIncompatibleDropHint",
46+
}
47+
}
2848
pub fn as_assign_mut(&mut self) -> Option<&mut (Place<'tcx>, Rvalue<'tcx>)> {
2949
match self {
3050
StatementKind::Assign(x) => Some(x),
@@ -862,3 +882,40 @@ impl<'tcx> BinOp {
862882
})
863883
}
864884
}
885+
886+
impl From<Mutability> for RawPtrKind {
887+
fn from(other: Mutability) -> Self {
888+
match other {
889+
Mutability::Mut => RawPtrKind::Mut,
890+
Mutability::Not => RawPtrKind::Const,
891+
}
892+
}
893+
}
894+
895+
impl RawPtrKind {
896+
pub fn is_fake(self) -> bool {
897+
match self {
898+
RawPtrKind::Mut | RawPtrKind::Const => false,
899+
RawPtrKind::FakeForPtrMetadata => true,
900+
}
901+
}
902+
903+
pub fn to_mutbl_lossy(self) -> Mutability {
904+
match self {
905+
RawPtrKind::Mut => Mutability::Mut,
906+
RawPtrKind::Const => Mutability::Not,
907+
908+
// We have no type corresponding to a fake borrow, so use
909+
// `*const` as an approximation.
910+
RawPtrKind::FakeForPtrMetadata => Mutability::Not,
911+
}
912+
}
913+
914+
pub fn ptr_str(self) -> &'static str {
915+
match self {
916+
RawPtrKind::Mut => "mut",
917+
RawPtrKind::Const => "const",
918+
RawPtrKind::FakeForPtrMetadata => "const (fake)",
919+
}
920+
}
921+
}

compiler/rustc_middle/src/mir/syntax.rs

-112
Original file line numberDiff line numberDiff line change
@@ -97,19 +97,6 @@ pub enum MirPhase {
9797
Runtime(RuntimePhase),
9898
}
9999

100-
impl MirPhase {
101-
pub fn name(&self) -> &'static str {
102-
match *self {
103-
MirPhase::Built => "built",
104-
MirPhase::Analysis(AnalysisPhase::Initial) => "analysis",
105-
MirPhase::Analysis(AnalysisPhase::PostCleanup) => "analysis-post-cleanup",
106-
MirPhase::Runtime(RuntimePhase::Initial) => "runtime",
107-
MirPhase::Runtime(RuntimePhase::PostCleanup) => "runtime-post-cleanup",
108-
MirPhase::Runtime(RuntimePhase::Optimized) => "runtime-optimized",
109-
}
110-
}
111-
}
112-
113100
/// See [`MirPhase::Analysis`].
114101
#[derive(Copy, Clone, TyEncodable, TyDecodable, Debug, PartialEq, Eq, PartialOrd, Ord)]
115102
#[derive(HashStable)]
@@ -206,43 +193,6 @@ pub enum RawPtrKind {
206193
FakeForPtrMetadata,
207194
}
208195

209-
impl From<Mutability> for RawPtrKind {
210-
fn from(other: Mutability) -> Self {
211-
match other {
212-
Mutability::Mut => RawPtrKind::Mut,
213-
Mutability::Not => RawPtrKind::Const,
214-
}
215-
}
216-
}
217-
218-
impl RawPtrKind {
219-
pub fn is_fake(self) -> bool {
220-
match self {
221-
RawPtrKind::Mut | RawPtrKind::Const => false,
222-
RawPtrKind::FakeForPtrMetadata => true,
223-
}
224-
}
225-
226-
pub fn to_mutbl_lossy(self) -> Mutability {
227-
match self {
228-
RawPtrKind::Mut => Mutability::Mut,
229-
RawPtrKind::Const => Mutability::Not,
230-
231-
// We have no type corresponding to a fake borrow, so use
232-
// `*const` as an approximation.
233-
RawPtrKind::FakeForPtrMetadata => Mutability::Not,
234-
}
235-
}
236-
237-
pub fn ptr_str(self) -> &'static str {
238-
match self {
239-
RawPtrKind::Mut => "mut",
240-
RawPtrKind::Const => "const",
241-
RawPtrKind::FakeForPtrMetadata => "const (fake)",
242-
}
243-
}
244-
}
245-
246196
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, TyEncodable, TyDecodable)]
247197
#[derive(Hash, HashStable)]
248198
pub enum MutBorrowKind {
@@ -515,29 +465,6 @@ pub enum StatementKind<'tcx> {
515465
},
516466
}
517467

518-
impl StatementKind<'_> {
519-
/// Returns a simple string representation of a `StatementKind` variant, independent of any
520-
/// values it might hold (e.g. `StatementKind::Assign` always returns `"Assign"`).
521-
pub const fn name(&self) -> &'static str {
522-
match self {
523-
StatementKind::Assign(..) => "Assign",
524-
StatementKind::FakeRead(..) => "FakeRead",
525-
StatementKind::SetDiscriminant { .. } => "SetDiscriminant",
526-
StatementKind::Deinit(..) => "Deinit",
527-
StatementKind::StorageLive(..) => "StorageLive",
528-
StatementKind::StorageDead(..) => "StorageDead",
529-
StatementKind::Retag(..) => "Retag",
530-
StatementKind::PlaceMention(..) => "PlaceMention",
531-
StatementKind::AscribeUserType(..) => "AscribeUserType",
532-
StatementKind::Coverage(..) => "Coverage",
533-
StatementKind::Intrinsic(..) => "Intrinsic",
534-
StatementKind::ConstEvalCounter => "ConstEvalCounter",
535-
StatementKind::Nop => "Nop",
536-
StatementKind::BackwardIncompatibleDropHint { .. } => "BackwardIncompatibleDropHint",
537-
}
538-
}
539-
}
540-
541468
#[derive(
542469
Clone,
543470
TyEncodable,
@@ -673,12 +600,6 @@ pub enum CallSource {
673600
Normal,
674601
}
675602

676-
impl CallSource {
677-
pub fn from_hir_call(self) -> bool {
678-
matches!(self, CallSource::Normal)
679-
}
680-
}
681-
682603
#[derive(Clone, Copy, Debug, TyEncodable, TyDecodable, Hash, HashStable, PartialEq)]
683604
#[derive(TypeFoldable, TypeVisitable)]
684605
/// The macro that an inline assembly block was created by
@@ -689,15 +610,6 @@ pub enum InlineAsmMacro {
689610
NakedAsm,
690611
}
691612

692-
impl InlineAsmMacro {
693-
pub const fn diverges(self, options: InlineAsmOptions) -> bool {
694-
match self {
695-
InlineAsmMacro::Asm => options.contains(InlineAsmOptions::NORETURN),
696-
InlineAsmMacro::NakedAsm => true,
697-
}
698-
}
699-
}
700-
701613
///////////////////////////////////////////////////////////////////////////
702614
// Terminators
703615

@@ -999,30 +911,6 @@ pub enum BackwardIncompatibleDropReason {
999911
Edition2024,
1000912
}
1001913

1002-
impl TerminatorKind<'_> {
1003-
/// Returns a simple string representation of a `TerminatorKind` variant, independent of any
1004-
/// values it might hold (e.g. `TerminatorKind::Call` always returns `"Call"`).
1005-
pub const fn name(&self) -> &'static str {
1006-
match self {
1007-
TerminatorKind::Goto { .. } => "Goto",
1008-
TerminatorKind::SwitchInt { .. } => "SwitchInt",
1009-
TerminatorKind::UnwindResume => "UnwindResume",
1010-
TerminatorKind::UnwindTerminate(_) => "UnwindTerminate",
1011-
TerminatorKind::Return => "Return",
1012-
TerminatorKind::Unreachable => "Unreachable",
1013-
TerminatorKind::Drop { .. } => "Drop",
1014-
TerminatorKind::Call { .. } => "Call",
1015-
TerminatorKind::TailCall { .. } => "TailCall",
1016-
TerminatorKind::Assert { .. } => "Assert",
1017-
TerminatorKind::Yield { .. } => "Yield",
1018-
TerminatorKind::CoroutineDrop => "CoroutineDrop",
1019-
TerminatorKind::FalseEdge { .. } => "FalseEdge",
1020-
TerminatorKind::FalseUnwind { .. } => "FalseUnwind",
1021-
TerminatorKind::InlineAsm { .. } => "InlineAsm",
1022-
}
1023-
}
1024-
}
1025-
1026914
#[derive(Debug, Clone, TyEncodable, TyDecodable, Hash, HashStable, PartialEq)]
1027915
pub struct SwitchTargets {
1028916
/// Possible values. For each value, the location to branch to is found in

compiler/rustc_middle/src/mir/terminator.rs

+39-1
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
33
use std::slice;
44

5+
use rustc_ast::InlineAsmOptions;
56
use rustc_data_structures::packed::Pu128;
67
use rustc_hir::LangItem;
78
use rustc_macros::{HashStable, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable};
89
use smallvec::{SmallVec, smallvec};
910

10-
use super::{TerminatorKind, *};
11+
use super::*;
1112

1213
impl SwitchTargets {
1314
/// Creates switch targets from an iterator of values and target blocks.
@@ -414,6 +415,28 @@ impl<'tcx> Terminator<'tcx> {
414415
}
415416

416417
impl<'tcx> TerminatorKind<'tcx> {
418+
/// Returns a simple string representation of a `TerminatorKind` variant, independent of any
419+
/// values it might hold (e.g. `TerminatorKind::Call` always returns `"Call"`).
420+
pub const fn name(&self) -> &'static str {
421+
match self {
422+
TerminatorKind::Goto { .. } => "Goto",
423+
TerminatorKind::SwitchInt { .. } => "SwitchInt",
424+
TerminatorKind::UnwindResume => "UnwindResume",
425+
TerminatorKind::UnwindTerminate(_) => "UnwindTerminate",
426+
TerminatorKind::Return => "Return",
427+
TerminatorKind::Unreachable => "Unreachable",
428+
TerminatorKind::Drop { .. } => "Drop",
429+
TerminatorKind::Call { .. } => "Call",
430+
TerminatorKind::TailCall { .. } => "TailCall",
431+
TerminatorKind::Assert { .. } => "Assert",
432+
TerminatorKind::Yield { .. } => "Yield",
433+
TerminatorKind::CoroutineDrop => "CoroutineDrop",
434+
TerminatorKind::FalseEdge { .. } => "FalseEdge",
435+
TerminatorKind::FalseUnwind { .. } => "FalseUnwind",
436+
TerminatorKind::InlineAsm { .. } => "InlineAsm",
437+
}
438+
}
439+
417440
#[inline]
418441
pub fn if_(cond: Operand<'tcx>, t: BasicBlock, f: BasicBlock) -> TerminatorKind<'tcx> {
419442
TerminatorKind::SwitchInt { discr: cond, targets: SwitchTargets::static_if(0, f, t) }
@@ -698,3 +721,18 @@ impl<'tcx> TerminatorKind<'tcx> {
698721
}
699722
}
700723
}
724+
725+
impl CallSource {
726+
pub fn from_hir_call(self) -> bool {
727+
matches!(self, CallSource::Normal)
728+
}
729+
}
730+
731+
impl InlineAsmMacro {
732+
pub const fn diverges(self, options: InlineAsmOptions) -> bool {
733+
match self {
734+
InlineAsmMacro::Asm => options.contains(InlineAsmOptions::NORETURN),
735+
InlineAsmMacro::NakedAsm => true,
736+
}
737+
}
738+
}

compiler/rustc_middle/src/ty/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub use rustc_session::lint::RegisteredTools;
4747
use rustc_span::hygiene::MacroKind;
4848
use rustc_span::{ExpnId, ExpnKind, Ident, Span, Symbol, kw, sym};
4949
pub use rustc_type_ir::relate::VarianceDiagInfo;
50-
pub use rustc_type_ir::{Movability, Mutability, *};
50+
pub use rustc_type_ir::*;
5151
use tracing::{debug, instrument};
5252
pub use vtable::*;
5353
use {rustc_ast as ast, rustc_attr_parsing as attr, rustc_hir as hir};

compiler/rustc_mir_build/src/builder/matches/match_pair.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::sync::Arc;
22

33
use rustc_middle::mir::*;
4-
use rustc_middle::thir::{self, *};
4+
use rustc_middle::thir::*;
55
use rustc_middle::ty::{self, Ty, TypeVisitableExt};
66

77
use crate::builder::Builder;
@@ -134,7 +134,7 @@ impl<'tcx> MatchPairTree<'tcx> {
134134
PatKind::Constant { value } => TestCase::Constant { value },
135135

136136
PatKind::AscribeUserType {
137-
ascription: thir::Ascription { ref annotation, variance },
137+
ascription: Ascription { ref annotation, variance },
138138
ref subpattern,
139139
..
140140
} => {

0 commit comments

Comments
 (0)