rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
97.29k stars 12.58k forks source link

ICE: `Encountered error SignatureMismatch` #129214

Open matthiaskrgr opened 1 month ago

matthiaskrgr commented 1 month ago

auto-reduced (treereduce-rust):

//@ run-pass

trait to_str {}

trait map<T> {
    fn map<U, F>(&self, f: F) -> Vec<U>
    where
        F: FnMut(&Box<usize>) -> U;
}
impl<T> map<T> for Vec<T> {
    fn map<U, F>(&self, mut f: F) -> Vec<U>
    where
        F: FnMut(&T) -> U,
    {
        let mut r = Vec::new();
        for i in self {
            r.push(f(i));
        }
        r
    }
}

fn foo<U, T: map<U>>(x: T) -> Vec<String> {
    x.map(|_e| "hi".to_string())
}

pub fn main() {
    assert_eq!(foo(vec![1]), ["hi".to_string()]);
}
original code

original: ````rust //@ run-pass #![repr(align=8)] trait to_str { fn to_string_(&self) -> String; } impl to_str for isize { fn to_string_(&self) -> String { self.to_string() } } impl to_str for String { fn to_string_(&self) -> String { self.clone() } } impl to_str for () { fn to_string_(&self) -> String { "()".to_string() } } trait map { fn map(&self, f: F) -> Vec where F: FnMut(&Box) -> U; } impl map for Vec { fn map(&self, mut f: F) -> Vec where F: FnMut(&T) -> U { let mut r = Vec::new(); for i in self { r.push(f(i)); } r } } fn foo>(x: T) -> Vec { x.map(|_e| "hi".to_string() ) } fn bar>(x: T) -> Vec { x.map(|_e| _e.to_string_() ) } pub fn main() { assert_eq!(foo(vec![1]), ["hi".to_string()]); assert_eq!(bar:: >(vec![4, 5]), ["4".to_string(), "5".to_string()]); assert_eq!(bar:: >(vec!["x".to_string(), "y".to_string()]), ["x".to_string(), "y".to_string()]); assert_eq!(bar::<(), Vec<()>>(vec![()]), ["()".to_string()]); } ````

Version information

rustc 1.82.0-nightly (0f26ee4fd 2024-08-17)
binary: rustc
commit-hash: 0f26ee4fd95a1c046582dfb18892f520788e2c2c
commit-date: 2024-08-17
host: x86_64-unknown-linux-gnu
release: 1.82.0-nightly
LLVM version: 19.1.0

Command: /home/matthias/.rustup/toolchains/master/bin/rustc -Zvalidate-mir -Copt-level=3 --crate-type=lib

Program output

``` warning: trait `to_str` should have an upper camel case name --> /tmp/icemaker_global_tempdir.CTvLxe24vLkE/rustc_testrunner_tmpdir_reporting.sonlNjO1Rab2/mvce.rs:3:7 | 3 | trait to_str {} | ^^^^^^ help: convert the identifier to upper camel case: `ToStr` | = note: `#[warn(non_camel_case_types)]` on by default warning: trait `map` should have an upper camel case name --> /tmp/icemaker_global_tempdir.CTvLxe24vLkE/rustc_testrunner_tmpdir_reporting.sonlNjO1Rab2/mvce.rs:5:7 | 5 | trait map { | ^^^ help: convert the identifier to upper camel case: `Map` error[E0276]: impl has stricter requirements than trait --> /tmp/icemaker_global_tempdir.CTvLxe24vLkE/rustc_testrunner_tmpdir_reporting.sonlNjO1Rab2/mvce.rs:13:12 | 6 | / fn map(&self, f: F) -> Vec 7 | | where 8 | | F: FnMut(&Box) -> U; | |___________________________________- definition of `map` from trait ... 13 | F: FnMut(&T) -> U, | ^^^^^^^^^^^^^^ impl has extra requirement `for<'a> F: FnMut(&'a T)` error[E0276]: impl has stricter requirements than trait --> /tmp/icemaker_global_tempdir.CTvLxe24vLkE/rustc_testrunner_tmpdir_reporting.sonlNjO1Rab2/mvce.rs:13:25 | 6 | / fn map(&self, f: F) -> Vec 7 | | where 8 | | F: FnMut(&Box) -> U; | |___________________________________- definition of `map` from trait ... 13 | F: FnMut(&T) -> U, | ^ impl has extra requirement `for<'a> F: FnOnce(&'a T)` error: internal compiler error: compiler/rustc_traits/src/codegen.rs:44:13: Encountered error `SignatureMismatch(SignatureMismatchData { found_trait_ref: <{closure@/tmp/icemaker_global_tempdir.CTvLxe24vLkE/rustc_testrunner_tmpdir_reporting.sonlNjO1Rab2/mvce.rs:24:11: 24:15} as std::ops::FnMut<(&std::boxed::Box,)>>, expected_trait_ref: <{closure@/tmp/icemaker_global_tempdir.CTvLxe24vLkE/rustc_testrunner_tmpdir_reporting.sonlNjO1Rab2/mvce.rs:24:11: 24:15} as std::ops::FnMut<(&i32,)>>, terr: Sorts(ExpectedFound { expected: i32, found: std::boxed::Box }) })` selecting `<{closure@/tmp/icemaker_global_tempdir.CTvLxe24vLkE/rustc_testrunner_tmpdir_reporting.sonlNjO1Rab2/mvce.rs:24:11: 24:15} as std::ops::FnMut<(&i32,)>>` during codegen thread 'rustc' panicked at compiler/rustc_traits/src/codegen.rs:44:13: Box stack backtrace: 0: 0x7d4a373c429d - ::fmt::hce35dec2bed7e8e1 1: 0x7d4a37c05297 - core::fmt::write::haaf8a728f3019c12 2: 0x7d4a38ebbd91 - std::io::Write::write_fmt::hb0dc5188703aea0d 3: 0x7d4a373c697b - std::panicking::default_hook::{{closure}}::h35c501ae74c82675 4: 0x7d4a373c65ee - std::panicking::default_hook::hc1ddd62643c4c855 5: 0x7d4a36558729 - std[54b021f941472252]::panicking::update_hook::>::{closure#0} 6: 0x7d4a373c7297 - std::panicking::rust_panic_with_hook::h7960ad04eaeb646d 7: 0x7d4a36593111 - std[54b021f941472252]::panicking::begin_panic::::{closure#0} 8: 0x7d4a36586156 - std[54b021f941472252]::sys::backtrace::__rust_end_short_backtrace::::{closure#0}, !> 9: 0x7d4a36581536 - std[54b021f941472252]::panicking::begin_panic:: 10: 0x7d4a3659c0f1 - ::emit_producing_guarantee 11: 0x7d4a36b5f6c4 - rustc_middle[10ec7aec7d9fdda3]::util::bug::opt_span_bug_fmt::::{closure#0} 12: 0x7d4a36b452da - rustc_middle[10ec7aec7d9fdda3]::ty::context::tls::with_opt::::{closure#0}, !>::{closure#0} 13: 0x7d4a36b4516b - rustc_middle[10ec7aec7d9fdda3]::ty::context::tls::with_context_opt::::{closure#0}, !>::{closure#0}, !> 14: 0x7d4a34650ac0 - rustc_middle[10ec7aec7d9fdda3]::util::bug::bug_fmt 15: 0x7d4a34628187 - rustc_traits[87fc0fd8b38a9555]::codegen::codegen_select_candidate 16: 0x7d4a381ef9f7 - rustc_query_impl[69287ea093d06d1d]::plumbing::__rust_begin_short_backtrace::> 17: 0x7d4a381efd23 - rustc_query_system[1449707d44461b06]::query::plumbing::try_execute_query::), rustc_middle[10ec7aec7d9fdda3]::query::erase::Erased<[u8; 16usize]>>, false, false, false>, rustc_query_impl[69287ea093d06d1d]::plumbing::QueryCtxt, false> 18: 0x7d4a381ef99d - rustc_query_impl[69287ea093d06d1d]::query_impl::codegen_select_candidate::get_query_non_incr::__rust_end_short_backtrace 19: 0x7d4a3514619c - rustc_ty_utils[6c9943a590e2da67]::instance::resolve_instance_raw 20: 0x7d4a383965e9 - rustc_query_impl[69287ea093d06d1d]::plumbing::__rust_begin_short_backtrace::> 21: 0x7d4a38396929 - rustc_query_system[1449707d44461b06]::query::plumbing::try_execute_query::)>, rustc_middle[10ec7aec7d9fdda3]::query::erase::Erased<[u8; 32usize]>>, false, false, false>, rustc_query_impl[69287ea093d06d1d]::plumbing::QueryCtxt, false> 22: 0x7d4a38396564 - rustc_query_impl[69287ea093d06d1d]::query_impl::resolve_instance_raw::get_query_non_incr::__rust_end_short_backtrace 23: 0x7d4a37c3b2d3 - ::try_resolve 24: 0x7d4a38ba52e9 - rustc_mir_transform[c8fa74b5a51f9a1a]::inline::cycle::mir_callgraph_reachable::process 25: 0x7d4a38ba5a30 - rustc_mir_transform[c8fa74b5a51f9a1a]::inline::cycle::mir_callgraph_reachable::process 26: 0x7d4a38ba4b14 - rustc_mir_transform[c8fa74b5a51f9a1a]::inline::cycle::mir_callgraph_reachable 27: 0x7d4a38ba49a9 - rustc_query_impl[69287ea093d06d1d]::plumbing::__rust_begin_short_backtrace::> 28: 0x7d4a38ba496b - >::call_once 29: 0x7d4a3838c719 - rustc_query_system[1449707d44461b06]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[69287ea093d06d1d]::plumbing::QueryCtxt, false> 30: 0x7d4a3838c44c - rustc_query_impl[69287ea093d06d1d]::query_impl::mir_callgraph_reachable::get_query_non_incr::__rust_end_short_backtrace 31: 0x7d4a385faf85 - ::try_inlining 32: 0x7d4a385f8820 - ::process_blocks 33: 0x7d4a385f7ce6 - ::run_pass 34: 0x7d4a37c02151 - rustc_mir_transform[c8fa74b5a51f9a1a]::pass_manager::run_passes_inner 35: 0x7d4a38605a37 - rustc_mir_transform[c8fa74b5a51f9a1a]::optimized_mir 36: 0x7d4a3862925d - rustc_query_impl[69287ea093d06d1d]::plumbing::__rust_begin_short_backtrace::> 37: 0x7d4a37c25ea7 - rustc_query_system[1449707d44461b06]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[69287ea093d06d1d]::plumbing::QueryCtxt, false> 38: 0x7d4a37c2545f - rustc_query_impl[69287ea093d06d1d]::query_impl::optimized_mir::get_query_non_incr::__rust_end_short_backtrace 39: 0x7d4a347845c4 - ::instance_mir 40: 0x7d4a38386406 - rustc_interface[f40e7651e6b02ea1]::passes::run_required_analyses 41: 0x7d4a3875c49e - rustc_interface[f40e7651e6b02ea1]::passes::analysis 42: 0x7d4a3875c471 - rustc_query_impl[69287ea093d06d1d]::plumbing::__rust_begin_short_backtrace::> 43: 0x7d4a38b867ee - rustc_query_system[1449707d44461b06]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[69287ea093d06d1d]::plumbing::QueryCtxt, false> 44: 0x7d4a38b8654f - rustc_query_impl[69287ea093d06d1d]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace 45: 0x7d4a389d38ea - rustc_interface[f40e7651e6b02ea1]::interface::run_compiler::, rustc_driver_impl[ec4d44b725e7aa11]::run_compiler::{closure#0}>::{closure#1} 46: 0x7d4a389b3210 - std[54b021f941472252]::sys::backtrace::__rust_begin_short_backtrace::, rustc_driver_impl[ec4d44b725e7aa11]::run_compiler::{closure#0}>::{closure#1}, core[5070cb7ec77c977]::result::Result<(), rustc_span[a5a4c6b08f7cf6f]::ErrorGuaranteed>>::{closure#0}, core[5070cb7ec77c977]::result::Result<(), rustc_span[a5a4c6b08f7cf6f]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[5070cb7ec77c977]::result::Result<(), rustc_span[a5a4c6b08f7cf6f]::ErrorGuaranteed>> 47: 0x7d4a389b387a - <::spawn_unchecked_, rustc_driver_impl[ec4d44b725e7aa11]::run_compiler::{closure#0}>::{closure#1}, core[5070cb7ec77c977]::result::Result<(), rustc_span[a5a4c6b08f7cf6f]::ErrorGuaranteed>>::{closure#0}, core[5070cb7ec77c977]::result::Result<(), rustc_span[a5a4c6b08f7cf6f]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[5070cb7ec77c977]::result::Result<(), rustc_span[a5a4c6b08f7cf6f]::ErrorGuaranteed>>::{closure#1} as core[5070cb7ec77c977]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} 48: 0x7d4a389b3beb - std::sys::pal::unix::thread::Thread::new::thread_start::he8fde62ed04f9a93 49: 0x7d4a3a11039d - 50: 0x7d4a3a19549c - 51: 0x0 - 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: rustc 1.82.0-nightly (0f26ee4fd 2024-08-17) running on x86_64-unknown-linux-gnu note: compiler flags: -Z validate-mir -C opt-level=3 --crate-type lib -Z dump-mir-dir=dir query stack during panic: #0 [codegen_select_candidate] computing candidate for `<{closure@/tmp/icemaker_global_tempdir.CTvLxe24vLkE/rustc_testrunner_tmpdir_reporting.sonlNjO1Rab2/mvce.rs:24:11: 24:15} as core::ops::function::FnMut<(&i32,)>>` #1 [resolve_instance_raw] resolving instance `<{closure@/tmp/icemaker_global_tempdir.CTvLxe24vLkE/rustc_testrunner_tmpdir_reporting.sonlNjO1Rab2/mvce.rs:24:11: 24:15} as core::ops::function::FnMut<(&i32,)>>::call_mut` end of query stack error: aborting due to 3 previous errors; 2 warnings emitted For more information about this error, try `rustc --explain E0276`. ```

cushionbadak commented 3 weeks ago

I found a really weird situation with this example. IT DOES NOT ICE if you save the reduced-code example file name as 129214_modified_1.rs and compile it with

rustc -Zvalidate-mir -Copt-level=3 --crate-type=lib 129214_modified_1.rs

However, it'll ICE when the file name is 129214.rs or 129214_modified_.rs.

I rechecked this with three different machines, one WSL-environment and two MacOS environment.

Meta

rustc --version --verbose:

rustc 1.83.0-nightly (0ee7cb5e3 2024-09-10)
binary: rustc
commit-hash: 0ee7cb5e3633502d9a90a85c3c367eccd59a0aba
commit-date: 2024-09-10
host: x86_64-apple-darwin
release: 1.83.0-nightly
LLVM version: 19.1.0

(be sure to use 2024-09-10 version to reproduce)

Error output

Output

``` warning: trait `to_str` should have an upper camel case name --> 129214_modified_1.rs:3:7 | 3 | trait to_str {} | ^^^^^^ help: convert the identifier to upper camel case: `ToStr` | = note: `#[warn(non_camel_case_types)]` on by default warning: trait `map` should have an upper camel case name --> 129214_modified_1.rs:5:7 | 5 | trait map { | ^^^ help: convert the identifier to upper camel case: `Map` error[E0276]: impl has stricter requirements than trait --> 129214_modified_1.rs:13:12 | 6 | / fn map(&self, f: F) -> Vec 7 | | where 8 | | F: FnMut(&Box) -> U; | |___________________________________- definition of `map` from trait ... 13 | F: FnMut(&T) -> U, | ^^^^^^^^^^^^^^ impl has extra requirement `for<'a> F: FnMut(&'a T)` error[E0276]: impl has stricter requirements than trait --> 129214_modified_1.rs:13:25 | 6 | / fn map(&self, f: F) -> Vec 7 | | where 8 | | F: FnMut(&Box) -> U; | |___________________________________- definition of `map` from trait ... 13 | F: FnMut(&T) -> U, | ^ impl has extra requirement `for<'a> F: FnOnce(&'a T)` error: aborting due to 2 previous errors; 2 warnings emitted For more information about this error, try `rustc --explain E0276`. ```

Manishearth commented 2 weeks ago