@@ -35,6 +35,26 @@ use crate::errors::{LifetimesOrBoundsMismatchOnTrait, MethodShouldReturnFuture};
3535
3636mod refine;
3737
38+ /// Call the query `tcx.compare_impl_item()` directly instead.
39+ pub ( super ) fn compare_impl_item (
40+ tcx : TyCtxt < ' _ > ,
41+ ( impl_item_def_id, trait_item_def_id) : ( LocalDefId , DefId ) ,
42+ ) -> Result < ( ) , ErrorGuaranteed > {
43+ let impl_item = tcx. associated_item ( impl_item_def_id) ;
44+ let trait_item = tcx. associated_item ( trait_item_def_id) ;
45+ let impl_trait_ref =
46+ tcx. impl_trait_ref ( impl_item. container_id ( tcx) ) . unwrap ( ) . instantiate_identity ( ) ;
47+ debug ! ( ?impl_trait_ref) ;
48+
49+ match impl_item. kind {
50+ ty:: AssocKind :: Fn => compare_impl_method_inner ( tcx, impl_item, trait_item, impl_trait_ref) ,
51+ ty:: AssocKind :: Type => compare_impl_ty_inner ( tcx, impl_item, trait_item, impl_trait_ref) ,
52+ ty:: AssocKind :: Const => {
53+ compare_impl_const_inner ( tcx, impl_item, trait_item, impl_trait_ref)
54+ }
55+ }
56+ }
57+
3858/// Checks that a method from an impl conforms to the signature of
3959/// the same method as declared in the trait.
4060///
@@ -44,22 +64,21 @@ mod refine;
4464/// - `trait_m`: the method in the trait
4565/// - `impl_trait_ref`: the TraitRef corresponding to the trait implementation
4666#[ instrument( level = "debug" , skip( tcx) ) ]
47- pub ( super ) fn compare_impl_method < ' tcx > (
67+ pub ( super ) fn compare_impl_method_inner < ' tcx > (
4868 tcx : TyCtxt < ' tcx > ,
4969 impl_m : ty:: AssocItem ,
5070 trait_m : ty:: AssocItem ,
5171 impl_trait_ref : ty:: TraitRef < ' tcx > ,
52- ) {
53- let _: Result < _ , ErrorGuaranteed > = try {
54- check_method_is_structurally_compatible ( tcx, impl_m, trait_m, impl_trait_ref, false ) ?;
55- compare_method_predicate_entailment ( tcx, impl_m, trait_m, impl_trait_ref) ?;
56- refine:: check_refining_return_position_impl_trait_in_trait (
57- tcx,
58- impl_m,
59- trait_m,
60- impl_trait_ref,
61- ) ;
62- } ;
72+ ) -> Result < ( ) , ErrorGuaranteed > {
73+ check_method_is_structurally_compatible ( tcx, impl_m, trait_m, impl_trait_ref, false ) ?;
74+ compare_method_predicate_entailment ( tcx, impl_m, trait_m, impl_trait_ref) ?;
75+ refine:: check_refining_return_position_impl_trait_in_trait (
76+ tcx,
77+ impl_m,
78+ trait_m,
79+ impl_trait_ref,
80+ ) ;
81+ Ok ( ( ) )
6382}
6483
6584/// Checks a bunch of different properties of the impl/trait methods for
@@ -1727,17 +1746,12 @@ fn compare_generic_param_kinds<'tcx>(
17271746 Ok ( ( ) )
17281747}
17291748
1730- /// Use `tcx.compare_impl_const` instead
1731- pub ( super ) fn compare_impl_const_raw (
1732- tcx : TyCtxt < ' _ > ,
1733- ( impl_const_item_def, trait_const_item_def) : ( LocalDefId , DefId ) ,
1749+ fn compare_impl_const_inner < ' tcx > (
1750+ tcx : TyCtxt < ' tcx > ,
1751+ impl_const_item : ty:: AssocItem ,
1752+ trait_const_item : ty:: AssocItem ,
1753+ impl_trait_ref : ty:: TraitRef < ' tcx > ,
17341754) -> Result < ( ) , ErrorGuaranteed > {
1735- let impl_const_item = tcx. associated_item ( impl_const_item_def) ;
1736- let trait_const_item = tcx. associated_item ( trait_const_item_def) ;
1737- let impl_trait_ref =
1738- tcx. impl_trait_ref ( impl_const_item. container_id ( tcx) ) . unwrap ( ) . instantiate_identity ( ) ;
1739- debug ! ( ?impl_trait_ref) ;
1740-
17411755 compare_number_of_generics ( tcx, impl_const_item, trait_const_item, false ) ?;
17421756 compare_generic_param_kinds ( tcx, impl_const_item, trait_const_item, false ) ?;
17431757 check_region_bounds_on_impl_item ( tcx, impl_const_item, trait_const_item, false ) ?;
@@ -1868,19 +1882,17 @@ fn compare_const_predicate_entailment<'tcx>(
18681882}
18691883
18701884#[ instrument( level = "debug" , skip( tcx) ) ]
1871- pub ( super ) fn compare_impl_ty < ' tcx > (
1885+ pub ( super ) fn compare_impl_ty_inner < ' tcx > (
18721886 tcx : TyCtxt < ' tcx > ,
18731887 impl_ty : ty:: AssocItem ,
18741888 trait_ty : ty:: AssocItem ,
18751889 impl_trait_ref : ty:: TraitRef < ' tcx > ,
1876- ) {
1877- let _: Result < ( ) , ErrorGuaranteed > = try {
1878- compare_number_of_generics ( tcx, impl_ty, trait_ty, false ) ?;
1879- compare_generic_param_kinds ( tcx, impl_ty, trait_ty, false ) ?;
1880- check_region_bounds_on_impl_item ( tcx, impl_ty, trait_ty, false ) ?;
1881- compare_type_predicate_entailment ( tcx, impl_ty, trait_ty, impl_trait_ref) ?;
1882- check_type_bounds ( tcx, trait_ty, impl_ty, impl_trait_ref) ?;
1883- } ;
1890+ ) -> Result < ( ) , ErrorGuaranteed > {
1891+ compare_number_of_generics ( tcx, impl_ty, trait_ty, false ) ?;
1892+ compare_generic_param_kinds ( tcx, impl_ty, trait_ty, false ) ?;
1893+ check_region_bounds_on_impl_item ( tcx, impl_ty, trait_ty, false ) ?;
1894+ compare_type_predicate_entailment ( tcx, impl_ty, trait_ty, impl_trait_ref) ?;
1895+ check_type_bounds ( tcx, trait_ty, impl_ty, impl_trait_ref)
18841896}
18851897
18861898/// The equivalent of [compare_method_predicate_entailment], but for associated types
0 commit comments