Skip to content

Commit

Permalink
Avoid checking HIR in variances_of.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjgillot committed Apr 10, 2022
1 parent 0c6e246 commit bbacfcb
Showing 1 changed file with 13 additions and 38 deletions.
51 changes: 13 additions & 38 deletions compiler/rustc_typeck/src/variance/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
//!
//! [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/variance.html

use hir::Node;
use rustc_arena::DroplessArena;
use rustc_hir as hir;
use rustc_hir::def::DefKind;
use rustc_hir::def_id::DefId;
use rustc_middle::ty::query::Providers;
use rustc_middle::ty::{self, CrateVariancesMap, TyCtxt};
Expand Down Expand Up @@ -38,42 +37,18 @@ fn crate_variances(tcx: TyCtxt<'_>, (): ()) -> CrateVariancesMap<'_> {
}

fn variances_of(tcx: TyCtxt<'_>, item_def_id: DefId) -> &[ty::Variance] {
let id = tcx.hir().local_def_id_to_hir_id(item_def_id.expect_local());
let unsupported = || {
// Variance not relevant.
span_bug!(tcx.hir().span(id), "asked to compute variance for wrong kind of item")
};
match tcx.hir().get(id) {
Node::Item(item) => match item.kind {
hir::ItemKind::Enum(..)
| hir::ItemKind::Struct(..)
| hir::ItemKind::Union(..)
| hir::ItemKind::Fn(..) => {}

_ => unsupported(),
},

Node::TraitItem(item) => match item.kind {
hir::TraitItemKind::Fn(..) => {}

_ => unsupported(),
},

Node::ImplItem(item) => match item.kind {
hir::ImplItemKind::Fn(..) => {}

_ => unsupported(),
},

Node::ForeignItem(item) => match item.kind {
hir::ForeignItemKind::Fn(..) => {}

_ => unsupported(),
},

Node::Variant(_) | Node::Ctor(..) => {}

_ => unsupported(),
match tcx.def_kind(item_def_id) {
DefKind::Fn
| DefKind::AssocFn
| DefKind::Enum
| DefKind::Struct
| DefKind::Union
| DefKind::Variant
| DefKind::Ctor(..) => {}
_ => {
// Variance not relevant.
span_bug!(tcx.def_span(item_def_id), "asked to compute variance for wrong kind of item")
}
}

// Everything else must be inferred.
Expand Down

0 comments on commit bbacfcb

Please sign in to comment.