Skip to content

Commit

Permalink
Auto merge of rust-lang#107601 - matthiaskrgr:rollup-07zaafe, r=matth…
Browse files Browse the repository at this point in the history
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#106919 (Recover `_` as `..` in field pattern)
 - rust-lang#107493 (Improve diagnostic for missing space in range pattern)
 - rust-lang#107515 (Improve pretty-printing of `HirIdValidator` errors)
 - rust-lang#107524 (Remove both StorageLive and StorageDead in CopyProp.)
 - rust-lang#107532 (Erase regions before doing uninhabited check in borrowck)
 - rust-lang#107559 (Rename `rust_2015` → `is_rust_2015`)
 - rust-lang#107577 (Reinstate the `hir-stats.rs` tests on stage 1.)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Feb 2, 2023
2 parents 97872b7 + 08181ea commit f312650
Show file tree
Hide file tree
Showing 52 changed files with 322 additions and 170 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_ast_pretty/src/pprust/state.rs
Expand Up @@ -131,7 +131,7 @@ pub fn print_crate<'a>(

// Currently, in Rust 2018 we don't have `extern crate std;` at the crate
// root, so this is not needed, and actually breaks things.
if edition.rust_2015() {
if edition.is_rust_2015() {
// `#![no_std]`
let fake_attr = attr::mk_attr_word(g, ast::AttrStyle::Inner, sym::no_std, DUMMY_SP);
s.print_attribute(&fake_attr);
Expand Down
5 changes: 4 additions & 1 deletion compiler/rustc_borrowck/src/type_check/mod.rs
Expand Up @@ -1484,7 +1484,10 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
}
}
None => {
if !sig.output().is_privately_uninhabited(self.tcx(), self.param_env) {
// The signature in this call can reference region variables,
// so erase them before calling a query.
let output_ty = self.tcx().erase_regions(sig.output());
if !output_ty.is_privately_uninhabited(self.tcx(), self.param_env) {
span_mirbug!(self, term, "call to converging function {:?} w/o dest", sig);
}
}
Expand Down
9 changes: 5 additions & 4 deletions compiler/rustc_error_messages/locales/en-US/parse.ftl
Expand Up @@ -203,8 +203,9 @@ parse_inclusive_range_extra_equals = unexpected `=` after inclusive range
.suggestion_remove_eq = use `..=` instead
.note = inclusive ranges end with a single equals sign (`..=`)
parse_inclusive_range_match_arrow = unexpected `=>` after open range
.suggestion_add_space = add a space between the pattern and `=>`
parse_inclusive_range_match_arrow = unexpected `>` after inclusive range
.label = this is parsed as an inclusive range `..=`
.suggestion = add a space between the pattern and `=>`
parse_inclusive_range_no_end = inclusive range with no end
.suggestion_open_range = use `..` instead
Expand Down Expand Up @@ -535,8 +536,8 @@ parse_dot_dot_dot_range_to_pattern_not_allowed = range-to patterns with `...` ar
parse_enum_pattern_instead_of_identifier = expected identifier, found enum pattern
parse_dot_dot_dot_for_remaining_fields = expected field pattern, found `...`
.suggestion = to omit remaining fields, use one fewer `.`
parse_dot_dot_dot_for_remaining_fields = expected field pattern, found `{$token_str}`
.suggestion = to omit remaining fields, use `..`
parse_expected_comma_after_pattern_field = expected `,`
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs
Expand Up @@ -454,8 +454,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
None if let Some(e) = self.tainted_by_errors() => self.tcx.ty_error_with_guaranteed(e),
None => {
bug!(
"no type for node {}: {} in fcx {}",
id,
"no type for node {} in fcx {}",
self.tcx.hir().node_to_string(id),
self.tag()
);
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_hir_typeck/src/mem_categorization.rs
Expand Up @@ -155,8 +155,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
None if self.is_tainted_by_errors() => Err(()),
None => {
bug!(
"no type for node {}: {} in mem_categorization",
id,
"no type for node {} in mem_categorization",
self.tcx().hir().node_to_string(id)
);
}
Expand Down
27 changes: 12 additions & 15 deletions compiler/rustc_middle/src/hir/map/mod.rs
Expand Up @@ -290,7 +290,7 @@ impl<'hir> Map<'hir> {
#[track_caller]
pub fn parent_id(self, hir_id: HirId) -> HirId {
self.opt_parent_id(hir_id)
.unwrap_or_else(|| bug!("No parent for node {:?}", self.node_to_string(hir_id)))
.unwrap_or_else(|| bug!("No parent for node {}", self.node_to_string(hir_id)))
}

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

fn hir_id_to_string(map: Map<'_>, id: HirId) -> String {
let id_str = format!(" (hir_id={})", id);

let path_str = |def_id: LocalDefId| map.tcx.def_path_str(def_id.to_def_id());

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

match map.find(id) {
Some(Node::Item(item)) => {
Expand Down Expand Up @@ -1225,18 +1223,18 @@ fn hir_id_to_string(map: Map<'_>, id: HirId) -> String {
ItemKind::TraitAlias(..) => "trait alias",
ItemKind::Impl { .. } => "impl",
};
format!("{} {}{}", item_str, path_str(item.owner_id.def_id), id_str)
format!("{id} ({item_str} {})", path_str(item.owner_id.def_id))
}
Some(Node::ForeignItem(item)) => {
format!("foreign item {}{}", path_str(item.owner_id.def_id), id_str)
format!("{id} (foreign item {})", path_str(item.owner_id.def_id))
}
Some(Node::ImplItem(ii)) => {
let kind = match ii.kind {
ImplItemKind::Const(..) => "assoc const",
ImplItemKind::Fn(..) => "method",
ImplItemKind::Type(_) => "assoc type",
};
format!("{} {} in {}{}", kind, ii.ident, path_str(ii.owner_id.def_id), id_str)
format!("{id} ({kind} `{}` in {})", ii.ident, path_str(ii.owner_id.def_id))
}
Some(Node::TraitItem(ti)) => {
let kind = match ti.kind {
Expand All @@ -1245,13 +1243,13 @@ fn hir_id_to_string(map: Map<'_>, id: HirId) -> String {
TraitItemKind::Type(..) => "assoc type",
};

format!("{} {} in {}{}", kind, ti.ident, path_str(ti.owner_id.def_id), id_str)
format!("{id} ({kind} `{}` in {})", ti.ident, path_str(ti.owner_id.def_id))
}
Some(Node::Variant(ref variant)) => {
format!("variant {} in {}{}", variant.ident, path_str(variant.def_id), id_str)
format!("{id} (variant `{}` in {})", variant.ident, path_str(variant.def_id))
}
Some(Node::Field(ref field)) => {
format!("field {} in {}{}", field.ident, path_str(field.def_id), id_str)
format!("{id} (field `{}` in {})", field.ident, path_str(field.def_id))
}
Some(Node::AnonConst(_)) => node_str("const"),
Some(Node::Expr(_)) => node_str("expr"),
Expand All @@ -1269,16 +1267,15 @@ fn hir_id_to_string(map: Map<'_>, id: HirId) -> String {
Some(Node::Infer(_)) => node_str("infer"),
Some(Node::Local(_)) => node_str("local"),
Some(Node::Ctor(ctor)) => format!(
"ctor {}{}",
"{id} (ctor {})",
ctor.ctor_def_id().map_or("<missing path>".into(), |def_id| path_str(def_id)),
id_str
),
Some(Node::Lifetime(_)) => node_str("lifetime"),
Some(Node::GenericParam(ref param)) => {
format!("generic_param {}{}", path_str(param.def_id), id_str)
format!("{id} (generic_param {})", path_str(param.def_id))
}
Some(Node::Crate(..)) => String::from("root_crate"),
None => format!("unknown node{}", id_str),
Some(Node::Crate(..)) => String::from("(root_crate)"),
None => format!("{id} (unknown node)"),
}
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/context.rs
Expand Up @@ -2171,7 +2171,7 @@ impl<'tcx> TyCtxt<'tcx> {
self.late_bound_vars_map(id.owner)
.and_then(|map| map.get(&id.local_id).cloned())
.unwrap_or_else(|| {
bug!("No bound vars found for {:?} ({:?})", self.hir().node_to_string(id), id)
bug!("No bound vars found for {}", self.hir().node_to_string(id))
})
.iter(),
)
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_middle/src/ty/typeck_results.rs
Expand Up @@ -372,7 +372,7 @@ impl<'tcx> TypeckResults<'tcx> {

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

Expand Down Expand Up @@ -551,9 +551,8 @@ fn validate_hir_id_for_typeck_results(hir_owner: OwnerId, hir_id: hir::HirId) {
fn invalid_hir_id_for_typeck_results(hir_owner: OwnerId, hir_id: hir::HirId) {
ty::tls::with(|tcx| {
bug!(
"node {} with HirId::owner {:?} cannot be placed in TypeckResults with hir_owner {:?}",
"node {} cannot be placed in TypeckResults with hir_owner {:?}",
tcx.hir().node_to_string(hir_id),
hir_id.owner,
hir_owner
)
});
Expand Down
25 changes: 14 additions & 11 deletions compiler/rustc_mir_transform/src/copy_prop.rs
Expand Up @@ -162,17 +162,20 @@ impl<'tcx> MutVisitor<'tcx> for Replacer<'_, 'tcx> {
}

fn visit_statement(&mut self, stmt: &mut Statement<'tcx>, loc: Location) {
if let StatementKind::StorageDead(l) = stmt.kind
&& self.storage_to_remove.contains(l)
{
stmt.make_nop();
} else if let StatementKind::Assign(box (ref place, ref mut rvalue)) = stmt.kind
&& place.as_local().is_some()
{
// Do not replace assignments.
self.visit_rvalue(rvalue, loc)
} else {
self.super_statement(stmt, loc);
match stmt.kind {
// When removing storage statements, we need to remove both (#107511).
StatementKind::StorageLive(l) | StatementKind::StorageDead(l)
if self.storage_to_remove.contains(l) =>
{
stmt.make_nop()
}
StatementKind::Assign(box (ref place, ref mut rvalue))
if place.as_local().is_some() =>
{
// Do not replace assignments.
self.visit_rvalue(rvalue, loc)
}
_ => self.super_statement(stmt, loc),
}
}
}
14 changes: 7 additions & 7 deletions compiler/rustc_parse/src/errors.rs
@@ -1,3 +1,5 @@
use std::borrow::Cow;

use rustc_ast::token::Token;
use rustc_ast::{Path, Visibility};
use rustc_errors::{fluent, AddToDiagnostic, Applicability, EmissionGuarantee, IntoDiagnostic};
Expand Down Expand Up @@ -668,13 +670,10 @@ pub(crate) struct InclusiveRangeExtraEquals {
#[diag(parse_inclusive_range_match_arrow)]
pub(crate) struct InclusiveRangeMatchArrow {
#[primary_span]
pub arrow: Span,
#[label]
pub span: Span,
#[suggestion(
suggestion_add_space,
style = "verbose",
code = " ",
applicability = "machine-applicable"
)]
#[suggestion(style = "verbose", code = " ", applicability = "machine-applicable")]
pub after_pat: Span,
}

Expand Down Expand Up @@ -1802,8 +1801,9 @@ pub(crate) struct EnumPatternInsteadOfIdentifier {
#[diag(parse_dot_dot_dot_for_remaining_fields)]
pub(crate) struct DotDotDotForRemainingFields {
#[primary_span]
#[suggestion(code = "..", applicability = "machine-applicable")]
#[suggestion(code = "..", style = "verbose", applicability = "machine-applicable")]
pub span: Span,
pub token_str: Cow<'static, str>,
}

#[derive(Diagnostic)]
Expand Down
8 changes: 8 additions & 0 deletions compiler/rustc_parse/src/parser/expr.rs
Expand Up @@ -2717,6 +2717,14 @@ impl<'a> Parser<'a> {
);
err.emit();
this.bump();
} else if matches!(
(&this.prev_token.kind, &this.token.kind),
(token::DotDotEq, token::Gt)
) {
// `error_inclusive_range_match_arrow` handles cases like `0..=> {}`,
// so we supress the error here
err.delay_as_bug();
this.bump();
} else {
return Err(err);
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_parse/src/parser/item.rs
Expand Up @@ -2247,7 +2247,7 @@ impl<'a> Parser<'a> {
let ext = self.parse_extern(case);

if let Async::Yes { span, .. } = asyncness {
if span.rust_2015() {
if span.is_rust_2015() {
self.sess.emit_err(AsyncFnIn2015 { span, help: HelpUseLatestEdition::new() });
}
}
Expand Down
20 changes: 12 additions & 8 deletions compiler/rustc_parse/src/parser/pat.rs
Expand Up @@ -743,7 +743,7 @@ impl<'a> Parser<'a> {
}
token::Gt if no_space => {
let after_pat = span.with_hi(span.hi() - rustc_span::BytePos(1)).shrink_to_hi();
self.sess.emit_err(InclusiveRangeMatchArrow { span, after_pat });
self.sess.emit_err(InclusiveRangeMatchArrow { span, arrow: tok.span, after_pat });
}
_ => {
self.sess.emit_err(InclusiveRangeNoEnd { span });
Expand Down Expand Up @@ -962,12 +962,15 @@ impl<'a> Parser<'a> {
}
ate_comma = false;

if self.check(&token::DotDot) || self.token == token::DotDotDot {
if self.check(&token::DotDot)
|| self.check_noexpect(&token::DotDotDot)
|| self.check_keyword(kw::Underscore)
{
etc = true;
let mut etc_sp = self.token.span;

self.recover_one_fewer_dotdot();
self.bump(); // `..` || `...`
self.recover_bad_dot_dot();
self.bump(); // `..` || `...` || `_`

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

/// Recover on `...` as if it were `..` to avoid further errors.
/// Recover on `...` or `_` as if it were `..` to avoid further errors.
/// See issue #46718.
fn recover_one_fewer_dotdot(&self) {
if self.token != token::DotDotDot {
fn recover_bad_dot_dot(&self) {
if self.token == token::DotDot {
return;
}

self.sess.emit_err(DotDotDotForRemainingFields { span: self.token.span });
let token_str = pprust::token_to_string(&self.token);
self.sess.emit_err(DotDotDotForRemainingFields { span: self.token.span, token_str });
}

fn parse_pat_field(&mut self, lo: Span, attrs: AttrVec) -> PResult<'a, PatField> {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_parse/src/parser/ty.rs
Expand Up @@ -614,7 +614,7 @@ impl<'a> Parser<'a> {
/// Is a `dyn B0 + ... + Bn` type allowed here?
fn is_explicit_dyn_type(&mut self) -> bool {
self.check_keyword(kw::Dyn)
&& (!self.token.uninterpolated_span().rust_2015()
&& (self.token.uninterpolated_span().rust_2018()
|| self.look_ahead(1, |t| {
(t.can_begin_bound() || t.kind == TokenKind::BinOp(token::Star))
&& !can_continue_type_after_non_fn_ident(t)
Expand Down
39 changes: 14 additions & 25 deletions compiler/rustc_passes/src/hir_id_validator.rs
Expand Up @@ -74,37 +74,26 @@ impl<'a, 'hir> HirIdValidator<'a, 'hir> {
.expect("owning item has no entry");

if max != self.hir_ids_seen.len() - 1 {
// Collect the missing ItemLocalIds
let missing: Vec<_> = (0..=max as u32)
.filter(|&i| !self.hir_ids_seen.contains(ItemLocalId::from_u32(i)))
.collect();

// Try to map those to something more useful
let mut missing_items = Vec::with_capacity(missing.len());
let hir = self.tcx.hir();
let pretty_owner = hir.def_path(owner.def_id).to_string_no_crate_verbose();

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

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

missing_items.push(format!(
"[local_id: {}, owner: {}]",
local_id,
self.tcx.hir().def_path(owner.def_id).to_string_no_crate_verbose()
));
}
self.error(|| {
format!(
"ItemLocalIds not assigned densely in {}. \
Max ItemLocalId = {}, missing IDs = {:#?}; seens IDs = {:#?}",
self.tcx.hir().def_path(owner.def_id).to_string_no_crate_verbose(),
max,
missing_items,
self.hir_ids_seen
.iter()
.map(|local_id| HirId { owner, local_id })
.map(|h| format!("({:?} {})", h, self.tcx.hir().node_to_string(h)))
.collect::<Vec<_>>()
Max ItemLocalId = {}, missing IDs = {:#?}; seen IDs = {:#?}",
pretty_owner, max, missing_items, seen_items
)
});
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_resolve/src/build_reduced_graph.rs
Expand Up @@ -265,7 +265,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
let ident = path.segments.get(0).expect("empty path in visibility").ident;
let crate_root = if ident.is_path_segment_keyword() {
None
} else if ident.span.rust_2015() {
} else if ident.span.is_rust_2015() {
Some(Segment::from_ident(Ident::new(
kw::PathRoot,
path.span.shrink_to_lo().with_ctxt(ident.span.ctxt()),
Expand Down Expand Up @@ -435,10 +435,10 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
// appears, so imports in braced groups can have roots prepended independently.
let is_glob = matches!(use_tree.kind, ast::UseTreeKind::Glob);
let crate_root = match prefix_iter.peek() {
Some(seg) if !seg.ident.is_path_segment_keyword() && seg.ident.span.rust_2015() => {
Some(seg) if !seg.ident.is_path_segment_keyword() && seg.ident.span.is_rust_2015() => {
Some(seg.ident.span.ctxt())
}
None if is_glob && use_tree.span.rust_2015() => Some(use_tree.span.ctxt()),
None if is_glob && use_tree.span.is_rust_2015() => Some(use_tree.span.ctxt()),
_ => None,
}
.map(|ctxt| {
Expand Down

0 comments on commit f312650

Please sign in to comment.