|
1 | 1 | use std::fmt; |
2 | 2 |
|
3 | 3 | use rustc_abi::ExternAbi; |
| 4 | +use rustc_errors::{E0570, struct_span_code_err}; |
4 | 5 | use rustc_feature::Features; |
5 | 6 | use rustc_session::Session; |
6 | 7 | use rustc_session::parse::feature_err; |
@@ -31,13 +32,28 @@ pub(crate) fn extern_abi_enabled( |
31 | 32 |
|
32 | 33 | #[allow(rustc::untranslatable_diagnostic)] |
33 | 34 | pub(crate) fn gate_unstable_abi(sess: &Session, features: &Features, span: Span, abi: ExternAbi) { |
34 | | - match extern_abi_enabled(features, span, abi) { |
35 | | - Ok(_) => (), |
36 | | - Err(unstable_abi) => { |
37 | | - let explain = unstable_abi.to_string(); |
38 | | - feature_err(sess, unstable_abi.feature, span, explain).emit(); |
39 | | - } |
| 35 | + let Err(unstable) = extern_abi_stability(abi) else { return }; |
| 36 | + // what are we doing here? this is mixing target support with stability? |
| 37 | + // well, unfortunately we allowed some ABIs to be used via fn pointers and such on stable, |
| 38 | + // so we can't simply error any time someone uses certain ABIs as we want to let the FCW ride. |
| 39 | + // however, for a number of *unstable* ABIs, we can simply fix them because they're unstable! |
| 40 | + // otherwise it's the same idea as checking during lowering at all: because `extern "ABI"` has to |
| 41 | + // be visible during lowering of some crate, we can easily nail use of certain ABIs before we |
| 42 | + // get to e.g. attempting to do invalid codegen for the target. |
| 43 | + if !sess.target.is_abi_supported(unstable.abi) { |
| 44 | + struct_span_code_err!( |
| 45 | + sess.dcx(), |
| 46 | + span, |
| 47 | + E0570, |
| 48 | + "`{abi}` is not a supported ABI for the current target", |
| 49 | + ) |
| 50 | + .emit(); |
| 51 | + } |
| 52 | + if features.enabled(unstable.feature) || span.allows_unstable(unstable.feature) { |
| 53 | + return; |
40 | 54 | } |
| 55 | + let explain = unstable.to_string(); |
| 56 | + feature_err(sess, unstable.feature, span, explain).emit(); |
41 | 57 | } |
42 | 58 |
|
43 | 59 | pub struct UnstableAbi { |
|
0 commit comments