Skip to content

Commit 938d8fd

Browse files
Move MirSource to rustc_middle
1 parent 141a977 commit 938d8fd

File tree

2 files changed

+35
-28
lines changed
  • compiler

2 files changed

+35
-28
lines changed

compiler/rustc_middle/src/mir/mod.rs

+32
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,38 @@ impl MirPhase {
111111
}
112112
}
113113

114+
/// Where a specific `mir::Body` comes from.
115+
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
116+
#[derive(HashStable, TyEncodable, TyDecodable, TypeFoldable)]
117+
pub struct MirSource<'tcx> {
118+
pub instance: InstanceDef<'tcx>,
119+
120+
/// If `Some`, this is a promoted rvalue within the parent function.
121+
pub promoted: Option<Promoted>,
122+
}
123+
124+
impl<'tcx> MirSource<'tcx> {
125+
pub fn item(def_id: DefId) -> Self {
126+
MirSource {
127+
instance: InstanceDef::Item(ty::WithOptConstParam::unknown(def_id)),
128+
promoted: None,
129+
}
130+
}
131+
132+
pub fn from_instance(instance: InstanceDef<'tcx>) -> Self {
133+
MirSource { instance, promoted: None }
134+
}
135+
136+
pub fn with_opt_param(self) -> ty::WithOptConstParam<DefId> {
137+
self.instance.with_opt_param()
138+
}
139+
140+
#[inline]
141+
pub fn def_id(&self) -> DefId {
142+
self.instance.def_id()
143+
}
144+
}
145+
114146
/// The lowered representation of a single function.
115147
#[derive(Clone, TyEncodable, TyDecodable, Debug, HashStable, TypeFoldable)]
116148
pub struct Body<'tcx> {

compiler/rustc_mir/src/transform/mod.rs

+3-28
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_middle::mir::visit::Visitor as _;
99
use rustc_middle::mir::{traversal, Body, ConstQualifs, MirPhase, Promoted};
1010
use rustc_middle::ty::query::Providers;
1111
use rustc_middle::ty::steal::Steal;
12-
use rustc_middle::ty::{self, InstanceDef, TyCtxt, TypeFoldable};
12+
use rustc_middle::ty::{self, TyCtxt, TypeFoldable};
1313
use rustc_span::{Span, Symbol};
1414
use std::borrow::Cow;
1515

@@ -49,6 +49,8 @@ pub mod uninhabited_enum_branching;
4949
pub mod unreachable_prop;
5050
pub mod validate;
5151

52+
pub use rustc_middle::mir::MirSource;
53+
5254
pub(crate) fn provide(providers: &mut Providers) {
5355
self::check_unsafety::provide(providers);
5456
*providers = Providers {
@@ -132,33 +134,6 @@ fn mir_keys(tcx: TyCtxt<'_>, krate: CrateNum) -> FxHashSet<LocalDefId> {
132134
set
133135
}
134136

135-
/// Where a specific `mir::Body` comes from.
136-
#[derive(Debug, Copy, Clone)]
137-
pub struct MirSource<'tcx> {
138-
pub instance: InstanceDef<'tcx>,
139-
140-
/// If `Some`, this is a promoted rvalue within the parent function.
141-
pub promoted: Option<Promoted>,
142-
}
143-
144-
impl<'tcx> MirSource<'tcx> {
145-
pub fn item(def_id: DefId) -> Self {
146-
MirSource {
147-
instance: InstanceDef::Item(ty::WithOptConstParam::unknown(def_id)),
148-
promoted: None,
149-
}
150-
}
151-
152-
pub fn with_opt_param(self) -> ty::WithOptConstParam<DefId> {
153-
self.instance.with_opt_param()
154-
}
155-
156-
#[inline]
157-
pub fn def_id(&self) -> DefId {
158-
self.instance.def_id()
159-
}
160-
}
161-
162137
/// Generates a default name for the pass based on the name of the
163138
/// type `T`.
164139
pub fn default_name<T: ?Sized>() -> Cow<'static, str> {

0 commit comments

Comments
 (0)