Rollup merge of #69375 - Menschenkindlein:master, r=Dylan-DPC

Rename CodeMap to SourceMap follow up

See https://github.com/rust-lang/rust/issues/51574
This commit is contained in:
Dylan DPC 2020-02-23 09:57:44 +01:00 committed by GitHub
commit bdd275de2a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 113 additions and 113 deletions

View File

@ -149,7 +149,7 @@ impl<'a> StableHashingContext<'a> {
#[inline] #[inline]
pub fn source_map(&mut self) -> &mut CachingSourceMapView<'a> { pub fn source_map(&mut self) -> &mut CachingSourceMapView<'a> {
match self.caching_source_map { match self.caching_source_map {
Some(ref mut cm) => cm, Some(ref mut sm) => sm,
ref mut none => { ref mut none => {
*none = Some(CachingSourceMapView::new(self.raw_source_map)); *none = Some(CachingSourceMapView::new(self.raw_source_map));
none.as_mut().unwrap() none.as_mut().unwrap()

View File

@ -106,10 +106,10 @@ pub fn report_unstable(
}; };
let msp: MultiSpan = span.into(); let msp: MultiSpan = span.into();
let cm = &sess.parse_sess.source_map(); let sm = &sess.parse_sess.source_map();
let span_key = msp.primary_span().and_then(|sp: Span| { let span_key = msp.primary_span().and_then(|sp: Span| {
if !sp.is_dummy() { if !sp.is_dummy() {
let file = cm.lookup_char_pos(sp.lo()).file; let file = sm.lookup_char_pos(sp.lo()).file;
if file.name.is_macros() { None } else { Some(span) } if file.name.is_macros() { None } else { Some(span) }
} else { } else {
None None

View File

@ -47,15 +47,15 @@ pub struct NoAnn;
impl PpAnn for NoAnn {} impl PpAnn for NoAnn {}
pub struct Comments<'a> { pub struct Comments<'a> {
cm: &'a SourceMap, sm: &'a SourceMap,
comments: Vec<comments::Comment>, comments: Vec<comments::Comment>,
current: usize, current: usize,
} }
impl<'a> Comments<'a> { impl<'a> Comments<'a> {
pub fn new(cm: &'a SourceMap, filename: FileName, input: String) -> Comments<'a> { pub fn new(sm: &'a SourceMap, filename: FileName, input: String) -> Comments<'a> {
let comments = comments::gather_comments(cm, filename, input); let comments = comments::gather_comments(sm, filename, input);
Comments { cm, comments, current: 0 } Comments { sm, comments, current: 0 }
} }
pub fn next(&self) -> Option<comments::Comment> { pub fn next(&self) -> Option<comments::Comment> {
@ -71,8 +71,8 @@ impl<'a> Comments<'a> {
if cmnt.style != comments::Trailing { if cmnt.style != comments::Trailing {
return None; return None;
} }
let span_line = self.cm.lookup_char_pos(span.hi()); let span_line = self.sm.lookup_char_pos(span.hi());
let comment_line = self.cm.lookup_char_pos(cmnt.pos); let comment_line = self.sm.lookup_char_pos(cmnt.pos);
let next = next_pos.unwrap_or_else(|| cmnt.pos + BytePos(1)); let next = next_pos.unwrap_or_else(|| cmnt.pos + BytePos(1));
if span.hi() < cmnt.pos && cmnt.pos < next && span_line.line == comment_line.line { if span.hi() < cmnt.pos && cmnt.pos < next && span_line.line == comment_line.line {
return Some(cmnt); return Some(cmnt);
@ -95,7 +95,7 @@ crate const INDENT_UNIT: usize = 4;
/// Requires you to pass an input filename and reader so that /// Requires you to pass an input filename and reader so that
/// it can scan the input text for comments to copy forward. /// it can scan the input text for comments to copy forward.
pub fn print_crate<'a>( pub fn print_crate<'a>(
cm: &'a SourceMap, sm: &'a SourceMap,
krate: &ast::Crate, krate: &ast::Crate,
filename: FileName, filename: FileName,
input: String, input: String,
@ -106,7 +106,7 @@ pub fn print_crate<'a>(
) -> String { ) -> String {
let mut s = State { let mut s = State {
s: pp::mk_printer(), s: pp::mk_printer(),
comments: Some(Comments::new(cm, filename, input)), comments: Some(Comments::new(sm, filename, input)),
ann, ann,
is_expanded, is_expanded,
}; };
@ -522,8 +522,8 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
self.hardbreak(); self.hardbreak();
} }
} }
if let Some(cm) = self.comments() { if let Some(cmnts) = self.comments() {
cm.current += 1; cmnts.current += 1;
} }
} }

View File

@ -452,8 +452,8 @@ pub fn print_after_hir_lowering<'tcx>(
call_with_pp_support_hir(&s, tcx, move |annotation, krate| { call_with_pp_support_hir(&s, tcx, move |annotation, krate| {
debug!("pretty printing source code {:?}", s); debug!("pretty printing source code {:?}", s);
let sess = annotation.sess(); let sess = annotation.sess();
let cm = sess.source_map(); let sm = sess.source_map();
*out = pprust_hir::print_crate(cm, krate, src_name, src, annotation.pp_ann()) *out = pprust_hir::print_crate(sm, krate, src_name, src, annotation.pp_ann())
}) })
} }

View File

@ -373,13 +373,13 @@ impl DiagnosticSpan {
impl DiagnosticSpanLine { impl DiagnosticSpanLine {
fn line_from_source_file( fn line_from_source_file(
fm: &rustc_span::SourceFile, sf: &rustc_span::SourceFile,
index: usize, index: usize,
h_start: usize, h_start: usize,
h_end: usize, h_end: usize,
) -> DiagnosticSpanLine { ) -> DiagnosticSpanLine {
DiagnosticSpanLine { DiagnosticSpanLine {
text: fm.get_line(index).map_or(String::new(), |l| l.into_owned()), text: sf.get_line(index).map_or(String::new(), |l| l.into_owned()),
highlight_start: h_start, highlight_start: h_start,
highlight_end: h_end, highlight_end: h_end,
} }
@ -392,13 +392,13 @@ impl DiagnosticSpanLine {
je.sm je.sm
.span_to_lines(span) .span_to_lines(span)
.map(|lines| { .map(|lines| {
let fm = &*lines.file; let sf = &*lines.file;
lines lines
.lines .lines
.iter() .iter()
.map(|line| { .map(|line| {
DiagnosticSpanLine::line_from_source_file( DiagnosticSpanLine::line_from_source_file(
fm, sf,
line.line_index, line.line_index,
line.start_col.0 + 1, line.start_col.0 + 1,
line.end_col.0 + 1, line.end_col.0 + 1,

View File

@ -144,7 +144,7 @@ pub struct SubstitutionPart {
impl CodeSuggestion { impl CodeSuggestion {
/// Returns the assembled code suggestions, whether they should be shown with an underline /// Returns the assembled code suggestions, whether they should be shown with an underline
/// and whether the substitution only differs in capitalization. /// and whether the substitution only differs in capitalization.
pub fn splice_lines(&self, cm: &SourceMap) -> Vec<(String, Vec<SubstitutionPart>, bool)> { pub fn splice_lines(&self, sm: &SourceMap) -> Vec<(String, Vec<SubstitutionPart>, bool)> {
use rustc_span::{CharPos, Pos}; use rustc_span::{CharPos, Pos};
fn push_trailing( fn push_trailing(
@ -176,7 +176,7 @@ impl CodeSuggestion {
.filter(|subst| { .filter(|subst| {
// Suggestions coming from macros can have malformed spans. This is a heavy // Suggestions coming from macros can have malformed spans. This is a heavy
// handed approach to avoid ICEs by ignoring the suggestion outright. // handed approach to avoid ICEs by ignoring the suggestion outright.
let invalid = subst.parts.iter().any(|item| cm.is_valid_span(item.span).is_err()); let invalid = subst.parts.iter().any(|item| sm.is_valid_span(item.span).is_err());
if invalid { if invalid {
debug!("splice_lines: suggestion contains an invalid span: {:?}", subst); debug!("splice_lines: suggestion contains an invalid span: {:?}", subst);
} }
@ -193,7 +193,7 @@ impl CodeSuggestion {
let hi = substitution.parts.iter().map(|part| part.span.hi()).max()?; let hi = substitution.parts.iter().map(|part| part.span.hi()).max()?;
let bounding_span = Span::with_root_ctxt(lo, hi); let bounding_span = Span::with_root_ctxt(lo, hi);
// The different spans might belong to different contexts, if so ignore suggestion. // The different spans might belong to different contexts, if so ignore suggestion.
let lines = cm.span_to_lines(bounding_span).ok()?; let lines = sm.span_to_lines(bounding_span).ok()?;
assert!(!lines.lines.is_empty()); assert!(!lines.lines.is_empty());
// To build up the result, we do this for each span: // To build up the result, we do this for each span:
@ -205,36 +205,36 @@ impl CodeSuggestion {
// - splice in the span substitution // - splice in the span substitution
// //
// Finally push the trailing line segment of the last span // Finally push the trailing line segment of the last span
let fm = &lines.file; let sf = &lines.file;
let mut prev_hi = cm.lookup_char_pos(bounding_span.lo()); let mut prev_hi = sm.lookup_char_pos(bounding_span.lo());
prev_hi.col = CharPos::from_usize(0); prev_hi.col = CharPos::from_usize(0);
let mut prev_line = fm.get_line(lines.lines[0].line_index); let mut prev_line = sf.get_line(lines.lines[0].line_index);
let mut buf = String::new(); let mut buf = String::new();
for part in &substitution.parts { for part in &substitution.parts {
let cur_lo = cm.lookup_char_pos(part.span.lo()); let cur_lo = sm.lookup_char_pos(part.span.lo());
if prev_hi.line == cur_lo.line { if prev_hi.line == cur_lo.line {
push_trailing(&mut buf, prev_line.as_ref(), &prev_hi, Some(&cur_lo)); push_trailing(&mut buf, prev_line.as_ref(), &prev_hi, Some(&cur_lo));
} else { } else {
push_trailing(&mut buf, prev_line.as_ref(), &prev_hi, None); push_trailing(&mut buf, prev_line.as_ref(), &prev_hi, None);
// push lines between the previous and current span (if any) // push lines between the previous and current span (if any)
for idx in prev_hi.line..(cur_lo.line - 1) { for idx in prev_hi.line..(cur_lo.line - 1) {
if let Some(line) = fm.get_line(idx) { if let Some(line) = sf.get_line(idx) {
buf.push_str(line.as_ref()); buf.push_str(line.as_ref());
buf.push('\n'); buf.push('\n');
} }
} }
if let Some(cur_line) = fm.get_line(cur_lo.line - 1) { if let Some(cur_line) = sf.get_line(cur_lo.line - 1) {
let end = std::cmp::min(cur_line.len(), cur_lo.col.to_usize()); let end = std::cmp::min(cur_line.len(), cur_lo.col.to_usize());
buf.push_str(&cur_line[..end]); buf.push_str(&cur_line[..end]);
} }
} }
buf.push_str(&part.snippet); buf.push_str(&part.snippet);
prev_hi = cm.lookup_char_pos(part.span.hi()); prev_hi = sm.lookup_char_pos(part.span.hi());
prev_line = fm.get_line(prev_hi.line - 1); prev_line = sf.get_line(prev_hi.line - 1);
} }
let only_capitalization = is_case_difference(cm, &buf, bounding_span); let only_capitalization = is_case_difference(sm, &buf, bounding_span);
// if the replacement already ends with a newline, don't print the next line // if the replacement already ends with a newline, don't print the next line
if !buf.ends_with('\n') { if !buf.ends_with('\n') {
push_trailing(&mut buf, prev_line.as_ref(), &prev_hi, None); push_trailing(&mut buf, prev_line.as_ref(), &prev_hi, None);
@ -363,23 +363,23 @@ impl Handler {
color_config: ColorConfig, color_config: ColorConfig,
can_emit_warnings: bool, can_emit_warnings: bool,
treat_err_as_bug: Option<usize>, treat_err_as_bug: Option<usize>,
cm: Option<Lrc<SourceMap>>, sm: Option<Lrc<SourceMap>>,
) -> Self { ) -> Self {
Self::with_tty_emitter_and_flags( Self::with_tty_emitter_and_flags(
color_config, color_config,
cm, sm,
HandlerFlags { can_emit_warnings, treat_err_as_bug, ..Default::default() }, HandlerFlags { can_emit_warnings, treat_err_as_bug, ..Default::default() },
) )
} }
pub fn with_tty_emitter_and_flags( pub fn with_tty_emitter_and_flags(
color_config: ColorConfig, color_config: ColorConfig,
cm: Option<Lrc<SourceMap>>, sm: Option<Lrc<SourceMap>>,
flags: HandlerFlags, flags: HandlerFlags,
) -> Self { ) -> Self {
let emitter = Box::new(EmitterWriter::stderr( let emitter = Box::new(EmitterWriter::stderr(
color_config, color_config,
cm, sm,
false, false,
false, false,
None, None,

View File

@ -140,13 +140,13 @@ pub const INDENT_UNIT: usize = 4;
/// Requires you to pass an input filename and reader so that /// Requires you to pass an input filename and reader so that
/// it can scan the input text for comments to copy forward. /// it can scan the input text for comments to copy forward.
pub fn print_crate<'a>( pub fn print_crate<'a>(
cm: &'a SourceMap, sm: &'a SourceMap,
krate: &hir::Crate<'_>, krate: &hir::Crate<'_>,
filename: FileName, filename: FileName,
input: String, input: String,
ann: &'a dyn PpAnn, ann: &'a dyn PpAnn,
) -> String { ) -> String {
let mut s = State::new_from_input(cm, filename, input, ann); let mut s = State::new_from_input(sm, filename, input, ann);
// When printing the AST, we sometimes need to inject `#[no_std]` here. // When printing the AST, we sometimes need to inject `#[no_std]` here.
// Since you can't compile the HIR, it's not necessary. // Since you can't compile the HIR, it's not necessary.
@ -158,12 +158,12 @@ pub fn print_crate<'a>(
impl<'a> State<'a> { impl<'a> State<'a> {
pub fn new_from_input( pub fn new_from_input(
cm: &'a SourceMap, sm: &'a SourceMap,
filename: FileName, filename: FileName,
input: String, input: String,
ann: &'a dyn PpAnn, ann: &'a dyn PpAnn,
) -> State<'a> { ) -> State<'a> {
State { s: pp::mk_printer(), comments: Some(Comments::new(cm, filename, input)), ann } State { s: pp::mk_printer(), comments: Some(Comments::new(sm, filename, input)), ann }
} }
} }

View File

@ -194,7 +194,7 @@ fn msg_span_from_early_bound_and_free_regions(
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
region: ty::Region<'tcx>, region: ty::Region<'tcx>,
) -> (String, Option<Span>) { ) -> (String, Option<Span>) {
let cm = tcx.sess.source_map(); let sm = tcx.sess.source_map();
let scope = region.free_region_binding_scope(tcx); let scope = region.free_region_binding_scope(tcx);
let node = tcx.hir().as_local_hir_id(scope).unwrap_or(hir::DUMMY_HIR_ID); 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(
}; };
let (prefix, span) = match *region { let (prefix, span) = match *region {
ty::ReEarlyBound(ref br) => { ty::ReEarlyBound(ref br) => {
let mut sp = cm.def_span(tcx.hir().span(node)); let mut sp = sm.def_span(tcx.hir().span(node));
if let Some(param) = if let Some(param) =
tcx.hir().get_generics(scope).and_then(|generics| generics.get_named(br.name)) tcx.hir().get_generics(scope).and_then(|generics| generics.get_named(br.name))
{ {
@ -216,7 +216,7 @@ fn msg_span_from_early_bound_and_free_regions(
(format!("the lifetime `{}` as defined on", br.name), sp) (format!("the lifetime `{}` as defined on", br.name), sp)
} }
ty::ReFree(ty::FreeRegion { bound_region: ty::BoundRegion::BrNamed(_, name), .. }) => { ty::ReFree(ty::FreeRegion { bound_region: ty::BoundRegion::BrNamed(_, name), .. }) => {
let mut sp = cm.def_span(tcx.hir().span(node)); let mut sp = sm.def_span(tcx.hir().span(node));
if let Some(param) = if let Some(param) =
tcx.hir().get_generics(scope).and_then(|generics| generics.get_named(name)) tcx.hir().get_generics(scope).and_then(|generics| generics.get_named(name))
{ {
@ -230,7 +230,7 @@ fn msg_span_from_early_bound_and_free_regions(
} }
_ => ( _ => (
format!("the lifetime `{}` as defined on", region), format!("the lifetime `{}` as defined on", region),
cm.def_span(tcx.hir().span(node)), sm.def_span(tcx.hir().span(node)),
), ),
}, },
_ => bug!(), _ => bug!(),

View File

@ -1625,10 +1625,10 @@ impl<'a> Parser<'a> {
let hi = self.token.span; let hi = self.token.span;
if require_comma { if require_comma {
let cm = self.sess.source_map(); let sm = self.sess.source_map();
self.expect_one_of(&[token::Comma], &[token::CloseDelim(token::Brace)]).map_err( self.expect_one_of(&[token::Comma], &[token::CloseDelim(token::Brace)]).map_err(
|mut err| { |mut err| {
match (cm.span_to_lines(expr.span), cm.span_to_lines(arm_start_span)) { match (sm.span_to_lines(expr.span), sm.span_to_lines(arm_start_span)) {
(Ok(ref expr_lines), Ok(ref arm_start_lines)) (Ok(ref expr_lines), Ok(ref arm_start_lines))
if arm_start_lines.lines[0].end_col == expr_lines.lines[0].end_col if arm_start_lines.lines[0].end_col == expr_lines.lines[0].end_col
&& expr_lines.lines.len() == 2 && expr_lines.lines.len() == 2

View File

@ -144,11 +144,11 @@ enum LiveNodeKind {
} }
fn live_node_kind_to_string(lnk: LiveNodeKind, tcx: TyCtxt<'_>) -> String { fn live_node_kind_to_string(lnk: LiveNodeKind, tcx: TyCtxt<'_>) -> String {
let cm = tcx.sess.source_map(); let sm = tcx.sess.source_map();
match lnk { match lnk {
UpvarNode(s) => format!("Upvar node [{}]", cm.span_to_string(s)), UpvarNode(s) => format!("Upvar node [{}]", sm.span_to_string(s)),
ExprNode(s) => format!("Expr node [{}]", cm.span_to_string(s)), ExprNode(s) => format!("Expr node [{}]", sm.span_to_string(s)),
VarDefNode(s) => format!("Var def node [{}]", cm.span_to_string(s)), VarDefNode(s) => format!("Var def node [{}]", sm.span_to_string(s)),
ExitNode => "Exit node".to_owned(), ExitNode => "Exit node".to_owned(),
} }
} }

View File

@ -90,9 +90,9 @@ impl<'tcx> Into<MissingLifetimeSpot<'tcx>> for &'tcx hir::Generics<'tcx> {
/// *Attention*: the method used is very fragile since it essentially duplicates the work of the /// *Attention*: the method used is very fragile since it essentially duplicates the work of the
/// parser. If you need to use this function or something similar, please consider updating the /// parser. If you need to use this function or something similar, please consider updating the
/// `source_map` functions and this function to something more robust. /// `source_map` functions and this function to something more robust.
fn reduce_impl_span_to_impl_keyword(cm: &SourceMap, impl_span: Span) -> Span { fn reduce_impl_span_to_impl_keyword(sm: &SourceMap, impl_span: Span) -> Span {
let impl_span = cm.span_until_char(impl_span, '<'); let impl_span = sm.span_until_char(impl_span, '<');
let impl_span = cm.span_until_whitespace(impl_span); let impl_span = sm.span_until_whitespace(impl_span);
impl_span impl_span
} }
@ -136,14 +136,14 @@ impl<'a> Resolver<'a> {
); );
err.span_label(span, format!("use of generic parameter from outer function")); err.span_label(span, format!("use of generic parameter from outer function"));
let cm = self.session.source_map(); let sm = self.session.source_map();
match outer_res { match outer_res {
Res::SelfTy(maybe_trait_defid, maybe_impl_defid) => { Res::SelfTy(maybe_trait_defid, maybe_impl_defid) => {
if let Some(impl_span) = if let Some(impl_span) =
maybe_impl_defid.and_then(|def_id| self.definitions.opt_span(def_id)) maybe_impl_defid.and_then(|def_id| self.definitions.opt_span(def_id))
{ {
err.span_label( err.span_label(
reduce_impl_span_to_impl_keyword(cm, impl_span), reduce_impl_span_to_impl_keyword(sm, impl_span),
"`Self` type implicitly declared here, by this `impl`", "`Self` type implicitly declared here, by this `impl`",
); );
} }
@ -180,7 +180,7 @@ impl<'a> Resolver<'a> {
// Try to retrieve the span of the function signature and generate a new // Try to retrieve the span of the function signature and generate a new
// message with a local type or const parameter. // message with a local type or const parameter.
let sugg_msg = &format!("try using a local generic parameter instead"); let sugg_msg = &format!("try using a local generic parameter instead");
if let Some((sugg_span, snippet)) = cm.generate_local_type_param_snippet(span) { if let Some((sugg_span, snippet)) = sm.generate_local_type_param_snippet(span) {
// Suggest the modification to the user // Suggest the modification to the user
err.span_suggestion( err.span_suggestion(
sugg_span, sugg_span,
@ -188,7 +188,7 @@ impl<'a> Resolver<'a> {
snippet, snippet,
Applicability::MachineApplicable, Applicability::MachineApplicable,
); );
} else if let Some(sp) = cm.generate_fn_name_span(span) { } else if let Some(sp) = sm.generate_fn_name_span(span) {
err.span_label( err.span_label(
sp, sp,
format!("try adding a local generic parameter in this method instead"), format!("try adding a local generic parameter in this method instead"),

View File

@ -725,21 +725,21 @@ impl<'a> LateResolutionVisitor<'a, '_, '_> {
/// Only used in a specific case of type ascription suggestions /// Only used in a specific case of type ascription suggestions
fn get_colon_suggestion_span(&self, start: Span) -> Span { fn get_colon_suggestion_span(&self, start: Span) -> Span {
let cm = self.r.session.source_map(); let sm = self.r.session.source_map();
start.to(cm.next_point(start)) start.to(sm.next_point(start))
} }
fn type_ascription_suggestion(&self, err: &mut DiagnosticBuilder<'_>, base_span: Span) { fn type_ascription_suggestion(&self, err: &mut DiagnosticBuilder<'_>, base_span: Span) {
let cm = self.r.session.source_map(); let sm = self.r.session.source_map();
let base_snippet = cm.span_to_snippet(base_span); let base_snippet = sm.span_to_snippet(base_span);
if let Some(sp) = self.diagnostic_metadata.current_type_ascription.last() { if let Some(sp) = self.diagnostic_metadata.current_type_ascription.last() {
let mut sp = *sp; let mut sp = *sp;
loop { loop {
// Try to find the `:`; bail on first non-':' / non-whitespace. // Try to find the `:`; bail on first non-':' / non-whitespace.
sp = cm.next_point(sp); sp = sm.next_point(sp);
if let Ok(snippet) = cm.span_to_snippet(sp.to(cm.next_point(sp))) { if let Ok(snippet) = sm.span_to_snippet(sp.to(sm.next_point(sp))) {
let line_sp = cm.lookup_char_pos(sp.hi()).line; let line_sp = sm.lookup_char_pos(sp.hi()).line;
let line_base_sp = cm.lookup_char_pos(base_span.lo()).line; let line_base_sp = sm.lookup_char_pos(base_span.lo()).line;
if snippet == ":" { if snippet == ":" {
let mut show_label = true; let mut show_label = true;
if line_sp != line_base_sp { if line_sp != line_base_sp {
@ -753,7 +753,7 @@ impl<'a> LateResolutionVisitor<'a, '_, '_> {
let colon_sp = self.get_colon_suggestion_span(sp); let colon_sp = self.get_colon_suggestion_span(sp);
let after_colon_sp = let after_colon_sp =
self.get_colon_suggestion_span(colon_sp.shrink_to_hi()); self.get_colon_suggestion_span(colon_sp.shrink_to_hi());
if !cm if !sm
.span_to_snippet(after_colon_sp) .span_to_snippet(after_colon_sp)
.map(|s| s == " ") .map(|s| s == " ")
.unwrap_or(false) .unwrap_or(false)
@ -770,8 +770,8 @@ impl<'a> LateResolutionVisitor<'a, '_, '_> {
let mut sp = after_colon_sp; let mut sp = after_colon_sp;
for _ in 0..100 { for _ in 0..100 {
// Try to find an assignment // Try to find an assignment
sp = cm.next_point(sp); sp = sm.next_point(sp);
let snippet = cm.span_to_snippet(sp.to(cm.next_point(sp))); let snippet = sm.span_to_snippet(sp.to(sm.next_point(sp)));
match snippet { match snippet {
Ok(ref x) if x.as_str() == "=" => { Ok(ref x) if x.as_str() == "=" => {
err.span_suggestion( err.span_suggestion(

View File

@ -1233,8 +1233,8 @@ impl<'l, 'tcx> Visitor<'l> for DumpVisitor<'l, 'tcx> {
let qualname = let qualname =
format!("::{}", self.tcx.def_path_str(self.tcx.hir().local_def_id_from_node_id(id))); format!("::{}", self.tcx.def_path_str(self.tcx.hir().local_def_id_from_node_id(id)));
let cm = self.tcx.sess.source_map(); let sm = self.tcx.sess.source_map();
let filename = cm.span_to_filename(span); let filename = sm.span_to_filename(span);
let data_id = id_from_node_id(id, &self.save_ctxt); let data_id = id_from_node_id(id, &self.save_ctxt);
let children = m.items.iter().map(|i| id_from_node_id(i.id, &self.save_ctxt)).collect(); let children = m.items.iter().map(|i| id_from_node_id(i.id, &self.save_ctxt)).collect();
let span = self.span_from_span(span); let span = self.span_from_span(span);

View File

@ -66,9 +66,9 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
fn span_from_span(&self, span: Span) -> SpanData { fn span_from_span(&self, span: Span) -> SpanData {
use rls_span::{Column, Row}; use rls_span::{Column, Row};
let cm = self.tcx.sess.source_map(); let sm = self.tcx.sess.source_map();
let start = cm.lookup_char_pos(span.lo()); let start = sm.lookup_char_pos(span.lo());
let end = cm.lookup_char_pos(span.hi()); let end = sm.lookup_char_pos(span.hi());
SpanData { SpanData {
file_name: start.file.name.to_string().into(), file_name: start.file.name.to_string().into(),
@ -258,8 +258,8 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
self.tcx.def_path_str(self.tcx.hir().local_def_id_from_node_id(item.id)) self.tcx.def_path_str(self.tcx.hir().local_def_id_from_node_id(item.id))
); );
let cm = self.tcx.sess.source_map(); let sm = self.tcx.sess.source_map();
let filename = cm.span_to_filename(m.inner); let filename = sm.span_to_filename(m.inner);
filter!(self.span_utils, item.ident.span); filter!(self.span_utils, item.ident.span);

View File

@ -124,9 +124,9 @@ pub struct ParseSess {
impl ParseSess { impl ParseSess {
pub fn new(file_path_mapping: FilePathMapping) -> Self { pub fn new(file_path_mapping: FilePathMapping) -> Self {
let cm = Lrc::new(SourceMap::new(file_path_mapping)); let sm = Lrc::new(SourceMap::new(file_path_mapping));
let handler = Handler::with_tty_emitter(ColorConfig::Auto, true, None, Some(cm.clone())); let handler = Handler::with_tty_emitter(ColorConfig::Auto, true, None, Some(sm.clone()));
ParseSess::with_span_handler(handler, cm) ParseSess::with_span_handler(handler, sm)
} }
pub fn with_span_handler(handler: Handler, source_map: Lrc<SourceMap>) -> Self { pub fn with_span_handler(handler: Handler, source_map: Lrc<SourceMap>) -> Self {
@ -148,9 +148,9 @@ impl ParseSess {
} }
pub fn with_silent_emitter() -> Self { pub fn with_silent_emitter() -> Self {
let cm = Lrc::new(SourceMap::new(FilePathMapping::empty())); let sm = Lrc::new(SourceMap::new(FilePathMapping::empty()));
let handler = Handler::with_emitter(false, None, Box::new(SilentEmitter)); let handler = Handler::with_emitter(false, None, Box::new(SilentEmitter));
ParseSess::with_span_handler(handler, cm) ParseSess::with_span_handler(handler, sm)
} }
#[inline] #[inline]

View File

@ -13,14 +13,14 @@ struct CacheEntry {
} }
#[derive(Clone)] #[derive(Clone)]
pub struct CachingSourceMapView<'cm> { pub struct CachingSourceMapView<'sm> {
source_map: &'cm SourceMap, source_map: &'sm SourceMap,
line_cache: [CacheEntry; 3], line_cache: [CacheEntry; 3],
time_stamp: usize, time_stamp: usize,
} }
impl<'cm> CachingSourceMapView<'cm> { impl<'sm> CachingSourceMapView<'sm> {
pub fn new(source_map: &'cm SourceMap) -> CachingSourceMapView<'cm> { pub fn new(source_map: &'sm SourceMap) -> CachingSourceMapView<'sm> {
let files = source_map.files(); let files = source_map.files();
let first_file = files[0].clone(); let first_file = files[0].clone();
let entry = CacheEntry { let entry = CacheEntry {

View File

@ -324,13 +324,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
hir_id: hir::HirId, hir_id: hir::HirId,
sp: Span, sp: Span,
) -> bool { ) -> bool {
let cm = self.sess().source_map(); let sm = self.sess().source_map();
let parent_id = self.tcx.hir().get_parent_node(hir_id); let parent_id = self.tcx.hir().get_parent_node(hir_id);
if let Some(parent) = self.tcx.hir().find(parent_id) { if let Some(parent) = self.tcx.hir().find(parent_id) {
// Account for fields // Account for fields
if let Node::Expr(hir::Expr { kind: hir::ExprKind::Struct(_, fields, ..), .. }) = parent if let Node::Expr(hir::Expr { kind: hir::ExprKind::Struct(_, fields, ..), .. }) = parent
{ {
if let Ok(src) = cm.span_to_snippet(sp) { if let Ok(src) = sm.span_to_snippet(sp) {
for field in *fields { for field in *fields {
if field.ident.as_str() == src && field.is_shorthand { if field.ident.as_str() == src && field.is_shorthand {
return true; return true;
@ -364,9 +364,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
checked_ty: Ty<'tcx>, checked_ty: Ty<'tcx>,
expected: Ty<'tcx>, expected: Ty<'tcx>,
) -> Option<(Span, &'static str, String)> { ) -> Option<(Span, &'static str, String)> {
let cm = self.sess().source_map(); let sm = self.sess().source_map();
let sp = expr.span; let sp = expr.span;
if !cm.span_to_filename(sp).is_real() { if !sm.span_to_filename(sp).is_real() {
// Ignore if span is from within a macro #41858, #58298. We previously used the macro // Ignore if span is from within a macro #41858, #58298. We previously used the macro
// call span, but that breaks down when the type error comes from multiple calls down. // call span, but that breaks down when the type error comes from multiple calls down.
return None; return None;
@ -388,7 +388,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if arr == self.tcx.types.u8 => if arr == self.tcx.types.u8 =>
{ {
if let hir::ExprKind::Lit(_) = expr.kind { if let hir::ExprKind::Lit(_) = expr.kind {
if let Ok(src) = cm.span_to_snippet(sp) { if let Ok(src) = sm.span_to_snippet(sp) {
if src.starts_with("b\"") { if src.starts_with("b\"") {
return Some(( return Some((
sp, sp,
@ -403,7 +403,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if arr == self.tcx.types.u8 => if arr == self.tcx.types.u8 =>
{ {
if let hir::ExprKind::Lit(_) = expr.kind { if let hir::ExprKind::Lit(_) = expr.kind {
if let Ok(src) = cm.span_to_snippet(sp) { if let Ok(src) = sm.span_to_snippet(sp) {
if src.starts_with("\"") { if src.starts_with("\"") {
return Some(( return Some((
sp, sp,
@ -450,7 +450,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
sugg_sp = arg.span; sugg_sp = arg.span;
} }
} }
if let Ok(src) = cm.span_to_snippet(sugg_sp) { if let Ok(src) = sm.span_to_snippet(sugg_sp) {
let needs_parens = match expr.kind { let needs_parens = match expr.kind {
// parenthesize if needed (Issue #46756) // parenthesize if needed (Issue #46756)
hir::ExprKind::Cast(_, _) | hir::ExprKind::Binary(_, _, _) => true, hir::ExprKind::Cast(_, _) | hir::ExprKind::Binary(_, _, _) => true,
@ -480,7 +480,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// | | // | |
// consider dereferencing here: `*opt` | // consider dereferencing here: `*opt` |
// expected mutable reference, found enum `Option` // expected mutable reference, found enum `Option`
if let Ok(src) = cm.span_to_snippet(left_expr.span) { if let Ok(src) = sm.span_to_snippet(left_expr.span) {
return Some(( return Some((
left_expr.span, left_expr.span,
"consider dereferencing here to assign to the mutable \ "consider dereferencing here to assign to the mutable \
@ -516,8 +516,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
{ {
// We have `&T`, check if what was expected was `T`. If so, // We have `&T`, check if what was expected was `T`. If so,
// we may want to suggest removing a `&`. // we may want to suggest removing a `&`.
if !cm.span_to_filename(expr.span).is_real() { if !sm.span_to_filename(expr.span).is_real() {
if let Ok(code) = cm.span_to_snippet(sp) { if let Ok(code) = sm.span_to_snippet(sp) {
if code.chars().next() == Some('&') { if code.chars().next() == Some('&') {
return Some(( return Some((
sp, sp,
@ -528,7 +528,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
return None; return None;
} }
if let Ok(code) = cm.span_to_snippet(expr.span) { if let Ok(code) = sm.span_to_snippet(expr.span) {
return Some((sp, "consider removing the borrow", code)); return Some((sp, "consider removing the borrow", code));
} }
} }
@ -562,7 +562,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let is_copy = self.infcx.type_is_copy_modulo_regions(self.param_env, expected, sp); let is_copy = self.infcx.type_is_copy_modulo_regions(self.param_env, expected, sp);
if is_copy && impls_deref { if is_copy && impls_deref {
if let Ok(code) = cm.span_to_snippet(sp) { if let Ok(code) = sm.span_to_snippet(sp) {
let message = if checked_ty.is_region_ptr() { let message = if checked_ty.is_region_ptr() {
"consider dereferencing the borrow" "consider dereferencing the borrow"
} else { } else {

View File

@ -33,8 +33,8 @@ impl ItemLikeVisitor<'v> for OrphanChecker<'tcx> {
); );
let trait_ref = self.tcx.impl_trait_ref(def_id).unwrap(); let trait_ref = self.tcx.impl_trait_ref(def_id).unwrap();
let trait_def_id = trait_ref.def_id; let trait_def_id = trait_ref.def_id;
let cm = self.tcx.sess.source_map(); let sm = self.tcx.sess.source_map();
let sp = cm.def_span(item.span); let sp = sm.def_span(item.span);
match traits::orphan_check(self.tcx, def_id) { match traits::orphan_check(self.tcx, def_id) {
Ok(()) => {} Ok(()) => {}
Err(traits::OrphanCheckErr::NonLocalInputType(tys)) => { Err(traits::OrphanCheckErr::NonLocalInputType(tys)) => {

View File

@ -263,9 +263,9 @@ impl Clean<Item> for doctree::Module<'_> {
// determine if we should display the inner contents or // determine if we should display the inner contents or
// the outer `mod` item for the source code. // the outer `mod` item for the source code.
let whence = { let whence = {
let cm = cx.sess().source_map(); let sm = cx.sess().source_map();
let outer = cm.lookup_char_pos(self.where_outer.lo()); let outer = sm.lookup_char_pos(self.where_outer.lo());
let inner = cm.lookup_char_pos(self.where_inner.lo()); let inner = sm.lookup_char_pos(self.where_inner.lo());
if outer.file.start_pos == inner.file.start_pos { if outer.file.start_pos == inner.file.start_pos {
// mod foo { ... } // mod foo { ... }
self.where_outer self.where_outer
@ -1917,10 +1917,10 @@ impl Clean<Span> for rustc_span::Span {
return Span::empty(); return Span::empty();
} }
let cm = cx.sess().source_map(); let sm = cx.sess().source_map();
let filename = cm.span_to_filename(*self); let filename = sm.span_to_filename(*self);
let lo = cm.lookup_char_pos(self.lo()); let lo = sm.lookup_char_pos(self.lo());
let hi = cm.lookup_char_pos(self.hi()); let hi = sm.lookup_char_pos(self.hi());
Span { Span {
filename, filename,
loline: lo.line, loline: lo.line,

View File

@ -177,7 +177,7 @@ pub fn new_handler(
Box::new( Box::new(
EmitterWriter::stderr( EmitterWriter::stderr(
color_config, color_config,
source_map.map(|cm| cm as _), source_map.map(|sm| sm as _),
short, short,
debugging_opts.teach, debugging_opts.teach,
debugging_opts.terminal_width, debugging_opts.terminal_width,

View File

@ -38,11 +38,11 @@ pub fn render_with_highlighting(
} }
let sess = ParseSess::with_silent_emitter(); let sess = ParseSess::with_silent_emitter();
let fm = sess let sf = sess
.source_map() .source_map()
.new_source_file(FileName::Custom(String::from("rustdoc-highlighting")), src.to_owned()); .new_source_file(FileName::Custom(String::from("rustdoc-highlighting")), src.to_owned());
let highlight_result = rustc_driver::catch_fatal_errors(|| { let highlight_result = rustc_driver::catch_fatal_errors(|| {
let lexer = lexer::StringReader::new(&sess, fm, None); let lexer = lexer::StringReader::new(&sess, sf, None);
let mut classifier = Classifier::new(lexer, sess.source_map()); let mut classifier = Classifier::new(lexer, sess.source_map());
let mut highlighted_source = vec![]; let mut highlighted_source = vec![];

View File

@ -32,9 +32,9 @@ impl<'a, 'tcx> SyntaxChecker<'a, 'tcx> {
let emitter = BufferEmitter { messages: Lrc::clone(&buffered_messages) }; let emitter = BufferEmitter { messages: Lrc::clone(&buffered_messages) };
let cm = Lrc::new(SourceMap::new(FilePathMapping::empty())); let sm = Lrc::new(SourceMap::new(FilePathMapping::empty()));
let handler = Handler::with_emitter(false, None, Box::new(emitter)); let handler = Handler::with_emitter(false, None, Box::new(emitter));
let sess = ParseSess::with_span_handler(handler, cm); let sess = ParseSess::with_span_handler(handler, sm);
let source_file = sess.source_map().new_source_file( let source_file = sess.source_map().new_source_file(
FileName::Custom(String::from("doctest")), FileName::Custom(String::from("doctest")),
dox[code_block.code].to_owned(), dox[code_block.code].to_owned(),

View File

@ -402,12 +402,12 @@ pub fn make_test(
// Any errors in parsing should also appear when the doctest is compiled for real, so just // Any errors in parsing should also appear when the doctest is compiled for real, so just
// send all the errors that libsyntax emits directly into a `Sink` instead of stderr. // send all the errors that libsyntax emits directly into a `Sink` instead of stderr.
let cm = Lrc::new(SourceMap::new(FilePathMapping::empty())); let sm = Lrc::new(SourceMap::new(FilePathMapping::empty()));
let emitter = let emitter =
EmitterWriter::new(box io::sink(), None, false, false, false, None, false); EmitterWriter::new(box io::sink(), None, false, false, false, None, false);
// FIXME(misdreavus): pass `-Z treat-err-as-bug` to the doctest parser // FIXME(misdreavus): pass `-Z treat-err-as-bug` to the doctest parser
let handler = Handler::with_emitter(false, None, box emitter); let handler = Handler::with_emitter(false, None, box emitter);
let sess = ParseSess::with_span_handler(handler, cm); let sess = ParseSess::with_span_handler(handler, sm);
let mut found_main = false; let mut found_main = false;
let mut found_extern_crate = cratename.is_none(); let mut found_extern_crate = cratename.is_none();

View File

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