@@ -67,6 +67,7 @@ use syntax::ast;
6767use syntax:: ast:: * ;
6868use syntax:: errors;
6969use syntax:: ext:: hygiene:: { Mark , SyntaxContext } ;
70+ use syntax:: feature_gate:: { emit_feature_err, GateIssue } ;
7071use syntax:: print:: pprust;
7172use syntax:: ptr:: P ;
7273use syntax:: source_map:: { self , respan, CompilerDesugaringKind , Spanned } ;
@@ -3429,19 +3430,24 @@ impl<'a> LoweringContext<'a> {
34293430 ParamMode :: Optional ,
34303431 ImplTraitContext :: Disallowed ,
34313432 ) ;
3433+ self . check_self_struct_ctor_feature ( & qpath) ;
34323434 hir:: PatKind :: TupleStruct (
34333435 qpath,
34343436 pats. iter ( ) . map ( |x| self . lower_pat ( x) ) . collect ( ) ,
34353437 ddpos,
34363438 )
34373439 }
3438- PatKind :: Path ( ref qself, ref path) => hir:: PatKind :: Path ( self . lower_qpath (
3439- p. id ,
3440- qself,
3441- path,
3442- ParamMode :: Optional ,
3443- ImplTraitContext :: Disallowed ,
3444- ) ) ,
3440+ PatKind :: Path ( ref qself, ref path) => {
3441+ let qpath = self . lower_qpath (
3442+ p. id ,
3443+ qself,
3444+ path,
3445+ ParamMode :: Optional ,
3446+ ImplTraitContext :: Disallowed ,
3447+ ) ;
3448+ self . check_self_struct_ctor_feature ( & qpath) ;
3449+ hir:: PatKind :: Path ( qpath)
3450+ }
34453451 PatKind :: Struct ( ref path, ref fields, etc) => {
34463452 let qpath = self . lower_qpath (
34473453 p. id ,
@@ -3828,13 +3834,17 @@ impl<'a> LoweringContext<'a> {
38283834 attrs : e. attrs . clone ( ) ,
38293835 } ;
38303836 }
3831- ExprKind :: Path ( ref qself, ref path) => hir:: ExprKind :: Path ( self . lower_qpath (
3832- e. id ,
3833- qself,
3834- path,
3835- ParamMode :: Optional ,
3836- ImplTraitContext :: Disallowed ,
3837- ) ) ,
3837+ ExprKind :: Path ( ref qself, ref path) => {
3838+ let qpath = self . lower_qpath (
3839+ e. id ,
3840+ qself,
3841+ path,
3842+ ParamMode :: Optional ,
3843+ ImplTraitContext :: Disallowed ,
3844+ ) ;
3845+ self . check_self_struct_ctor_feature ( & qpath) ;
3846+ hir:: ExprKind :: Path ( qpath)
3847+ }
38383848 ExprKind :: Break ( opt_label, ref opt_expr) => {
38393849 let destination = if self . is_in_loop_condition && opt_label. is_none ( ) {
38403850 hir:: Destination {
@@ -4815,6 +4825,18 @@ impl<'a> LoweringContext<'a> {
48154825 ThinVec :: new ( ) ) ) ;
48164826 P ( self . expr_call ( e. span , from_err, hir_vec ! [ e] ) )
48174827 }
4828+
4829+ fn check_self_struct_ctor_feature ( & self , qp : & hir:: QPath ) {
4830+ if let hir:: QPath :: Resolved ( _, ref p) = qp {
4831+ if p. segments . len ( ) == 1 &&
4832+ p. segments [ 0 ] . ident . name == keywords:: SelfType . name ( ) &&
4833+ !self . sess . features_untracked ( ) . self_struct_ctor {
4834+ emit_feature_err ( & self . sess . parse_sess , "self_struct_ctor" ,
4835+ p. span , GateIssue :: Language ,
4836+ "`Self` struct constructors are unstable" ) ;
4837+ }
4838+ }
4839+ }
48184840}
48194841
48204842fn body_ids ( bodies : & BTreeMap < hir:: BodyId , hir:: Body > ) -> Vec < hir:: BodyId > {
0 commit comments