|
1 | 1 | use crate::check::{FnCtxt, Inherited}; |
2 | 2 | use crate::constrained_generic_params::{identify_constrained_generic_params, Parameter}; |
3 | 3 |
|
4 | | -use crate::hir::def_id::DefId; |
| 4 | +use rustc::hir::def_id::DefId; |
| 5 | +use rustc::hir::ItemKind; |
5 | 6 | use rustc::infer::opaque_types::may_define_opaque_type; |
6 | 7 | use rustc::middle::lang_items; |
7 | 8 | use rustc::traits::{self, ObligationCause, ObligationCauseCode}; |
8 | 9 | use rustc::ty::subst::{InternalSubsts, Subst}; |
9 | | -use rustc::ty::{self, GenericParamDefKind, ToPredicate, Ty, TyCtxt, TypeFoldable}; |
| 10 | +use rustc::ty::{self, AdtKind, GenericParamDefKind, ToPredicate, Ty, TyCtxt, TypeFoldable}; |
10 | 11 | use rustc::util::nodemap::{FxHashMap, FxHashSet}; |
11 | 12 |
|
12 | 13 | use errors::DiagnosticBuilder; |
@@ -252,6 +253,15 @@ fn for_id(tcx: TyCtxt<'_>, id: hir::HirId, span: Span) -> CheckWfFcxBuilder<'_> |
252 | 253 | } |
253 | 254 | } |
254 | 255 |
|
| 256 | +fn item_adt_kind(kind: &ItemKind<'_>) -> Option<AdtKind> { |
| 257 | + match kind { |
| 258 | + ItemKind::Struct(..) => Some(AdtKind::Struct), |
| 259 | + ItemKind::Union(..) => Some(AdtKind::Union), |
| 260 | + ItemKind::Enum(..) => Some(AdtKind::Enum), |
| 261 | + _ => None, |
| 262 | + } |
| 263 | +} |
| 264 | + |
255 | 265 | /// In a type definition, we check that to ensure that the types of the fields are well-formed. |
256 | 266 | fn check_type_defn<'tcx, F>( |
257 | 267 | tcx: TyCtxt<'tcx>, |
@@ -297,7 +307,7 @@ fn check_type_defn<'tcx, F>( |
297 | 307 | field.span, |
298 | 308 | fcx.body_id, |
299 | 309 | traits::FieldSized { |
300 | | - adt_kind: match item.kind.adt_kind() { |
| 310 | + adt_kind: match item_adt_kind(&item.kind) { |
301 | 311 | Some(i) => i, |
302 | 312 | None => bug!(), |
303 | 313 | }, |
|
0 commit comments