@@ -8,7 +8,7 @@ use rustc_errors::{
8
8
use rustc_hir as hir;
9
9
use rustc_hir:: def:: { DefKind , Res } ;
10
10
use rustc_hir:: intravisit;
11
- use rustc_hir:: { GenericParamKind , ImplItemKind , TraitItemKind } ;
11
+ use rustc_hir:: { GenericParamKind , ImplItemKind } ;
12
12
use rustc_infer:: infer:: outlives:: env:: OutlivesEnvironment ;
13
13
use rustc_infer:: infer:: type_variable:: { TypeVariableOrigin , TypeVariableOriginKind } ;
14
14
use rustc_infer:: infer:: { self , InferCtxt , TyCtxtInferExt } ;
@@ -918,7 +918,7 @@ fn report_trait_method_mismatch<'tcx>(
918
918
// When the `impl` receiver is an arbitrary self type, like `self: Box<Self>`, the
919
919
// span points only at the type `Box<Self`>, but we want to cover the whole
920
920
// argument pattern and type.
921
- let ImplItemKind :: Fn ( ref sig, body) = tcx. hir ( ) . expect_impl_item ( impl_m. def_id . expect_local ( ) ) . kind else { bug ! ( "{impl_m:?} is not a method" ) } ;
921
+ let ( sig, body) = tcx. hir ( ) . expect_impl_item ( impl_m. def_id . expect_local ( ) ) . expect_fn ( ) ;
922
922
let span = tcx
923
923
. hir ( )
924
924
. body_param_names ( body)
@@ -1080,12 +1080,12 @@ fn extract_spans_for_error_reporting<'tcx>(
1080
1080
) -> ( Span , Option < Span > ) {
1081
1081
let tcx = infcx. tcx ;
1082
1082
let mut impl_args = {
1083
- let ImplItemKind :: Fn ( sig, _) = & tcx. hir ( ) . expect_impl_item ( impl_m. def_id . expect_local ( ) ) . kind else { bug ! ( "{:?} is not a method" , impl_m ) } ;
1083
+ let ( sig, _) = tcx. hir ( ) . expect_impl_item ( impl_m. def_id . expect_local ( ) ) . expect_fn ( ) ;
1084
1084
sig. decl . inputs . iter ( ) . map ( |t| t. span ) . chain ( iter:: once ( sig. decl . output . span ( ) ) )
1085
1085
} ;
1086
1086
1087
1087
let trait_args = trait_m. def_id . as_local ( ) . map ( |def_id| {
1088
- let TraitItemKind :: Fn ( sig, _) = & tcx. hir ( ) . expect_trait_item ( def_id) . kind else { bug ! ( "{:?} is not a TraitItemKind::Fn" , trait_m ) } ;
1088
+ let ( sig, _) = tcx. hir ( ) . expect_trait_item ( def_id) . expect_fn ( ) ;
1089
1089
sig. decl . inputs . iter ( ) . map ( |t| t. span ) . chain ( iter:: once ( sig. decl . output . span ( ) ) )
1090
1090
} ) ;
1091
1091
@@ -1358,7 +1358,7 @@ fn compare_number_of_method_arguments<'tcx>(
1358
1358
. def_id
1359
1359
. as_local ( )
1360
1360
. and_then ( |def_id| {
1361
- let TraitItemKind :: Fn ( trait_m_sig, _) = & tcx. hir ( ) . expect_trait_item ( def_id) . kind else { bug ! ( "{:?} is not a method" , impl_m ) } ;
1361
+ let ( trait_m_sig, _) = & tcx. hir ( ) . expect_trait_item ( def_id) . expect_fn ( ) ;
1362
1362
let pos = trait_number_args. saturating_sub ( 1 ) ;
1363
1363
trait_m_sig. decl . inputs . get ( pos) . map ( |arg| {
1364
1364
if pos == 0 {
@@ -1370,7 +1370,7 @@ fn compare_number_of_method_arguments<'tcx>(
1370
1370
} )
1371
1371
. or ( trait_item_span) ;
1372
1372
1373
- let ImplItemKind :: Fn ( impl_m_sig, _) = & tcx. hir ( ) . expect_impl_item ( impl_m. def_id . expect_local ( ) ) . kind else { bug ! ( "{:?} is not a method" , impl_m ) } ;
1373
+ let ( impl_m_sig, _) = & tcx. hir ( ) . expect_impl_item ( impl_m. def_id . expect_local ( ) ) . expect_fn ( ) ;
1374
1374
let pos = impl_number_args. saturating_sub ( 1 ) ;
1375
1375
let impl_span = impl_m_sig
1376
1376
. decl
@@ -1506,7 +1506,7 @@ fn compare_synthetic_generics<'tcx>(
1506
1506
let _: Option < _ > = try {
1507
1507
let impl_m = impl_m. def_id . as_local ( ) ?;
1508
1508
let impl_m = tcx. hir ( ) . expect_impl_item ( impl_m) ;
1509
- let hir :: ImplItemKind :: Fn ( sig, _) = & impl_m. kind else { unreachable ! ( ) } ;
1509
+ let ( sig, _) = impl_m. expect_fn ( ) ;
1510
1510
let input_tys = sig. decl . inputs ;
1511
1511
1512
1512
struct Visitor ( Option < Span > , hir:: def_id:: LocalDefId ) ;
@@ -1704,7 +1704,7 @@ pub(super) fn compare_impl_const_raw(
1704
1704
) ;
1705
1705
1706
1706
// Locate the Span containing just the type of the offending impl
1707
- let ImplItemKind :: Const ( ty, _) = tcx. hir ( ) . expect_impl_item ( impl_const_item_def) . kind else { bug ! ( "{impl_const_item:?} is not a impl const" ) } ;
1707
+ let ( ty, _) = tcx. hir ( ) . expect_impl_item ( impl_const_item_def) . expect_const ( ) ;
1708
1708
cause. span = ty. span ;
1709
1709
1710
1710
let mut diag = struct_span_err ! (
@@ -1717,7 +1717,7 @@ pub(super) fn compare_impl_const_raw(
1717
1717
1718
1718
let trait_c_span = trait_const_item_def. as_local ( ) . map ( |trait_c_def_id| {
1719
1719
// Add a label to the Span containing just the type of the const
1720
- let TraitItemKind :: Const ( ty, _) = tcx. hir ( ) . expect_trait_item ( trait_c_def_id) . kind else { bug ! ( "{trait_const_item:?} is not a trait const" ) } ;
1720
+ let ( ty, _) = tcx. hir ( ) . expect_trait_item ( trait_c_def_id) . expect_const ( ) ;
1721
1721
ty. span
1722
1722
} ) ;
1723
1723
0 commit comments