@@ -16,8 +16,9 @@ use rustc_middle::ty::{
1616 self , ImplTraitInTraitData , IsSuggestable , Ty , TyCtxt , TypeFoldable , TypeFolder ,
1717 TypeSuperFoldable , TypeSuperVisitable , TypeVisitable , TypeVisitableExt , TypeVisitor ,
1818} ;
19+ use rustc_session:: parse:: feature_err;
1920use rustc_span:: symbol:: Ident ;
20- use rustc_span:: { Span , DUMMY_SP } ;
21+ use rustc_span:: { sym , Span , DUMMY_SP } ;
2122
2223use super :: ItemCtxt ;
2324use super :: { bad_placeholder, is_suggestable_infer_ty} ;
@@ -639,7 +640,7 @@ fn find_opaque_ty_constraints_for_tait(tcx: TyCtxt<'_>, def_id: LocalDefId) -> T
639640 let concrete_opaque_types = & self . tcx . mir_borrowck ( item_def_id) . concrete_opaque_types ;
640641 debug ! ( ?concrete_opaque_types) ;
641642 if let Some ( & concrete_type) = concrete_opaque_types. get ( & self . def_id ) {
642- if !may_define_opaque_type ( self . tcx , item_def_id, self . def_id ) {
643+ if !may_define_opaque_type ( self . tcx , item_def_id, self . def_id , concrete_type . span ) {
643644 self . tcx . sess . emit_err ( OpaqueTypeConstrainedButNotInSig {
644645 span : concrete_type. span ,
645646 item_span : self . tcx . def_span ( item_def_id) ,
@@ -758,6 +759,7 @@ fn may_define_opaque_type<'tcx>(
758759 tcx : TyCtxt < ' tcx > ,
759760 def_id : LocalDefId ,
760761 opaque_def_id : LocalDefId ,
762+ span : Span ,
761763) -> bool {
762764 if tcx. is_descendant_of ( opaque_def_id. to_def_id ( ) , def_id. to_def_id ( ) ) {
763765 // If the opaque type is defined in the body of a function, that function
@@ -766,7 +768,7 @@ fn may_define_opaque_type<'tcx>(
766768 }
767769
768770 if tcx. is_closure ( def_id. to_def_id ( ) ) {
769- return may_define_opaque_type ( tcx, tcx. local_parent ( def_id) , opaque_def_id) ;
771+ return may_define_opaque_type ( tcx, tcx. local_parent ( def_id) , opaque_def_id, span ) ;
770772 }
771773
772774 let param_env = tcx. param_env ( def_id) ;
@@ -860,8 +862,25 @@ fn may_define_opaque_type<'tcx>(
860862 _ => false ,
861863 } ;
862864 trace ! ( ?tait_in_fn_sig) ;
863- tait_in_fn_sig
864- || has_tait ( tcx. predicates_of ( def_id. to_def_id ( ) ) . predicates , opaque_def_id, tcx, param_env)
865+ if tait_in_fn_sig {
866+ return true ;
867+ }
868+ let tait_in_where_bounds =
869+ has_tait ( tcx. predicates_of ( def_id. to_def_id ( ) ) . predicates , opaque_def_id, tcx, param_env) ;
870+ if tcx. features ( ) . type_alias_impl_trait_in_where_bounds {
871+ tait_in_where_bounds
872+ } else {
873+ if tait_in_where_bounds {
874+ feature_err (
875+ & tcx. sess . parse_sess ,
876+ sym:: type_alias_impl_trait_in_where_bounds,
877+ span,
878+ "type alias impl trait is only usable in argument or return types" ,
879+ )
880+ . emit ( ) ;
881+ }
882+ false
883+ }
865884}
866885
867886fn find_opaque_ty_constraints_for_rpit (
@@ -1072,8 +1091,6 @@ fn infer_placeholder_type<'a>(
10721091
10731092fn check_feature_inherent_assoc_ty ( tcx : TyCtxt < ' _ > , span : Span ) {
10741093 if !tcx. features ( ) . inherent_associated_types {
1075- use rustc_session:: parse:: feature_err;
1076- use rustc_span:: symbol:: sym;
10771094 feature_err (
10781095 & tcx. sess . parse_sess ,
10791096 sym:: inherent_associated_types,
0 commit comments