@@ -67,6 +67,7 @@ use syntax::ast;
67
67
use syntax:: ast:: * ;
68
68
use syntax:: errors;
69
69
use syntax:: ext:: hygiene:: { Mark , SyntaxContext } ;
70
+ use syntax:: feature_gate:: { emit_feature_err, GateIssue } ;
70
71
use syntax:: print:: pprust;
71
72
use syntax:: ptr:: P ;
72
73
use syntax:: source_map:: { self , respan, CompilerDesugaringKind , Spanned } ;
@@ -3429,19 +3430,24 @@ impl<'a> LoweringContext<'a> {
3429
3430
ParamMode :: Optional ,
3430
3431
ImplTraitContext :: Disallowed ,
3431
3432
) ;
3433
+ self . check_self_struct_ctor_feature ( & qpath) ;
3432
3434
hir:: PatKind :: TupleStruct (
3433
3435
qpath,
3434
3436
pats. iter ( ) . map ( |x| self . lower_pat ( x) ) . collect ( ) ,
3435
3437
ddpos,
3436
3438
)
3437
3439
}
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
+ }
3445
3451
PatKind :: Struct ( ref path, ref fields, etc) => {
3446
3452
let qpath = self . lower_qpath (
3447
3453
p. id ,
@@ -3828,13 +3834,17 @@ impl<'a> LoweringContext<'a> {
3828
3834
attrs : e. attrs . clone ( ) ,
3829
3835
} ;
3830
3836
}
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
+ }
3838
3848
ExprKind :: Break ( opt_label, ref opt_expr) => {
3839
3849
let destination = if self . is_in_loop_condition && opt_label. is_none ( ) {
3840
3850
hir:: Destination {
@@ -4815,6 +4825,18 @@ impl<'a> LoweringContext<'a> {
4815
4825
ThinVec :: new ( ) ) ) ;
4816
4826
P ( self . expr_call ( e. span , from_err, hir_vec ! [ e] ) )
4817
4827
}
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
+ }
4818
4840
}
4819
4841
4820
4842
fn body_ids ( bodies : & BTreeMap < hir:: BodyId , hir:: Body > ) -> Vec < hir:: BodyId > {
0 commit comments