Skip to content

Commit fa688b8

Browse files
try to improve control flow
1 parent 2f19e8b commit fa688b8

File tree

1 file changed

+22
-29
lines changed
  • compiler/rustc_hir_analysis/src

1 file changed

+22
-29
lines changed

compiler/rustc_hir_analysis/src/lib.rs

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -116,49 +116,42 @@ fn require_c_abi_if_c_variadic(
116116
abi: ExternAbi,
117117
span: Span,
118118
) {
119-
const CONVENTIONS_UNSTABLE: &str =
120-
"`C`, `cdecl`, `system`, `aapcs`, `win64`, `sysv64` or `efiapi`";
121119
const CONVENTIONS_STABLE: &str = "`C` or `cdecl`";
122120
const UNSTABLE_EXPLAIN: &str =
123121
"using calling conventions other than `C` or `cdecl` for varargs functions is unstable";
124122

123+
// ABIs which can stably use varargs
125124
if !decl.c_variadic || matches!(abi, ExternAbi::C { .. } | ExternAbi::Cdecl { .. }) {
126125
return;
127126
}
128127

128+
// ABIs with feature-gated stability
129129
let extended_abi_support = tcx.features().extended_varargs_abi_support();
130130
let extern_system_varargs = tcx.features().extern_system_varargs();
131-
let conventions = if extended_abi_support { CONVENTIONS_UNSTABLE } else { CONVENTIONS_STABLE };
131+
132+
// If the feature gate has been enabled, we can stop here
133+
if extern_system_varargs && let ExternAbi::System { .. } = abi {
134+
return;
135+
};
136+
if extended_abi_support && abi.supports_varargs() {
137+
return;
138+
};
139+
140+
// Looks like we need to pick an error to emit.
141+
// Is there any feature which we could have enabled to make this work?
132142
match abi {
133143
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-
}
144+
feature_err(&tcx.sess, sym::extern_system_varargs, span, UNSTABLE_EXPLAIN)
141145
}
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-
}
146+
abi if abi.supports_varargs() => {
147+
feature_err(&tcx.sess, sym::extended_varargs_abi_support, span, UNSTABLE_EXPLAIN)
158148
}
159-
};
160-
161-
tcx.dcx().emit_err(errors::VariadicFunctionCompatibleConvention { span, conventions });
149+
_ => tcx.dcx().create_err(errors::VariadicFunctionCompatibleConvention {
150+
span,
151+
conventions: CONVENTIONS_STABLE,
152+
}),
153+
}
154+
.emit();
162155
}
163156

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

0 commit comments

Comments
 (0)