@@ -8,7 +8,7 @@ use rustc_errors::{
88use rustc_hir as hir;
99use rustc_hir:: def:: { DefKind , Res } ;
1010use rustc_hir:: intravisit;
11- use rustc_hir:: { GenericParamKind , ImplItemKind , TraitItemKind } ;
11+ use rustc_hir:: { GenericParamKind , ImplItemKind } ;
1212use rustc_infer:: infer:: outlives:: env:: OutlivesEnvironment ;
1313use rustc_infer:: infer:: type_variable:: { TypeVariableOrigin , TypeVariableOriginKind } ;
1414use rustc_infer:: infer:: { self , InferCtxt , TyCtxtInferExt } ;
@@ -918,7 +918,7 @@ fn report_trait_method_mismatch<'tcx>(
918918 // When the `impl` receiver is an arbitrary self type, like `self: Box<Self>`, the
919919 // span points only at the type `Box<Self`>, but we want to cover the whole
920920 // 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 ( ) ;
922922 let span = tcx
923923 . hir ( )
924924 . body_param_names ( body)
@@ -1080,12 +1080,12 @@ fn extract_spans_for_error_reporting<'tcx>(
10801080) -> ( Span , Option < Span > ) {
10811081 let tcx = infcx. tcx ;
10821082 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 ( ) ;
10841084 sig. decl . inputs . iter ( ) . map ( |t| t. span ) . chain ( iter:: once ( sig. decl . output . span ( ) ) )
10851085 } ;
10861086
10871087 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 ( ) ;
10891089 sig. decl . inputs . iter ( ) . map ( |t| t. span ) . chain ( iter:: once ( sig. decl . output . span ( ) ) )
10901090 } ) ;
10911091
@@ -1358,7 +1358,7 @@ fn compare_number_of_method_arguments<'tcx>(
13581358 . def_id
13591359 . as_local ( )
13601360 . 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 ( ) ;
13621362 let pos = trait_number_args. saturating_sub ( 1 ) ;
13631363 trait_m_sig. decl . inputs . get ( pos) . map ( |arg| {
13641364 if pos == 0 {
@@ -1370,7 +1370,7 @@ fn compare_number_of_method_arguments<'tcx>(
13701370 } )
13711371 . or ( trait_item_span) ;
13721372
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 ( ) ;
13741374 let pos = impl_number_args. saturating_sub ( 1 ) ;
13751375 let impl_span = impl_m_sig
13761376 . decl
@@ -1506,7 +1506,7 @@ fn compare_synthetic_generics<'tcx>(
15061506 let _: Option < _ > = try {
15071507 let impl_m = impl_m. def_id . as_local ( ) ?;
15081508 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 ( ) ;
15101510 let input_tys = sig. decl . inputs ;
15111511
15121512 struct Visitor ( Option < Span > , hir:: def_id:: LocalDefId ) ;
@@ -1704,7 +1704,7 @@ pub(super) fn compare_impl_const_raw(
17041704 ) ;
17051705
17061706 // 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 ( ) ;
17081708 cause. span = ty. span ;
17091709
17101710 let mut diag = struct_span_err ! (
@@ -1717,7 +1717,7 @@ pub(super) fn compare_impl_const_raw(
17171717
17181718 let trait_c_span = trait_const_item_def. as_local ( ) . map ( |trait_c_def_id| {
17191719 // 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 ( ) ;
17211721 ty. span
17221722 } ) ;
17231723
0 commit comments