Skip to content

Commit bdd275d

Browse files
authoredFeb 23, 2020
Rollup merge of rust-lang#69375 - Menschenkindlein:master, r=Dylan-DPC
Rename CodeMap to SourceMap follow up See rust-lang#51574
2 parents ae50725 + 20c9a40 commit bdd275d

File tree

24 files changed

+113
-113
lines changed

24 files changed

+113
-113
lines changed
 

‎src/librustc/ich/hcx.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ impl<'a> StableHashingContext<'a> {
149149
#[inline]
150150
pub fn source_map(&mut self) -> &mut CachingSourceMapView<'a> {
151151
match self.caching_source_map {
152-
Some(ref mut cm) => cm,
152+
Some(ref mut sm) => sm,
153153
ref mut none => {
154154
*none = Some(CachingSourceMapView::new(self.raw_source_map));
155155
none.as_mut().unwrap()

‎src/librustc/middle/stability.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,10 @@ pub fn report_unstable(
106106
};
107107

108108
let msp: MultiSpan = span.into();
109-
let cm = &sess.parse_sess.source_map();
109+
let sm = &sess.parse_sess.source_map();
110110
let span_key = msp.primary_span().and_then(|sp: Span| {
111111
if !sp.is_dummy() {
112-
let file = cm.lookup_char_pos(sp.lo()).file;
112+
let file = sm.lookup_char_pos(sp.lo()).file;
113113
if file.name.is_macros() { None } else { Some(span) }
114114
} else {
115115
None

‎src/librustc_ast_pretty/pprust.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ pub struct NoAnn;
4747
impl PpAnn for NoAnn {}
4848

4949
pub struct Comments<'a> {
50-
cm: &'a SourceMap,
50+
sm: &'a SourceMap,
5151
comments: Vec<comments::Comment>,
5252
current: usize,
5353
}
5454

5555
impl<'a> Comments<'a> {
56-
pub fn new(cm: &'a SourceMap, filename: FileName, input: String) -> Comments<'a> {
57-
let comments = comments::gather_comments(cm, filename, input);
58-
Comments { cm, comments, current: 0 }
56+
pub fn new(sm: &'a SourceMap, filename: FileName, input: String) -> Comments<'a> {
57+
let comments = comments::gather_comments(sm, filename, input);
58+
Comments { sm, comments, current: 0 }
5959
}
6060

6161
pub fn next(&self) -> Option<comments::Comment> {
@@ -71,8 +71,8 @@ impl<'a> Comments<'a> {
7171
if cmnt.style != comments::Trailing {
7272
return None;
7373
}
74-
let span_line = self.cm.lookup_char_pos(span.hi());
75-
let comment_line = self.cm.lookup_char_pos(cmnt.pos);
74+
let span_line = self.sm.lookup_char_pos(span.hi());
75+
let comment_line = self.sm.lookup_char_pos(cmnt.pos);
7676
let next = next_pos.unwrap_or_else(|| cmnt.pos + BytePos(1));
7777
if span.hi() < cmnt.pos && cmnt.pos < next && span_line.line == comment_line.line {
7878
return Some(cmnt);
@@ -95,7 +95,7 @@ crate const INDENT_UNIT: usize = 4;
9595
/// Requires you to pass an input filename and reader so that
9696
/// it can scan the input text for comments to copy forward.
9797
pub fn print_crate<'a>(
98-
cm: &'a SourceMap,
98+
sm: &'a SourceMap,
9999
krate: &ast::Crate,
100100
filename: FileName,
101101
input: String,
@@ -106,7 +106,7 @@ pub fn print_crate<'a>(
106106
) -> String {
107107
let mut s = State {
108108
s: pp::mk_printer(),
109-
comments: Some(Comments::new(cm, filename, input)),
109+
comments: Some(Comments::new(sm, filename, input)),
110110
ann,
111111
is_expanded,
112112
};
@@ -522,8 +522,8 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
522522
self.hardbreak();
523523
}
524524
}
525-
if let Some(cm) = self.comments() {
526-
cm.current += 1;
525+
if let Some(cmnts) = self.comments() {
526+
cmnts.current += 1;
527527
}
528528
}
529529

‎src/librustc_driver/pretty.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -452,8 +452,8 @@ pub fn print_after_hir_lowering<'tcx>(
452452
call_with_pp_support_hir(&s, tcx, move |annotation, krate| {
453453
debug!("pretty printing source code {:?}", s);
454454
let sess = annotation.sess();
455-
let cm = sess.source_map();
456-
*out = pprust_hir::print_crate(cm, krate, src_name, src, annotation.pp_ann())
455+
let sm = sess.source_map();
456+
*out = pprust_hir::print_crate(sm, krate, src_name, src, annotation.pp_ann())
457457
})
458458
}
459459

‎src/librustc_errors/json.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -373,13 +373,13 @@ impl DiagnosticSpan {
373373

374374
impl DiagnosticSpanLine {
375375
fn line_from_source_file(
376-
fm: &rustc_span::SourceFile,
376+
sf: &rustc_span::SourceFile,
377377
index: usize,
378378
h_start: usize,
379379
h_end: usize,
380380
) -> DiagnosticSpanLine {
381381
DiagnosticSpanLine {
382-
text: fm.get_line(index).map_or(String::new(), |l| l.into_owned()),
382+
text: sf.get_line(index).map_or(String::new(), |l| l.into_owned()),
383383
highlight_start: h_start,
384384
highlight_end: h_end,
385385
}
@@ -392,13 +392,13 @@ impl DiagnosticSpanLine {
392392
je.sm
393393
.span_to_lines(span)
394394
.map(|lines| {
395-
let fm = &*lines.file;
395+
let sf = &*lines.file;
396396
lines
397397
.lines
398398
.iter()
399399
.map(|line| {
400400
DiagnosticSpanLine::line_from_source_file(
401-
fm,
401+
sf,
402402
line.line_index,
403403
line.start_col.0 + 1,
404404
line.end_col.0 + 1,

‎src/librustc_errors/lib.rs

+16-16
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ pub struct SubstitutionPart {
144144
impl CodeSuggestion {
145145
/// Returns the assembled code suggestions, whether they should be shown with an underline
146146
/// and whether the substitution only differs in capitalization.
147-
pub fn splice_lines(&self, cm: &SourceMap) -> Vec<(String, Vec<SubstitutionPart>, bool)> {
147+
pub fn splice_lines(&self, sm: &SourceMap) -> Vec<(String, Vec<SubstitutionPart>, bool)> {
148148
use rustc_span::{CharPos, Pos};
149149

150150
fn push_trailing(
@@ -176,7 +176,7 @@ impl CodeSuggestion {
176176
.filter(|subst| {
177177
// Suggestions coming from macros can have malformed spans. This is a heavy
178178
// handed approach to avoid ICEs by ignoring the suggestion outright.
179-
let invalid = subst.parts.iter().any(|item| cm.is_valid_span(item.span).is_err());
179+
let invalid = subst.parts.iter().any(|item| sm.is_valid_span(item.span).is_err());
180180
if invalid {
181181
debug!("splice_lines: suggestion contains an invalid span: {:?}", subst);
182182
}
@@ -193,7 +193,7 @@ impl CodeSuggestion {
193193
let hi = substitution.parts.iter().map(|part| part.span.hi()).max()?;
194194
let bounding_span = Span::with_root_ctxt(lo, hi);
195195
// The different spans might belong to different contexts, if so ignore suggestion.
196-
let lines = cm.span_to_lines(bounding_span).ok()?;
196+
let lines = sm.span_to_lines(bounding_span).ok()?;
197197
assert!(!lines.lines.is_empty());
198198

199199
// To build up the result, we do this for each span:
@@ -205,36 +205,36 @@ impl CodeSuggestion {
205205
// - splice in the span substitution
206206
//
207207
// Finally push the trailing line segment of the last span
208-
let fm = &lines.file;
209-
let mut prev_hi = cm.lookup_char_pos(bounding_span.lo());
208+
let sf = &lines.file;
209+
let mut prev_hi = sm.lookup_char_pos(bounding_span.lo());
210210
prev_hi.col = CharPos::from_usize(0);
211211

212-
let mut prev_line = fm.get_line(lines.lines[0].line_index);
212+
let mut prev_line = sf.get_line(lines.lines[0].line_index);
213213
let mut buf = String::new();
214214

215215
for part in &substitution.parts {
216-
let cur_lo = cm.lookup_char_pos(part.span.lo());
216+
let cur_lo = sm.lookup_char_pos(part.span.lo());
217217
if prev_hi.line == cur_lo.line {
218218
push_trailing(&mut buf, prev_line.as_ref(), &prev_hi, Some(&cur_lo));
219219
} else {
220220
push_trailing(&mut buf, prev_line.as_ref(), &prev_hi, None);
221221
// push lines between the previous and current span (if any)
222222
for idx in prev_hi.line..(cur_lo.line - 1) {
223-
if let Some(line) = fm.get_line(idx) {
223+
if let Some(line) = sf.get_line(idx) {
224224
buf.push_str(line.as_ref());
225225
buf.push('\n');
226226
}
227227
}
228-
if let Some(cur_line) = fm.get_line(cur_lo.line - 1) {
228+
if let Some(cur_line) = sf.get_line(cur_lo.line - 1) {
229229
let end = std::cmp::min(cur_line.len(), cur_lo.col.to_usize());
230230
buf.push_str(&cur_line[..end]);
231231
}
232232
}
233233
buf.push_str(&part.snippet);
234-
prev_hi = cm.lookup_char_pos(part.span.hi());
235-
prev_line = fm.get_line(prev_hi.line - 1);
234+
prev_hi = sm.lookup_char_pos(part.span.hi());
235+
prev_line = sf.get_line(prev_hi.line - 1);
236236
}
237-
let only_capitalization = is_case_difference(cm, &buf, bounding_span);
237+
let only_capitalization = is_case_difference(sm, &buf, bounding_span);
238238
// if the replacement already ends with a newline, don't print the next line
239239
if !buf.ends_with('\n') {
240240
push_trailing(&mut buf, prev_line.as_ref(), &prev_hi, None);
@@ -363,23 +363,23 @@ impl Handler {
363363
color_config: ColorConfig,
364364
can_emit_warnings: bool,
365365
treat_err_as_bug: Option<usize>,
366-
cm: Option<Lrc<SourceMap>>,
366+
sm: Option<Lrc<SourceMap>>,
367367
) -> Self {
368368
Self::with_tty_emitter_and_flags(
369369
color_config,
370-
cm,
370+
sm,
371371
HandlerFlags { can_emit_warnings, treat_err_as_bug, ..Default::default() },
372372
)
373373
}
374374

375375
pub fn with_tty_emitter_and_flags(
376376
color_config: ColorConfig,
377-
cm: Option<Lrc<SourceMap>>,
377+
sm: Option<Lrc<SourceMap>>,
378378
flags: HandlerFlags,
379379
) -> Self {
380380
let emitter = Box::new(EmitterWriter::stderr(
381381
color_config,
382-
cm,
382+
sm,
383383
false,
384384
false,
385385
None,

‎src/librustc_hir/print.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,13 @@ pub const INDENT_UNIT: usize = 4;
140140
/// Requires you to pass an input filename and reader so that
141141
/// it can scan the input text for comments to copy forward.
142142
pub fn print_crate<'a>(
143-
cm: &'a SourceMap,
143+
sm: &'a SourceMap,
144144
krate: &hir::Crate<'_>,
145145
filename: FileName,
146146
input: String,
147147
ann: &'a dyn PpAnn,
148148
) -> String {
149-
let mut s = State::new_from_input(cm, filename, input, ann);
149+
let mut s = State::new_from_input(sm, filename, input, ann);
150150

151151
// When printing the AST, we sometimes need to inject `#[no_std]` here.
152152
// Since you can't compile the HIR, it's not necessary.
@@ -158,12 +158,12 @@ pub fn print_crate<'a>(
158158

159159
impl<'a> State<'a> {
160160
pub fn new_from_input(
161-
cm: &'a SourceMap,
161+
sm: &'a SourceMap,
162162
filename: FileName,
163163
input: String,
164164
ann: &'a dyn PpAnn,
165165
) -> State<'a> {
166-
State { s: pp::mk_printer(), comments: Some(Comments::new(cm, filename, input)), ann }
166+
State { s: pp::mk_printer(), comments: Some(Comments::new(sm, filename, input)), ann }
167167
}
168168
}
169169

‎src/librustc_infer/infer/error_reporting/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ fn msg_span_from_early_bound_and_free_regions(
194194
tcx: TyCtxt<'tcx>,
195195
region: ty::Region<'tcx>,
196196
) -> (String, Option<Span>) {
197-
let cm = tcx.sess.source_map();
197+
let sm = tcx.sess.source_map();
198198

199199
let scope = region.free_region_binding_scope(tcx);
200200
let node = tcx.hir().as_local_hir_id(scope).unwrap_or(hir::DUMMY_HIR_ID);
@@ -207,7 +207,7 @@ fn msg_span_from_early_bound_and_free_regions(
207207
};
208208
let (prefix, span) = match *region {
209209
ty::ReEarlyBound(ref br) => {
210-
let mut sp = cm.def_span(tcx.hir().span(node));
210+
let mut sp = sm.def_span(tcx.hir().span(node));
211211
if let Some(param) =
212212
tcx.hir().get_generics(scope).and_then(|generics| generics.get_named(br.name))
213213
{
@@ -216,7 +216,7 @@ fn msg_span_from_early_bound_and_free_regions(
216216
(format!("the lifetime `{}` as defined on", br.name), sp)
217217
}
218218
ty::ReFree(ty::FreeRegion { bound_region: ty::BoundRegion::BrNamed(_, name), .. }) => {
219-
let mut sp = cm.def_span(tcx.hir().span(node));
219+
let mut sp = sm.def_span(tcx.hir().span(node));
220220
if let Some(param) =
221221
tcx.hir().get_generics(scope).and_then(|generics| generics.get_named(name))
222222
{
@@ -230,7 +230,7 @@ fn msg_span_from_early_bound_and_free_regions(
230230
}
231231
_ => (
232232
format!("the lifetime `{}` as defined on", region),
233-
cm.def_span(tcx.hir().span(node)),
233+
sm.def_span(tcx.hir().span(node)),
234234
),
235235
},
236236
_ => bug!(),

‎src/librustc_parse/parser/expr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1625,10 +1625,10 @@ impl<'a> Parser<'a> {
16251625
let hi = self.token.span;
16261626

16271627
if require_comma {
1628-
let cm = self.sess.source_map();
1628+
let sm = self.sess.source_map();
16291629
self.expect_one_of(&[token::Comma], &[token::CloseDelim(token::Brace)]).map_err(
16301630
|mut err| {
1631-
match (cm.span_to_lines(expr.span), cm.span_to_lines(arm_start_span)) {
1631+
match (sm.span_to_lines(expr.span), sm.span_to_lines(arm_start_span)) {
16321632
(Ok(ref expr_lines), Ok(ref arm_start_lines))
16331633
if arm_start_lines.lines[0].end_col == expr_lines.lines[0].end_col
16341634
&& expr_lines.lines.len() == 2

‎src/librustc_passes/liveness.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,11 @@ enum LiveNodeKind {
144144
}
145145

146146
fn live_node_kind_to_string(lnk: LiveNodeKind, tcx: TyCtxt<'_>) -> String {
147-
let cm = tcx.sess.source_map();
147+
let sm = tcx.sess.source_map();
148148
match lnk {
149-
UpvarNode(s) => format!("Upvar node [{}]", cm.span_to_string(s)),
150-
ExprNode(s) => format!("Expr node [{}]", cm.span_to_string(s)),
151-
VarDefNode(s) => format!("Var def node [{}]", cm.span_to_string(s)),
149+
UpvarNode(s) => format!("Upvar node [{}]", sm.span_to_string(s)),
150+
ExprNode(s) => format!("Expr node [{}]", sm.span_to_string(s)),
151+
VarDefNode(s) => format!("Var def node [{}]", sm.span_to_string(s)),
152152
ExitNode => "Exit node".to_owned(),
153153
}
154154
}

‎src/librustc_resolve/diagnostics.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ impl<'tcx> Into<MissingLifetimeSpot<'tcx>> for &'tcx hir::Generics<'tcx> {
9090
/// *Attention*: the method used is very fragile since it essentially duplicates the work of the
9191
/// parser. If you need to use this function or something similar, please consider updating the
9292
/// `source_map` functions and this function to something more robust.
93-
fn reduce_impl_span_to_impl_keyword(cm: &SourceMap, impl_span: Span) -> Span {
94-
let impl_span = cm.span_until_char(impl_span, '<');
95-
let impl_span = cm.span_until_whitespace(impl_span);
93+
fn reduce_impl_span_to_impl_keyword(sm: &SourceMap, impl_span: Span) -> Span {
94+
let impl_span = sm.span_until_char(impl_span, '<');
95+
let impl_span = sm.span_until_whitespace(impl_span);
9696
impl_span
9797
}
9898

@@ -136,14 +136,14 @@ impl<'a> Resolver<'a> {
136136
);
137137
err.span_label(span, format!("use of generic parameter from outer function"));
138138

139-
let cm = self.session.source_map();
139+
let sm = self.session.source_map();
140140
match outer_res {
141141
Res::SelfTy(maybe_trait_defid, maybe_impl_defid) => {
142142
if let Some(impl_span) =
143143
maybe_impl_defid.and_then(|def_id| self.definitions.opt_span(def_id))
144144
{
145145
err.span_label(
146-
reduce_impl_span_to_impl_keyword(cm, impl_span),
146+
reduce_impl_span_to_impl_keyword(sm, impl_span),
147147
"`Self` type implicitly declared here, by this `impl`",
148148
);
149149
}
@@ -180,15 +180,15 @@ impl<'a> Resolver<'a> {
180180
// Try to retrieve the span of the function signature and generate a new
181181
// message with a local type or const parameter.
182182
let sugg_msg = &format!("try using a local generic parameter instead");
183-
if let Some((sugg_span, snippet)) = cm.generate_local_type_param_snippet(span) {
183+
if let Some((sugg_span, snippet)) = sm.generate_local_type_param_snippet(span) {
184184
// Suggest the modification to the user
185185
err.span_suggestion(
186186
sugg_span,
187187
sugg_msg,
188188
snippet,
189189
Applicability::MachineApplicable,
190190
);
191-
} else if let Some(sp) = cm.generate_fn_name_span(span) {
191+
} else if let Some(sp) = sm.generate_fn_name_span(span) {
192192
err.span_label(
193193
sp,
194194
format!("try adding a local generic parameter in this method instead"),

‎src/librustc_resolve/late/diagnostics.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -725,21 +725,21 @@ impl<'a> LateResolutionVisitor<'a, '_, '_> {
725725

726726
/// Only used in a specific case of type ascription suggestions
727727
fn get_colon_suggestion_span(&self, start: Span) -> Span {
728-
let cm = self.r.session.source_map();
729-
start.to(cm.next_point(start))
728+
let sm = self.r.session.source_map();
729+
start.to(sm.next_point(start))
730730
}
731731

732732
fn type_ascription_suggestion(&self, err: &mut DiagnosticBuilder<'_>, base_span: Span) {
733-
let cm = self.r.session.source_map();
734-
let base_snippet = cm.span_to_snippet(base_span);
733+
let sm = self.r.session.source_map();
734+
let base_snippet = sm.span_to_snippet(base_span);
735735
if let Some(sp) = self.diagnostic_metadata.current_type_ascription.last() {
736736
let mut sp = *sp;
737737
loop {
738738
// Try to find the `:`; bail on first non-':' / non-whitespace.
739-
sp = cm.next_point(sp);
740-
if let Ok(snippet) = cm.span_to_snippet(sp.to(cm.next_point(sp))) {
741-
let line_sp = cm.lookup_char_pos(sp.hi()).line;
742-
let line_base_sp = cm.lookup_char_pos(base_span.lo()).line;
739+
sp = sm.next_point(sp);
740+
if let Ok(snippet) = sm.span_to_snippet(sp.to(sm.next_point(sp))) {
741+
let line_sp = sm.lookup_char_pos(sp.hi()).line;
742+
let line_base_sp = sm.lookup_char_pos(base_span.lo()).line;
743743
if snippet == ":" {
744744
let mut show_label = true;
745745
if line_sp != line_base_sp {
@@ -753,7 +753,7 @@ impl<'a> LateResolutionVisitor<'a, '_, '_> {
753753
let colon_sp = self.get_colon_suggestion_span(sp);
754754
let after_colon_sp =
755755
self.get_colon_suggestion_span(colon_sp.shrink_to_hi());
756-
if !cm
756+
if !sm
757757
.span_to_snippet(after_colon_sp)
758758
.map(|s| s == " ")
759759
.unwrap_or(false)
@@ -770,8 +770,8 @@ impl<'a> LateResolutionVisitor<'a, '_, '_> {
770770
let mut sp = after_colon_sp;
771771
for _ in 0..100 {
772772
// Try to find an assignment
773-
sp = cm.next_point(sp);
774-
let snippet = cm.span_to_snippet(sp.to(cm.next_point(sp)));
773+
sp = sm.next_point(sp);
774+
let snippet = sm.span_to_snippet(sp.to(sm.next_point(sp)));
775775
match snippet {
776776
Ok(ref x) if x.as_str() == "=" => {
777777
err.span_suggestion(

‎src/librustc_save_analysis/dump_visitor.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1233,8 +1233,8 @@ impl<'l, 'tcx> Visitor<'l> for DumpVisitor<'l, 'tcx> {
12331233
let qualname =
12341234
format!("::{}", self.tcx.def_path_str(self.tcx.hir().local_def_id_from_node_id(id)));
12351235

1236-
let cm = self.tcx.sess.source_map();
1237-
let filename = cm.span_to_filename(span);
1236+
let sm = self.tcx.sess.source_map();
1237+
let filename = sm.span_to_filename(span);
12381238
let data_id = id_from_node_id(id, &self.save_ctxt);
12391239
let children = m.items.iter().map(|i| id_from_node_id(i.id, &self.save_ctxt)).collect();
12401240
let span = self.span_from_span(span);

‎src/librustc_save_analysis/lib.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
6666
fn span_from_span(&self, span: Span) -> SpanData {
6767
use rls_span::{Column, Row};
6868

69-
let cm = self.tcx.sess.source_map();
70-
let start = cm.lookup_char_pos(span.lo());
71-
let end = cm.lookup_char_pos(span.hi());
69+
let sm = self.tcx.sess.source_map();
70+
let start = sm.lookup_char_pos(span.lo());
71+
let end = sm.lookup_char_pos(span.hi());
7272

7373
SpanData {
7474
file_name: start.file.name.to_string().into(),
@@ -258,8 +258,8 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
258258
self.tcx.def_path_str(self.tcx.hir().local_def_id_from_node_id(item.id))
259259
);
260260

261-
let cm = self.tcx.sess.source_map();
262-
let filename = cm.span_to_filename(m.inner);
261+
let sm = self.tcx.sess.source_map();
262+
let filename = sm.span_to_filename(m.inner);
263263

264264
filter!(self.span_utils, item.ident.span);
265265

‎src/librustc_session/parse.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,9 @@ pub struct ParseSess {
124124

125125
impl ParseSess {
126126
pub fn new(file_path_mapping: FilePathMapping) -> Self {
127-
let cm = Lrc::new(SourceMap::new(file_path_mapping));
128-
let handler = Handler::with_tty_emitter(ColorConfig::Auto, true, None, Some(cm.clone()));
129-
ParseSess::with_span_handler(handler, cm)
127+
let sm = Lrc::new(SourceMap::new(file_path_mapping));
128+
let handler = Handler::with_tty_emitter(ColorConfig::Auto, true, None, Some(sm.clone()));
129+
ParseSess::with_span_handler(handler, sm)
130130
}
131131

132132
pub fn with_span_handler(handler: Handler, source_map: Lrc<SourceMap>) -> Self {
@@ -148,9 +148,9 @@ impl ParseSess {
148148
}
149149

150150
pub fn with_silent_emitter() -> Self {
151-
let cm = Lrc::new(SourceMap::new(FilePathMapping::empty()));
151+
let sm = Lrc::new(SourceMap::new(FilePathMapping::empty()));
152152
let handler = Handler::with_emitter(false, None, Box::new(SilentEmitter));
153-
ParseSess::with_span_handler(handler, cm)
153+
ParseSess::with_span_handler(handler, sm)
154154
}
155155

156156
#[inline]

‎src/librustc_span/caching_source_map_view.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ struct CacheEntry {
1313
}
1414

1515
#[derive(Clone)]
16-
pub struct CachingSourceMapView<'cm> {
17-
source_map: &'cm SourceMap,
16+
pub struct CachingSourceMapView<'sm> {
17+
source_map: &'sm SourceMap,
1818
line_cache: [CacheEntry; 3],
1919
time_stamp: usize,
2020
}
2121

22-
impl<'cm> CachingSourceMapView<'cm> {
23-
pub fn new(source_map: &'cm SourceMap) -> CachingSourceMapView<'cm> {
22+
impl<'sm> CachingSourceMapView<'sm> {
23+
pub fn new(source_map: &'sm SourceMap) -> CachingSourceMapView<'sm> {
2424
let files = source_map.files();
2525
let first_file = files[0].clone();
2626
let entry = CacheEntry {

‎src/librustc_typeck/check/demand.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -324,13 +324,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
324324
hir_id: hir::HirId,
325325
sp: Span,
326326
) -> bool {
327-
let cm = self.sess().source_map();
327+
let sm = self.sess().source_map();
328328
let parent_id = self.tcx.hir().get_parent_node(hir_id);
329329
if let Some(parent) = self.tcx.hir().find(parent_id) {
330330
// Account for fields
331331
if let Node::Expr(hir::Expr { kind: hir::ExprKind::Struct(_, fields, ..), .. }) = parent
332332
{
333-
if let Ok(src) = cm.span_to_snippet(sp) {
333+
if let Ok(src) = sm.span_to_snippet(sp) {
334334
for field in *fields {
335335
if field.ident.as_str() == src && field.is_shorthand {
336336
return true;
@@ -364,9 +364,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
364364
checked_ty: Ty<'tcx>,
365365
expected: Ty<'tcx>,
366366
) -> Option<(Span, &'static str, String)> {
367-
let cm = self.sess().source_map();
367+
let sm = self.sess().source_map();
368368
let sp = expr.span;
369-
if !cm.span_to_filename(sp).is_real() {
369+
if !sm.span_to_filename(sp).is_real() {
370370
// Ignore if span is from within a macro #41858, #58298. We previously used the macro
371371
// call span, but that breaks down when the type error comes from multiple calls down.
372372
return None;
@@ -388,7 +388,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
388388
if arr == self.tcx.types.u8 =>
389389
{
390390
if let hir::ExprKind::Lit(_) = expr.kind {
391-
if let Ok(src) = cm.span_to_snippet(sp) {
391+
if let Ok(src) = sm.span_to_snippet(sp) {
392392
if src.starts_with("b\"") {
393393
return Some((
394394
sp,
@@ -403,7 +403,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
403403
if arr == self.tcx.types.u8 =>
404404
{
405405
if let hir::ExprKind::Lit(_) = expr.kind {
406-
if let Ok(src) = cm.span_to_snippet(sp) {
406+
if let Ok(src) = sm.span_to_snippet(sp) {
407407
if src.starts_with("\"") {
408408
return Some((
409409
sp,
@@ -450,7 +450,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
450450
sugg_sp = arg.span;
451451
}
452452
}
453-
if let Ok(src) = cm.span_to_snippet(sugg_sp) {
453+
if let Ok(src) = sm.span_to_snippet(sugg_sp) {
454454
let needs_parens = match expr.kind {
455455
// parenthesize if needed (Issue #46756)
456456
hir::ExprKind::Cast(_, _) | hir::ExprKind::Binary(_, _, _) => true,
@@ -480,7 +480,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
480480
// | |
481481
// consider dereferencing here: `*opt` |
482482
// expected mutable reference, found enum `Option`
483-
if let Ok(src) = cm.span_to_snippet(left_expr.span) {
483+
if let Ok(src) = sm.span_to_snippet(left_expr.span) {
484484
return Some((
485485
left_expr.span,
486486
"consider dereferencing here to assign to the mutable \
@@ -516,8 +516,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
516516
{
517517
// We have `&T`, check if what was expected was `T`. If so,
518518
// we may want to suggest removing a `&`.
519-
if !cm.span_to_filename(expr.span).is_real() {
520-
if let Ok(code) = cm.span_to_snippet(sp) {
519+
if !sm.span_to_filename(expr.span).is_real() {
520+
if let Ok(code) = sm.span_to_snippet(sp) {
521521
if code.chars().next() == Some('&') {
522522
return Some((
523523
sp,
@@ -528,7 +528,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
528528
}
529529
return None;
530530
}
531-
if let Ok(code) = cm.span_to_snippet(expr.span) {
531+
if let Ok(code) = sm.span_to_snippet(expr.span) {
532532
return Some((sp, "consider removing the borrow", code));
533533
}
534534
}
@@ -562,7 +562,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
562562
let is_copy = self.infcx.type_is_copy_modulo_regions(self.param_env, expected, sp);
563563

564564
if is_copy && impls_deref {
565-
if let Ok(code) = cm.span_to_snippet(sp) {
565+
if let Ok(code) = sm.span_to_snippet(sp) {
566566
let message = if checked_ty.is_region_ptr() {
567567
"consider dereferencing the borrow"
568568
} else {

‎src/librustc_typeck/coherence/orphan.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ impl ItemLikeVisitor<'v> for OrphanChecker<'tcx> {
3333
);
3434
let trait_ref = self.tcx.impl_trait_ref(def_id).unwrap();
3535
let trait_def_id = trait_ref.def_id;
36-
let cm = self.tcx.sess.source_map();
37-
let sp = cm.def_span(item.span);
36+
let sm = self.tcx.sess.source_map();
37+
let sp = sm.def_span(item.span);
3838
match traits::orphan_check(self.tcx, def_id) {
3939
Ok(()) => {}
4040
Err(traits::OrphanCheckErr::NonLocalInputType(tys)) => {

‎src/librustdoc/clean/mod.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,9 @@ impl Clean<Item> for doctree::Module<'_> {
263263
// determine if we should display the inner contents or
264264
// the outer `mod` item for the source code.
265265
let whence = {
266-
let cm = cx.sess().source_map();
267-
let outer = cm.lookup_char_pos(self.where_outer.lo());
268-
let inner = cm.lookup_char_pos(self.where_inner.lo());
266+
let sm = cx.sess().source_map();
267+
let outer = sm.lookup_char_pos(self.where_outer.lo());
268+
let inner = sm.lookup_char_pos(self.where_inner.lo());
269269
if outer.file.start_pos == inner.file.start_pos {
270270
// mod foo { ... }
271271
self.where_outer
@@ -1917,10 +1917,10 @@ impl Clean<Span> for rustc_span::Span {
19171917
return Span::empty();
19181918
}
19191919

1920-
let cm = cx.sess().source_map();
1921-
let filename = cm.span_to_filename(*self);
1922-
let lo = cm.lookup_char_pos(self.lo());
1923-
let hi = cm.lookup_char_pos(self.hi());
1920+
let sm = cx.sess().source_map();
1921+
let filename = sm.span_to_filename(*self);
1922+
let lo = sm.lookup_char_pos(self.lo());
1923+
let hi = sm.lookup_char_pos(self.hi());
19241924
Span {
19251925
filename,
19261926
loline: lo.line,

‎src/librustdoc/core.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ pub fn new_handler(
177177
Box::new(
178178
EmitterWriter::stderr(
179179
color_config,
180-
source_map.map(|cm| cm as _),
180+
source_map.map(|sm| sm as _),
181181
short,
182182
debugging_opts.teach,
183183
debugging_opts.terminal_width,

‎src/librustdoc/html/highlight.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ pub fn render_with_highlighting(
3838
}
3939

4040
let sess = ParseSess::with_silent_emitter();
41-
let fm = sess
41+
let sf = sess
4242
.source_map()
4343
.new_source_file(FileName::Custom(String::from("rustdoc-highlighting")), src.to_owned());
4444
let highlight_result = rustc_driver::catch_fatal_errors(|| {
45-
let lexer = lexer::StringReader::new(&sess, fm, None);
45+
let lexer = lexer::StringReader::new(&sess, sf, None);
4646
let mut classifier = Classifier::new(lexer, sess.source_map());
4747

4848
let mut highlighted_source = vec![];

‎src/librustdoc/passes/check_code_block_syntax.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ impl<'a, 'tcx> SyntaxChecker<'a, 'tcx> {
3232

3333
let emitter = BufferEmitter { messages: Lrc::clone(&buffered_messages) };
3434

35-
let cm = Lrc::new(SourceMap::new(FilePathMapping::empty()));
35+
let sm = Lrc::new(SourceMap::new(FilePathMapping::empty()));
3636
let handler = Handler::with_emitter(false, None, Box::new(emitter));
37-
let sess = ParseSess::with_span_handler(handler, cm);
37+
let sess = ParseSess::with_span_handler(handler, sm);
3838
let source_file = sess.source_map().new_source_file(
3939
FileName::Custom(String::from("doctest")),
4040
dox[code_block.code].to_owned(),

‎src/librustdoc/test.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -402,12 +402,12 @@ pub fn make_test(
402402

403403
// Any errors in parsing should also appear when the doctest is compiled for real, so just
404404
// send all the errors that libsyntax emits directly into a `Sink` instead of stderr.
405-
let cm = Lrc::new(SourceMap::new(FilePathMapping::empty()));
405+
let sm = Lrc::new(SourceMap::new(FilePathMapping::empty()));
406406
let emitter =
407407
EmitterWriter::new(box io::sink(), None, false, false, false, None, false);
408408
// FIXME(misdreavus): pass `-Z treat-err-as-bug` to the doctest parser
409409
let handler = Handler::with_emitter(false, None, box emitter);
410-
let sess = ParseSess::with_span_handler(handler, cm);
410+
let sess = ParseSess::with_span_handler(handler, sm);
411411

412412
let mut found_main = false;
413413
let mut found_extern_crate = cratename.is_none();

‎src/libsyntax/util/comments.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@ fn split_block_comment_into_lines(text: &str, col: CharPos) -> Vec<String> {
189189
// it appears this function is called only from pprust... that's
190190
// probably not a good thing.
191191
pub fn gather_comments(sm: &SourceMap, path: FileName, src: String) -> Vec<Comment> {
192-
let cm = SourceMap::new(sm.path_mapping().clone());
193-
let source_file = cm.new_source_file(path, src);
192+
let sm = SourceMap::new(sm.path_mapping().clone());
193+
let source_file = sm.new_source_file(path, src);
194194
let text = (*source_file.src.as_ref().unwrap()).clone();
195195

196196
let text: &str = text.as_str();

0 commit comments

Comments
 (0)
Please sign in to comment.