-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Convert some ABI tests to use extern "rust-invalid"
#142992
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
Merged
bors
merged 5 commits into
rust-lang:master
from
workingjubilee:dont-validate-naughty-abis
Jun 26, 2025
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
586a9d1
tests: split out unsupported-in-impls.rs
workingjubilee 12d05d8
tests: migrate unsupported-abi-transmute.rs to extern "rust-invalid"
workingjubilee 78652b7
tests: specify why extern "rust-invalid" cannot be used in varargs test
workingjubilee 087dabf
Sprinkle breadcrumbs around to lead people to the rust-invalid ABI
workingjubilee c24914e
compiler: fussily sort the huge AbiMap match
workingjubilee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,12 @@ | ||
//@ add-core-stubs | ||
//@ compile-flags: --crate-type=lib --target x86_64-unknown-none | ||
//@ needs-llvm-components: x86 | ||
// Check we error before unsupported ABIs reach codegen stages. | ||
|
||
//@ edition: 2018 | ||
#![no_core] | ||
#![feature(no_core, lang_items)] | ||
extern crate minicore; | ||
use minicore::*; | ||
//@ compile-flags: --crate-type=lib | ||
#![feature(rustc_attrs)] | ||
|
||
// Check we error before unsupported ABIs reach codegen stages. | ||
use core::mem; | ||
|
||
fn anything() { | ||
let a = unsafe { mem::transmute::<usize, extern "thiscall" fn(i32)>(4) }(2); | ||
let a = unsafe { mem::transmute::<usize, extern "rust-invalid" fn(i32)>(4) }(2); | ||
//~^ ERROR: is not a supported ABI for the current target [E0570] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Test for https://github.com/rust-lang/rust/issues/86232 | ||
// Due to AST-to-HIR lowering nuances, we used to allow unsupported ABIs to "leak" into the HIR | ||
// without being checked, as we would check after generating the ExternAbi. | ||
// Checking afterwards only works if we examine every HIR construct that contains an ExternAbi, | ||
// and those may be very different in HIR, even if they read the same in source. | ||
// This made it very easy to make mistakes. | ||
// | ||
// Here we test that an unsupported ABI in various impl-related positions will be rejected, | ||
// both in the original declarations and the actual implementations. | ||
|
||
#![feature(rustc_attrs)] | ||
//@ compile-flags: --crate-type lib | ||
|
||
pub struct FnPtrBearer { | ||
pub ptr: extern "rust-invalid" fn(), | ||
//~^ ERROR: is not a supported ABI | ||
} | ||
|
||
impl FnPtrBearer { | ||
pub extern "rust-invalid" fn inherent_fn(self) { | ||
//~^ ERROR: is not a supported ABI | ||
(self.ptr)() | ||
} | ||
} | ||
|
||
pub trait Trait { | ||
extern "rust-invalid" fn trait_fn(self); | ||
//~^ ERROR: is not a supported ABI | ||
} | ||
|
||
impl Trait for FnPtrBearer { | ||
extern "rust-invalid" fn trait_fn(self) { | ||
//~^ ERROR: is not a supported ABI | ||
self.inherent_fn() | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
error[E0570]: "rust-invalid" is not a supported ABI for the current target | ||
--> $DIR/unsupported-in-impls.rs:15:21 | ||
| | ||
LL | pub ptr: extern "rust-invalid" fn(), | ||
| ^^^^^^^^^^^^^^ | ||
|
||
error[E0570]: "rust-invalid" is not a supported ABI for the current target | ||
--> $DIR/unsupported-in-impls.rs:20:16 | ||
| | ||
LL | pub extern "rust-invalid" fn inherent_fn(self) { | ||
| ^^^^^^^^^^^^^^ | ||
|
||
error[E0570]: "rust-invalid" is not a supported ABI for the current target | ||
--> $DIR/unsupported-in-impls.rs:27:12 | ||
| | ||
LL | extern "rust-invalid" fn trait_fn(self); | ||
| ^^^^^^^^^^^^^^ | ||
|
||
error[E0570]: "rust-invalid" is not a supported ABI for the current target | ||
--> $DIR/unsupported-in-impls.rs:32:12 | ||
| | ||
LL | extern "rust-invalid" fn trait_fn(self) { | ||
| ^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 4 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0570`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An alternative would be to, in fact, say "yes,
extern "rust-invalid"
can support varargs", but that seems silly.