Skip to content

Commit 5ea306e

Browse files
committed
Move Opaque to stable_mir
1 parent 5830382 commit 5ea306e

File tree

7 files changed

+35
-38
lines changed

7 files changed

+35
-38
lines changed

compiler/rustc_smir/src/rustc_internal/mod.rs

-21
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
//! For that, we define APIs that will temporarily be public to 3P that exposes rustc internal APIs
44
//! until stable MIR is complete.
55
6-
use std::fmt::Debug;
76
use std::ops::{ControlFlow, Index};
87

98
use crate::rustc_internal;
@@ -136,26 +135,6 @@ pub fn run(tcx: TyCtxt<'_>, f: impl FnOnce()) {
136135
);
137136
}
138137

139-
/// A type that provides internal information but that can still be used for debug purpose.
140-
#[derive(Clone)]
141-
pub struct Opaque(String);
142-
143-
impl std::fmt::Display for Opaque {
144-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
145-
write!(f, "{}", self.0)
146-
}
147-
}
148-
149-
impl std::fmt::Debug for Opaque {
150-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
151-
write!(f, "{:?}", self.0)
152-
}
153-
}
154-
155-
pub(crate) fn opaque<T: Debug>(value: &T) -> Opaque {
156-
Opaque(format!("{value:?}"))
157-
}
158-
159138
pub struct StableMir<B = (), C = ()>
160139
where
161140
B: Send,

compiler/rustc_smir/src/rustc_smir/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@
77
//!
88
//! For now, we are developing everything inside `rustc`, thus, we keep this module private.
99
10-
use crate::rustc_internal::opaque;
1110
use crate::stable_mir::mir::{CopyNonOverlapping, UserTypeProjection, VariantIdx};
1211
use crate::stable_mir::ty::{
1312
FloatTy, GenericParamDef, IntTy, Movability, RigidTy, Span, TyKind, UintTy,
1413
};
15-
use crate::stable_mir::{self, CompilerError, Context};
14+
use crate::stable_mir::{self, opaque, CompilerError, Context};
1615
use hir::def::DefKind;
1716
use rustc_hir as hir;
1817
use rustc_middle::mir::interpret::{alloc_range, AllocId};

compiler/rustc_smir/src/stable_mir/fold.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
use std::ops::ControlFlow;
22

3-
use crate::rustc_internal::Opaque;
4-
5-
use super::ty::{
6-
Allocation, Binder, Const, ConstDef, ConstantKind, ExistentialPredicate, FnSig, GenericArgKind,
7-
GenericArgs, Promoted, RigidTy, TermKind, Ty, TyKind, UnevaluatedConst,
3+
use super::{
4+
ty::{
5+
Allocation, Binder, Const, ConstDef, ConstantKind, ExistentialPredicate, FnSig,
6+
GenericArgKind, GenericArgs, Promoted, RigidTy, TermKind, Ty, TyKind, UnevaluatedConst,
7+
},
8+
Opaque,
89
};
910

1011
pub trait Folder: Sized {

compiler/rustc_smir/src/stable_mir/mir/body.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use crate::rustc_internal::Opaque;
21
use crate::stable_mir::ty::{
32
AdtDef, ClosureDef, Const, GeneratorDef, GenericArgs, Movability, Region,
43
};
4+
use crate::stable_mir::Opaque;
55
use crate::stable_mir::{self, ty::Ty, Span};
66

77
#[derive(Clone, Debug)]

compiler/rustc_smir/src/stable_mir/mod.rs

+20-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ use std::cell::Cell;
1515
use std::fmt;
1616
use std::fmt::Debug;
1717

18-
use crate::rustc_internal::Opaque;
19-
2018
use self::ty::{
2119
GenericPredicates, Generics, ImplDef, ImplTrait, Span, TraitDecl, TraitDef, Ty, TyKind,
2220
};
@@ -210,3 +208,23 @@ pub(crate) fn with<R>(f: impl FnOnce(&mut dyn Context) -> R) -> R {
210208
f(unsafe { *(ptr as *mut &mut dyn Context) })
211209
})
212210
}
211+
212+
/// A type that provides internal information but that can still be used for debug purpose.
213+
#[derive(Clone)]
214+
pub struct Opaque(String);
215+
216+
impl std::fmt::Display for Opaque {
217+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
218+
write!(f, "{}", self.0)
219+
}
220+
}
221+
222+
impl std::fmt::Debug for Opaque {
223+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
224+
write!(f, "{:?}", self.0)
225+
}
226+
}
227+
228+
pub(crate) fn opaque<T: Debug>(value: &T) -> Opaque {
229+
Opaque(format!("{value:?}"))
230+
}

compiler/rustc_smir/src/stable_mir/ty.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
use super::{
22
mir::Safety,
33
mir::{Body, Mutability},
4-
with, AllocId, DefId,
4+
with, AllocId, DefId, Opaque,
55
};
6-
use crate::rustc_internal::Opaque;
76
use std::fmt::{self, Debug, Formatter};
87

98
#[derive(Copy, Clone)]

compiler/rustc_smir/src/stable_mir/visitor.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
use std::ops::ControlFlow;
22

3-
use crate::rustc_internal::Opaque;
4-
5-
use super::ty::{
6-
Allocation, Binder, Const, ConstDef, ExistentialPredicate, FnSig, GenericArgKind, GenericArgs,
7-
Promoted, RigidTy, TermKind, Ty, UnevaluatedConst,
3+
use super::{
4+
ty::{
5+
Allocation, Binder, Const, ConstDef, ExistentialPredicate, FnSig, GenericArgKind,
6+
GenericArgs, Promoted, RigidTy, TermKind, Ty, UnevaluatedConst,
7+
},
8+
Opaque,
89
};
910

1011
pub trait Visitor: Sized {

0 commit comments

Comments
 (0)