@@ -35,6 +35,24 @@ use crate::errors::{LifetimesOrBoundsMismatchOnTrait, MethodShouldReturnFuture};
35
35
36
36
mod refine;
37
37
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 : LocalDefId ,
42
+ ) -> Result < ( ) , ErrorGuaranteed > {
43
+ let impl_item = tcx. associated_item ( impl_item_def_id) ;
44
+ let trait_item = tcx. associated_item ( impl_item. trait_item_def_id . unwrap ( ) ) ;
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 ( tcx, impl_item, trait_item, impl_trait_ref) ,
51
+ ty:: AssocKind :: Type => compare_impl_ty ( tcx, impl_item, trait_item, impl_trait_ref) ,
52
+ ty:: AssocKind :: Const => compare_impl_const ( tcx, impl_item, trait_item, impl_trait_ref) ,
53
+ }
54
+ }
55
+
38
56
/// Checks that a method from an impl conforms to the signature of
39
57
/// the same method as declared in the trait.
40
58
///
@@ -44,22 +62,21 @@ mod refine;
44
62
/// - `trait_m`: the method in the trait
45
63
/// - `impl_trait_ref`: the TraitRef corresponding to the trait implementation
46
64
#[ instrument( level = "debug" , skip( tcx) ) ]
47
- pub ( super ) fn compare_impl_method < ' tcx > (
65
+ fn compare_impl_method < ' tcx > (
48
66
tcx : TyCtxt < ' tcx > ,
49
67
impl_m : ty:: AssocItem ,
50
68
trait_m : ty:: AssocItem ,
51
69
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
- } ;
70
+ ) -> Result < ( ) , ErrorGuaranteed > {
71
+ check_method_is_structurally_compatible ( tcx, impl_m, trait_m, impl_trait_ref, false ) ?;
72
+ compare_method_predicate_entailment ( tcx, impl_m, trait_m, impl_trait_ref) ?;
73
+ refine:: check_refining_return_position_impl_trait_in_trait (
74
+ tcx,
75
+ impl_m,
76
+ trait_m,
77
+ impl_trait_ref,
78
+ ) ;
79
+ Ok ( ( ) )
63
80
}
64
81
65
82
/// Checks a bunch of different properties of the impl/trait methods for
@@ -1721,17 +1738,12 @@ fn compare_generic_param_kinds<'tcx>(
1721
1738
Ok ( ( ) )
1722
1739
}
1723
1740
1724
- /// Use `tcx.compare_impl_const` instead
1725
- pub ( super ) fn compare_impl_const_raw (
1726
- tcx : TyCtxt < ' _ > ,
1727
- ( impl_const_item_def, trait_const_item_def) : ( LocalDefId , DefId ) ,
1741
+ fn compare_impl_const < ' tcx > (
1742
+ tcx : TyCtxt < ' tcx > ,
1743
+ impl_const_item : ty:: AssocItem ,
1744
+ trait_const_item : ty:: AssocItem ,
1745
+ impl_trait_ref : ty:: TraitRef < ' tcx > ,
1728
1746
) -> Result < ( ) , ErrorGuaranteed > {
1729
- let impl_const_item = tcx. associated_item ( impl_const_item_def) ;
1730
- let trait_const_item = tcx. associated_item ( trait_const_item_def) ;
1731
- let impl_trait_ref =
1732
- tcx. impl_trait_ref ( impl_const_item. container_id ( tcx) ) . unwrap ( ) . instantiate_identity ( ) ;
1733
- debug ! ( ?impl_trait_ref) ;
1734
-
1735
1747
compare_number_of_generics ( tcx, impl_const_item, trait_const_item, false ) ?;
1736
1748
compare_generic_param_kinds ( tcx, impl_const_item, trait_const_item, false ) ?;
1737
1749
check_region_bounds_on_impl_item ( tcx, impl_const_item, trait_const_item, false ) ?;
@@ -1862,19 +1874,17 @@ fn compare_const_predicate_entailment<'tcx>(
1862
1874
}
1863
1875
1864
1876
#[ instrument( level = "debug" , skip( tcx) ) ]
1865
- pub ( super ) fn compare_impl_ty < ' tcx > (
1877
+ fn compare_impl_ty < ' tcx > (
1866
1878
tcx : TyCtxt < ' tcx > ,
1867
1879
impl_ty : ty:: AssocItem ,
1868
1880
trait_ty : ty:: AssocItem ,
1869
1881
impl_trait_ref : ty:: TraitRef < ' tcx > ,
1870
- ) {
1871
- let _: Result < ( ) , ErrorGuaranteed > = try {
1872
- compare_number_of_generics ( tcx, impl_ty, trait_ty, false ) ?;
1873
- compare_generic_param_kinds ( tcx, impl_ty, trait_ty, false ) ?;
1874
- check_region_bounds_on_impl_item ( tcx, impl_ty, trait_ty, false ) ?;
1875
- compare_type_predicate_entailment ( tcx, impl_ty, trait_ty, impl_trait_ref) ?;
1876
- check_type_bounds ( tcx, trait_ty, impl_ty, impl_trait_ref) ?;
1877
- } ;
1882
+ ) -> Result < ( ) , ErrorGuaranteed > {
1883
+ compare_number_of_generics ( tcx, impl_ty, trait_ty, false ) ?;
1884
+ compare_generic_param_kinds ( tcx, impl_ty, trait_ty, false ) ?;
1885
+ check_region_bounds_on_impl_item ( tcx, impl_ty, trait_ty, false ) ?;
1886
+ compare_type_predicate_entailment ( tcx, impl_ty, trait_ty, impl_trait_ref) ?;
1887
+ check_type_bounds ( tcx, trait_ty, impl_ty, impl_trait_ref)
1878
1888
}
1879
1889
1880
1890
/// The equivalent of [compare_method_predicate_entailment], but for associated types
0 commit comments