Skip to content

Commit 6d0e58b

Browse files
committed
Auto merge of #69393 - Dylan-DPC:rollup-rxbd1zg, r=Dylan-DPC
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
2 parents b1f395d + d6414f5 commit 6d0e58b

File tree

42 files changed

+357
-301
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+357
-301
lines changed

Diff for: 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()

Diff for: 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

Diff for: src/librustc_ast_lowering/item.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -297,28 +297,28 @@ impl<'hir> LoweringContext<'_, 'hir> {
297297
ItemKind::Mod(ref m) => hir::ItemKind::Mod(self.lower_mod(m)),
298298
ItemKind::ForeignMod(ref nm) => hir::ItemKind::ForeignMod(self.lower_foreign_mod(nm)),
299299
ItemKind::GlobalAsm(ref ga) => hir::ItemKind::GlobalAsm(self.lower_global_asm(ga)),
300-
ItemKind::TyAlias(ref ty, ref generics) => match ty.kind.opaque_top_hack() {
300+
ItemKind::TyAlias(ref generics, _, Some(ref ty)) => match ty.kind.opaque_top_hack() {
301301
None => {
302302
let ty = self.lower_ty(ty, ImplTraitContext::disallowed());
303303
let generics = self.lower_generics(generics, ImplTraitContext::disallowed());
304304
hir::ItemKind::TyAlias(ty, generics)
305305
}
306306
Some(bounds) => {
307+
let ctx = || ImplTraitContext::OpaqueTy(None, hir::OpaqueTyOrigin::Misc);
307308
let ty = hir::OpaqueTy {
308-
generics: self.lower_generics(
309-
generics,
310-
ImplTraitContext::OpaqueTy(None, hir::OpaqueTyOrigin::Misc),
311-
),
312-
bounds: self.lower_param_bounds(
313-
bounds,
314-
ImplTraitContext::OpaqueTy(None, hir::OpaqueTyOrigin::Misc),
315-
),
309+
generics: self.lower_generics(generics, ctx()),
310+
bounds: self.lower_param_bounds(bounds, ctx()),
316311
impl_trait_fn: None,
317312
origin: hir::OpaqueTyOrigin::TypeAlias,
318313
};
319314
hir::ItemKind::OpaqueTy(ty)
320315
}
321316
},
317+
ItemKind::TyAlias(ref generics, _, None) => {
318+
let ty = self.arena.alloc(self.ty(span, hir::TyKind::Err));
319+
let generics = self.lower_generics(generics, ImplTraitContext::disallowed());
320+
hir::ItemKind::TyAlias(ty, generics)
321+
}
322322
ItemKind::Enum(ref enum_definition, ref generics) => hir::ItemKind::Enum(
323323
hir::EnumDef {
324324
variants: self.arena.alloc_from_iter(

Diff for: src/librustc_ast_lowering/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
462462
ItemKind::Struct(_, ref generics)
463463
| ItemKind::Union(_, ref generics)
464464
| ItemKind::Enum(_, ref generics)
465-
| ItemKind::TyAlias(_, ref generics)
465+
| ItemKind::TyAlias(ref generics, ..)
466466
| ItemKind::Trait(_, _, ref generics, ..) => {
467467
let def_id = self.lctx.resolver.definitions().local_def_id(item.id);
468468
let count = generics

Diff for: src/librustc_ast_passes/ast_validation.rs

+7
Original file line numberDiff line numberDiff line change
@@ -969,6 +969,13 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
969969
let msg = "free static item without body";
970970
self.error_item_without_body(item.span, "static", msg, " = <expr>;");
971971
}
972+
ItemKind::TyAlias(_, ref bounds, ref body) => {
973+
if body.is_none() {
974+
let msg = "free type alias without body";
975+
self.error_item_without_body(item.span, "type", msg, " = <type>;");
976+
}
977+
self.check_type_no_bounds(bounds, "this context");
978+
}
972979
_ => {}
973980
}
974981

Diff for: src/librustc_ast_passes/feature_gate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
372372
gate_feature_post!(&self, decl_macro, i.span, msg);
373373
}
374374

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

377377
_ => {}
378378
}

Diff for: src/librustc_ast_pretty/pprust.rs

+14-22
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

@@ -1185,18 +1185,10 @@ impl<'a> State<'a> {
11851185
self.s.word(ga.asm.to_string());
11861186
self.end();
11871187
}
1188-
ast::ItemKind::TyAlias(ref ty, ref generics) => {
1189-
self.head(visibility_qualified(&item.vis, "type"));
1190-
self.print_ident(item.ident);
1191-
self.print_generic_params(&generics.params);
1192-
self.end(); // end the inner ibox
1193-
1194-
self.print_where_clause(&generics.where_clause);
1195-
self.s.space();
1196-
self.word_space("=");
1197-
self.print_type(ty);
1198-
self.s.word(";");
1199-
self.end(); // end the outer ibox
1188+
ast::ItemKind::TyAlias(ref generics, ref bounds, ref ty) => {
1189+
let def = ast::Defaultness::Final;
1190+
let ty = ty.as_deref();
1191+
self.print_associated_type(item.ident, generics, bounds, ty, &item.vis, def);
12001192
}
12011193
ast::ItemKind::Enum(ref enum_definition, ref params) => {
12021194
self.print_enum_def(enum_definition, params, item.ident, item.span, &item.vis);

Diff for: 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

Diff for: 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,

Diff for: 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,

Diff for: 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

Diff for: 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!(),

Diff for: 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

0 commit comments

Comments
 (0)