99//! fixed, but for the moment it's easier to do these checks early.
1010
1111use crate :: constrained_generic_params as cgp;
12+ use min_specialization:: check_min_specialization;
13+
1214use rustc:: ty:: query:: Providers ;
1315use rustc:: ty:: { self , TyCtxt , TypeFoldable } ;
1416use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
1517use rustc_errors:: struct_span_err;
1618use rustc_hir as hir;
1719use rustc_hir:: def_id:: DefId ;
1820use rustc_hir:: itemlikevisit:: ItemLikeVisitor ;
21+ use rustc_span:: Span ;
22+
1923use std:: collections:: hash_map:: Entry :: { Occupied , Vacant } ;
2024
21- use rustc_span :: Span ;
25+ mod min_specialization ;
2226
2327/// Checks that all the type/lifetime parameters on an impl also
2428/// appear in the trait ref or self type (or are constrained by a
@@ -60,7 +64,9 @@ pub fn impl_wf_check(tcx: TyCtxt<'_>) {
6064}
6165
6266fn check_mod_impl_wf ( tcx : TyCtxt < ' _ > , module_def_id : DefId ) {
63- tcx. hir ( ) . visit_item_likes_in_module ( module_def_id, & mut ImplWfCheck { tcx } ) ;
67+ let min_specialization = tcx. features ( ) . min_specialization ;
68+ tcx. hir ( )
69+ . visit_item_likes_in_module ( module_def_id, & mut ImplWfCheck { tcx, min_specialization } ) ;
6470}
6571
6672pub fn provide ( providers : & mut Providers < ' _ > ) {
@@ -69,6 +75,7 @@ pub fn provide(providers: &mut Providers<'_>) {
6975
7076struct ImplWfCheck < ' tcx > {
7177 tcx : TyCtxt < ' tcx > ,
78+ min_specialization : bool ,
7279}
7380
7481impl ItemLikeVisitor < ' tcx > for ImplWfCheck < ' tcx > {
@@ -77,6 +84,9 @@ impl ItemLikeVisitor<'tcx> for ImplWfCheck<'tcx> {
7784 let impl_def_id = self . tcx . hir ( ) . local_def_id ( item. hir_id ) ;
7885 enforce_impl_params_are_constrained ( self . tcx , impl_def_id, items) ;
7986 enforce_impl_items_are_distinct ( self . tcx , items) ;
87+ if self . min_specialization {
88+ check_min_specialization ( self . tcx , impl_def_id, item. span ) ;
89+ }
8090 }
8191 }
8292
0 commit comments