Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not ICE when we have -Zunpretty=expanded with invalid ABI #99360

Merged
merged 1 commit into from
Jul 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Copy link
Member Author

@compiler-errors compiler-errors Jul 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Do we want to error when we have an invalid ABI and we don't go thru HIR lowering, like with -Zunpretty=expanded?

Since we're not going thru HIR lowering, we don't emit the error at the normal place we expect it, but if we want, we could emit an error instead of delaying an error here, depending on the pretty print mode.

Right now this just allows invalid ABI strings, but I have no strong opinions either way.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per the reference there should be no ast-level constraint for abi. I think it is fine to leave it as is in ast.

span,
&format!("unrecognized ABI not caught in lowering: {}", abi),
);
}
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down
13 changes: 13 additions & 0 deletions src/test/ui/codemap_tests/unicode.expanded.stdout
Original file line number Diff line number Diff line change
@@ -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() {}
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 5 additions & 1 deletion src/test/ui/codemap_tests/unicode.rs
Original file line number Diff line number Diff line change
@@ -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() { }