Skip to content

Commit f312650

Browse files
committed
Auto merge of #107601 - matthiaskrgr:rollup-07zaafe, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - #106919 (Recover `_` as `..` in field pattern) - #107493 (Improve diagnostic for missing space in range pattern) - #107515 (Improve pretty-printing of `HirIdValidator` errors) - #107524 (Remove both StorageLive and StorageDead in CopyProp.) - #107532 (Erase regions before doing uninhabited check in borrowck) - #107559 (Rename `rust_2015` → `is_rust_2015`) - #107577 (Reinstate the `hir-stats.rs` tests on stage 1.) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 97872b7 + 08181ea commit f312650

File tree

52 files changed

+322
-170
lines changed

Some content is hidden

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

52 files changed

+322
-170
lines changed

compiler/rustc_ast_pretty/src/pprust/state.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ pub fn print_crate<'a>(
131131

132132
// Currently, in Rust 2018 we don't have `extern crate std;` at the crate
133133
// root, so this is not needed, and actually breaks things.
134-
if edition.rust_2015() {
134+
if edition.is_rust_2015() {
135135
// `#![no_std]`
136136
let fake_attr = attr::mk_attr_word(g, ast::AttrStyle::Inner, sym::no_std, DUMMY_SP);
137137
s.print_attribute(&fake_attr);

compiler/rustc_borrowck/src/type_check/mod.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1484,7 +1484,10 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
14841484
}
14851485
}
14861486
None => {
1487-
if !sig.output().is_privately_uninhabited(self.tcx(), self.param_env) {
1487+
// The signature in this call can reference region variables,
1488+
// so erase them before calling a query.
1489+
let output_ty = self.tcx().erase_regions(sig.output());
1490+
if !output_ty.is_privately_uninhabited(self.tcx(), self.param_env) {
14881491
span_mirbug!(self, term, "call to converging function {:?} w/o dest", sig);
14891492
}
14901493
}

compiler/rustc_error_messages/locales/en-US/parse.ftl

+5-4
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,9 @@ parse_inclusive_range_extra_equals = unexpected `=` after inclusive range
203203
.suggestion_remove_eq = use `..=` instead
204204
.note = inclusive ranges end with a single equals sign (`..=`)
205205
206-
parse_inclusive_range_match_arrow = unexpected `=>` after open range
207-
.suggestion_add_space = add a space between the pattern and `=>`
206+
parse_inclusive_range_match_arrow = unexpected `>` after inclusive range
207+
.label = this is parsed as an inclusive range `..=`
208+
.suggestion = add a space between the pattern and `=>`
208209
209210
parse_inclusive_range_no_end = inclusive range with no end
210211
.suggestion_open_range = use `..` instead
@@ -535,8 +536,8 @@ parse_dot_dot_dot_range_to_pattern_not_allowed = range-to patterns with `...` ar
535536
536537
parse_enum_pattern_instead_of_identifier = expected identifier, found enum pattern
537538
538-
parse_dot_dot_dot_for_remaining_fields = expected field pattern, found `...`
539-
.suggestion = to omit remaining fields, use one fewer `.`
539+
parse_dot_dot_dot_for_remaining_fields = expected field pattern, found `{$token_str}`
540+
.suggestion = to omit remaining fields, use `..`
540541
541542
parse_expected_comma_after_pattern_field = expected `,`
542543

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -454,8 +454,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
454454
None if let Some(e) = self.tainted_by_errors() => self.tcx.ty_error_with_guaranteed(e),
455455
None => {
456456
bug!(
457-
"no type for node {}: {} in fcx {}",
458-
id,
457+
"no type for node {} in fcx {}",
459458
self.tcx.hir().node_to_string(id),
460459
self.tag()
461460
);

compiler/rustc_hir_typeck/src/mem_categorization.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
155155
None if self.is_tainted_by_errors() => Err(()),
156156
None => {
157157
bug!(
158-
"no type for node {}: {} in mem_categorization",
159-
id,
158+
"no type for node {} in mem_categorization",
160159
self.tcx().hir().node_to_string(id)
161160
);
162161
}

compiler/rustc_middle/src/hir/map/mod.rs

+12-15
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ impl<'hir> Map<'hir> {
290290
#[track_caller]
291291
pub fn parent_id(self, hir_id: HirId) -> HirId {
292292
self.opt_parent_id(hir_id)
293-
.unwrap_or_else(|| bug!("No parent for node {:?}", self.node_to_string(hir_id)))
293+
.unwrap_or_else(|| bug!("No parent for node {}", self.node_to_string(hir_id)))
294294
}
295295

296296
pub fn get_parent(self, hir_id: HirId) -> Node<'hir> {
@@ -1191,12 +1191,10 @@ fn upstream_crates(tcx: TyCtxt<'_>) -> Vec<(StableCrateId, Svh)> {
11911191
}
11921192

11931193
fn hir_id_to_string(map: Map<'_>, id: HirId) -> String {
1194-
let id_str = format!(" (hir_id={})", id);
1195-
11961194
let path_str = |def_id: LocalDefId| map.tcx.def_path_str(def_id.to_def_id());
11971195

11981196
let span_str = || map.tcx.sess.source_map().span_to_snippet(map.span(id)).unwrap_or_default();
1199-
let node_str = |prefix| format!("{} {}{}", prefix, span_str(), id_str);
1197+
let node_str = |prefix| format!("{id} ({prefix} `{}`)", span_str());
12001198

12011199
match map.find(id) {
12021200
Some(Node::Item(item)) => {
@@ -1225,18 +1223,18 @@ fn hir_id_to_string(map: Map<'_>, id: HirId) -> String {
12251223
ItemKind::TraitAlias(..) => "trait alias",
12261224
ItemKind::Impl { .. } => "impl",
12271225
};
1228-
format!("{} {}{}", item_str, path_str(item.owner_id.def_id), id_str)
1226+
format!("{id} ({item_str} {})", path_str(item.owner_id.def_id))
12291227
}
12301228
Some(Node::ForeignItem(item)) => {
1231-
format!("foreign item {}{}", path_str(item.owner_id.def_id), id_str)
1229+
format!("{id} (foreign item {})", path_str(item.owner_id.def_id))
12321230
}
12331231
Some(Node::ImplItem(ii)) => {
12341232
let kind = match ii.kind {
12351233
ImplItemKind::Const(..) => "assoc const",
12361234
ImplItemKind::Fn(..) => "method",
12371235
ImplItemKind::Type(_) => "assoc type",
12381236
};
1239-
format!("{} {} in {}{}", kind, ii.ident, path_str(ii.owner_id.def_id), id_str)
1237+
format!("{id} ({kind} `{}` in {})", ii.ident, path_str(ii.owner_id.def_id))
12401238
}
12411239
Some(Node::TraitItem(ti)) => {
12421240
let kind = match ti.kind {
@@ -1245,13 +1243,13 @@ fn hir_id_to_string(map: Map<'_>, id: HirId) -> String {
12451243
TraitItemKind::Type(..) => "assoc type",
12461244
};
12471245

1248-
format!("{} {} in {}{}", kind, ti.ident, path_str(ti.owner_id.def_id), id_str)
1246+
format!("{id} ({kind} `{}` in {})", ti.ident, path_str(ti.owner_id.def_id))
12491247
}
12501248
Some(Node::Variant(ref variant)) => {
1251-
format!("variant {} in {}{}", variant.ident, path_str(variant.def_id), id_str)
1249+
format!("{id} (variant `{}` in {})", variant.ident, path_str(variant.def_id))
12521250
}
12531251
Some(Node::Field(ref field)) => {
1254-
format!("field {} in {}{}", field.ident, path_str(field.def_id), id_str)
1252+
format!("{id} (field `{}` in {})", field.ident, path_str(field.def_id))
12551253
}
12561254
Some(Node::AnonConst(_)) => node_str("const"),
12571255
Some(Node::Expr(_)) => node_str("expr"),
@@ -1269,16 +1267,15 @@ fn hir_id_to_string(map: Map<'_>, id: HirId) -> String {
12691267
Some(Node::Infer(_)) => node_str("infer"),
12701268
Some(Node::Local(_)) => node_str("local"),
12711269
Some(Node::Ctor(ctor)) => format!(
1272-
"ctor {}{}",
1270+
"{id} (ctor {})",
12731271
ctor.ctor_def_id().map_or("<missing path>".into(), |def_id| path_str(def_id)),
1274-
id_str
12751272
),
12761273
Some(Node::Lifetime(_)) => node_str("lifetime"),
12771274
Some(Node::GenericParam(ref param)) => {
1278-
format!("generic_param {}{}", path_str(param.def_id), id_str)
1275+
format!("{id} (generic_param {})", path_str(param.def_id))
12791276
}
1280-
Some(Node::Crate(..)) => String::from("root_crate"),
1281-
None => format!("unknown node{}", id_str),
1277+
Some(Node::Crate(..)) => String::from("(root_crate)"),
1278+
None => format!("{id} (unknown node)"),
12821279
}
12831280
}
12841281

compiler/rustc_middle/src/ty/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2171,7 +2171,7 @@ impl<'tcx> TyCtxt<'tcx> {
21712171
self.late_bound_vars_map(id.owner)
21722172
.and_then(|map| map.get(&id.local_id).cloned())
21732173
.unwrap_or_else(|| {
2174-
bug!("No bound vars found for {:?} ({:?})", self.hir().node_to_string(id), id)
2174+
bug!("No bound vars found for {}", self.hir().node_to_string(id))
21752175
})
21762176
.iter(),
21772177
)

compiler/rustc_middle/src/ty/typeck_results.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ impl<'tcx> TypeckResults<'tcx> {
372372

373373
pub fn node_type(&self, id: hir::HirId) -> Ty<'tcx> {
374374
self.node_type_opt(id).unwrap_or_else(|| {
375-
bug!("node_type: no type for node `{}`", tls::with(|tcx| tcx.hir().node_to_string(id)))
375+
bug!("node_type: no type for node {}", tls::with(|tcx| tcx.hir().node_to_string(id)))
376376
})
377377
}
378378

@@ -551,9 +551,8 @@ fn validate_hir_id_for_typeck_results(hir_owner: OwnerId, hir_id: hir::HirId) {
551551
fn invalid_hir_id_for_typeck_results(hir_owner: OwnerId, hir_id: hir::HirId) {
552552
ty::tls::with(|tcx| {
553553
bug!(
554-
"node {} with HirId::owner {:?} cannot be placed in TypeckResults with hir_owner {:?}",
554+
"node {} cannot be placed in TypeckResults with hir_owner {:?}",
555555
tcx.hir().node_to_string(hir_id),
556-
hir_id.owner,
557556
hir_owner
558557
)
559558
});

compiler/rustc_mir_transform/src/copy_prop.rs

+14-11
Original file line numberDiff line numberDiff line change
@@ -162,17 +162,20 @@ impl<'tcx> MutVisitor<'tcx> for Replacer<'_, 'tcx> {
162162
}
163163

164164
fn visit_statement(&mut self, stmt: &mut Statement<'tcx>, loc: Location) {
165-
if let StatementKind::StorageDead(l) = stmt.kind
166-
&& self.storage_to_remove.contains(l)
167-
{
168-
stmt.make_nop();
169-
} else if let StatementKind::Assign(box (ref place, ref mut rvalue)) = stmt.kind
170-
&& place.as_local().is_some()
171-
{
172-
// Do not replace assignments.
173-
self.visit_rvalue(rvalue, loc)
174-
} else {
175-
self.super_statement(stmt, loc);
165+
match stmt.kind {
166+
// When removing storage statements, we need to remove both (#107511).
167+
StatementKind::StorageLive(l) | StatementKind::StorageDead(l)
168+
if self.storage_to_remove.contains(l) =>
169+
{
170+
stmt.make_nop()
171+
}
172+
StatementKind::Assign(box (ref place, ref mut rvalue))
173+
if place.as_local().is_some() =>
174+
{
175+
// Do not replace assignments.
176+
self.visit_rvalue(rvalue, loc)
177+
}
178+
_ => self.super_statement(stmt, loc),
176179
}
177180
}
178181
}

compiler/rustc_parse/src/errors.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::borrow::Cow;
2+
13
use rustc_ast::token::Token;
24
use rustc_ast::{Path, Visibility};
35
use rustc_errors::{fluent, AddToDiagnostic, Applicability, EmissionGuarantee, IntoDiagnostic};
@@ -668,13 +670,10 @@ pub(crate) struct InclusiveRangeExtraEquals {
668670
#[diag(parse_inclusive_range_match_arrow)]
669671
pub(crate) struct InclusiveRangeMatchArrow {
670672
#[primary_span]
673+
pub arrow: Span,
674+
#[label]
671675
pub span: Span,
672-
#[suggestion(
673-
suggestion_add_space,
674-
style = "verbose",
675-
code = " ",
676-
applicability = "machine-applicable"
677-
)]
676+
#[suggestion(style = "verbose", code = " ", applicability = "machine-applicable")]
678677
pub after_pat: Span,
679678
}
680679

@@ -1802,8 +1801,9 @@ pub(crate) struct EnumPatternInsteadOfIdentifier {
18021801
#[diag(parse_dot_dot_dot_for_remaining_fields)]
18031802
pub(crate) struct DotDotDotForRemainingFields {
18041803
#[primary_span]
1805-
#[suggestion(code = "..", applicability = "machine-applicable")]
1804+
#[suggestion(code = "..", style = "verbose", applicability = "machine-applicable")]
18061805
pub span: Span,
1806+
pub token_str: Cow<'static, str>,
18071807
}
18081808

18091809
#[derive(Diagnostic)]

compiler/rustc_parse/src/parser/expr.rs

+8
Original file line numberDiff line numberDiff line change
@@ -2717,6 +2717,14 @@ impl<'a> Parser<'a> {
27172717
);
27182718
err.emit();
27192719
this.bump();
2720+
} else if matches!(
2721+
(&this.prev_token.kind, &this.token.kind),
2722+
(token::DotDotEq, token::Gt)
2723+
) {
2724+
// `error_inclusive_range_match_arrow` handles cases like `0..=> {}`,
2725+
// so we supress the error here
2726+
err.delay_as_bug();
2727+
this.bump();
27202728
} else {
27212729
return Err(err);
27222730
}

compiler/rustc_parse/src/parser/item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2247,7 +2247,7 @@ impl<'a> Parser<'a> {
22472247
let ext = self.parse_extern(case);
22482248

22492249
if let Async::Yes { span, .. } = asyncness {
2250-
if span.rust_2015() {
2250+
if span.is_rust_2015() {
22512251
self.sess.emit_err(AsyncFnIn2015 { span, help: HelpUseLatestEdition::new() });
22522252
}
22532253
}

compiler/rustc_parse/src/parser/pat.rs

+12-8
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ impl<'a> Parser<'a> {
743743
}
744744
token::Gt if no_space => {
745745
let after_pat = span.with_hi(span.hi() - rustc_span::BytePos(1)).shrink_to_hi();
746-
self.sess.emit_err(InclusiveRangeMatchArrow { span, after_pat });
746+
self.sess.emit_err(InclusiveRangeMatchArrow { span, arrow: tok.span, after_pat });
747747
}
748748
_ => {
749749
self.sess.emit_err(InclusiveRangeNoEnd { span });
@@ -962,12 +962,15 @@ impl<'a> Parser<'a> {
962962
}
963963
ate_comma = false;
964964

965-
if self.check(&token::DotDot) || self.token == token::DotDotDot {
965+
if self.check(&token::DotDot)
966+
|| self.check_noexpect(&token::DotDotDot)
967+
|| self.check_keyword(kw::Underscore)
968+
{
966969
etc = true;
967970
let mut etc_sp = self.token.span;
968971

969-
self.recover_one_fewer_dotdot();
970-
self.bump(); // `..` || `...`
972+
self.recover_bad_dot_dot();
973+
self.bump(); // `..` || `...` || `_`
971974

972975
if self.token == token::CloseDelim(Delimiter::Brace) {
973976
etc_span = Some(etc_sp);
@@ -1060,14 +1063,15 @@ impl<'a> Parser<'a> {
10601063
Ok((fields, etc))
10611064
}
10621065

1063-
/// Recover on `...` as if it were `..` to avoid further errors.
1066+
/// Recover on `...` or `_` as if it were `..` to avoid further errors.
10641067
/// See issue #46718.
1065-
fn recover_one_fewer_dotdot(&self) {
1066-
if self.token != token::DotDotDot {
1068+
fn recover_bad_dot_dot(&self) {
1069+
if self.token == token::DotDot {
10671070
return;
10681071
}
10691072

1070-
self.sess.emit_err(DotDotDotForRemainingFields { span: self.token.span });
1073+
let token_str = pprust::token_to_string(&self.token);
1074+
self.sess.emit_err(DotDotDotForRemainingFields { span: self.token.span, token_str });
10711075
}
10721076

10731077
fn parse_pat_field(&mut self, lo: Span, attrs: AttrVec) -> PResult<'a, PatField> {

compiler/rustc_parse/src/parser/ty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ impl<'a> Parser<'a> {
614614
/// Is a `dyn B0 + ... + Bn` type allowed here?
615615
fn is_explicit_dyn_type(&mut self) -> bool {
616616
self.check_keyword(kw::Dyn)
617-
&& (!self.token.uninterpolated_span().rust_2015()
617+
&& (self.token.uninterpolated_span().rust_2018()
618618
|| self.look_ahead(1, |t| {
619619
(t.can_begin_bound() || t.kind == TokenKind::BinOp(token::Star))
620620
&& !can_continue_type_after_non_fn_ident(t)

compiler/rustc_passes/src/hir_id_validator.rs

+14-25
Original file line numberDiff line numberDiff line change
@@ -74,37 +74,26 @@ impl<'a, 'hir> HirIdValidator<'a, 'hir> {
7474
.expect("owning item has no entry");
7575

7676
if max != self.hir_ids_seen.len() - 1 {
77-
// Collect the missing ItemLocalIds
78-
let missing: Vec<_> = (0..=max as u32)
79-
.filter(|&i| !self.hir_ids_seen.contains(ItemLocalId::from_u32(i)))
80-
.collect();
81-
82-
// Try to map those to something more useful
83-
let mut missing_items = Vec::with_capacity(missing.len());
77+
let hir = self.tcx.hir();
78+
let pretty_owner = hir.def_path(owner.def_id).to_string_no_crate_verbose();
8479

85-
for local_id in missing {
86-
let hir_id = HirId { owner, local_id: ItemLocalId::from_u32(local_id) };
80+
let missing_items: Vec<_> = (0..=max as u32)
81+
.map(|i| ItemLocalId::from_u32(i))
82+
.filter(|&local_id| !self.hir_ids_seen.contains(local_id))
83+
.map(|local_id| hir.node_to_string(HirId { owner, local_id }))
84+
.collect();
8785

88-
trace!("missing hir id {:#?}", hir_id);
86+
let seen_items: Vec<_> = self
87+
.hir_ids_seen
88+
.iter()
89+
.map(|local_id| hir.node_to_string(HirId { owner, local_id }))
90+
.collect();
8991

90-
missing_items.push(format!(
91-
"[local_id: {}, owner: {}]",
92-
local_id,
93-
self.tcx.hir().def_path(owner.def_id).to_string_no_crate_verbose()
94-
));
95-
}
9692
self.error(|| {
9793
format!(
9894
"ItemLocalIds not assigned densely in {}. \
99-
Max ItemLocalId = {}, missing IDs = {:#?}; seens IDs = {:#?}",
100-
self.tcx.hir().def_path(owner.def_id).to_string_no_crate_verbose(),
101-
max,
102-
missing_items,
103-
self.hir_ids_seen
104-
.iter()
105-
.map(|local_id| HirId { owner, local_id })
106-
.map(|h| format!("({:?} {})", h, self.tcx.hir().node_to_string(h)))
107-
.collect::<Vec<_>>()
95+
Max ItemLocalId = {}, missing IDs = {:#?}; seen IDs = {:#?}",
96+
pretty_owner, max, missing_items, seen_items
10897
)
10998
});
11099
}

compiler/rustc_resolve/src/build_reduced_graph.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
265265
let ident = path.segments.get(0).expect("empty path in visibility").ident;
266266
let crate_root = if ident.is_path_segment_keyword() {
267267
None
268-
} else if ident.span.rust_2015() {
268+
} else if ident.span.is_rust_2015() {
269269
Some(Segment::from_ident(Ident::new(
270270
kw::PathRoot,
271271
path.span.shrink_to_lo().with_ctxt(ident.span.ctxt()),
@@ -435,10 +435,10 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
435435
// appears, so imports in braced groups can have roots prepended independently.
436436
let is_glob = matches!(use_tree.kind, ast::UseTreeKind::Glob);
437437
let crate_root = match prefix_iter.peek() {
438-
Some(seg) if !seg.ident.is_path_segment_keyword() && seg.ident.span.rust_2015() => {
438+
Some(seg) if !seg.ident.is_path_segment_keyword() && seg.ident.span.is_rust_2015() => {
439439
Some(seg.ident.span.ctxt())
440440
}
441-
None if is_glob && use_tree.span.rust_2015() => Some(use_tree.span.ctxt()),
441+
None if is_glob && use_tree.span.is_rust_2015() => Some(use_tree.span.ctxt()),
442442
_ => None,
443443
}
444444
.map(|ctxt| {

0 commit comments

Comments
 (0)