Skip to content

Commit

Permalink
Auto merge of #69393 - Dylan-DPC:rollup-rxbd1zg, r=Dylan-DPC
Browse files Browse the repository at this point in the history
Rollup of 5 pull requests

Successful merges:

 - #69336 (Do not ping the infrastructure team on toolstate changes)
 - #69351 (Improve external MinGW detection)
 - #69361 (parse: allow `type Foo: Ord` syntactically)
 - #69375 (Rename CodeMap to SourceMap follow up)
 - #69376 (parser: Cleanup `Parser::bump_with` and its uses)

Failed merges:

r? @ghost
  • Loading branch information
bors committed Feb 23, 2020
2 parents b1f395d + d6414f5 commit 6d0e58b
Show file tree
Hide file tree
Showing 42 changed files with 357 additions and 301 deletions.
2 changes: 1 addition & 1 deletion src/librustc/ich/hcx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ impl<'a> StableHashingContext<'a> {
#[inline]
pub fn source_map(&mut self) -> &mut CachingSourceMapView<'a> {
match self.caching_source_map {
Some(ref mut cm) => cm,
Some(ref mut sm) => sm,
ref mut none => {
*none = Some(CachingSourceMapView::new(self.raw_source_map));
none.as_mut().unwrap()
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ pub fn report_unstable(
};

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| {
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) }
} else {
None
Expand Down
18 changes: 9 additions & 9 deletions src/librustc_ast_lowering/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,28 +297,28 @@ impl<'hir> LoweringContext<'_, 'hir> {
ItemKind::Mod(ref m) => hir::ItemKind::Mod(self.lower_mod(m)),
ItemKind::ForeignMod(ref nm) => hir::ItemKind::ForeignMod(self.lower_foreign_mod(nm)),
ItemKind::GlobalAsm(ref ga) => hir::ItemKind::GlobalAsm(self.lower_global_asm(ga)),
ItemKind::TyAlias(ref ty, ref generics) => match ty.kind.opaque_top_hack() {
ItemKind::TyAlias(ref generics, _, Some(ref ty)) => match ty.kind.opaque_top_hack() {
None => {
let ty = self.lower_ty(ty, ImplTraitContext::disallowed());
let generics = self.lower_generics(generics, ImplTraitContext::disallowed());
hir::ItemKind::TyAlias(ty, generics)
}
Some(bounds) => {
let ctx = || ImplTraitContext::OpaqueTy(None, hir::OpaqueTyOrigin::Misc);
let ty = hir::OpaqueTy {
generics: self.lower_generics(
generics,
ImplTraitContext::OpaqueTy(None, hir::OpaqueTyOrigin::Misc),
),
bounds: self.lower_param_bounds(
bounds,
ImplTraitContext::OpaqueTy(None, hir::OpaqueTyOrigin::Misc),
),
generics: self.lower_generics(generics, ctx()),
bounds: self.lower_param_bounds(bounds, ctx()),
impl_trait_fn: None,
origin: hir::OpaqueTyOrigin::TypeAlias,
};
hir::ItemKind::OpaqueTy(ty)
}
},
ItemKind::TyAlias(ref generics, _, None) => {
let ty = self.arena.alloc(self.ty(span, hir::TyKind::Err));
let generics = self.lower_generics(generics, ImplTraitContext::disallowed());
hir::ItemKind::TyAlias(ty, generics)
}
ItemKind::Enum(ref enum_definition, ref generics) => hir::ItemKind::Enum(
hir::EnumDef {
variants: self.arena.alloc_from_iter(
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_ast_lowering/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
ItemKind::Struct(_, ref generics)
| ItemKind::Union(_, ref generics)
| ItemKind::Enum(_, ref generics)
| ItemKind::TyAlias(_, ref generics)
| ItemKind::TyAlias(ref generics, ..)
| ItemKind::Trait(_, _, ref generics, ..) => {
let def_id = self.lctx.resolver.definitions().local_def_id(item.id);
let count = generics
Expand Down
7 changes: 7 additions & 0 deletions src/librustc_ast_passes/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,13 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
let msg = "free static item without body";
self.error_item_without_body(item.span, "static", msg, " = <expr>;");
}
ItemKind::TyAlias(_, ref bounds, ref body) => {
if body.is_none() {
let msg = "free type alias without body";
self.error_item_without_body(item.span, "type", msg, " = <type>;");
}
self.check_type_no_bounds(bounds, "this context");
}
_ => {}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_ast_passes/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
gate_feature_post!(&self, decl_macro, i.span, msg);
}

ast::ItemKind::TyAlias(ref ty, ..) => self.check_impl_trait(&ty),
ast::ItemKind::TyAlias(_, _, Some(ref ty)) => self.check_impl_trait(&ty),

_ => {}
}
Expand Down
36 changes: 14 additions & 22 deletions src/librustc_ast_pretty/pprust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ pub struct NoAnn;
impl PpAnn for NoAnn {}

pub struct Comments<'a> {
cm: &'a SourceMap,
sm: &'a SourceMap,
comments: Vec<comments::Comment>,
current: usize,
}

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

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

Expand Down Expand Up @@ -1185,18 +1185,10 @@ impl<'a> State<'a> {
self.s.word(ga.asm.to_string());
self.end();
}
ast::ItemKind::TyAlias(ref ty, ref generics) => {
self.head(visibility_qualified(&item.vis, "type"));
self.print_ident(item.ident);
self.print_generic_params(&generics.params);
self.end(); // end the inner ibox

self.print_where_clause(&generics.where_clause);
self.s.space();
self.word_space("=");
self.print_type(ty);
self.s.word(";");
self.end(); // end the outer ibox
ast::ItemKind::TyAlias(ref generics, ref bounds, ref ty) => {
let def = ast::Defaultness::Final;
let ty = ty.as_deref();
self.print_associated_type(item.ident, generics, bounds, ty, &item.vis, def);
}
ast::ItemKind::Enum(ref enum_definition, ref params) => {
self.print_enum_def(enum_definition, params, item.ident, item.span, &item.vis);
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_driver/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,8 +452,8 @@ pub fn print_after_hir_lowering<'tcx>(
call_with_pp_support_hir(&s, tcx, move |annotation, krate| {
debug!("pretty printing source code {:?}", s);
let sess = annotation.sess();
let cm = sess.source_map();
*out = pprust_hir::print_crate(cm, krate, src_name, src, annotation.pp_ann())
let sm = sess.source_map();
*out = pprust_hir::print_crate(sm, krate, src_name, src, annotation.pp_ann())
})
}

Expand Down
8 changes: 4 additions & 4 deletions src/librustc_errors/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,13 +373,13 @@ impl DiagnosticSpan {

impl DiagnosticSpanLine {
fn line_from_source_file(
fm: &rustc_span::SourceFile,
sf: &rustc_span::SourceFile,
index: usize,
h_start: usize,
h_end: usize,
) -> 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_end: h_end,
}
Expand All @@ -392,13 +392,13 @@ impl DiagnosticSpanLine {
je.sm
.span_to_lines(span)
.map(|lines| {
let fm = &*lines.file;
let sf = &*lines.file;
lines
.lines
.iter()
.map(|line| {
DiagnosticSpanLine::line_from_source_file(
fm,
sf,
line.line_index,
line.start_col.0 + 1,
line.end_col.0 + 1,
Expand Down
32 changes: 16 additions & 16 deletions src/librustc_errors/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ pub struct SubstitutionPart {
impl CodeSuggestion {
/// Returns the assembled code suggestions, whether they should be shown with an underline
/// 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};

fn push_trailing(
Expand Down Expand Up @@ -176,7 +176,7 @@ impl CodeSuggestion {
.filter(|subst| {
// Suggestions coming from macros can have malformed spans. This is a heavy
// 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 {
debug!("splice_lines: suggestion contains an invalid span: {:?}", subst);
}
Expand All @@ -193,7 +193,7 @@ impl CodeSuggestion {
let hi = substitution.parts.iter().map(|part| part.span.hi()).max()?;
let bounding_span = Span::with_root_ctxt(lo, hi);
// 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());

// To build up the result, we do this for each span:
Expand All @@ -205,36 +205,36 @@ impl CodeSuggestion {
// - splice in the span substitution
//
// Finally push the trailing line segment of the last span
let fm = &lines.file;
let mut prev_hi = cm.lookup_char_pos(bounding_span.lo());
let sf = &lines.file;
let mut prev_hi = sm.lookup_char_pos(bounding_span.lo());
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();

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 {
push_trailing(&mut buf, prev_line.as_ref(), &prev_hi, Some(&cur_lo));
} else {
push_trailing(&mut buf, prev_line.as_ref(), &prev_hi, None);
// push lines between the previous and current span (if any)
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('\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());
buf.push_str(&cur_line[..end]);
}
}
buf.push_str(&part.snippet);
prev_hi = cm.lookup_char_pos(part.span.hi());
prev_line = fm.get_line(prev_hi.line - 1);
prev_hi = sm.lookup_char_pos(part.span.hi());
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 !buf.ends_with('\n') {
push_trailing(&mut buf, prev_line.as_ref(), &prev_hi, None);
Expand Down Expand Up @@ -363,23 +363,23 @@ impl Handler {
color_config: ColorConfig,
can_emit_warnings: bool,
treat_err_as_bug: Option<usize>,
cm: Option<Lrc<SourceMap>>,
sm: Option<Lrc<SourceMap>>,
) -> Self {
Self::with_tty_emitter_and_flags(
color_config,
cm,
sm,
HandlerFlags { can_emit_warnings, treat_err_as_bug, ..Default::default() },
)
}

pub fn with_tty_emitter_and_flags(
color_config: ColorConfig,
cm: Option<Lrc<SourceMap>>,
sm: Option<Lrc<SourceMap>>,
flags: HandlerFlags,
) -> Self {
let emitter = Box::new(EmitterWriter::stderr(
color_config,
cm,
sm,
false,
false,
None,
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_hir/print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,13 @@ pub const INDENT_UNIT: usize = 4;
/// Requires you to pass an input filename and reader so that
/// it can scan the input text for comments to copy forward.
pub fn print_crate<'a>(
cm: &'a SourceMap,
sm: &'a SourceMap,
krate: &hir::Crate<'_>,
filename: FileName,
input: String,
ann: &'a dyn PpAnn,
) -> 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.
// Since you can't compile the HIR, it's not necessary.
Expand All @@ -158,12 +158,12 @@ pub fn print_crate<'a>(

impl<'a> State<'a> {
pub fn new_from_input(
cm: &'a SourceMap,
sm: &'a SourceMap,
filename: FileName,
input: String,
ann: &'a dyn PpAnn,
) -> 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 }
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/librustc_infer/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ fn msg_span_from_early_bound_and_free_regions(
tcx: TyCtxt<'tcx>,
region: ty::Region<'tcx>,
) -> (String, Option<Span>) {
let cm = tcx.sess.source_map();
let sm = tcx.sess.source_map();

let scope = region.free_region_binding_scope(tcx);
let node = tcx.hir().as_local_hir_id(scope).unwrap_or(hir::DUMMY_HIR_ID);
Expand All @@ -207,7 +207,7 @@ fn msg_span_from_early_bound_and_free_regions(
};
let (prefix, span) = match *region {
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) =
tcx.hir().get_generics(scope).and_then(|generics| generics.get_named(br.name))
{
Expand All @@ -216,7 +216,7 @@ fn msg_span_from_early_bound_and_free_regions(
(format!("the lifetime `{}` as defined on", br.name), sp)
}
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) =
tcx.hir().get_generics(scope).and_then(|generics| generics.get_named(name))
{
Expand All @@ -230,7 +230,7 @@ fn msg_span_from_early_bound_and_free_regions(
}
_ => (
format!("the lifetime `{}` as defined on", region),
cm.def_span(tcx.hir().span(node)),
sm.def_span(tcx.hir().span(node)),
),
},
_ => bug!(),
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_parse/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1625,10 +1625,10 @@ impl<'a> Parser<'a> {
let hi = self.token.span;

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(
|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))
if arm_start_lines.lines[0].end_col == expr_lines.lines[0].end_col
&& expr_lines.lines.len() == 2
Expand Down
Loading

0 comments on commit 6d0e58b

Please sign in to comment.