Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 5 pull requests #70481

Closed
wants to merge 11 commits into from
16 changes: 11 additions & 5 deletions src/librustc/hir/map/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,8 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
// Make sure that the DepNode of some node coincides with the HirId
// owner of that node.
if cfg!(debug_assertions) {
let node_id = self.definitions.hir_to_node_id(hir_id);
assert_eq!(self.definitions.node_to_hir_id(node_id), hir_id);
let node_id = self.definitions.hir_id_to_node_id(hir_id);
assert_eq!(self.definitions.node_id_to_hir_id(node_id), hir_id);

if hir_id.owner != self.current_dep_node_owner {
let node_str = match self.definitions.opt_local_def_id(node_id) {
Expand Down Expand Up @@ -342,7 +342,9 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
debug!("visit_item: {:?}", i);
debug_assert_eq!(
i.hir_id.owner,
self.definitions.opt_local_def_id(self.definitions.hir_to_node_id(i.hir_id)).unwrap()
self.definitions
.opt_local_def_id(self.definitions.hir_id_to_node_id(i.hir_id))
.unwrap()
);
self.with_dep_node_owner(i.hir_id.owner, i, |this, hash| {
this.insert_with_hash(i.span, i.hir_id, Node::Item(i), hash);
Expand Down Expand Up @@ -374,7 +376,9 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
fn visit_trait_item(&mut self, ti: &'hir TraitItem<'hir>) {
debug_assert_eq!(
ti.hir_id.owner,
self.definitions.opt_local_def_id(self.definitions.hir_to_node_id(ti.hir_id)).unwrap()
self.definitions
.opt_local_def_id(self.definitions.hir_id_to_node_id(ti.hir_id))
.unwrap()
);
self.with_dep_node_owner(ti.hir_id.owner, ti, |this, hash| {
this.insert_with_hash(ti.span, ti.hir_id, Node::TraitItem(ti), hash);
Expand All @@ -388,7 +392,9 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
fn visit_impl_item(&mut self, ii: &'hir ImplItem<'hir>) {
debug_assert_eq!(
ii.hir_id.owner,
self.definitions.opt_local_def_id(self.definitions.hir_to_node_id(ii.hir_id)).unwrap()
self.definitions
.opt_local_def_id(self.definitions.hir_id_to_node_id(ii.hir_id))
.unwrap()
);
self.with_dep_node_owner(ii.hir_id.owner, ii, |this, hash| {
this.insert_with_hash(ii.span, ii.hir_id, Node::ImplItem(ii), hash);
Expand Down
12 changes: 6 additions & 6 deletions src/librustc/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ impl<'hir> Map<'hir> {
#[inline]
pub fn local_def_id_from_node_id(&self, node: NodeId) -> DefId {
self.opt_local_def_id_from_node_id(node).unwrap_or_else(|| {
let hir_id = self.node_to_hir_id(node);
let hir_id = self.node_id_to_hir_id(node);
bug!(
"local_def_id_from_node_id: no entry for `{}`, which has a map of `{:?}`",
node,
Expand All @@ -184,7 +184,7 @@ impl<'hir> Map<'hir> {

#[inline]
pub fn opt_local_def_id(&self, hir_id: HirId) -> Option<DefId> {
let node_id = self.hir_to_node_id(hir_id);
let node_id = self.hir_id_to_node_id(hir_id);
self.opt_local_def_id_from_node_id(node_id)
}

Expand All @@ -204,13 +204,13 @@ impl<'hir> Map<'hir> {
}

#[inline]
pub fn hir_to_node_id(&self, hir_id: HirId) -> NodeId {
self.tcx.definitions.hir_to_node_id(hir_id)
pub fn hir_id_to_node_id(&self, hir_id: HirId) -> NodeId {
self.tcx.definitions.hir_id_to_node_id(hir_id)
}

#[inline]
pub fn node_to_hir_id(&self, node_id: NodeId) -> HirId {
self.tcx.definitions.node_to_hir_id(node_id)
pub fn node_id_to_hir_id(&self, node_id: NodeId) -> HirId {
self.tcx.definitions.node_id_to_hir_id(node_id)
}

#[inline]
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ich/hcx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ impl<'a> StableHashingContext<'a> {

#[inline]
pub fn node_to_hir_id(&self, node_id: ast::NodeId) -> hir::HirId {
self.definitions.node_to_hir_id(node_id)
self.definitions.node_id_to_hir_id(node_id)
}

#[inline]
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1126,11 +1126,11 @@ impl<'tcx> TyCtxt<'tcx> {

let mut trait_map: FxHashMap<_, FxHashMap<_, _>> = FxHashMap::default();
for (k, v) in resolutions.trait_map {
let hir_id = definitions.node_to_hir_id(k);
let hir_id = definitions.node_id_to_hir_id(k);
let map = trait_map.entry(hir_id.owner).or_default();
let v = v
.into_iter()
.map(|tc| tc.map_import_ids(|id| definitions.node_to_hir_id(id)))
.map(|tc| tc.map_import_ids(|id| definitions.node_id_to_hir_id(id)))
.collect();
map.insert(hir_id.local_id, StableVec::new(v));
}
Expand All @@ -1154,7 +1154,7 @@ impl<'tcx> TyCtxt<'tcx> {
.map(|(k, v)| {
let exports: Vec<_> = v
.into_iter()
.map(|e| e.map_id(|id| definitions.node_to_hir_id(id)))
.map(|e| e.map_id(|id| definitions.node_id_to_hir_id(id)))
.collect();
(k, exports)
})
Expand Down
19 changes: 18 additions & 1 deletion src/librustc_expand/mbe/macro_rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ fn suggest_slice_pat(e: &mut DiagnosticBuilder<'_>, site_span: Span, parser: &Pa
fn emit_frag_parse_err(
mut e: DiagnosticBuilder<'_>,
parser: &Parser<'_>,
orig_parser: &mut Parser<'_>,
site_span: Span,
macro_ident: ast::Ident,
arm_span: Span,
Expand Down Expand Up @@ -118,6 +119,21 @@ fn emit_frag_parse_err(
AstFragmentKind::Pat if macro_ident.name == sym::vec => {
suggest_slice_pat(&mut e, site_span, parser);
}
// Try a statement if an expression is wanted but failed and suggest adding `;` to call.
AstFragmentKind::Expr => match parse_ast_fragment(orig_parser, AstFragmentKind::Stmts) {
Err(mut err) => err.cancel(),
Ok(_) => {
e.note(
"the macro call doesn't expand to an expression, but it can expand to a statement",
);
e.span_suggestion_verbose(
site_span.shrink_to_hi(),
"add `;` to interpret the expansion as a statement",
";".to_string(),
Applicability::MaybeIncorrect,
);
}
},
_ => annotate_err_with_kind(&mut e, kind, site_span),
};
e.emit();
Expand All @@ -126,10 +142,11 @@ fn emit_frag_parse_err(
impl<'a> ParserAnyMacro<'a> {
crate fn make(mut self: Box<ParserAnyMacro<'a>>, kind: AstFragmentKind) -> AstFragment {
let ParserAnyMacro { site_span, macro_ident, ref mut parser, arm_span } = *self;
let snapshot = &mut parser.clone();
let fragment = match parse_ast_fragment(parser, kind) {
Ok(f) => f,
Err(err) => {
emit_frag_parse_err(err, parser, site_span, macro_ident, arm_span, kind);
emit_frag_parse_err(err, parser, snapshot, site_span, macro_ident, arm_span, kind);
return kind.dummy(site_span);
}
};
Expand Down
6 changes: 2 additions & 4 deletions src/librustc_hir/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,15 +353,13 @@ impl Definitions {
}
}

// FIXME(eddyb) rename to `hir_id_to_node_id`.
#[inline]
pub fn hir_to_node_id(&self, hir_id: hir::HirId) -> ast::NodeId {
pub fn hir_id_to_node_id(&self, hir_id: hir::HirId) -> ast::NodeId {
self.hir_id_to_node_id[&hir_id]
}

// FIXME(eddyb) rename to `node_id_to_hir_id`.
#[inline]
pub fn node_to_hir_id(&self, node_id: ast::NodeId) -> hir::HirId {
pub fn node_id_to_hir_id(&self, node_id: ast::NodeId) -> hir::HirId {
self.node_id_to_hir_id[node_id]
}

Expand Down
2 changes: 0 additions & 2 deletions src/librustc_mir/borrow_check/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
&mut err,
&param.name.as_str(),
"Copy",
tcx.sess.source_map(),
span,
None,
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/transform/check_unsafety.rs
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ pub fn check_unsafety(tcx: TyCtxt<'_>, def_id: DefId) {
}

let mut unsafe_blocks: Vec<_> = unsafe_blocks.iter().collect();
unsafe_blocks.sort_by_cached_key(|(hir_id, _)| tcx.hir().hir_to_node_id(*hir_id));
unsafe_blocks.sort_by_cached_key(|(hir_id, _)| tcx.hir().hir_id_to_node_id(*hir_id));
let used_unsafe: FxHashSet<_> =
unsafe_blocks.iter().flat_map(|&&(id, used)| used.then_some(id)).collect();
for &(block_id, is_used) in unsafe_blocks {
Expand Down
2 changes: 2 additions & 0 deletions src/librustc_mir_build/hair/pattern/check_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ impl<'tcx> MatchVisitor<'_, 'tcx> {
}

adt_defined_here(cx, &mut err, pattern_ty, &witnesses);
err.note(&format!("the matched value is of type `{}`", pattern_ty));
err.emit();
});
}
Expand Down Expand Up @@ -483,6 +484,7 @@ fn check_exhaustive<'p, 'tcx>(
"ensure that all possible cases are being handled, \
possibly by adding wildcards or more match arms",
);
err.note(&format!("the matched value is of type `{}`", scrut_ty));
err.emit();
}

Expand Down
34 changes: 17 additions & 17 deletions src/librustc_save_analysis/dump_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
collector.visit_pat(&arg.pat);

for (id, ident, ..) in collector.collected_idents {
let hir_id = self.tcx.hir().node_to_hir_id(id);
let hir_id = self.tcx.hir().node_id_to_hir_id(id);
let typ = match self.save_ctxt.tables.node_type_opt(hir_id) {
Some(s) => s.to_string(),
None => continue,
Expand Down Expand Up @@ -268,7 +268,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
) {
debug!("process_method: {}:{}", id, ident);

let hir_id = self.tcx.hir().node_to_hir_id(id);
let hir_id = self.tcx.hir().node_id_to_hir_id(id);
self.nest_tables(id, |v| {
if let Some(mut method_data) = v.save_ctxt.get_method_data(id, ident, span) {
v.process_formals(&sig.decl.inputs, &method_data.qualname);
Expand Down Expand Up @@ -308,7 +308,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
fn process_struct_field_def(&mut self, field: &ast::StructField, parent_id: NodeId) {
let field_data = self.save_ctxt.get_field_data(field, parent_id);
if let Some(field_data) = field_data {
let hir_id = self.tcx.hir().node_to_hir_id(field.id);
let hir_id = self.tcx.hir().node_id_to_hir_id(field.id);
self.dumper.dump_def(&access_from!(self.save_ctxt, field, hir_id), field_data);
}
}
Expand Down Expand Up @@ -360,7 +360,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
ty_params: &'l ast::Generics,
body: Option<&'l ast::Block>,
) {
let hir_id = self.tcx.hir().node_to_hir_id(item.id);
let hir_id = self.tcx.hir().node_id_to_hir_id(item.id);
self.nest_tables(item.id, |v| {
if let Some(fn_data) = v.save_ctxt.get_item_data(item) {
down_cast_data!(fn_data, DefData, item.span);
Expand Down Expand Up @@ -402,7 +402,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
typ: &'l ast::Ty,
expr: Option<&'l ast::Expr>,
) {
let hir_id = self.tcx.hir().node_to_hir_id(item.id);
let hir_id = self.tcx.hir().node_id_to_hir_id(item.id);
self.nest_tables(item.id, |v| {
if let Some(var_data) = v.save_ctxt.get_item_data(item) {
down_cast_data!(var_data, DefData, item.span);
Expand All @@ -429,7 +429,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
if !self.span.filter_generated(ident.span) {
let sig = sig::assoc_const_signature(id, ident.name, typ, expr, &self.save_ctxt);
let span = self.span_from_span(ident.span);
let hir_id = self.tcx.hir().node_to_hir_id(id);
let hir_id = self.tcx.hir().node_id_to_hir_id(id);

self.dumper.dump_def(
&access_from_vis!(self.save_ctxt, vis, hir_id),
Expand Down Expand Up @@ -503,7 +503,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {

if !self.span.filter_generated(item.ident.span) {
let span = self.span_from_span(item.ident.span);
let hir_id = self.tcx.hir().node_to_hir_id(item.id);
let hir_id = self.tcx.hir().node_id_to_hir_id(item.id);
self.dumper.dump_def(
&access_from!(self.save_ctxt, item, hir_id),
Def {
Expand Down Expand Up @@ -546,7 +546,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
};
down_cast_data!(enum_data, DefData, item.span);

let hir_id = self.tcx.hir().node_to_hir_id(item.id);
let hir_id = self.tcx.hir().node_id_to_hir_id(item.id);
let access = access_from!(self.save_ctxt, item, hir_id);

for variant in &enum_definition.variants {
Expand Down Expand Up @@ -699,7 +699,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
let id = id_from_node_id(item.id, &self.save_ctxt);
let span = self.span_from_span(item.ident.span);
let children = methods.iter().map(|i| id_from_node_id(i.id, &self.save_ctxt)).collect();
let hir_id = self.tcx.hir().node_to_hir_id(item.id);
let hir_id = self.tcx.hir().node_id_to_hir_id(item.id);
self.dumper.dump_def(
&access_from!(self.save_ctxt, item, hir_id),
Def {
Expand Down Expand Up @@ -759,7 +759,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
fn process_mod(&mut self, item: &ast::Item) {
if let Some(mod_data) = self.save_ctxt.get_item_data(item) {
down_cast_data!(mod_data, DefData, item.span);
let hir_id = self.tcx.hir().node_to_hir_id(item.id);
let hir_id = self.tcx.hir().node_id_to_hir_id(item.id);
self.dumper.dump_def(&access_from!(self.save_ctxt, item, hir_id), mod_data);
}
}
Expand Down Expand Up @@ -864,7 +864,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
match p.kind {
PatKind::Struct(ref _path, ref fields, _) => {
// FIXME do something with _path?
let hir_id = self.tcx.hir().node_to_hir_id(p.id);
let hir_id = self.tcx.hir().node_id_to_hir_id(p.id);
let adt = match self.save_ctxt.tables.node_type_opt(hir_id) {
Some(ty) if ty.ty_adt_def().is_some() => ty.ty_adt_def().unwrap(),
_ => {
Expand Down Expand Up @@ -903,7 +903,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
for (id, ident, _) in collector.collected_idents {
match self.save_ctxt.get_path_res(id) {
Res::Local(hir_id) => {
let id = self.tcx.hir().hir_to_node_id(hir_id);
let id = self.tcx.hir().hir_id_to_node_id(hir_id);
let typ = self
.save_ctxt
.tables
Expand Down Expand Up @@ -1126,7 +1126,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {

// The access is calculated using the current tree ID, but with the root tree's visibility
// (since nested trees don't have their own visibility).
let hir_id = self.tcx.hir().node_to_hir_id(id);
let hir_id = self.tcx.hir().node_id_to_hir_id(id);
let access = access_from!(self.save_ctxt, root_item, hir_id);

// The parent `DefId` of a given use tree is always the enclosing item.
Expand Down Expand Up @@ -1321,7 +1321,7 @@ impl<'l, 'tcx> Visitor<'l> for DumpVisitor<'l, 'tcx> {
if !self.span.filter_generated(item.ident.span) {
let span = self.span_from_span(item.ident.span);
let id = id_from_node_id(item.id, &self.save_ctxt);
let hir_id = self.tcx.hir().node_to_hir_id(item.id);
let hir_id = self.tcx.hir().node_id_to_hir_id(item.id);

self.dumper.dump_def(
&access_from!(self.save_ctxt, item, hir_id),
Expand Down Expand Up @@ -1420,7 +1420,7 @@ impl<'l, 'tcx> Visitor<'l> for DumpVisitor<'l, 'tcx> {
self.process_macro_use(ex.span);
match ex.kind {
ast::ExprKind::Struct(ref path, ref fields, ref base) => {
let expr_hir_id = self.save_ctxt.tcx.hir().node_to_hir_id(ex.id);
let expr_hir_id = self.save_ctxt.tcx.hir().node_id_to_hir_id(ex.id);
let hir_expr = self.save_ctxt.tcx.hir().expect_expr(expr_hir_id);
let adt = match self.save_ctxt.tables.expr_ty_opt(&hir_expr) {
Some(ty) if ty.ty_adt_def().is_some() => ty.ty_adt_def().unwrap(),
Expand All @@ -1429,7 +1429,7 @@ impl<'l, 'tcx> Visitor<'l> for DumpVisitor<'l, 'tcx> {
return;
}
};
let node_id = self.save_ctxt.tcx.hir().hir_to_node_id(hir_expr.hir_id);
let node_id = self.save_ctxt.tcx.hir().hir_id_to_node_id(hir_expr.hir_id);
let res = self.save_ctxt.get_path_res(node_id);
self.process_struct_lit(ex, path, fields, adt.variant_of_res(res), base)
}
Expand Down Expand Up @@ -1514,7 +1514,7 @@ impl<'l, 'tcx> Visitor<'l> for DumpVisitor<'l, 'tcx> {
}

fn visit_foreign_item(&mut self, item: &'l ast::ForeignItem) {
let hir_id = self.tcx.hir().node_to_hir_id(item.id);
let hir_id = self.tcx.hir().node_id_to_hir_id(item.id);
let access = access_from!(self.save_ctxt, item, hir_id);

match item.kind {
Expand Down
Loading