@@ -26,11 +26,11 @@ use rustc_middle::ty::{
2626 self , AdtKind , CanonicalUserType , DefIdTree , GenericParamDefKind , ToPolyTraitRef , ToPredicate ,
2727 Ty , UserType ,
2828} ;
29- use rustc_session:: lint;
30- use rustc_span:: hygiene:: DesugaringKind ;
29+ use rustc_session:: { lint, parse:: feature_err} ;
3130use rustc_span:: source_map:: { original_sp, DUMMY_SP } ;
3231use rustc_span:: symbol:: { kw, sym, Ident } ;
3332use rustc_span:: { self , BytePos , MultiSpan , Span } ;
33+ use rustc_span:: { hygiene:: DesugaringKind , Symbol } ;
3434use rustc_trait_selection:: infer:: InferCtxtExt as _;
3535use rustc_trait_selection:: opaque_types:: InferCtxtExt as _;
3636use rustc_trait_selection:: traits:: error_reporting:: InferCtxtExt as _;
@@ -362,6 +362,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
362362 parent_id : hir:: HirId ,
363363 value : T ,
364364 value_span : Span ,
365+ feature : Option < Symbol > ,
365366 ) -> T {
366367 let parent_def_id = self . tcx . hir ( ) . local_def_id ( parent_id) ;
367368 debug ! (
@@ -380,7 +381,21 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
380381
381382 let mut opaque_types = self . opaque_types . borrow_mut ( ) ;
382383 let mut opaque_types_vars = self . opaque_types_vars . borrow_mut ( ) ;
384+
383385 for ( ty, decl) in opaque_type_map {
386+ if let Some ( feature) = feature {
387+ if let hir:: OpaqueTyOrigin :: TyAlias = decl. origin {
388+ if !self . tcx . features ( ) . enabled ( feature) {
389+ feature_err (
390+ & self . tcx . sess . parse_sess ,
391+ feature,
392+ value_span,
393+ "type alias impl trait is not permitted here" ,
394+ )
395+ . emit ( ) ;
396+ }
397+ }
398+ }
384399 let _ = opaque_types. insert ( ty, decl) ;
385400 let _ = opaque_types_vars. insert ( decl. concrete_ty , decl. opaque_type ) ;
386401 }
0 commit comments