Skip to content

Commit f10f0f0

Browse files
authored
Rollup merge of rust-lang#137092 - RalfJung:abi_unsupported_vector_types-better-error, r=compiler-errors
abi_unsupported_vector_types: say which type is the problem
2 parents d3556c6 + 313e852 commit f10f0f0

13 files changed

+129
-124
lines changed

compiler/rustc_monomorphize/messages.ftl

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
monomorphize_abi_error_disabled_vector_type_call =
2-
this function call uses a SIMD vector type that (with the chosen ABI) requires the `{$required_feature}` target feature, which is not enabled in the caller
2+
this function call uses SIMD vector type `{$ty}` which (with the chosen ABI) requires the `{$required_feature}` target feature, which is not enabled in the caller
33
.label = function called here
44
.help = consider enabling it globally (`-C target-feature=+{$required_feature}`) or locally (`#[target_feature(enable="{$required_feature}")]`)
55
monomorphize_abi_error_disabled_vector_type_def =
6-
this function definition uses a SIMD vector type that (with the chosen ABI) requires the `{$required_feature}` target feature, which is not enabled
6+
this function definition uses SIMD vector type `{$ty}` which (with the chosen ABI) requires the `{$required_feature}` target feature, which is not enabled
77
.label = function defined here
88
.help = consider enabling it globally (`-C target-feature=+{$required_feature}`) or locally (`#[target_feature(enable="{$required_feature}")]`)
99
1010
monomorphize_abi_error_unsupported_vector_type_call =
11-
this function call uses a SIMD vector type that is not currently supported with the chosen ABI
11+
this function call uses SIMD vector type `{$ty}` which is not currently supported with the chosen ABI
1212
.label = function called here
1313
monomorphize_abi_error_unsupported_vector_type_def =
14-
this function definition uses a SIMD vector type that is not currently supported with the chosen ABI
14+
this function definition uses SIMD vector type `{$ty}` which is not currently supported with the chosen ABI
1515
.label = function defined here
1616
1717
monomorphize_couldnt_dump_mono_stats =

compiler/rustc_monomorphize/src/errors.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::path::PathBuf;
22

33
use rustc_macros::{Diagnostic, LintDiagnostic};
4+
use rustc_middle::ty::Ty;
45
use rustc_span::{Span, Symbol};
56

67
#[derive(Diagnostic)]
@@ -75,6 +76,7 @@ pub(crate) struct AbiErrorDisabledVectorTypeDef<'a> {
7576
#[label]
7677
pub span: Span,
7778
pub required_feature: &'a str,
79+
pub ty: Ty<'a>,
7880
}
7981

8082
#[derive(LintDiagnostic)]
@@ -84,18 +86,21 @@ pub(crate) struct AbiErrorDisabledVectorTypeCall<'a> {
8486
#[label]
8587
pub span: Span,
8688
pub required_feature: &'a str,
89+
pub ty: Ty<'a>,
8790
}
8891

8992
#[derive(LintDiagnostic)]
9093
#[diag(monomorphize_abi_error_unsupported_vector_type_def)]
91-
pub(crate) struct AbiErrorUnsupportedVectorTypeDef {
94+
pub(crate) struct AbiErrorUnsupportedVectorTypeDef<'a> {
9295
#[label]
9396
pub span: Span,
97+
pub ty: Ty<'a>,
9498
}
9599

96100
#[derive(LintDiagnostic)]
97101
#[diag(monomorphize_abi_error_unsupported_vector_type_call)]
98-
pub(crate) struct AbiErrorUnsupportedVectorTypeCall {
102+
pub(crate) struct AbiErrorUnsupportedVectorTypeCall<'a> {
99103
#[label]
100104
pub span: Span,
105+
pub ty: Ty<'a>,
101106
}

compiler/rustc_monomorphize/src/mono_checks/abi_check.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ fn do_check_abi<'tcx>(
3434
tcx: TyCtxt<'tcx>,
3535
abi: &FnAbi<'tcx, Ty<'tcx>>,
3636
target_feature_def: DefId,
37-
mut emit_err: impl FnMut(Option<&'static str>),
37+
mut emit_err: impl FnMut(Ty<'tcx>, Option<&'static str>),
3838
) {
3939
let feature_def = tcx.sess.target.features_for_correct_vector_abi();
4040
let codegen_attrs = tcx.codegen_fn_attrs(target_feature_def);
@@ -45,15 +45,15 @@ fn do_check_abi<'tcx>(
4545
let feature = match feature_def.iter().find(|(bits, _)| size.bits() <= *bits) {
4646
Some((_, feature)) => feature,
4747
None => {
48-
emit_err(None);
48+
emit_err(arg_abi.layout.ty, None);
4949
continue;
5050
}
5151
};
5252
let feature_sym = Symbol::intern(feature);
5353
if !tcx.sess.unstable_target_features.contains(&feature_sym)
5454
&& !codegen_attrs.target_features.iter().any(|x| x.name == feature_sym)
5555
{
56-
emit_err(Some(&feature));
56+
emit_err(arg_abi.layout.ty, Some(&feature));
5757
}
5858
}
5959
}
@@ -69,21 +69,21 @@ fn check_instance_abi<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) {
6969
// function.
7070
return;
7171
};
72-
do_check_abi(tcx, abi, instance.def_id(), |required_feature| {
72+
do_check_abi(tcx, abi, instance.def_id(), |ty, required_feature| {
7373
let span = tcx.def_span(instance.def_id());
7474
if let Some(required_feature) = required_feature {
7575
tcx.emit_node_span_lint(
7676
ABI_UNSUPPORTED_VECTOR_TYPES,
7777
CRATE_HIR_ID,
7878
span,
79-
AbiErrorDisabledVectorTypeDef { span, required_feature },
79+
AbiErrorDisabledVectorTypeDef { span, required_feature, ty },
8080
);
8181
} else {
8282
tcx.emit_node_span_lint(
8383
ABI_UNSUPPORTED_VECTOR_TYPES,
8484
CRATE_HIR_ID,
8585
span,
86-
AbiErrorUnsupportedVectorTypeDef { span },
86+
AbiErrorUnsupportedVectorTypeDef { span, ty },
8787
);
8888
}
8989
})
@@ -123,20 +123,20 @@ fn check_call_site_abi<'tcx>(
123123
// ABI failed to compute; this will not get through codegen.
124124
return;
125125
};
126-
do_check_abi(tcx, callee_abi, caller.def_id(), |required_feature| {
126+
do_check_abi(tcx, callee_abi, caller.def_id(), |ty, required_feature| {
127127
if let Some(required_feature) = required_feature {
128128
tcx.emit_node_span_lint(
129129
ABI_UNSUPPORTED_VECTOR_TYPES,
130130
CRATE_HIR_ID,
131131
span,
132-
AbiErrorDisabledVectorTypeCall { span, required_feature },
132+
AbiErrorDisabledVectorTypeCall { span, required_feature, ty },
133133
);
134134
} else {
135135
tcx.emit_node_span_lint(
136136
ABI_UNSUPPORTED_VECTOR_TYPES,
137137
CRATE_HIR_ID,
138138
span,
139-
AbiErrorUnsupportedVectorTypeCall { span },
139+
AbiErrorUnsupportedVectorTypeCall { span, ty },
140140
);
141141
}
142142
});

tests/ui/simd-abi-checks-empty-list.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ trait Copy {}
1515
pub struct SimdVec([i32; 4]);
1616

1717
pub extern "C" fn pass_by_vec(_: SimdVec) {}
18-
//~^ this function definition uses a SIMD vector type that is not currently supported with the chosen ABI
18+
//~^ this function definition uses SIMD vector type `SimdVec` which is not currently supported with the chosen ABI
1919
//~| WARNING this was previously accepted by the compiler

tests/ui/simd-abi-checks-empty-list.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
warning: this function definition uses a SIMD vector type that is not currently supported with the chosen ABI
1+
warning: this function definition uses SIMD vector type `SimdVec` which is not currently supported with the chosen ABI
22
--> $DIR/simd-abi-checks-empty-list.rs:17:1
33
|
44
LL | pub extern "C" fn pass_by_vec(_: SimdVec) {}
@@ -11,7 +11,7 @@ LL | pub extern "C" fn pass_by_vec(_: SimdVec) {}
1111
warning: 1 warning emitted
1212

1313
Future incompatibility report: Future breakage diagnostic:
14-
warning: this function definition uses a SIMD vector type that is not currently supported with the chosen ABI
14+
warning: this function definition uses SIMD vector type `SimdVec` which is not currently supported with the chosen ABI
1515
--> $DIR/simd-abi-checks-empty-list.rs:17:1
1616
|
1717
LL | pub extern "C" fn pass_by_vec(_: SimdVec) {}

tests/ui/simd-abi-checks-s390x.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ impl<T: Copy> Copy for TransparentWrapper<T> {}
4444

4545
#[no_mangle]
4646
extern "C" fn vector_ret_small(x: &i8x8) -> i8x8 {
47-
//~^ ERROR this function definition uses a SIMD vector type that (with the chosen ABI) requires the `vector` target feature, which is not enabled
47+
//~^ ERROR requires the `vector` target feature, which is not enabled
4848
//~^^ WARN this was previously accepted
4949
*x
5050
}
5151
#[no_mangle]
5252
extern "C" fn vector_ret(x: &i8x16) -> i8x16 {
53-
//~^ ERROR this function definition uses a SIMD vector type that (with the chosen ABI) requires the `vector` target feature, which is not enabled
53+
//~^ ERROR requires the `vector` target feature, which is not enabled
5454
//~^^ WARN this was previously accepted
5555
*x
5656
}
@@ -99,15 +99,15 @@ extern "C" fn vector_wrapper_ret_large(x: &Wrapper<i8x32>) -> Wrapper<i8x32> {
9999
extern "C" fn vector_transparent_wrapper_ret_small(
100100
x: &TransparentWrapper<i8x8>,
101101
) -> TransparentWrapper<i8x8> {
102-
//~^^^ ERROR this function definition uses a SIMD vector type that (with the chosen ABI) requires the `vector` target feature, which is not enabled
102+
//~^^^ ERROR requires the `vector` target feature, which is not enabled
103103
//~^^^^ WARN this was previously accepted
104104
*x
105105
}
106106
#[no_mangle]
107107
extern "C" fn vector_transparent_wrapper_ret(
108108
x: &TransparentWrapper<i8x16>,
109109
) -> TransparentWrapper<i8x16> {
110-
//~^^^ ERROR this function definition uses a SIMD vector type that (with the chosen ABI) requires the `vector` target feature, which is not enabled
110+
//~^^^ ERROR requires the `vector` target feature, which is not enabled
111111
//~^^^^ WARN this was previously accepted
112112
*x
113113
}
@@ -121,13 +121,13 @@ extern "C" fn vector_transparent_wrapper_ret_large(
121121

122122
#[no_mangle]
123123
extern "C" fn vector_arg_small(x: i8x8) -> i64 {
124-
//~^ ERROR this function definition uses a SIMD vector type that (with the chosen ABI) requires the `vector` target feature, which is not enabled
124+
//~^ ERROR requires the `vector` target feature, which is not enabled
125125
//~^^ WARN this was previously accepted
126126
unsafe { *(&x as *const i8x8 as *const i64) }
127127
}
128128
#[no_mangle]
129129
extern "C" fn vector_arg(x: i8x16) -> i64 {
130-
//~^ ERROR this function definition uses a SIMD vector type that (with the chosen ABI) requires the `vector` target feature, which is not enabled
130+
//~^ ERROR requires the `vector` target feature, which is not enabled
131131
//~^^ WARN this was previously accepted
132132
unsafe { *(&x as *const i8x16 as *const i64) }
133133
}
@@ -139,13 +139,13 @@ extern "C" fn vector_arg_large(x: i8x32) -> i64 {
139139

140140
#[no_mangle]
141141
extern "C" fn vector_wrapper_arg_small(x: Wrapper<i8x8>) -> i64 {
142-
//~^ ERROR this function definition uses a SIMD vector type that (with the chosen ABI) requires the `vector` target feature, which is not enabled
142+
//~^ ERROR requires the `vector` target feature, which is not enabled
143143
//~^^ WARN this was previously accepted
144144
unsafe { *(&x as *const Wrapper<i8x8> as *const i64) }
145145
}
146146
#[no_mangle]
147147
extern "C" fn vector_wrapper_arg(x: Wrapper<i8x16>) -> i64 {
148-
//~^ ERROR this function definition uses a SIMD vector type that (with the chosen ABI) requires the `vector` target feature, which is not enabled
148+
//~^ ERROR requires the `vector` target feature, which is not enabled
149149
//~^^ WARN this was previously accepted
150150
unsafe { *(&x as *const Wrapper<i8x16> as *const i64) }
151151
}
@@ -157,13 +157,13 @@ extern "C" fn vector_wrapper_arg_large(x: Wrapper<i8x32>) -> i64 {
157157

158158
#[no_mangle]
159159
extern "C" fn vector_transparent_wrapper_arg_small(x: TransparentWrapper<i8x8>) -> i64 {
160-
//~^ ERROR this function definition uses a SIMD vector type that (with the chosen ABI) requires the `vector` target feature, which is not enabled
160+
//~^ ERROR requires the `vector` target feature, which is not enabled
161161
//~^^ WARN this was previously accepted
162162
unsafe { *(&x as *const TransparentWrapper<i8x8> as *const i64) }
163163
}
164164
#[no_mangle]
165165
extern "C" fn vector_transparent_wrapper_arg(x: TransparentWrapper<i8x16>) -> i64 {
166-
//~^ ERROR this function definition uses a SIMD vector type that (with the chosen ABI) requires the `vector` target feature, which is not enabled
166+
//~^ ERROR requires the `vector` target feature, which is not enabled
167167
//~^^ WARN this was previously accepted
168168
unsafe { *(&x as *const TransparentWrapper<i8x16> as *const i64) }
169169
}

0 commit comments

Comments
 (0)