Open cushionbadak opened 2 weeks ago
The error that we're trying to print out is
error[E0308]: mismatched types
--> poc.rs:7:33
|
7 | let _: ConstBytes<b"AAA"> = ConstBytes::<b"BBB">;
| ------------------ ^^^^^^^^^^^^^^^^^^^^ expected `&[{0x41 as *mut u8}, {0x41 as *mut u8}, {0x41 as *mut u8}]`, found `&[{0x42 as *mut u8}, {0x42 as *mut u8}, {0x42 as *mut u8}]`
| |
| expected due to this
|
= note: expected struct `ConstBytes<&[{0x41 as *mut u8}, {0x41 as *mut u8}, {0x41 as *mut u8}]>`
found struct `ConstBytes<&[{0x42 as *mut u8}, {0x42 as *mut u8}, {0x42 as *mut u8}]>`
The size mismatch happens because each integer is a constant of size 1 byte, but as the expected type is a pointer, the pretty printer hits https://github.com/rust-lang/rust/blob/7608018cbdac9e55d0d13529cf43adc33d53efcf/compiler/rustc_middle/src/ty/print/pretty.rs#L1745-L1747
Code
(manually reduced)
Original Code
```Rust //@ revisions: full min #![cfg_attr(full, feature(adt_const_params))] #![cfg_attr(full, allow(incomplete_features))] struct ConstString;
//[min]~^ ERROR
struct ConstBytes() / mem::size_of::<*mut u8>()]>;
//[min]~^ ERROR
pub fn main() {
let _: ConstString<"Hello"> = ConstString::<"Hello">;
let _: ConstString<"Hello"> = None::>; //~ ERROR mismatched types
let _: ConstString<"āćā¦"> = ConstString::<"āćā¦">;
let _: ConstString<"āćā¦"> = ConstString::<"āćā„">; //~ ERROR mismatched types
let _: ConstBytes = ConstBytes::<{&[0x41, 0x41, 0x41]}>;
let _: ConstBytes = ConstBytes::; //~ ERROR mismatched types
}
// from tests/ui/const-generics/slice-const-param-mismatch.rs
```
Meta
rustc --version --verbose
:Error output
Command:
rustc
Backtrace
``` thread 'rustc' panicked at compiler/rustc_middle/src/ty/consts/int.rs:263:13: Box
stack backtrace:
0: std::panicking::begin_panic::
1: ::emit_producing_guarantee
2: rustc_middle::util::bug::opt_span_bug_fmt::::{closure#0}
3: rustc_middle::ty::context::tls::with_opt::::{closure#0}, !>::{closure#0}
4: rustc_middle::ty::context::tls::with_context_opt::::{closure#0}, !>::{closure#0}, !>
5: rustc_middle::util::bug::bug_fmt
6: ::pretty_print_const_scalar_int
7: ::pretty_print_const_valtree
8: ::pretty_print_const
9: ::pretty_print_const_valtree
10: ::pretty_print_const_valtree
11: ::pretty_print_const
12: ::fmt
13: ::cmp
14: ::values_str
15: ::note_type_err
16: ::report_and_explain_type_error
17: ::demand_coerce_diag
18: ::check_decl
19: ::check_block_with_expected
20: ::check_expr_with_expectation_and_args
21: ::check_return_expr
22: rustc_hir_typeck::check::check_fn
23: rustc_hir_typeck::typeck
[... omitted 1 frame ...]
24: ::par_body_owners::::{closure#0}
25: rustc_hir_analysis::check_crate
26: rustc_interface::passes::run_required_analyses
27: rustc_interface::passes::analysis
[... omitted 1 frame ...]
28: >::enter::, rustc_driver_impl::run_compiler::{closure#0}::{closure#1}::{closure#5}>
29: rustc_interface::interface::run_compiler::, rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
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
note: please make sure that you have updated to the latest nightly
note: please attach the file at `/Volumes/T7/workspace/blackbox icemaker ź²°ź³¼/240926_240401_blackbox_result/rustc-ice-2024-09-30T08_07_24-63216.txt` to your bug report
query stack during panic:
#0 [typeck] type-checking `main`
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0741`.
```
Note
compiler/rustc_middle/src/ty/consts/int.rs Line-263
https://github.com/rust-lang/rust/blob/7608018cbdac9e55d0d13529cf43adc33d53efcf/compiler/rustc_middle/src/ty/consts/int.rs#L261-L265126359 has identical ICE location.
nightly-2024-02-15
@rustbot label +F-adt_const_params