Skip to content

Commit bbacfcb

Browse files
committed
Avoid checking HIR in variances_of.
1 parent 0c6e246 commit bbacfcb

File tree

1 file changed

+13
-38
lines changed
  • compiler/rustc_typeck/src/variance

1 file changed

+13
-38
lines changed

compiler/rustc_typeck/src/variance/mod.rs

+13-38
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
//!
44
//! [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/variance.html
55
6-
use hir::Node;
76
use rustc_arena::DroplessArena;
8-
use rustc_hir as hir;
7+
use rustc_hir::def::DefKind;
98
use rustc_hir::def_id::DefId;
109
use rustc_middle::ty::query::Providers;
1110
use rustc_middle::ty::{self, CrateVariancesMap, TyCtxt};
@@ -38,42 +37,18 @@ fn crate_variances(tcx: TyCtxt<'_>, (): ()) -> CrateVariancesMap<'_> {
3837
}
3938

4039
fn variances_of(tcx: TyCtxt<'_>, item_def_id: DefId) -> &[ty::Variance] {
41-
let id = tcx.hir().local_def_id_to_hir_id(item_def_id.expect_local());
42-
let unsupported = || {
43-
// Variance not relevant.
44-
span_bug!(tcx.hir().span(id), "asked to compute variance for wrong kind of item")
45-
};
46-
match tcx.hir().get(id) {
47-
Node::Item(item) => match item.kind {
48-
hir::ItemKind::Enum(..)
49-
| hir::ItemKind::Struct(..)
50-
| hir::ItemKind::Union(..)
51-
| hir::ItemKind::Fn(..) => {}
52-
53-
_ => unsupported(),
54-
},
55-
56-
Node::TraitItem(item) => match item.kind {
57-
hir::TraitItemKind::Fn(..) => {}
58-
59-
_ => unsupported(),
60-
},
61-
62-
Node::ImplItem(item) => match item.kind {
63-
hir::ImplItemKind::Fn(..) => {}
64-
65-
_ => unsupported(),
66-
},
67-
68-
Node::ForeignItem(item) => match item.kind {
69-
hir::ForeignItemKind::Fn(..) => {}
70-
71-
_ => unsupported(),
72-
},
73-
74-
Node::Variant(_) | Node::Ctor(..) => {}
75-
76-
_ => unsupported(),
40+
match tcx.def_kind(item_def_id) {
41+
DefKind::Fn
42+
| DefKind::AssocFn
43+
| DefKind::Enum
44+
| DefKind::Struct
45+
| DefKind::Union
46+
| DefKind::Variant
47+
| DefKind::Ctor(..) => {}
48+
_ => {
49+
// Variance not relevant.
50+
span_bug!(tcx.def_span(item_def_id), "asked to compute variance for wrong kind of item")
51+
}
7752
}
7853

7954
// Everything else must be inferred.

0 commit comments

Comments
 (0)