Skip to content

Commit d6a55d3

Browse files
committed
change fn name, return loc info, local name
1 parent 1d9481f commit d6a55d3

File tree

3 files changed

+14
-24
lines changed

3 files changed

+14
-24
lines changed

compiler/rustc_smir/src/rustc_smir/mod.rs

+8-19
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ use rustc_middle::ty::{self, Ty, TyCtxt, Variance};
1717
use rustc_span::def_id::{CrateNum, DefId, LOCAL_CRATE};
1818
use rustc_target::abi::FieldIdx;
1919
use stable_mir::mir::{CopyNonOverlapping, Statement, UserTypeProjection, VariantIdx};
20-
use stable_mir::ty::{FloatTy, GenericParamDef, IntTy, Movability, RigidTy, Span, TyKind, UintTy};
20+
use stable_mir::ty::{
21+
FloatTy, GenericParamDef, IntTy, LineInfo, Movability, RigidTy, Span, TyKind, UintTy,
22+
};
2123
use stable_mir::{self, opaque, Context, Filename};
2224
use tracing::debug;
2325

@@ -50,7 +52,7 @@ impl<'tcx> Context for Tables<'tcx> {
5052
self.tcx.def_path_str(self[def_id])
5153
}
5254

53-
fn print_span(&self, span: stable_mir::ty::Span) -> String {
55+
fn span_to_string(&self, span: stable_mir::ty::Span) -> String {
5456
self.tcx.sess.source_map().span_to_diagnostic_string(self[span])
5557
}
5658

@@ -61,27 +63,14 @@ impl<'tcx> Context for Tables<'tcx> {
6163
.sess
6264
.source_map()
6365
.span_to_filename(self[*span])
64-
.display(rustc_span::FileNameDisplayPreference::Short)
66+
.display(rustc_span::FileNameDisplayPreference::Local)
6567
.to_string(),
6668
)
6769
}
6870

69-
fn get_lines(&self, span: &Span) -> Vec<stable_mir::ty::LineInfo> {
70-
let lines = &self
71-
.tcx
72-
.sess
73-
.source_map()
74-
.span_to_lines(self[*span])
75-
.unwrap()
76-
.lines
77-
.iter()
78-
.map(|line| stable_mir::ty::LineInfo {
79-
line_index: line.line_index + 1,
80-
start_col: line.start_col.0 + 1,
81-
end_col: line.end_col.0 + 1,
82-
})
83-
.collect::<Vec<stable_mir::ty::LineInfo>>();
84-
lines.to_vec()
71+
fn get_lines(&self, span: &Span) -> LineInfo {
72+
let lines = &self.tcx.sess.source_map().span_to_location_info(self[*span]);
73+
LineInfo { start_line: lines.1, start_col: lines.2, end_line: lines.3, end_col: lines.4 }
8574
}
8675

8776
fn def_kind(&mut self, def_id: stable_mir::DefId) -> stable_mir::DefKind {

compiler/stable_mir/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -201,13 +201,13 @@ pub trait Context {
201201
fn name_of_def_id(&self, def_id: DefId) -> String;
202202

203203
/// Returns printable, human readable form of `Span`
204-
fn print_span(&self, span: Span) -> String;
204+
fn span_to_string(&self, span: Span) -> String;
205205

206206
/// Return filename from given `Span`, for diagnostic purposes
207207
fn get_filename(&self, span: &Span) -> Filename;
208208

209209
/// Return lines corresponding to this `Span`
210-
fn get_lines(&self, span: &Span) -> Vec<LineInfo>;
210+
fn get_lines(&self, span: &Span) -> LineInfo;
211211

212212
/// Returns the `kind` of given `DefId`
213213
fn def_kind(&mut self, def_id: DefId) -> DefKind;

compiler/stable_mir/src/ty.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ impl Debug for Span {
8181
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
8282
f.debug_struct("Span")
8383
.field("id", &self.0)
84-
.field("repr", &with(|cx| cx.print_span(*self)))
84+
.field("repr", &with(|cx| cx.span_to_string(*self)))
8585
.finish()
8686
}
8787
}
@@ -93,7 +93,7 @@ impl Span {
9393
}
9494

9595
/// Return lines that corespond to this `Span`
96-
pub fn get_lines(&self) -> Vec<LineInfo> {
96+
pub fn get_lines(&self) -> LineInfo {
9797
with(|c| c.get_lines(&self))
9898
}
9999
}
@@ -102,8 +102,9 @@ impl Span {
102102
/// Information you get from `Span` in a struct form.
103103
/// Line and col start from 1.
104104
pub struct LineInfo {
105-
pub line_index: usize,
105+
pub start_line: usize,
106106
pub start_col: usize,
107+
pub end_line: usize,
107108
pub end_col: usize,
108109
}
109110

0 commit comments

Comments
 (0)