@@ -640,7 +640,9 @@ fn find_opaque_ty_constraints_for_tait(tcx: TyCtxt<'_>, def_id: LocalDefId) -> T
640
640
let concrete_opaque_types = & self . tcx . mir_borrowck ( item_def_id) . concrete_opaque_types ;
641
641
debug ! ( ?concrete_opaque_types) ;
642
642
if let Some ( & concrete_type) = concrete_opaque_types. get ( & self . def_id ) {
643
- if !may_define_opaque_type ( self . tcx , item_def_id, self . def_id , concrete_type. span ) {
643
+ if let Err ( item_def_id) =
644
+ may_define_opaque_type ( self . tcx , item_def_id, self . def_id , concrete_type. span )
645
+ {
644
646
self . tcx . sess . emit_err ( OpaqueTypeConstrainedButNotInSig {
645
647
span : concrete_type. span ,
646
648
item_span : self . tcx . def_span ( item_def_id) ,
@@ -666,8 +668,12 @@ fn find_opaque_ty_constraints_for_tait(tcx: TyCtxt<'_>, def_id: LocalDefId) -> T
666
668
self . tcx . hir ( )
667
669
}
668
670
fn visit_expr ( & mut self , ex : & ' tcx Expr < ' tcx > ) {
669
- if let hir:: ExprKind :: Closure ( closure) = ex. kind {
670
- self . check ( closure. def_id ) ;
671
+ match ex. kind {
672
+ hir:: ExprKind :: Closure ( closure) => {
673
+ self . check ( closure. def_id ) ;
674
+ }
675
+ hir:: ExprKind :: ConstBlock ( anon) => self . check ( anon. def_id ) ,
676
+ _ => ( ) ,
671
677
}
672
678
intravisit:: walk_expr ( self , ex) ;
673
679
}
@@ -760,14 +766,14 @@ fn may_define_opaque_type<'tcx>(
760
766
def_id : LocalDefId ,
761
767
opaque_def_id : LocalDefId ,
762
768
span : Span ,
763
- ) -> bool {
769
+ ) -> Result < ( ) , LocalDefId > {
764
770
if tcx. is_descendant_of ( opaque_def_id. to_def_id ( ) , def_id. to_def_id ( ) ) {
765
771
// If the opaque type is defined in the body of a function, that function
766
772
// may constrain the opaque type since it can't mention it in bounds.
767
- return true ;
773
+ return Ok ( ( ) ) ;
768
774
}
769
775
770
- if tcx. is_closure ( def_id. to_def_id ( ) ) {
776
+ if tcx. is_typeck_child ( def_id. to_def_id ( ) ) {
771
777
return may_define_opaque_type ( tcx, tcx. local_parent ( def_id) , opaque_def_id, span) ;
772
778
}
773
779
@@ -863,12 +869,12 @@ fn may_define_opaque_type<'tcx>(
863
869
} ;
864
870
trace ! ( ?tait_in_fn_sig) ;
865
871
if tait_in_fn_sig {
866
- return true ;
872
+ return Ok ( ( ) ) ;
867
873
}
868
874
let tait_in_where_bounds =
869
875
has_tait ( tcx. predicates_of ( def_id. to_def_id ( ) ) . predicates , opaque_def_id, tcx, param_env) ;
870
876
if tcx. features ( ) . type_alias_impl_trait_in_where_bounds {
871
- tait_in_where_bounds
877
+ if tait_in_where_bounds { Ok ( ( ) ) } else { Err ( def_id ) }
872
878
} else {
873
879
if tait_in_where_bounds {
874
880
feature_err (
@@ -879,7 +885,7 @@ fn may_define_opaque_type<'tcx>(
879
885
)
880
886
. emit ( ) ;
881
887
}
882
- false
888
+ Err ( def_id )
883
889
}
884
890
}
885
891
0 commit comments