@@ -32,7 +32,7 @@ use rustc::middle::lang_items;
32
32
use rustc_target:: spec:: abi:: Abi ;
33
33
use syntax:: attr;
34
34
use syntax:: ast:: LitKind ;
35
- use syntax:: feature_gate:: { UnstableFeatures , emit_feature_err, GateIssue } ;
35
+ use syntax:: feature_gate:: { UnstableFeatures , feature_err , emit_feature_err, GateIssue } ;
36
36
use syntax_pos:: { Span , DUMMY_SP } ;
37
37
38
38
use std:: fmt;
@@ -189,17 +189,12 @@ impl<'a, 'tcx> Qualifier<'a, 'tcx, 'tcx> {
189
189
fn statement_like ( & mut self ) {
190
190
self . add ( Qualif :: NOT_CONST ) ;
191
191
if self . mode != Mode :: Fn {
192
- if self . span . allows_unstable ( ) {
193
- emit_feature_err ( & self . tcx . sess . parse_sess , "const_let" ,
194
- self . span , GateIssue :: Language ,
195
- "statements in const fn are unstable" ) ;
196
- }
197
- let mut err = struct_span_err ! (
198
- self . tcx. sess,
192
+ let mut err = feature_err (
193
+ & self . tcx . sess . parse_sess ,
194
+ "const_let" ,
199
195
self . span ,
200
- E0016 ,
201
- "blocks in {}s are limited to items and tail expressions" ,
202
- self . mode
196
+ GateIssue :: Language ,
197
+ & format ! ( "statements in {}s are unstable" , self . mode) ,
203
198
) ;
204
199
if self . tcx . sess . teach ( & err. get_code ( ) . unwrap ( ) ) {
205
200
err. note ( "Blocks in constants may only contain items (such as constant, function \
@@ -365,7 +360,7 @@ impl<'a, 'tcx> Qualifier<'a, 'tcx, 'tcx> {
365
360
TerminatorKind :: FalseUnwind { .. } => None ,
366
361
367
362
TerminatorKind :: Return => {
368
- if self . tcx . sess . features_untracked ( ) . const_let {
363
+ if ! self . tcx . sess . features_untracked ( ) . const_let {
369
364
// Check for unused values. This usually means
370
365
// there are extra statements in the AST.
371
366
for temp in mir. temps_iter ( ) {
@@ -466,10 +461,10 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
466
461
self . not_const ( ) ;
467
462
}
468
463
LocalKind :: Var if !self . tcx . sess . features_untracked ( ) . const_let => {
469
- if self . mode != Mode :: Fn && self . span . allows_unstable ( ) {
464
+ if self . mode != Mode :: Fn {
470
465
emit_feature_err ( & self . tcx . sess . parse_sess , "const_let" ,
471
466
self . span , GateIssue :: Language ,
472
- "let bindings in const fn are unstable" ) ;
467
+ & format ! ( "let bindings in {}s are unstable" , self . mode ) ) ;
473
468
}
474
469
self . add ( Qualif :: NOT_CONST ) ;
475
470
}
@@ -1105,15 +1100,11 @@ This does not pose a problem by itself because they can't be accessed directly."
1105
1100
// Avoid a generic error for other uses of arguments.
1106
1101
if self . qualif . intersects ( Qualif :: FN_ARGUMENT ) {
1107
1102
let decl = & self . mir . local_decls [ index] ;
1108
- if decl. source_info . span . allows_unstable ( ) {
1109
- emit_feature_err ( & self . tcx . sess . parse_sess , "const_let" ,
1110
- decl. source_info . span , GateIssue :: Language ,
1111
- "locals and patterns in const fn are unstable" ) ;
1112
- }
1113
- let mut err = struct_span_err ! (
1114
- self . tcx. sess,
1103
+ let mut err = feature_err (
1104
+ & self . tcx . sess . parse_sess ,
1105
+ "const_let" ,
1115
1106
decl. source_info . span ,
1116
- E0022 ,
1107
+ GateIssue :: Language ,
1117
1108
"arguments of constant functions can only be immutable by-value bindings"
1118
1109
) ;
1119
1110
if self . tcx . sess . teach ( & err. get_code ( ) . unwrap ( ) ) {
0 commit comments