From 26ecd44160f54395b3bd5558cc5352f49cb0a0ba Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sat, 16 Jul 2022 20:35:54 -0700 Subject: [PATCH] Do not ICE when we have -Zunpretty=expand with invalid ABI --- compiler/rustc_ast_passes/src/feature_gate.rs | 10 ++++++---- compiler/rustc_session/src/config.rs | 8 ++++++++ src/test/ui/codemap_tests/unicode.expanded.stdout | 13 +++++++++++++ .../{unicode.stderr => unicode.normal.stderr} | 2 +- src/test/ui/codemap_tests/unicode.rs | 6 +++++- 5 files changed, 33 insertions(+), 6 deletions(-) create mode 100644 src/test/ui/codemap_tests/unicode.expanded.stdout rename src/test/ui/codemap_tests/{unicode.stderr => unicode.normal.stderr} (96%) diff --git a/compiler/rustc_ast_passes/src/feature_gate.rs b/compiler/rustc_ast_passes/src/feature_gate.rs index e69f85eacf7cd..5830a755a872d 100644 --- a/compiler/rustc_ast_passes/src/feature_gate.rs +++ b/compiler/rustc_ast_passes/src/feature_gate.rs @@ -274,10 +274,12 @@ impl<'a> PostExpansionVisitor<'a> { ); } abi => { - self.sess.parse_sess.span_diagnostic.delay_span_bug( - span, - &format!("unrecognized ABI not caught in lowering: {}", abi), - ); + if self.sess.opts.pretty.map_or(true, |ppm| ppm.needs_hir()) { + self.sess.parse_sess.span_diagnostic.delay_span_bug( + span, + &format!("unrecognized ABI not caught in lowering: {}", abi), + ); + } } } } diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index 0e52bf34661d6..55307b9cebb70 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -2707,6 +2707,14 @@ impl PpMode { | MirCFG => true, } } + pub fn needs_hir(&self) -> bool { + use PpMode::*; + match *self { + Source(_) | AstTree(_) => false, + + Hir(_) | HirTree | ThirTree | Mir | MirCFG => true, + } + } pub fn needs_analysis(&self) -> bool { use PpMode::*; diff --git a/src/test/ui/codemap_tests/unicode.expanded.stdout b/src/test/ui/codemap_tests/unicode.expanded.stdout new file mode 100644 index 0000000000000..d14bb42b2fdb2 --- /dev/null +++ b/src/test/ui/codemap_tests/unicode.expanded.stdout @@ -0,0 +1,13 @@ +#![feature(prelude_import)] +#![no_std] +#[prelude_import] +use ::std::prelude::rust_2015::*; +#[macro_use] +extern crate std; +// revisions: normal expanded +//[expanded] check-pass +//[expanded]compile-flags: -Zunpretty=expanded + +extern "路濫狼á́́" fn foo() {} + +fn main() {} diff --git a/src/test/ui/codemap_tests/unicode.stderr b/src/test/ui/codemap_tests/unicode.normal.stderr similarity index 96% rename from src/test/ui/codemap_tests/unicode.stderr rename to src/test/ui/codemap_tests/unicode.normal.stderr index bf7aaa5f0ebbf..60f8cff84b30c 100644 --- a/src/test/ui/codemap_tests/unicode.stderr +++ b/src/test/ui/codemap_tests/unicode.normal.stderr @@ -1,5 +1,5 @@ error[E0703]: invalid ABI: found `路濫狼á́́` - --> $DIR/unicode.rs:1:8 + --> $DIR/unicode.rs:5:8 | LL | extern "路濫狼á́́" fn foo() {} | ^^^^^^^^^ invalid ABI diff --git a/src/test/ui/codemap_tests/unicode.rs b/src/test/ui/codemap_tests/unicode.rs index 7180e903b5c3c..4df9a5270c317 100644 --- a/src/test/ui/codemap_tests/unicode.rs +++ b/src/test/ui/codemap_tests/unicode.rs @@ -1,3 +1,7 @@ -extern "路濫狼á́́" fn foo() {} //~ ERROR invalid ABI +// revisions: normal expanded +//[expanded] check-pass +//[expanded]compile-flags: -Zunpretty=expanded + +extern "路濫狼á́́" fn foo() {} //[normal]~ ERROR invalid ABI fn main() { }