hir_analysis: check number of vectors in tuples

Introduces a new check in `rustc_hir_analysis` enforcing that tuples of
scalable vectors should only up to eight vectors.
This commit is contained in:
David Wood
2026-02-19 11:03:14 +00:00
parent 3bc6ea5673
commit f760fdd8dc
3 changed files with 51 additions and 26 deletions
+11 -2
View File
@@ -1489,8 +1489,17 @@ fn check_scalable_vector(tcx: TyCtxt<'_>, span: Span, def_id: LocalDefId, scalab
return;
}
ScalableElt::Container if fields.is_empty() => {
let mut err =
tcx.dcx().struct_span_err(span, "scalable vectors must have a single field");
let mut err = tcx
.dcx()
.struct_span_err(span, "scalable vector tuples must have at least one field");
err.help("tuples of scalable vectors can only contain multiple of the same scalable vector type");
err.emit();
return;
}
ScalableElt::Container if fields.len() > 8 => {
let mut err = tcx
.dcx()
.struct_span_err(span, "scalable vector tuples can have at most eight fields");
err.help("tuples of scalable vectors can only contain multiple of the same scalable vector type");
err.emit();
return;
+11 -3
View File
@@ -3,6 +3,9 @@
#![allow(internal_features)]
#![feature(rustc_attrs)]
#[rustc_scalable_vector(4)]
struct Valid(f32);
#[rustc_scalable_vector(4)]
struct NoFieldsStructWithElementCount {}
//~^ ERROR: scalable vectors must have a single field
@@ -19,16 +22,16 @@ struct NoFieldsStructWithElementCount {}
#[rustc_scalable_vector]
struct NoFieldsStructWithoutElementCount {}
//~^ ERROR: scalable vectors must have a single field
//~^ ERROR: scalable vector tuples must have at least one field
//~^^ ERROR: scalable vectors must be tuple structs
#[rustc_scalable_vector]
struct NoFieldsTupleWithoutElementCount();
//~^ ERROR: scalable vectors must have a single field
//~^ ERROR: scalable vector tuples must have at least one field
#[rustc_scalable_vector]
struct NoFieldsUnitWithoutElementCount;
//~^ ERROR: scalable vectors must have a single field
//~^ ERROR: scalable vector tuples must have at least one field
//~^^ ERROR: scalable vectors must be tuple structs
#[rustc_scalable_vector(4)]
@@ -58,3 +61,8 @@ struct MultipleFieldsStructWithoutElementCount {
#[rustc_scalable_vector(2)]
struct SingleFieldStruct { _ty: f64 }
//~^ ERROR: scalable vectors must be tuple structs
#[rustc_scalable_vector]
struct TooManyFieldsWithoutElementCount(
Valid, Valid, Valid, Valid, Valid, Valid, Valid, Valid, Valid);
//~^^ ERROR: scalable vector tuples can have at most eight fields
+29 -21
View File
@@ -1,29 +1,29 @@
error: scalable vectors must be tuple structs
--> $DIR/illformed.rs:7:1
--> $DIR/illformed.rs:10:1
|
LL | struct NoFieldsStructWithElementCount {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: scalable vectors must be tuple structs
--> $DIR/illformed.rs:16:1
--> $DIR/illformed.rs:19:1
|
LL | struct NoFieldsUnitWithElementCount;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: scalable vectors must be tuple structs
--> $DIR/illformed.rs:21:1
--> $DIR/illformed.rs:24:1
|
LL | struct NoFieldsStructWithoutElementCount {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: scalable vectors must be tuple structs
--> $DIR/illformed.rs:30:1
--> $DIR/illformed.rs:33:1
|
LL | struct NoFieldsUnitWithoutElementCount;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: scalable vectors must be tuple structs
--> $DIR/illformed.rs:35:1
--> $DIR/illformed.rs:38:1
|
LL | / struct MultipleFieldsStructWithElementCount {
LL | |
@@ -34,7 +34,7 @@ LL | | }
| |_^
error: scalable vectors must be tuple structs
--> $DIR/illformed.rs:47:1
--> $DIR/illformed.rs:50:1
|
LL | / struct MultipleFieldsStructWithoutElementCount {
LL | |
@@ -44,13 +44,13 @@ LL | | }
| |_^
error: scalable vectors must be tuple structs
--> $DIR/illformed.rs:59:1
--> $DIR/illformed.rs:62:1
|
LL | struct SingleFieldStruct { _ty: f64 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: scalable vectors must have a single field
--> $DIR/illformed.rs:7:1
--> $DIR/illformed.rs:10:1
|
LL | struct NoFieldsStructWithElementCount {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -58,7 +58,7 @@ LL | struct NoFieldsStructWithElementCount {}
= help: scalable vector types' only field must be a primitive scalar type
error: scalable vectors must have a single field
--> $DIR/illformed.rs:12:1
--> $DIR/illformed.rs:15:1
|
LL | struct NoFieldsTupleWithElementCount();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -66,31 +66,31 @@ LL | struct NoFieldsTupleWithElementCount();
= help: scalable vector types' only field must be a primitive scalar type
error: scalable vectors must have a single field
--> $DIR/illformed.rs:16:1
--> $DIR/illformed.rs:19:1
|
LL | struct NoFieldsUnitWithElementCount;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: scalable vector types' only field must be a primitive scalar type
error: scalable vectors must have a single field
--> $DIR/illformed.rs:21:1
error: scalable vector tuples must have at least one field
--> $DIR/illformed.rs:24:1
|
LL | struct NoFieldsStructWithoutElementCount {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: tuples of scalable vectors can only contain multiple of the same scalable vector type
error: scalable vectors must have a single field
--> $DIR/illformed.rs:26:1
error: scalable vector tuples must have at least one field
--> $DIR/illformed.rs:29:1
|
LL | struct NoFieldsTupleWithoutElementCount();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: tuples of scalable vectors can only contain multiple of the same scalable vector type
error: scalable vectors must have a single field
--> $DIR/illformed.rs:30:1
error: scalable vector tuples must have at least one field
--> $DIR/illformed.rs:33:1
|
LL | struct NoFieldsUnitWithoutElementCount;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -98,28 +98,36 @@ LL | struct NoFieldsUnitWithoutElementCount;
= help: tuples of scalable vectors can only contain multiple of the same scalable vector type
error: scalable vectors cannot have multiple fields
--> $DIR/illformed.rs:35:1
--> $DIR/illformed.rs:38:1
|
LL | struct MultipleFieldsStructWithElementCount {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: scalable vectors cannot have multiple fields
--> $DIR/illformed.rs:43:1
--> $DIR/illformed.rs:46:1
|
LL | struct MultipleFieldsTupleWithElementCount(f32, u32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: scalable vector structs can only have scalable vector fields
--> $DIR/illformed.rs:49:5
--> $DIR/illformed.rs:52:5
|
LL | _ty: f32,
| ^^^^^^^^
error: scalable vector structs can only have scalable vector fields
--> $DIR/illformed.rs:55:47
--> $DIR/illformed.rs:58:47
|
LL | struct MultipleFieldsTupleWithoutElementCount(f32, u32);
| ^^^
error: aborting due to 17 previous errors
error: scalable vector tuples can have at most eight fields
--> $DIR/illformed.rs:66:1
|
LL | struct TooManyFieldsWithoutElementCount(
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: tuples of scalable vectors can only contain multiple of the same scalable vector type
error: aborting due to 18 previous errors