Open cushionbadak opened 1 month ago
Regression in https://github.com/rust-lang-ci/rust/commit/d48eec570e52dd40d56dfe2ace23860a2f4d1bcc The PR introducing the regression in this rollup is #123367: Safe Transmute: Compute transmutability from `rustc_target:…
searched nightlies: from nightly-2023-01-01 to nightly-2024-05-30 regressed nightly: nightly-2024-04-09 searched commit range: https://github.com/rust-lang/rust/compare/9d5cdf75aa42faaf0b58ba21a510117e8d0051a3...ab5bda1aa70f707014e2e691e43bc37a8819252a regressed commit: https://github.com/rust-lang/rust/commit/ab5bda1aa70f707014e2e691e43bc37a8819252a
Code
(hand-reduced)
(original)
```Rust //@ compile-flags: -C opt-level=0 #![crate_type = "lib"] pub enum ApiError {} #[allow(dead_code)] pub struct TokioError { b: bool, } pub enum Error { Api { source: ApiError }, Ethereum, Tokio { source: TokioError }, } struct Api; impl IntoError for Api {
type Source = ApiError;
// CHECK-LABEL: @into_error
// CHECK: llvm.trap()
// Also check the next two instructions to make sure we do not match against `trap`
// elsewhere in the code.
// CHECK-NEXT: load
// CHECK-NEXT: ret
#[no_mangle]
fn into_error(self, error: Self::) -> Error {
Error::Api { source: error }
}
}
pub trait IntoError {
/// The underlying error
type Source;
/// Combine the information to produce the error
fn into_error(self, source: Self::Source) -> E;
}
//@ check-pass
//! The presence of safety invariants in the source type does not affect
//! transmutability.
#![crate_type = "lib"]
#![feature(transmutability)]
#![allow(dead_code)]
mod assert {
use std::mem::BikeshedIntrinsicFrom;
pub fn is_transmutable()
where
Dst: BikeshedIntrinsicFrom // safety is NOT assumed
{}
}
fn test() {
#[repr(C)]
struct Src;
type Dst = Error;
assert::is_transmutable::();
}
```
Meta
rustc --version --verbose
:Error output
Command:
rustc
Backtrace
``` thread 'rustc' panicked at compiler/rustc_const_eval/src/interpret/discriminant.rs:288:22: overflow computing relative variant idx stack backtrace: 0: _rust_begin_unwind 1: core::panicking::panic_fmt 2: core::option::expect_failed 3: rustc_const_eval::const_eval::tag_for_variant_provider [... omitted 2 frames ...] 4:>::from_enum
5: ::is_transmutable
6: ::confirm_candidate
7: ::evaluate_candidate::{closure#0}::{closure#0}
8: ::probe::, ::evaluation_probe<::evaluate_candidate::{closure#0}::{closure#0}>::{closure#0}>
9: ::evaluate_trait_predicate_recursively::{closure#0}::{closure#1}
10: ::evaluate_trait_predicate_recursively::{closure#0}
11: ::evaluate_predicate_recursively::{closure#0}::{closure#0}
12: ::evaluate_root_obligation::{closure#0}
13: ::evaluate_root_obligation
14: rustc_traits::evaluate_obligation::evaluate_obligation
[... omitted 2 frames ...]
15: ::evaluate_obligation
16: ::evaluate_obligation_no_overflow
17: ::process_trait_obligation
18: ::process_obligation
19: >::process_obligations::
20: as rustc_infer::traits::engine::TraitEngine>::select_where_possible
21: ::check_argument_types
22: ::confirm_builtin_call
23: ::check_expr_kind
24: ::check_expr_with_expectation_and_args
25: ::check_block_with_expected
26: ::check_expr_with_expectation_and_args
27: ::check_return_expr
28: rustc_hir_typeck::check::check_fn
29: rustc_hir_typeck::typeck
[... omitted 1 frame ...]
30: ::par_body_owners::::{closure#0}
31: rustc_hir_analysis::check_crate
32: rustc_interface::passes::run_required_analyses
33: rustc_interface::passes::analysis
[... omitted 1 frame ...]
34: >::enter::, rustc_driver_impl::run_compiler::{closure#0}::{closure#1}::{closure#3}>
35: 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.
error: the compiler unexpectedly panicked. this is a bug.
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/240607_100chaos_tree_combine_typ/icefiles/rustc-ice-2024-06-11T10_43_12-38775.txt` to your bug report
query stack during panic:
#0 [tag_for_variant] computing variant tag for enum
#1 [evaluate_obligation] evaluating trait selection obligation `Error: core::mem::transmutability::BikeshedIntrinsicFrom`
#2 [typeck] type-checking `test`
#3 [analysis] running analysis passes on this crate
end of query stack
```
Notes
compiler/rustc_const_eval/src/interpret/discriminant.rs L288
https://github.com/rust-lang/rust/blob/b5b13568fb5da4ac988bde370008d6134d3dfe6c/compiler/rustc_const_eval/src/interpret/discriminant.rs#L276-L288Ethereum
orTokio
removed from enum definition in the reduced ICE triggering code (Line 10, 11), #125811 will be triggered.compiler/rustc_const_eval/src/interpret/discriminant.rs L245
) https://github.com/rust-lang/rust/blob/b5b13568fb5da4ac988bde370008d6134d3dfe6c/compiler/rustc_const_eval/src/interpret/discriminant.rs#L243-L247@rustbot label +F-transmutability