Skip to content

Commit 154eb95

Browse files
try to improve control flow
accept diffs become more nightly-sensitive
1 parent 2f19e8b commit 154eb95

6 files changed

+36
-67
lines changed

compiler/rustc_hir_analysis/src/lib.rs

+26-27
Original file line numberDiff line numberDiff line change
@@ -122,43 +122,42 @@ fn require_c_abi_if_c_variadic(
122122
const UNSTABLE_EXPLAIN: &str =
123123
"using calling conventions other than `C` or `cdecl` for varargs functions is unstable";
124124

125+
// ABIs which can stably use varargs
125126
if !decl.c_variadic || matches!(abi, ExternAbi::C { .. } | ExternAbi::Cdecl { .. }) {
126127
return;
127128
}
128129

130+
// ABIs with feature-gated stability
129131
let extended_abi_support = tcx.features().extended_varargs_abi_support();
130132
let extern_system_varargs = tcx.features().extern_system_varargs();
131-
let conventions = if extended_abi_support { CONVENTIONS_UNSTABLE } else { CONVENTIONS_STABLE };
133+
134+
// If the feature gate has been enabled, we can stop here
135+
if extern_system_varargs && let ExternAbi::System { .. } = abi {
136+
return;
137+
};
138+
if extended_abi_support && abi.supports_varargs() {
139+
return;
140+
};
141+
142+
// Looks like we need to pick an error to emit.
143+
// Is there any feature which we could have enabled to make this work?
132144
match abi {
133145
ExternAbi::System { .. } => {
134-
// User enabled additional ABI support for varargs and function ABI matches those ones.
135-
if extern_system_varargs {
136-
return;
137-
} else {
138-
// Using this ABI would be ok, if the feature for additional ABI support was enabled.
139-
feature_err(&tcx.sess, sym::extern_system_varargs, span, UNSTABLE_EXPLAIN).emit();
140-
}
146+
feature_err(&tcx.sess, sym::extern_system_varargs, span, UNSTABLE_EXPLAIN)
141147
}
142-
abi => {
143-
if abi.supports_varargs() {
144-
// User enabled additional ABI support for varargs and function ABI matches those ones.
145-
if extended_abi_support {
146-
return;
147-
} else {
148-
// Using this ABI would be ok, if the feature for additional ABI support was enabled.
149-
feature_err(
150-
&tcx.sess,
151-
sym::extended_varargs_abi_support,
152-
span,
153-
UNSTABLE_EXPLAIN,
154-
)
155-
.emit();
156-
};
157-
}
148+
abi if abi.supports_varargs() => {
149+
feature_err(&tcx.sess, sym::extended_varargs_abi_support, span, UNSTABLE_EXPLAIN)
158150
}
159-
};
160-
161-
tcx.dcx().emit_err(errors::VariadicFunctionCompatibleConvention { span, conventions });
151+
_ => tcx.dcx().create_err(errors::VariadicFunctionCompatibleConvention {
152+
span,
153+
conventions: if tcx.sess.opts.unstable_features.is_nightly_build() {
154+
CONVENTIONS_UNSTABLE
155+
} else {
156+
CONVENTIONS_STABLE
157+
},
158+
}),
159+
}
160+
.emit();
162161
}
163162

164163
pub fn provide(providers: &mut Providers) {

tests/ui/c-variadic/feature-gate-extended_varargs_abi_support.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
//@ only-x86_64
22

33
fn efiapi(f: extern "efiapi" fn(usize, ...)) {
4-
//~^ ERROR: C-variadic function must have a compatible calling convention, like `C` or `cdecl`
5-
//~^^ ERROR: using calling conventions other than `C` or `cdecl` for varargs functions is unstable
4+
//~^ ERROR: using calling conventions other than `C` or `cdecl` for varargs functions is unstable
65
f(22, 44);
76
}
87
fn sysv(f: extern "sysv64" fn(usize, ...)) {
9-
//~^ ERROR: C-variadic function must have a compatible calling convention, like `C` or `cdecl`
10-
//~^^ ERROR: using calling conventions other than `C` or `cdecl` for varargs functions is unstable
8+
//~^ ERROR: using calling conventions other than `C` or `cdecl` for varargs functions is unstable
119
f(22, 44);
1210
}
1311
fn win(f: extern "win64" fn(usize, ...)) {
14-
//~^ ERROR: C-variadic function must have a compatible calling convention, like `C` or `cdecl`
15-
//~^^ ERROR: using calling conventions other than `C` or `cdecl` for varargs functions is unstable
12+
//~^ ERROR: using calling conventions other than `C` or `cdecl` for varargs functions is unstable
1613
f(22, 44);
1714
}
1815

tests/ui/c-variadic/feature-gate-extended_varargs_abi_support.stderr

+4-23
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,8 @@ LL | fn efiapi(f: extern "efiapi" fn(usize, ...)) {
88
= help: add `#![feature(extended_varargs_abi_support)]` to the crate attributes to enable
99
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
1010

11-
error[E0045]: C-variadic function must have a compatible calling convention, like `C` or `cdecl`
12-
--> $DIR/feature-gate-extended_varargs_abi_support.rs:3:14
13-
|
14-
LL | fn efiapi(f: extern "efiapi" fn(usize, ...)) {
15-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C-variadic function must have a compatible calling convention
16-
1711
error[E0658]: using calling conventions other than `C` or `cdecl` for varargs functions is unstable
18-
--> $DIR/feature-gate-extended_varargs_abi_support.rs:8:12
12+
--> $DIR/feature-gate-extended_varargs_abi_support.rs:7:12
1913
|
2014
LL | fn sysv(f: extern "sysv64" fn(usize, ...)) {
2115
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -24,14 +18,8 @@ LL | fn sysv(f: extern "sysv64" fn(usize, ...)) {
2418
= help: add `#![feature(extended_varargs_abi_support)]` to the crate attributes to enable
2519
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
2620

27-
error[E0045]: C-variadic function must have a compatible calling convention, like `C` or `cdecl`
28-
--> $DIR/feature-gate-extended_varargs_abi_support.rs:8:12
29-
|
30-
LL | fn sysv(f: extern "sysv64" fn(usize, ...)) {
31-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C-variadic function must have a compatible calling convention
32-
3321
error[E0658]: using calling conventions other than `C` or `cdecl` for varargs functions is unstable
34-
--> $DIR/feature-gate-extended_varargs_abi_support.rs:13:11
22+
--> $DIR/feature-gate-extended_varargs_abi_support.rs:11:11
3523
|
3624
LL | fn win(f: extern "win64" fn(usize, ...)) {
3725
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -40,13 +28,6 @@ LL | fn win(f: extern "win64" fn(usize, ...)) {
4028
= help: add `#![feature(extended_varargs_abi_support)]` to the crate attributes to enable
4129
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
4230

43-
error[E0045]: C-variadic function must have a compatible calling convention, like `C` or `cdecl`
44-
--> $DIR/feature-gate-extended_varargs_abi_support.rs:13:11
45-
|
46-
LL | fn win(f: extern "win64" fn(usize, ...)) {
47-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C-variadic function must have a compatible calling convention
48-
49-
error: aborting due to 6 previous errors
31+
error: aborting due to 3 previous errors
5032

51-
Some errors have detailed explanations: E0045, E0658.
52-
For more information about an error, try `rustc --explain E0045`.
33+
For more information about this error, try `rustc --explain E0658`.

tests/ui/c-variadic/variadic-ffi-1.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0045]: C-variadic function must have a compatible calling convention, like `C` or `cdecl`
1+
error[E0045]: C-variadic function must have a compatible calling convention, like `C`, `cdecl`, `system`, `aapcs`, `win64`, `sysv64` or `efiapi`
22
--> $DIR/variadic-ffi-1.rs:9:5
33
|
44
LL | fn printf(_: *const u8, ...);

tests/ui/feature-gates/feature-gate-extern_system_varargs.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
fn system(f: extern "system" fn(usize, ...)) {
22
//~^ ERROR using calling conventions other than `C` or `cdecl` for varargs functions is unstable
3-
//~| ERROR C-variadic function must have a compatible calling convention, like `C` or `cdecl`
43

54
f(22, 44);
65
}

tests/ui/feature-gates/feature-gate-extern_system_varargs.stderr

+2-9
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,6 @@ LL | fn system(f: extern "system" fn(usize, ...)) {
88
= help: add `#![feature(extern_system_varargs)]` to the crate attributes to enable
99
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
1010

11-
error[E0045]: C-variadic function must have a compatible calling convention, like `C` or `cdecl`
12-
--> $DIR/feature-gate-extern_system_varargs.rs:1:14
13-
|
14-
LL | fn system(f: extern "system" fn(usize, ...)) {
15-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C-variadic function must have a compatible calling convention
16-
17-
error: aborting due to 2 previous errors
11+
error: aborting due to 1 previous error
1812

19-
Some errors have detailed explanations: E0045, E0658.
20-
For more information about an error, try `rustc --explain E0045`.
13+
For more information about this error, try `rustc --explain E0658`.

0 commit comments

Comments
 (0)