Skip to content

Commit cdb50c6

Browse files
committed
Auto merge of #70383 - Centril:rollup-hmfft3y, r=Centril
Rollup of 7 pull requests Successful merges: - #70331 (Increase verbosity when using update syntax with private fields) - #70349 (move `hir_id_validation` to `rustc_passes` + simplify `hir::map` code) - #70361 (Update backtrace crate to 0.3.46) - #70364 (resolve: Remove `rustc_attrs` as a standalone feature gate) - #70369 (Fix smaller issues with invalid placeholder type errors) - #70373 (normalize some imports & prefer direct ones) - #70376 (Add test for #66312) Failed merges: r? @ghost
2 parents 02046a5 + 83fc855 commit cdb50c6

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

+315
-377
lines changed

Cargo.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,9 @@ checksum = "1d49d90015b3c36167a20fe2810c5cd875ad504b39cff3d4eae7977e6b7c1cb2"
121121

122122
[[package]]
123123
name = "backtrace"
124-
version = "0.3.45"
124+
version = "0.3.46"
125125
source = "registry+https://github.com/rust-lang/crates.io-index"
126-
checksum = "ad235dabf00f36301792cfe82499880ba54c6486be094d1047b02bacb67c14e8"
126+
checksum = "b1e692897359247cc6bb902933361652380af0f1b7651ae5c5013407f30e109e"
127127
dependencies = [
128128
"backtrace-sys",
129129
"cfg-if",
@@ -135,9 +135,9 @@ dependencies = [
135135

136136
[[package]]
137137
name = "backtrace-sys"
138-
version = "0.1.34"
138+
version = "0.1.35"
139139
source = "registry+https://github.com/rust-lang/crates.io-index"
140-
checksum = "ca797db0057bae1a7aa2eef3283a874695455cecf08a43bfb8507ee0ebc1ed69"
140+
checksum = "7de8aba10a69c8e8d7622c5710229485ec32e9d55fdad160ea559c086fdcd118"
141141
dependencies = [
142142
"cc",
143143
"compiler_builtins",

src/librustc/dep_graph/dep_node.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@
4949
//! user of the `DepNode` API of having to know how to compute the expected
5050
//! fingerprint for a given set of node parameters.
5151
52-
use crate::hir::map::DefPathHash;
53-
use crate::ich::Fingerprint;
5452
use crate::mir;
5553
use crate::mir::interpret::{GlobalId, LitToConstInput};
5654
use crate::traits;
@@ -62,7 +60,9 @@ use crate::traits::query::{
6260
use crate::ty::subst::SubstsRef;
6361
use crate::ty::{self, ParamEnvAnd, Ty, TyCtxt};
6462

63+
use rustc_data_structures::fingerprint::Fingerprint;
6564
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, CRATE_DEF_INDEX};
65+
use rustc_hir::definitions::DefPathHash;
6666
use rustc_hir::HirId;
6767
use rustc_span::symbol::Symbol;
6868
use std::hash::Hash;

src/librustc/hir/map/collector.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::arena::Arena;
2-
use crate::hir::map::definitions::{self, DefPathHash};
32
use crate::hir::map::{Entry, HirOwnerData, Map};
43
use crate::hir::{Owner, OwnerNodes, ParentedNode};
54
use crate::ich::StableHashingContext;
@@ -11,6 +10,7 @@ use rustc_data_structures::svh::Svh;
1110
use rustc_hir as hir;
1211
use rustc_hir::def_id::CRATE_DEF_INDEX;
1312
use rustc_hir::def_id::{LocalDefId, LOCAL_CRATE};
13+
use rustc_hir::definitions::{self, DefPathHash};
1414
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
1515
use rustc_hir::*;
1616
use rustc_index::vec::{Idx, IndexVec};

src/librustc/hir/map/mod.rs

+74-138
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ use rustc_ast::ast::{self, Name, NodeId};
77
use rustc_data_structures::svh::Svh;
88
use rustc_hir::def::{DefKind, Res};
99
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE};
10-
pub use rustc_hir::definitions;
11-
pub use rustc_hir::definitions::{DefKey, DefPath, DefPathData, DefPathHash};
12-
pub use rustc_hir::definitions::{Definitions, DisambiguatedDefPathData};
10+
use rustc_hir::definitions::{DefKey, DefPath, Definitions};
1311
use rustc_hir::intravisit;
1412
use rustc_hir::itemlikevisit::ItemLikeVisitor;
1513
use rustc_hir::print::Nested;
@@ -23,8 +21,6 @@ use rustc_target::spec::abi::Abi;
2321

2422
pub mod blocks;
2523
mod collector;
26-
mod hir_id_validator;
27-
pub use hir_id_validator::check_crate;
2824

2925
/// Represents an entry and its parent `HirId`.
3026
#[derive(Copy, Clone, Debug)]
@@ -44,79 +40,42 @@ impl<'hir> Entry<'hir> {
4440

4541
fn fn_decl<'hir>(node: Node<'hir>) -> Option<&'hir FnDecl<'hir>> {
4642
match node {
47-
Node::Item(ref item) => match item.kind {
48-
ItemKind::Fn(ref sig, _, _) => Some(&sig.decl),
49-
_ => None,
50-
},
51-
52-
Node::TraitItem(ref item) => match item.kind {
53-
TraitItemKind::Fn(ref sig, _) => Some(&sig.decl),
54-
_ => None,
55-
},
56-
57-
Node::ImplItem(ref item) => match item.kind {
58-
ImplItemKind::Fn(ref sig, _) => Some(&sig.decl),
59-
_ => None,
60-
},
61-
62-
Node::Expr(ref expr) => match expr.kind {
63-
ExprKind::Closure(_, ref fn_decl, ..) => Some(fn_decl),
64-
_ => None,
65-
},
66-
43+
Node::Item(Item { kind: ItemKind::Fn(sig, _, _), .. })
44+
| Node::TraitItem(TraitItem { kind: TraitItemKind::Fn(sig, _), .. })
45+
| Node::ImplItem(ImplItem { kind: ImplItemKind::Fn(sig, _), .. }) => Some(&sig.decl),
46+
Node::Expr(Expr { kind: ExprKind::Closure(_, fn_decl, ..), .. }) => Some(fn_decl),
6747
_ => None,
6848
}
6949
}
7050

7151
fn fn_sig<'hir>(node: Node<'hir>) -> Option<&'hir FnSig<'hir>> {
7252
match &node {
73-
Node::Item(item) => match &item.kind {
74-
ItemKind::Fn(sig, _, _) => Some(sig),
75-
_ => None,
76-
},
77-
78-
Node::TraitItem(item) => match &item.kind {
79-
TraitItemKind::Fn(sig, _) => Some(sig),
80-
_ => None,
81-
},
82-
83-
Node::ImplItem(item) => match &item.kind {
84-
ImplItemKind::Fn(sig, _) => Some(sig),
85-
_ => None,
86-
},
87-
53+
Node::Item(Item { kind: ItemKind::Fn(sig, _, _), .. })
54+
| Node::TraitItem(TraitItem { kind: TraitItemKind::Fn(sig, _), .. })
55+
| Node::ImplItem(ImplItem { kind: ImplItemKind::Fn(sig, _), .. }) => Some(sig),
8856
_ => None,
8957
}
9058
}
9159

9260
fn associated_body<'hir>(node: Node<'hir>) -> Option<BodyId> {
9361
match node {
94-
Node::Item(item) => match item.kind {
95-
ItemKind::Const(_, body) | ItemKind::Static(.., body) | ItemKind::Fn(.., body) => {
96-
Some(body)
97-
}
98-
_ => None,
99-
},
100-
101-
Node::TraitItem(item) => match item.kind {
102-
TraitItemKind::Const(_, Some(body)) | TraitItemKind::Fn(_, TraitFn::Provided(body)) => {
103-
Some(body)
104-
}
105-
_ => None,
106-
},
107-
108-
Node::ImplItem(item) => match item.kind {
109-
ImplItemKind::Const(_, body) | ImplItemKind::Fn(_, body) => Some(body),
110-
_ => None,
111-
},
62+
Node::Item(Item {
63+
kind: ItemKind::Const(_, body) | ItemKind::Static(.., body) | ItemKind::Fn(.., body),
64+
..
65+
})
66+
| Node::TraitItem(TraitItem {
67+
kind:
68+
TraitItemKind::Const(_, Some(body)) | TraitItemKind::Fn(_, TraitFn::Provided(body)),
69+
..
70+
})
71+
| Node::ImplItem(ImplItem {
72+
kind: ImplItemKind::Const(_, body) | ImplItemKind::Fn(_, body),
73+
..
74+
})
75+
| Node::Expr(Expr { kind: ExprKind::Closure(.., body, _, _), .. }) => Some(*body),
11276

11377
Node::AnonConst(constant) => Some(constant.body),
11478

115-
Node::Expr(expr) => match expr.kind {
116-
ExprKind::Closure(.., body, _, _) => Some(body),
117-
_ => None,
118-
},
119-
12079
_ => None,
12180
}
12281
}
@@ -520,20 +479,21 @@ impl<'hir> Map<'hir> {
520479
}
521480

522481
pub fn get_generics(&self, id: DefId) -> Option<&'hir Generics<'hir>> {
523-
self.get_if_local(id).and_then(|node| match node {
524-
Node::ImplItem(ref impl_item) => Some(&impl_item.generics),
525-
Node::TraitItem(ref trait_item) => Some(&trait_item.generics),
526-
Node::Item(ref item) => match item.kind {
527-
ItemKind::Fn(_, ref generics, _)
528-
| ItemKind::TyAlias(_, ref generics)
529-
| ItemKind::Enum(_, ref generics)
530-
| ItemKind::Struct(_, ref generics)
531-
| ItemKind::Union(_, ref generics)
532-
| ItemKind::Trait(_, _, ref generics, ..)
533-
| ItemKind::TraitAlias(ref generics, _)
534-
| ItemKind::Impl { ref generics, .. } => Some(generics),
535-
_ => None,
536-
},
482+
self.get_if_local(id).and_then(|node| match &node {
483+
Node::ImplItem(impl_item) => Some(&impl_item.generics),
484+
Node::TraitItem(trait_item) => Some(&trait_item.generics),
485+
Node::Item(Item {
486+
kind:
487+
ItemKind::Fn(_, generics, _)
488+
| ItemKind::TyAlias(_, generics)
489+
| ItemKind::Enum(_, generics)
490+
| ItemKind::Struct(_, generics)
491+
| ItemKind::Union(_, generics)
492+
| ItemKind::Trait(_, _, generics, ..)
493+
| ItemKind::TraitAlias(generics, _)
494+
| ItemKind::Impl { generics, .. },
495+
..
496+
}) => Some(generics),
537497
_ => None,
538498
})
539499
}
@@ -573,11 +533,12 @@ impl<'hir> Map<'hir> {
573533
_ => return false,
574534
}
575535
match self.find(self.get_parent_node(id)) {
576-
Some(Node::Item(_)) | Some(Node::TraitItem(_)) | Some(Node::ImplItem(_)) => true,
577-
Some(Node::Expr(e)) => match e.kind {
578-
ExprKind::Closure(..) => true,
579-
_ => false,
580-
},
536+
Some(
537+
Node::Item(_)
538+
| Node::TraitItem(_)
539+
| Node::ImplItem(_)
540+
| Node::Expr(Expr { kind: ExprKind::Closure(..), .. }),
541+
) => true,
581542
_ => false,
582543
}
583544
}
@@ -644,12 +605,8 @@ impl<'hir> Map<'hir> {
644605
if let (Some((_, next_node)), false) = (iter.peek(), ignore_tail) {
645606
match next_node {
646607
Node::Block(Block { expr: None, .. }) => return None,
647-
Node::Block(Block { expr: Some(expr), .. }) => {
648-
if hir_id != expr.hir_id {
649-
// The current node is not the tail expression of its parent.
650-
return None;
651-
}
652-
}
608+
// The current node is not the tail expression of its parent.
609+
Node::Block(Block { expr: Some(e), .. }) if hir_id != e.hir_id => return None,
653610
_ => {}
654611
}
655612
}
@@ -659,14 +616,11 @@ impl<'hir> Map<'hir> {
659616
| Node::TraitItem(_)
660617
| Node::Expr(Expr { kind: ExprKind::Closure(..), .. })
661618
| Node::ImplItem(_) => return Some(hir_id),
662-
Node::Expr(ref expr) => {
663-
match expr.kind {
664-
// Ignore `return`s on the first iteration
665-
ExprKind::Loop(..) | ExprKind::Ret(..) => return None,
666-
_ => {}
667-
}
619+
// Ignore `return`s on the first iteration
620+
Node::Expr(Expr { kind: ExprKind::Loop(..) | ExprKind::Ret(..), .. })
621+
| Node::Local(_) => {
622+
return None;
668623
}
669-
Node::Local(_) => return None,
670624
_ => {}
671625
}
672626
}
@@ -710,17 +664,12 @@ impl<'hir> Map<'hir> {
710664
pub fn get_match_if_cause(&self, hir_id: HirId) -> Option<&'hir Expr<'hir>> {
711665
for (_, node) in self.parent_iter(hir_id) {
712666
match node {
713-
Node::Item(_) | Node::ForeignItem(_) | Node::TraitItem(_) | Node::ImplItem(_) => {
714-
break;
715-
}
716-
Node::Expr(expr) => match expr.kind {
717-
ExprKind::Match(_, _, _) => return Some(expr),
718-
_ => {}
719-
},
720-
Node::Stmt(stmt) => match stmt.kind {
721-
StmtKind::Local(_) => break,
722-
_ => {}
723-
},
667+
Node::Item(_)
668+
| Node::ForeignItem(_)
669+
| Node::TraitItem(_)
670+
| Node::ImplItem(_)
671+
| Node::Stmt(Stmt { kind: StmtKind::Local(_), .. }) => break,
672+
Node::Expr(expr @ Expr { kind: ExprKind::Match(..), .. }) => return Some(expr),
724673
_ => {}
725674
}
726675
}
@@ -730,32 +679,22 @@ impl<'hir> Map<'hir> {
730679
/// Returns the nearest enclosing scope. A scope is roughly an item or block.
731680
pub fn get_enclosing_scope(&self, hir_id: HirId) -> Option<HirId> {
732681
for (hir_id, node) in self.parent_iter(hir_id) {
733-
if match node {
734-
Node::Item(i) => match i.kind {
682+
if let Node::Item(Item {
683+
kind:
735684
ItemKind::Fn(..)
736685
| ItemKind::Mod(..)
737686
| ItemKind::Enum(..)
738687
| ItemKind::Struct(..)
739688
| ItemKind::Union(..)
740689
| ItemKind::Trait(..)
741-
| ItemKind::Impl { .. } => true,
742-
_ => false,
743-
},
744-
Node::ForeignItem(fi) => match fi.kind {
745-
ForeignItemKind::Fn(..) => true,
746-
_ => false,
747-
},
748-
Node::TraitItem(ti) => match ti.kind {
749-
TraitItemKind::Fn(..) => true,
750-
_ => false,
751-
},
752-
Node::ImplItem(ii) => match ii.kind {
753-
ImplItemKind::Fn(..) => true,
754-
_ => false,
755-
},
756-
Node::Block(_) => true,
757-
_ => false,
758-
} {
690+
| ItemKind::Impl { .. },
691+
..
692+
})
693+
| Node::ForeignItem(ForeignItem { kind: ForeignItemKind::Fn(..), .. })
694+
| Node::TraitItem(TraitItem { kind: TraitItemKind::Fn(..), .. })
695+
| Node::ImplItem(ImplItem { kind: ImplItemKind::Fn(..), .. })
696+
| Node::Block(_) = node
697+
{
759698
return Some(hir_id);
760699
}
761700
}
@@ -771,11 +710,11 @@ impl<'hir> Map<'hir> {
771710
return CRATE_HIR_ID;
772711
}
773712
match self.get(scope) {
774-
Node::Item(i) => match i.kind {
775-
ItemKind::OpaqueTy(OpaqueTy { impl_trait_fn: None, .. }) => {}
776-
_ => break,
777-
},
778-
Node::Block(_) => {}
713+
Node::Item(Item {
714+
kind: ItemKind::OpaqueTy(OpaqueTy { impl_trait_fn: None, .. }),
715+
..
716+
})
717+
| Node::Block(_) => {}
779718
_ => break,
780719
}
781720
}
@@ -823,14 +762,11 @@ impl<'hir> Map<'hir> {
823762

824763
pub fn expect_variant_data(&self, id: HirId) -> &'hir VariantData<'hir> {
825764
match self.find(id) {
826-
Some(Node::Item(i)) => match i.kind {
827-
ItemKind::Struct(ref struct_def, _) | ItemKind::Union(ref struct_def, _) => {
828-
struct_def
829-
}
830-
_ => bug!("struct ID bound to non-struct {}", self.node_to_string(id)),
831-
},
765+
Some(
766+
Node::Ctor(vd)
767+
| Node::Item(Item { kind: ItemKind::Struct(vd, _) | ItemKind::Union(vd, _), .. }),
768+
) => vd,
832769
Some(Node::Variant(variant)) => &variant.data,
833-
Some(Node::Ctor(data)) => data,
834770
_ => bug!("expected struct or variant, found {}", self.node_to_string(id)),
835771
}
836772
}

src/librustc/ich/hcx.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
use crate::hir::map::definitions::{DefPathHash, Definitions};
2-
use crate::ich::{self, CachingSourceMapView};
1+
use crate::ich;
32
use crate::middle::cstore::CrateStore;
43
use crate::ty::{fast_reject, TyCtxt};
54

@@ -9,10 +8,11 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
98
use rustc_data_structures::sync::Lrc;
109
use rustc_hir as hir;
1110
use rustc_hir::def_id::{DefId, LocalDefId};
11+
use rustc_hir::definitions::{DefPathHash, Definitions};
1212
use rustc_session::Session;
1313
use rustc_span::source_map::SourceMap;
1414
use rustc_span::symbol::Symbol;
15-
use rustc_span::{BytePos, SourceFile};
15+
use rustc_span::{BytePos, CachingSourceMapView, SourceFile};
1616

1717
use smallvec::SmallVec;
1818
use std::cmp::Ord;

0 commit comments

Comments
 (0)