Skip to content

Commit 7e8fef2

Browse files
committed
Reject #[splat] in TypeInfo, for now
1 parent d83e6d9 commit 7e8fef2

6 files changed

Lines changed: 188 additions & 11 deletions

File tree

compiler/rustc_const_eval/src/const_eval/type_info.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_ast::Mutability;
77
use rustc_hir::LangItem;
88
use rustc_middle::span_bug;
99
use rustc_middle::ty::layout::TyAndLayout;
10-
use rustc_middle::ty::{self, Const, FnHeader, FnSigKind, FnSigTys, ScalarInt, Ty, TyCtxt};
10+
use rustc_middle::ty::{self, Const, FnHeader, FnSigTys, ScalarInt, Ty, TyCtxt};
1111
use rustc_span::{Symbol, sym};
1212

1313
use crate::const_eval::CompileTimeMachine;
@@ -466,13 +466,8 @@ impl<'tcx> InterpCx<'tcx, CompileTimeMachine<'tcx>> {
466466
self.write_scalar(Scalar::from_bool(fn_sig_kind.c_variadic()), &field_place)?;
467467
}
468468
sym::splat => {
469-
self.write_scalar(
470-
// Use the same encoding as FnSigKind.splatted
471-
Scalar::from_u16(
472-
fn_sig_kind.splatted().unwrap_or(FnSigKind::NO_SPLATTED_ARG_INDEX),
473-
),
474-
&field_place,
475-
)?;
469+
// FIXME(splat): use the same encoding as FnSigKind.splatted
470+
span_bug!(self.tcx.def_span(field.did), "const `#[splat]` is not implemented")
476471
}
477472
other => span_bug!(self.tcx.def_span(field.did), "unimplemented field {other}"),
478473
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//@ failure-status: 101
2+
3+
//@ normalize-stderr: "thread.*panicked at compiler.*" -> ""
4+
//@ normalize-stderr: "note: rustc.*running on.*" -> "note: rustc {version} running on {platform}"
5+
//@ normalize-stderr: "note: compiler flags.*\n\n" -> ""
6+
//@ normalize-stderr: " +\d{1,}: .*\n" -> ""
7+
//@ normalize-stderr: " + at .*\n" -> ""
8+
//@ normalize-stderr: ".*omitted \d{1,} frames?.*\n" -> ""
9+
//@ normalize-stderr: ".*note: Some details are omitted.*\n" -> ""
10+
11+
//! Test using `#[splat]` on tuple arguments of simple function pointers.
12+
//! Currently ICEs, but if we fix it, we'll want to know and update this test to pass.
13+
14+
#![allow(incomplete_features)]
15+
#![feature(splat)]
16+
17+
const fn tuple_args_const(#[splat] (_a, _b): (u32, i8)) {}
18+
19+
fn main() {
20+
// FIXME(splat): not currently supported, can be supported when we no longer require a DefId in
21+
// MIR lowering
22+
// FIXME(rustfmt): the attribute gets deleted by rustfmt
23+
24+
// Functions
25+
26+
#[rustfmt::skip]
27+
const FN_PTR: fn(#[splat] (u32, i8)) = tuple_args_const;
28+
const _: () = FN_PTR(1, 2); //~ ERROR no splatted def for function or method callee
29+
const _: () = FN_PTR(1u32, 2i8); //~ ERROR no splatted def for function or method callee
30+
31+
// FIXME(splat): should splatted functions be callable with tupled and un-tupled arguments?
32+
// Add a tupled test for each call if they are.
33+
const _: () = FN_PTR((1, 2)); //~ ERROR this splatted function takes 2 arguments, but 1 was provided
34+
35+
// Function pointers
36+
#[rustfmt::skip]
37+
const FN_PTR_PTR: *const fn(#[splat] (u32, i8)) =
38+
tuple_args_const as *const fn(#[splat] (u32, i8));
39+
const _: () = (*FN_PTR_PTR)(1, 2); //~ ERROR no splatted def for function or method callee
40+
const _: () = (*FN_PTR_PTR)(1u32, 2i8); //~ ERROR no splatted def for function or method callee
41+
}
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
error: internal compiler error: compiler/rustc_mir_build/src/thir/cx/expr.rs:1314:13: no splatted def for function or method callee
2+
--> $DIR/splat-fn-ptr-tuple-const-ice.rs:28:19
3+
|
4+
LL | const _: () = FN_PTR(1, 2);
5+
| ^^^^^^^^^^^^
6+
7+
8+
9+
Box<dyn Any>
10+
stack backtrace:
11+
12+
note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md
13+
14+
note: please make sure that you have updated to the latest nightly
15+
16+
note: rustc {version} running on {platform}
17+
18+
query stack during panic:
19+
#0 [thir_body] building THIR for `main::_`
20+
#1 [check_match] match-checking `main::_`
21+
#2 [mir_built] building MIR for `main::_`
22+
#3 [trivial_const] checking if `main::_` is a trivial const
23+
#4 [eval_to_const_value_raw] simplifying constant for the type system `main::_`
24+
#5 [analysis] running analysis passes on crate `splat_fn_ptr_tuple_const_ice`
25+
end of query stack
26+
error: internal compiler error: compiler/rustc_mir_build/src/thir/cx/expr.rs:1314:13: no splatted def for function or method callee
27+
--> $DIR/splat-fn-ptr-tuple-const-ice.rs:29:19
28+
|
29+
LL | const _: () = FN_PTR(1u32, 2i8);
30+
| ^^^^^^^^^^^^^^^^^
31+
32+
33+
34+
Box<dyn Any>
35+
stack backtrace:
36+
37+
note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md
38+
39+
note: please make sure that you have updated to the latest nightly
40+
41+
note: rustc {version} running on {platform}
42+
43+
query stack during panic:
44+
#0 [thir_body] building THIR for `main::_`
45+
#1 [check_match] match-checking `main::_`
46+
#2 [mir_built] building MIR for `main::_`
47+
#3 [trivial_const] checking if `main::_` is a trivial const
48+
#4 [eval_to_const_value_raw] simplifying constant for the type system `main::_`
49+
#5 [analysis] running analysis passes on crate `splat_fn_ptr_tuple_const_ice`
50+
end of query stack
51+
error[E0057]: this splatted function takes 2 arguments, but 1 was provided
52+
--> $DIR/splat-fn-ptr-tuple-const-ice.rs:33:19
53+
|
54+
LL | const _: () = FN_PTR((1, 2));
55+
| ^^^^^^^^^^^^^^
56+
57+
error: internal compiler error: compiler/rustc_mir_build/src/thir/cx/expr.rs:1314:13: no splatted def for function or method callee
58+
--> $DIR/splat-fn-ptr-tuple-const-ice.rs:39:19
59+
|
60+
LL | const _: () = (*FN_PTR_PTR)(1, 2);
61+
| ^^^^^^^^^^^^^^^^^^^
62+
63+
64+
65+
Box<dyn Any>
66+
stack backtrace:
67+
68+
note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md
69+
70+
note: please make sure that you have updated to the latest nightly
71+
72+
note: rustc {version} running on {platform}
73+
74+
query stack during panic:
75+
#0 [thir_body] building THIR for `main::_`
76+
#1 [check_match] match-checking `main::_`
77+
#2 [mir_built] building MIR for `main::_`
78+
#3 [trivial_const] checking if `main::_` is a trivial const
79+
#4 [eval_to_const_value_raw] simplifying constant for the type system `main::_`
80+
#5 [analysis] running analysis passes on crate `splat_fn_ptr_tuple_const_ice`
81+
end of query stack
82+
error: internal compiler error: compiler/rustc_mir_build/src/thir/cx/expr.rs:1314:13: no splatted def for function or method callee
83+
--> $DIR/splat-fn-ptr-tuple-const-ice.rs:40:19
84+
|
85+
LL | const _: () = (*FN_PTR_PTR)(1u32, 2i8);
86+
| ^^^^^^^^^^^^^^^^^^^^^^^^
87+
88+
89+
90+
Box<dyn Any>
91+
stack backtrace:
92+
93+
note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md
94+
95+
note: please make sure that you have updated to the latest nightly
96+
97+
note: rustc {version} running on {platform}
98+
99+
query stack during panic:
100+
#0 [thir_body] building THIR for `main::_`
101+
#1 [check_match] match-checking `main::_`
102+
#2 [mir_built] building MIR for `main::_`
103+
#3 [trivial_const] checking if `main::_` is a trivial const
104+
#4 [eval_to_const_value_raw] simplifying constant for the type system `main::_`
105+
#5 [analysis] running analysis passes on crate `splat_fn_ptr_tuple_const_ice`
106+
end of query stack
107+
error: aborting due to 5 previous errors
108+
109+
For more information about this error, try `rustc --explain E0057`.
Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
//@ normalize-stderr: ".*omitted \d{1,} frames?.*\n" -> ""
99
//@ normalize-stderr: ".*note: Some details are omitted.*\n" -> ""
1010

11-
//! Test using `#[splat]` on tuple arguments of simple functions.
11+
//! Test using `#[splat]` on tuple arguments of simple function pointers.
1212
//! Currently ICEs, but if we fix it, we'll want to know and update this test to pass.
1313
1414
#![allow(incomplete_features)]
@@ -18,10 +18,13 @@ fn tuple_args(#[splat] (_a, _b): (u32, i8)) {}
1818

1919
fn splat_non_terminal_arg(#[splat] (_a, _b): (u32, i8), _c: f64) {}
2020

21+
const fn tuple_args_const(#[splat] (_a, _b): (u32, i8)) {}
22+
2123
fn main() {
2224
// FIXME(splat): not currently supported, can be supported when we no longer require a DefId in
2325
// MIR lowering
2426
// FIXME(rustfmt): the attribute gets deleted by rustfmt
27+
2528
// Functions
2629
#[rustfmt::skip]
2730
let fn_ptr: fn(#[splat] (u32, i8)) = tuple_args;
@@ -37,6 +40,16 @@ fn main() {
3740
fn_ptr(1, 2, 3.5);
3841
fn_ptr(1u32, 2i8, 3.5f64);
3942

43+
#[rustfmt::skip]
44+
let fn_ptr: fn(#[splat] (u32, i8)) = tuple_args_const;
45+
fn_ptr(1, 2);
46+
fn_ptr(1u32, 2i8);
47+
48+
#[rustfmt::skip]
49+
const FN_PTR: fn(#[splat] (u32, i8)) = tuple_args_const;
50+
FN_PTR(1, 2);
51+
FN_PTR(1u32, 2i8);
52+
4053
// Function pointers
4154
#[rustfmt::skip]
4255
let fn_ptr: *const fn(#[splat] (u32, i8)) = tuple_args as *const fn(#[splat] (u32, i8));
@@ -48,4 +61,10 @@ fn main() {
4861
splat_non_terminal_arg as *const fn(#[splat] (u32, i8), f64);
4962
(*fn_ptr)(1, 2, 3.5);
5063
(*fn_ptr)(1u32, 2i8, 3.5f64);
64+
65+
#[rustfmt::skip]
66+
const FN_PTR_PTR: *const fn(#[splat] (u32, i8)) =
67+
tuple_args_const as *const fn(#[splat] (u32, i8));
68+
(*FN_PTR_PTR)(1, 2);
69+
(*FN_PTR_PTR)(1u32, 2i8);
5170
}

tests/ui/splat/splat-fn-ptr-tuple.stderr renamed to tests/ui/splat/splat-fn-ptr-tuple-ice.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: internal compiler error: compiler/rustc_mir_build/src/thir/cx/expr.rs:1314:13: no splatted def for function or method callee
2-
--> $DIR/splat-fn-ptr-tuple.rs:28:5
2+
--> $DIR/splat-fn-ptr-tuple-ice.rs:31:5
33
|
44
LL | fn_ptr(1, 2);
55
| ^^^^^^^^^^^^
@@ -18,7 +18,7 @@ note: rustc {version} running on {platform}
1818
query stack during panic:
1919
#0 [thir_body] building THIR for `main`
2020
#1 [check_unsafety] unsafety-checking `main`
21-
#2 [analysis] running analysis passes on crate `splat_fn_ptr_tuple`
21+
#2 [analysis] running analysis passes on crate `splat_fn_ptr_tuple_ice`
2222
end of query stack
2323
error: aborting due to 1 previous error
2424

tests/ui/splat/splat-fn-tuple-simple.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ fn tuple_args(#[splat] (_a, _b): (u32, i8)) {}
88

99
fn splat_non_terminal_arg(#[splat] (_a, _b): (u32, i8), _c: f64) {}
1010

11+
const fn tuple_args_const(#[splat] (_a, _b): (u32, i8)) {}
12+
1113
fn main() {
1214
tuple_args(1, 2);
1315
// FIXME(splat): should splatted functions be callable with tupled and un-tupled arguments?
@@ -20,6 +22,9 @@ fn main() {
2022
splat_non_terminal_arg(1, 2, 3.5);
2123
splat_non_terminal_arg(1u32, 2i8, 3.5f64);
2224

25+
tuple_args_const(1, 2);
26+
tuple_args_const(1u32, 2i8);
27+
2328
#[expect(unused_variables, reason = "FIXME(splat or lint): this is obviously used")]
2429
let fn_ptr = tuple_args;
2530
fn_ptr(1, 2);
@@ -29,4 +34,12 @@ fn main() {
2934
let fn_ptr = splat_non_terminal_arg;
3035
fn_ptr(1, 2, 3.5);
3136
fn_ptr(1u32, 2i8, 3.5f64);
37+
38+
#[expect(unused_variables, reason = "FIXME(splat or lint): this is obviously used")]
39+
let fn_ptr = tuple_args_const;
40+
fn_ptr(1, 2);
41+
fn_ptr(1u32, 2i8);
42+
43+
const _: () = tuple_args_const(1, 2);
44+
const _: () = tuple_args_const(1u32, 2i8);
3245
}

0 commit comments

Comments
 (0)