@@ -12,6 +12,7 @@ use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKi
12
12
use rustc_infer:: infer:: { self , InferCtxt , TyCtxtInferExt } ;
13
13
use rustc_infer:: traits:: util;
14
14
use rustc_middle:: ty:: error:: { ExpectedFound , TypeError } ;
15
+ use rustc_middle:: ty:: query:: Providers ;
15
16
use rustc_middle:: ty:: util:: ExplicitSelf ;
16
17
use rustc_middle:: ty:: {
17
18
self , DefIdTree , InternalSubsts , Ty , TypeFoldable , TypeFolder , TypeSuperFoldable , TypeVisitable ,
@@ -25,62 +26,52 @@ use rustc_trait_selection::traits::{
25
26
} ;
26
27
use std:: iter;
27
28
29
+ pub ( super ) fn provide ( providers : & mut Providers ) {
30
+ * providers = Providers {
31
+ compare_impl_const : compare_impl_const_raw,
32
+ compare_impl_method : compare_impl_method_raw,
33
+ compare_impl_ty : compare_impl_ty_raw,
34
+ collect_trait_impl_trait_tys,
35
+ ..* providers
36
+ } ;
37
+ }
38
+
28
39
/// Checks that a method from an impl conforms to the signature of
29
40
/// the same method as declared in the trait.
30
- ///
31
- /// # Parameters
32
- ///
33
- /// - `impl_m`: type of the method we are checking
34
- /// - `impl_m_span`: span to use for reporting errors
35
- /// - `trait_m`: the method in the trait
36
- /// - `impl_trait_ref`: the TraitRef corresponding to the trait implementation
37
- pub ( super ) fn compare_impl_method < ' tcx > (
38
- tcx : TyCtxt < ' tcx > ,
39
- impl_m : & ty:: AssocItem ,
40
- trait_m : & ty:: AssocItem ,
41
- impl_trait_ref : ty:: TraitRef < ' tcx > ,
42
- trait_item_span : Option < Span > ,
43
- ) {
44
- debug ! ( "compare_impl_method(impl_trait_ref={:?})" , impl_trait_ref) ;
41
+ fn compare_impl_method_raw (
42
+ tcx : TyCtxt < ' _ > ,
43
+ ( impl_m_def_id, trait_m_def_id) : ( LocalDefId , DefId ) ,
44
+ ) -> Result < ( ) , ErrorGuaranteed > {
45
+ let impl_m = tcx. associated_item ( impl_m_def_id) ;
46
+ let impl_m_span = tcx. def_span ( impl_m_def_id) ;
47
+ let trait_m = tcx. associated_item ( trait_m_def_id) ;
48
+ let impl_trait_ref = tcx. impl_trait_ref ( impl_m. container_id ( tcx) ) . unwrap ( ) ;
49
+ let trait_item_span = tcx. hir ( ) . span_if_local ( trait_m_def_id) ;
45
50
46
- let impl_m_span = tcx . def_span ( impl_m . def_id ) ;
51
+ debug ! ( "compare_impl_method(impl_trait_ref={:?})" , impl_trait_ref ) ;
47
52
48
- if let Err ( _) = compare_self_type ( tcx, impl_m, impl_m_span, trait_m, impl_trait_ref) {
49
- return ;
50
- }
53
+ compare_self_type ( tcx, impl_m, impl_m_span, trait_m, impl_trait_ref) ?;
51
54
52
- if let Err ( _) = compare_number_of_generics ( tcx, impl_m, trait_m, trait_item_span, false ) {
53
- return ;
54
- }
55
+ compare_number_of_generics ( tcx, impl_m, trait_m, trait_item_span, false ) ?;
55
56
56
- if let Err ( _) = compare_generic_param_kinds ( tcx, impl_m, trait_m, false ) {
57
- return ;
58
- }
57
+ compare_generic_param_kinds ( tcx, impl_m, trait_m, false ) ?;
59
58
60
- if let Err ( _) =
61
- compare_number_of_method_arguments ( tcx, impl_m, impl_m_span, trait_m, trait_item_span)
62
- {
63
- return ;
64
- }
59
+ compare_number_of_method_arguments ( tcx, impl_m, impl_m_span, trait_m, trait_item_span) ?;
65
60
66
- if let Err ( _) = compare_synthetic_generics ( tcx, impl_m, trait_m) {
67
- return ;
68
- }
61
+ compare_synthetic_generics ( tcx, impl_m, trait_m) ?;
69
62
70
- if let Err ( _) = compare_asyncness ( tcx, impl_m, impl_m_span, trait_m, trait_item_span) {
71
- return ;
72
- }
63
+ compare_asyncness ( tcx, impl_m, impl_m_span, trait_m, trait_item_span) ?;
73
64
74
- if let Err ( _ ) = compare_method_predicate_entailment (
65
+ compare_method_predicate_entailment (
75
66
tcx,
76
67
impl_m,
77
68
impl_m_span,
78
69
trait_m,
79
70
impl_trait_ref,
80
71
CheckImpliedWfMode :: Check ,
81
- ) {
82
- return ;
83
- }
72
+ ) ? ;
73
+
74
+ Ok ( ( ) )
84
75
}
85
76
86
77
/// This function is best explained by example. Consider a trait:
@@ -442,13 +433,13 @@ fn compare_asyncness<'tcx>(
442
433
}
443
434
444
435
#[ instrument( skip( tcx) , level = "debug" , ret) ]
445
- pub ( super ) fn collect_trait_impl_trait_tys < ' tcx > (
436
+ fn collect_trait_impl_trait_tys < ' tcx > (
446
437
tcx : TyCtxt < ' tcx > ,
447
438
def_id : DefId ,
448
439
) -> Result < & ' tcx FxHashMap < DefId , Ty < ' tcx > > , ErrorGuaranteed > {
449
- let impl_m = tcx. opt_associated_item ( def_id) . unwrap ( ) ;
450
- let trait_m = tcx. opt_associated_item ( impl_m. trait_item_def_id . unwrap ( ) ) . unwrap ( ) ;
451
- let impl_trait_ref = tcx. impl_trait_ref ( impl_m. impl_container ( tcx) . unwrap ( ) ) . unwrap ( ) ;
440
+ let impl_m = tcx. associated_item ( def_id) ;
441
+ let trait_m = tcx. associated_item ( impl_m. trait_item_def_id . unwrap ( ) ) ;
442
+ let impl_trait_ref = tcx. impl_trait_ref ( impl_m. container_id ( tcx) ) . unwrap ( ) ;
452
443
let param_env = tcx. param_env ( def_id) ;
453
444
454
445
// First, check a few of the same thing as `compare_impl_method`, just so we don't ICE during substitutions later.
@@ -1517,7 +1508,7 @@ fn compare_generic_param_kinds<'tcx>(
1517
1508
}
1518
1509
1519
1510
/// Use `tcx.compare_impl_const` instead
1520
- pub ( super ) fn compare_impl_const_raw (
1511
+ fn compare_impl_const_raw (
1521
1512
tcx : TyCtxt < ' _ > ,
1522
1513
( impl_const_item_def, trait_const_item_def) : ( LocalDefId , DefId ) ,
1523
1514
) -> Result < ( ) , ErrorGuaranteed > {
@@ -1623,26 +1614,28 @@ pub(super) fn compare_impl_const_raw(
1623
1614
Ok ( ( ) )
1624
1615
}
1625
1616
1626
- pub ( super ) fn compare_impl_ty < ' tcx > (
1617
+ fn compare_impl_ty_raw < ' tcx > (
1627
1618
tcx : TyCtxt < ' tcx > ,
1628
- impl_ty : & ty:: AssocItem ,
1629
- impl_ty_span : Span ,
1630
- trait_ty : & ty:: AssocItem ,
1631
- impl_trait_ref : ty:: TraitRef < ' tcx > ,
1632
- trait_item_span : Option < Span > ,
1633
- ) {
1634
- debug ! ( "compare_impl_type(impl_trait_ref={:?})" , impl_trait_ref) ;
1619
+ ( impl_ty_def_id, trait_ty_def_id) : ( LocalDefId , DefId ) ,
1620
+ ) -> Result < ( ) , ErrorGuaranteed > {
1621
+ let impl_ty = tcx. associated_item ( impl_ty_def_id) ;
1622
+ let impl_ty_span = tcx. def_span ( impl_ty_def_id) ;
1623
+ let trait_ty = tcx. associated_item ( trait_ty_def_id) ;
1624
+ let impl_trait_ref = tcx. impl_trait_ref ( impl_ty. container_id ( tcx) ) . unwrap ( ) ;
1625
+ let trait_item_span = tcx. hir ( ) . span_if_local ( trait_ty_def_id) ;
1626
+
1627
+ debug ! ( "compare_impl_ty(impl_trait_ref={:?})" , impl_trait_ref) ;
1635
1628
1636
- let _: Result < ( ) , ErrorGuaranteed > = ( || {
1637
- compare_number_of_generics ( tcx, impl_ty, trait_ty, trait_item_span, false ) ?;
1629
+ compare_number_of_generics ( tcx, impl_ty, trait_ty, trait_item_span, false ) ?;
1638
1630
1639
- compare_generic_param_kinds ( tcx, impl_ty, trait_ty, false ) ?;
1631
+ compare_generic_param_kinds ( tcx, impl_ty, trait_ty, false ) ?;
1640
1632
1641
- let sp = tcx. def_span ( impl_ty. def_id ) ;
1642
- compare_type_predicate_entailment ( tcx, impl_ty, sp, trait_ty, impl_trait_ref) ?;
1633
+ let sp = tcx. def_span ( impl_ty. def_id ) ;
1634
+ compare_type_predicate_entailment ( tcx, impl_ty, sp, trait_ty, impl_trait_ref) ?;
1643
1635
1644
- check_type_bounds ( tcx, trait_ty, impl_ty, impl_ty_span, impl_trait_ref)
1645
- } ) ( ) ;
1636
+ check_type_bounds ( tcx, trait_ty, impl_ty, impl_ty_span, impl_trait_ref) ?;
1637
+
1638
+ Ok ( ( ) )
1646
1639
}
1647
1640
1648
1641
/// The equivalent of [compare_method_predicate_entailment], but for associated types
0 commit comments