Skip to content

Commit 15cefe4

Browse files
committed
Make sure feature gate errors are recoverable
1 parent b99fb2f commit 15cefe4

20 files changed

+32
-58
lines changed

src/librustc/lint/levels.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,24 +222,22 @@ impl<'a> LintLevelsBuilder<'a> {
222222
match item.node {
223223
ast::MetaItemKind::Word => {} // actual lint names handled later
224224
ast::MetaItemKind::NameValue(ref name_value) => {
225-
let gate_reasons = !self.sess.features_untracked().lint_reasons;
226225
if item.ident == "reason" {
227226
// found reason, reslice meta list to exclude it
228227
metas = &metas[0..metas.len()-1];
229228
// FIXME (#55112): issue unused-attributes lint if we thereby
230229
// don't have any lint names (`#[level(reason = "foo")]`)
231230
if let ast::LitKind::Str(rationale, _) = name_value.node {
232-
if gate_reasons {
231+
if !self.sess.features_untracked().lint_reasons {
233232
feature_gate::emit_feature_err(
234233
&self.sess.parse_sess,
235234
"lint_reasons",
236235
item.span,
237236
feature_gate::GateIssue::Language,
238237
"lint reasons are experimental"
239238
);
240-
} else {
241-
reason = Some(rationale);
242239
}
240+
reason = Some(rationale);
243241
} else {
244242
let mut err = bad_attr(name_value.span);
245243
err.help("reason must be a string literal");

src/librustc_typeck/collect.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2210,7 +2210,6 @@ fn from_target_feature(
22102210
feature_gate::GateIssue::Language,
22112211
&format!("the target feature `{}` is currently unstable", feature),
22122212
);
2213-
return None;
22142213
}
22152214
Some(Symbol::intern(feature))
22162215
}));

src/libsyntax/ext/expand.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,6 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
722722
emit_feature_err(this.cx.parse_sess, &*feature.as_str(), span,
723723
GateIssue::Library(Some(issue)), &explain);
724724
this.cx.trace_macros_diag();
725-
return Err(kind.dummy(span));
726725
}
727726
}
728727

src/libsyntax_ext/asm.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt,
4949
sp,
5050
feature_gate::GateIssue::Language,
5151
feature_gate::EXPLAIN_ASM);
52-
return DummyResult::expr(sp);
5352
}
5453

5554
// Split the tts before the first colon, to avoid `asm!("x": y)` being

src/libsyntax_ext/concat_idents.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ pub fn expand_syntax_ext<'cx>(cx: &'cx mut ExtCtxt,
2020
sp,
2121
feature_gate::GateIssue::Language,
2222
feature_gate::EXPLAIN_CONCAT_IDENTS);
23-
return base::DummyResult::expr(sp);
2423
}
2524

2625
if tts.is_empty() {

src/libsyntax_ext/format.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,6 @@ pub fn expand_format_args_nl<'cx>(
713713
sp,
714714
feature_gate::GateIssue::Language,
715715
feature_gate::EXPLAIN_FORMAT_ARGS_NL);
716-
return DummyResult::expr(sp);
717716
}
718717
sp = sp.apply_mark(ecx.current_expansion.mark);
719718
match parse_args(ecx, sp, tts) {

src/libsyntax_ext/global_asm.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ pub fn expand_global_asm<'cx>(cx: &'cx mut ExtCtxt,
2929
sp,
3030
feature_gate::GateIssue::Language,
3131
feature_gate::EXPLAIN_GLOBAL_ASM);
32-
return DummyResult::any(sp);
3332
}
3433

3534
let mut p = cx.new_parser_from_tts(tts);

src/libsyntax_ext/log_syntax.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ pub fn expand_syntax_ext<'cx>(cx: &'cx mut base::ExtCtxt,
1414
sp,
1515
feature_gate::GateIssue::Language,
1616
feature_gate::EXPLAIN_LOG_SYNTAX);
17-
return base::DummyResult::any(sp);
1817
}
1918

2019
println!("{}", print::pprust::tts_to_string(tts));

src/libsyntax_ext/test_case.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ pub fn expand(
3131
attr_sp,
3232
feature_gate::GateIssue::Language,
3333
feature_gate::EXPLAIN_CUSTOM_TEST_FRAMEWORKS);
34-
35-
return vec![anno_item];
3634
}
3735

3836
if !ecx.ecfg.should_test { return vec![]; }

src/libsyntax_ext/trace_macros.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ pub fn expand_trace_macros(cx: &mut ExtCtxt,
1515
sp,
1616
feature_gate::GateIssue::Language,
1717
feature_gate::EXPLAIN_TRACE_MACROS);
18-
return base::DummyResult::any(sp);
1918
}
2019

2120
match (tt.len(), tt.first()) {

src/test/ui/feature-gates/feature-gate-asm2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
fn main() {
44
unsafe {
5-
println!("{}", asm!("")); //~ ERROR inline assembly is not stable
5+
println!("{:?}", asm!("")); //~ ERROR inline assembly is not stable
66
}
77
}

src/test/ui/feature-gates/feature-gate-asm2.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0658]: inline assembly is not stable enough for use and is subject to change (see issue #29722)
22
--> $DIR/feature-gate-asm2.rs:5:24
33
|
4-
LL | println!("{}", asm!("")); //~ ERROR inline assembly is not stable
5-
| ^^^^^^^^
4+
LL | println!("{:?}", asm!("")); //~ ERROR inline assembly is not stable
5+
| ^^^^^^^^
66
|
77
= help: add #![feature(asm)] to the crate attributes to enable
88

src/test/ui/feature-gates/feature-gate-concat_idents2.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22

33
fn main() {
44
concat_idents!(a, b); //~ ERROR `concat_idents` is not stable enough
5+
//~| ERROR cannot find value `ab` in this scope
56
}

src/test/ui/feature-gates/feature-gate-concat_idents2.stderr

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ LL | concat_idents!(a, b); //~ ERROR `concat_idents` is not stable enough
66
|
77
= help: add #![feature(concat_idents)] to the crate attributes to enable
88

9-
error: aborting due to previous error
9+
error[E0425]: cannot find value `ab` in this scope
10+
--> $DIR/feature-gate-concat_idents2.rs:14:5
11+
|
12+
LL | concat_idents!(a, b); //~ ERROR `concat_idents` is not stable enough
13+
| ^^^^^^^^^^^^^^^^^^^^^ not found in this scope
14+
15+
error: aborting due to 2 previous errors
1016

11-
For more information about this error, try `rustc --explain E0658`.
17+
Some errors occurred: E0425, E0658.
18+
For more information about an error, try `rustc --explain E0425`.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// gate-test-log_syntax
22

33
fn main() {
4-
println!("{}", log_syntax!()); //~ ERROR `log_syntax!` is not stable
4+
println!("{:?}", log_syntax!()); //~ ERROR `log_syntax!` is not stable
55
}

src/test/ui/feature-gates/feature-gate-log_syntax2.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0658]: `log_syntax!` is not stable enough for use and is subject to change (see issue #29598)
22
--> $DIR/feature-gate-log_syntax2.rs:4:20
33
|
4-
LL | println!("{}", log_syntax!()); //~ ERROR `log_syntax!` is not stable
5-
| ^^^^^^^^^^^^^
4+
LL | println!("{:?}", log_syntax!()); //~ ERROR `log_syntax!` is not stable
5+
| ^^^^^^^^^^^^^
66
|
77
= help: add #![feature(log_syntax)] to the crate attributes to enable
88

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

src/test/ui/trace_macros-gate.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,9 @@
22

33
fn main() {
44
trace_macros!(); //~ ERROR `trace_macros` is not stable
5-
trace_macros!(1); //~ ERROR `trace_macros` is not stable
6-
trace_macros!(ident); //~ ERROR `trace_macros` is not stable
7-
trace_macros!(for); //~ ERROR `trace_macros` is not stable
8-
trace_macros!(true,); //~ ERROR `trace_macros` is not stable
9-
trace_macros!(false 1); //~ ERROR `trace_macros` is not stable
10-
11-
// Errors are signalled early for the above, before expansion.
12-
// See trace_macros-gate2 and trace_macros-gate3. for examples
13-
// of the below being caught.
5+
//~| ERROR trace_macros! accepts only `true` or `false`
6+
trace_macros!(true); //~ ERROR `trace_macros` is not stable
7+
trace_macros!(false); //~ ERROR `trace_macros` is not stable
148

159
macro_rules! expando {
1610
($x: ident) => { trace_macros!($x) } //~ ERROR `trace_macros` is not stable

src/test/ui/trace_macros-gate.stderr

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,48 +6,30 @@ LL | trace_macros!(); //~ ERROR `trace_macros` is not stable
66
|
77
= help: add #![feature(trace_macros)] to the crate attributes to enable
88

9-
error[E0658]: `trace_macros` is not stable enough for use and is subject to change (see issue #29598)
10-
--> $DIR/trace_macros-gate.rs:5:5
11-
|
12-
LL | trace_macros!(1); //~ ERROR `trace_macros` is not stable
13-
| ^^^^^^^^^^^^^^^^^
9+
error: trace_macros! accepts only `true` or `false`
10+
--> $DIR/trace_macros-gate.rs:14:5
1411
|
15-
= help: add #![feature(trace_macros)] to the crate attributes to enable
12+
LL | trace_macros!(); //~ ERROR `trace_macros` is not stable
13+
| ^^^^^^^^^^^^^^^^
1614

1715
error[E0658]: `trace_macros` is not stable enough for use and is subject to change (see issue #29598)
1816
--> $DIR/trace_macros-gate.rs:6:5
1917
|
20-
LL | trace_macros!(ident); //~ ERROR `trace_macros` is not stable
21-
| ^^^^^^^^^^^^^^^^^^^^^
18+
LL | trace_macros!(true); //~ ERROR `trace_macros` is not stable
19+
| ^^^^^^^^^^^^^^^^^^^^
2220
|
2321
= help: add #![feature(trace_macros)] to the crate attributes to enable
2422

2523
error[E0658]: `trace_macros` is not stable enough for use and is subject to change (see issue #29598)
2624
--> $DIR/trace_macros-gate.rs:7:5
2725
|
28-
LL | trace_macros!(for); //~ ERROR `trace_macros` is not stable
29-
| ^^^^^^^^^^^^^^^^^^^
30-
|
31-
= help: add #![feature(trace_macros)] to the crate attributes to enable
32-
33-
error[E0658]: `trace_macros` is not stable enough for use and is subject to change (see issue #29598)
34-
--> $DIR/trace_macros-gate.rs:8:5
35-
|
36-
LL | trace_macros!(true,); //~ ERROR `trace_macros` is not stable
26+
LL | trace_macros!(false); //~ ERROR `trace_macros` is not stable
3727
| ^^^^^^^^^^^^^^^^^^^^^
3828
|
3929
= help: add #![feature(trace_macros)] to the crate attributes to enable
4030

4131
error[E0658]: `trace_macros` is not stable enough for use and is subject to change (see issue #29598)
42-
--> $DIR/trace_macros-gate.rs:9:5
43-
|
44-
LL | trace_macros!(false 1); //~ ERROR `trace_macros` is not stable
45-
| ^^^^^^^^^^^^^^^^^^^^^^^
46-
|
47-
= help: add #![feature(trace_macros)] to the crate attributes to enable
48-
49-
error[E0658]: `trace_macros` is not stable enough for use and is subject to change (see issue #29598)
50-
--> $DIR/trace_macros-gate.rs:16:26
32+
--> $DIR/trace_macros-gate.rs:20:26
5133
|
5234
LL | ($x: ident) => { trace_macros!($x) } //~ ERROR `trace_macros` is not stable
5335
| ^^^^^^^^^^^^^^^^^
@@ -57,6 +39,6 @@ LL | expando!(true);
5739
|
5840
= help: add #![feature(trace_macros)] to the crate attributes to enable
5941

60-
error: aborting due to 7 previous errors
42+
error: aborting due to 5 previous errors
6143

6244
For more information about this error, try `rustc --explain E0658`.

0 commit comments

Comments
 (0)