Skip to content

Commit

Permalink
Make sure feature gate errors are recoverable
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Dec 20, 2018
1 parent a053ae2 commit 29f3d7b
Show file tree
Hide file tree
Showing 20 changed files with 34 additions and 60 deletions.
6 changes: 2 additions & 4 deletions src/librustc/lint/levels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,24 +232,22 @@ impl<'a> LintLevelsBuilder<'a> {
match item.node {
ast::MetaItemKind::Word => {} // actual lint names handled later
ast::MetaItemKind::NameValue(ref name_value) => {
let gate_reasons = !self.sess.features_untracked().lint_reasons;
if item.ident == "reason" {
// found reason, reslice meta list to exclude it
metas = &metas[0..metas.len()-1];
// FIXME (#55112): issue unused-attributes lint if we thereby
// don't have any lint names (`#[level(reason = "foo")]`)
if let ast::LitKind::Str(rationale, _) = name_value.node {
if gate_reasons {
if !self.sess.features_untracked().lint_reasons {
feature_gate::emit_feature_err(
&self.sess.parse_sess,
"lint_reasons",
item.span,
feature_gate::GateIssue::Language,
"lint reasons are experimental"
);
} else {
reason = Some(rationale);
}
reason = Some(rationale);
} else {
let mut err = bad_attr(name_value.span);
err.help("reason must be a string literal");
Expand Down
1 change: 0 additions & 1 deletion src/librustc_typeck/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2220,7 +2220,6 @@ fn from_target_feature(
feature_gate::GateIssue::Language,
&format!("the target feature `{}` is currently unstable", feature),
);
return None;
}
Some(Symbol::intern(feature))
}));
Expand Down
1 change: 0 additions & 1 deletion src/libsyntax/ext/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,6 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
emit_feature_err(this.cx.parse_sess, &*feature.as_str(), span,
GateIssue::Library(Some(issue)), &explain);
this.cx.trace_macros_diag();
return Err(kind.dummy(span));
}
}

Expand Down
1 change: 0 additions & 1 deletion src/libsyntax_ext/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt,
sp,
feature_gate::GateIssue::Language,
feature_gate::EXPLAIN_ASM);
return DummyResult::expr(sp);
}

// Split the tts before the first colon, to avoid `asm!("x": y)` being
Expand Down
1 change: 0 additions & 1 deletion src/libsyntax_ext/concat_idents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ pub fn expand_syntax_ext<'cx>(cx: &'cx mut ExtCtxt,
sp,
feature_gate::GateIssue::Language,
feature_gate::EXPLAIN_CONCAT_IDENTS);
return base::DummyResult::expr(sp);
}

if tts.is_empty() {
Expand Down
1 change: 0 additions & 1 deletion src/libsyntax_ext/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,6 @@ pub fn expand_format_args_nl<'cx>(
sp,
feature_gate::GateIssue::Language,
feature_gate::EXPLAIN_FORMAT_ARGS_NL);
return DummyResult::expr(sp);
}
sp = sp.apply_mark(ecx.current_expansion.mark);
match parse_args(ecx, sp, tts) {
Expand Down
1 change: 0 additions & 1 deletion src/libsyntax_ext/global_asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ pub fn expand_global_asm<'cx>(cx: &'cx mut ExtCtxt,
sp,
feature_gate::GateIssue::Language,
feature_gate::EXPLAIN_GLOBAL_ASM);
return DummyResult::any(sp);
}

let mut p = cx.new_parser_from_tts(tts);
Expand Down
1 change: 0 additions & 1 deletion src/libsyntax_ext/log_syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ pub fn expand_syntax_ext<'cx>(cx: &'cx mut base::ExtCtxt,
sp,
feature_gate::GateIssue::Language,
feature_gate::EXPLAIN_LOG_SYNTAX);
return base::DummyResult::any(sp);
}

println!("{}", print::pprust::tts_to_string(tts));
Expand Down
2 changes: 0 additions & 2 deletions src/libsyntax_ext/test_case.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ pub fn expand(
attr_sp,
feature_gate::GateIssue::Language,
feature_gate::EXPLAIN_CUSTOM_TEST_FRAMEWORKS);

return vec![anno_item];
}

if !ecx.ecfg.should_test { return vec![]; }
Expand Down
1 change: 0 additions & 1 deletion src/libsyntax_ext/trace_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ pub fn expand_trace_macros(cx: &mut ExtCtxt,
sp,
feature_gate::GateIssue::Language,
feature_gate::EXPLAIN_TRACE_MACROS);
return base::DummyResult::any(sp);
}

match (tt.len(), tt.first()) {
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/feature-gates/feature-gate-asm2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@

fn main() {
unsafe {
println!("{}", asm!("")); //~ ERROR inline assembly is not stable
println!("{:?}", asm!("")); //~ ERROR inline assembly is not stable
}
}
6 changes: 3 additions & 3 deletions src/test/ui/feature-gates/feature-gate-asm2.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error[E0658]: inline assembly is not stable enough for use and is subject to change (see issue #29722)
--> $DIR/feature-gate-asm2.rs:15:24
--> $DIR/feature-gate-asm2.rs:15:26
|
LL | println!("{}", asm!("")); //~ ERROR inline assembly is not stable
| ^^^^^^^^
LL | println!("{:?}", asm!("")); //~ ERROR inline assembly is not stable
| ^^^^^^^^
|
= help: add #![feature(asm)] to the crate attributes to enable

Expand Down
1 change: 1 addition & 0 deletions src/test/ui/feature-gates/feature-gate-concat_idents2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@

fn main() {
concat_idents!(a, b); //~ ERROR `concat_idents` is not stable enough
//~| ERROR cannot find value `ab` in this scope
}
11 changes: 9 additions & 2 deletions src/test/ui/feature-gates/feature-gate-concat_idents2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ LL | concat_idents!(a, b); //~ ERROR `concat_idents` is not stable enough
|
= help: add #![feature(concat_idents)] to the crate attributes to enable

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

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0658`.
Some errors occurred: E0425, E0658.
For more information about an error, try `rustc --explain E0425`.
1 change: 1 addition & 0 deletions src/test/ui/feature-gates/feature-gate-log_syntax.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

2 changes: 1 addition & 1 deletion src/test/ui/feature-gates/feature-gate-log_syntax2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
// gate-test-log_syntax

fn main() {
println!("{}", log_syntax!()); //~ ERROR `log_syntax!` is not stable
println!("{:?}", log_syntax!()); //~ ERROR `log_syntax!` is not stable
}
6 changes: 3 additions & 3 deletions src/test/ui/feature-gates/feature-gate-log_syntax2.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error[E0658]: `log_syntax!` is not stable enough for use and is subject to change (see issue #29598)
--> $DIR/feature-gate-log_syntax2.rs:14:20
--> $DIR/feature-gate-log_syntax2.rs:14:22
|
LL | println!("{}", log_syntax!()); //~ ERROR `log_syntax!` is not stable
| ^^^^^^^^^^^^^
LL | println!("{:?}", log_syntax!()); //~ ERROR `log_syntax!` is not stable
| ^^^^^^^^^^^^^
|
= help: add #![feature(log_syntax)] to the crate attributes to enable

Expand Down
1 change: 1 addition & 0 deletions src/test/ui/feature-gates/feature-gate-log_syntax2.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

12 changes: 3 additions & 9 deletions src/test/ui/trace_macros-gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,9 @@

fn main() {
trace_macros!(); //~ ERROR `trace_macros` is not stable
trace_macros!(1); //~ ERROR `trace_macros` is not stable
trace_macros!(ident); //~ ERROR `trace_macros` is not stable
trace_macros!(for); //~ ERROR `trace_macros` is not stable
trace_macros!(true,); //~ ERROR `trace_macros` is not stable
trace_macros!(false 1); //~ ERROR `trace_macros` is not stable

// Errors are signalled early for the above, before expansion.
// See trace_macros-gate2 and trace_macros-gate3. for examples
// of the below being caught.
//~| ERROR trace_macros! accepts only `true` or `false`
trace_macros!(true); //~ ERROR `trace_macros` is not stable
trace_macros!(false); //~ ERROR `trace_macros` is not stable

macro_rules! expando {
($x: ident) => { trace_macros!($x) } //~ ERROR `trace_macros` is not stable
Expand Down
36 changes: 9 additions & 27 deletions src/test/ui/trace_macros-gate.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,48 +6,30 @@ LL | trace_macros!(); //~ ERROR `trace_macros` is not stable
|
= help: add #![feature(trace_macros)] to the crate attributes to enable

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

error[E0658]: `trace_macros` is not stable enough for use and is subject to change (see issue #29598)
--> $DIR/trace_macros-gate.rs:16:5
|
LL | trace_macros!(ident); //~ ERROR `trace_macros` is not stable
| ^^^^^^^^^^^^^^^^^^^^^
LL | trace_macros!(true); //~ ERROR `trace_macros` is not stable
| ^^^^^^^^^^^^^^^^^^^^
|
= help: add #![feature(trace_macros)] to the crate attributes to enable

error[E0658]: `trace_macros` is not stable enough for use and is subject to change (see issue #29598)
--> $DIR/trace_macros-gate.rs:17:5
|
LL | trace_macros!(for); //~ ERROR `trace_macros` is not stable
| ^^^^^^^^^^^^^^^^^^^
|
= help: add #![feature(trace_macros)] to the crate attributes to enable

error[E0658]: `trace_macros` is not stable enough for use and is subject to change (see issue #29598)
--> $DIR/trace_macros-gate.rs:18:5
|
LL | trace_macros!(true,); //~ ERROR `trace_macros` is not stable
LL | trace_macros!(false); //~ ERROR `trace_macros` is not stable
| ^^^^^^^^^^^^^^^^^^^^^
|
= help: add #![feature(trace_macros)] to the crate attributes to enable

error[E0658]: `trace_macros` is not stable enough for use and is subject to change (see issue #29598)
--> $DIR/trace_macros-gate.rs:19:5
|
LL | trace_macros!(false 1); //~ ERROR `trace_macros` is not stable
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= help: add #![feature(trace_macros)] to the crate attributes to enable

error[E0658]: `trace_macros` is not stable enough for use and is subject to change (see issue #29598)
--> $DIR/trace_macros-gate.rs:26:26
--> $DIR/trace_macros-gate.rs:20:26
|
LL | ($x: ident) => { trace_macros!($x) } //~ ERROR `trace_macros` is not stable
| ^^^^^^^^^^^^^^^^^
Expand All @@ -57,6 +39,6 @@ LL | expando!(true);
|
= help: add #![feature(trace_macros)] to the crate attributes to enable

error: aborting due to 7 previous errors
error: aborting due to 5 previous errors

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

0 comments on commit 29f3d7b

Please sign in to comment.