Skip to content

Commit 6c56cac

Browse files
committed
fix misc printing
1 parent 9e9ca4a commit 6c56cac

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

compiler/rustc_smir/src/rustc_smir/context.rs

+8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
//! This trait is currently the main interface between the Rust compiler,
44
//! and the `stable_mir` crate.
55
6+
use crate::rustc_smir::stable_mir::opaque;
67
use rustc_middle::ty::print::{with_forced_trimmed_paths, with_no_trimmed_paths};
78
use rustc_middle::ty::{GenericPredicates, Instance, ParamEnv, ScalarInt, ValTree};
89
use rustc_span::def_id::LOCAL_CRATE;
@@ -14,6 +15,7 @@ use stable_mir::ty::{
1415
AdtDef, AdtKind, Allocation, ClosureDef, ClosureKind, Const, FnDef, GenericArgs, LineInfo,
1516
RigidTy, Span, TyKind,
1617
};
18+
use stable_mir::Opaque;
1719
use stable_mir::{self, Crate, CrateItem, Error, Filename, ItemKind, Symbol};
1820
use std::cell::RefCell;
1921

@@ -230,6 +232,12 @@ impl<'tcx> Context for TablesWrapper<'tcx> {
230232
internal(cnst).to_string()
231233
}
232234

235+
fn adt_literal(&self, adt: &AdtDef) -> Opaque {
236+
let mut tables = self.0.borrow_mut();
237+
let internal = adt.internal(&mut *tables);
238+
opaque(&internal)
239+
}
240+
233241
fn span_of_an_item(&self, def_id: stable_mir::DefId) -> Span {
234242
let mut tables = self.0.borrow_mut();
235243
tables.tcx.def_span(tables[def_id]).stable(&mut *tables)

compiler/stable_mir/src/compiler_interface.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ use crate::ty::{
1414
Ty, TyKind,
1515
};
1616
use crate::{
17-
mir, Crate, CrateItem, CrateItems, DefId, Error, Filename, ImplTraitDecls, ItemKind, Symbol,
18-
TraitDecls,
17+
mir, Crate, CrateItem, CrateItems, DefId, Error, Filename, ImplTraitDecls, ItemKind, Opaque,
18+
Symbol, TraitDecls,
1919
};
2020

2121
/// This trait defines the interface between stable_mir and the Rust compiler.
@@ -79,6 +79,9 @@ pub trait Context {
7979
/// Returns literal value of a const as a string.
8080
fn const_literal(&self, cnst: &Const) -> String;
8181

82+
/// Returns literal version of a Adt as a Opaque
83+
fn adt_literal(&self, adt: &AdtDef) -> Opaque;
84+
8285
/// `Span` of an item
8386
fn span_of_an_item(&self, def_id: DefId) -> Span;
8487

compiler/stable_mir/src/mir/body.rs

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ impl Body {
8787
Ok(())
8888
})
8989
.collect::<Result<Vec<_>, _>>()?;
90+
writeln!(w, "}}")?;
9091
Ok(())
9192
}
9293
}

compiler/stable_mir/src/mir/pretty.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ pub fn function_body(body: &Body) -> String {
3636
pretty_body.push_str(format!("{}", pretty_ty(local.ty.kind())).as_str());
3737
pretty_body.push_str(";\n");
3838
});
39-
pretty_body.push_str("}");
4039
pretty_body
4140
}
4241

@@ -98,6 +97,7 @@ pub fn pretty_rvalue(rval: &Rvalue) -> String {
9897
pretty.push_str(format!("(*_{})", addr.local).as_str());
9998
}
10099
Rvalue::Aggregate(aggregatekind, operands) => {
100+
// FIXME: Add pretty_aggregate function that returns a pretty string
101101
pretty.push_str(format!("{:#?}", aggregatekind).as_str());
102102
pretty.push_str("(");
103103
operands.iter().enumerate().for_each(|(i, op)| {
@@ -196,7 +196,7 @@ pub fn pretty_ty(ty: TyKind) -> String {
196196
FloatTy::F64 => "f64".to_string(),
197197
},
198198
RigidTy::Adt(def, _) => {
199-
format!("{:#?}", with(|cx| cx.def_ty(def.0)))
199+
format!("{}", with(|cx| cx.adt_literal(&def)))
200200
}
201201
RigidTy::Str => "str".to_string(),
202202
RigidTy::Array(ty, len) => {

0 commit comments

Comments
 (0)