Skip to content

Commit bdd275d

Browse files
authored
Rollup merge of #69375 - Menschenkindlein:master, r=Dylan-DPC
Rename CodeMap to SourceMap follow up See #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"),

0 commit comments

Comments
 (0)