rust-lang / rust

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

ICE: unexpected non-type Node::GenericParam #129205

Closed matthiaskrgr closed 2 months ago

matthiaskrgr commented 2 months ago

auto-reduced (treereduce-rust):

fn test_generic<T: Copy>(val: T) -> T {
    let _ = T::try_from(val).unwrap();
}
original code

original: ````rust #![deny(clippy::useless_conversion)] #![allow( clippy::needless_if, clippy::unnecessary_fallible_conversions, clippy::manual_unwrap_or_default )] fn test_generic(val: T) -> T { let _ = T::try_from(val).unwrap(); //~^ ERROR: useless conversion to the same type: `T` val.try_into().unwrap() //~^ ERROR: useless conversion to the same type: `T` } fn test_generic2 + Into, U: From>(val: T) { // ok let _: i32 = val.try_into().unwrap(); let _: U = val.try_into().unwrap(); let _ = U::try_from(val).unwrap(); } fn main() { test_generic(10i32); test_generic2::(10i32); let _: String = "foo".try_into().unwrap(); let _: String = TryFrom::try_from("foo").unwrap(); let _ = String::try_from("foo").unwrap(); #[allow(clippy::useless_conversion)] { let _ = String::try_from("foo").unwrap(); let _: String = "foo".try_into().unwrap(); } let _: String = "foo".to_string().try_into().unwrap(); //~^ ERROR: useless conversion to the same type: `std::string::String` let _: String = TryFrom::try_from("foo".to_string()).unwrap(); //~^ ERROR: useless conversion to the same type: `std::string::String` let _ = String::try_from("foo".to_string()).unwrap(); //~^ ERROR: useless conversion to the same type: `std::string::String` let _ = String::try_from(format!("A: {:04}", 123)).unwrap(); //~^ ERROR: useless conversion to the same type: `std::string::String` let _: String = format!("Hello {}", "world").try_into().unwrap(); //~^ ERROR: useless conversion to the same type: `std::string::String` let _: String = String::new().try_into().unwrap(); //~^ ERROR: useless conversion to the same type: `std::string::String` let _: String = match String::from("_").try_into() { //~^ ERROR: useless conversion to the same type: `std::string::String` Ok(a) => a, Err(_) => String::new(), }; // FIXME this is a false negative #[allow(clippy::cmp_owned)] if String::from("a") == TryInto::::try_into(String::from("a")).unwrap() {} } ````

Version information

rustc 1.82.0-nightly (9b318d2e9 2024-08-17)
binary: rustc
commit-hash: 9b318d2e93ce35e7ba32d8cfa96a1dbe63a7bed1
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

Program output

``` error[E0601]: `main` function not found in crate `mvce` --> /tmp/icemaker_global_tempdir.sXqwjI7Mv8KU/rustc_testrunner_tmpdir_reporting.B11rGugxJB7Z/mvce.rs:3:2 | 3 | } | ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.sXqwjI7Mv8KU/rustc_testrunner_tmpdir_reporting.B11rGugxJB7Z/mvce.rs` error: internal compiler error: compiler/rustc_hir_analysis/src/collect/type_of.rs:582:18: unexpected non-type Node::GenericParam: Type { default: None, synthetic: false } thread 'rustc' panicked at compiler/rustc_hir_analysis/src/collect/type_of.rs:582:18: Box stack backtrace: 0: 0x73887d5b28dd - ::fmt::hbc01d7b608be4cd7 1: 0x73887de05157 - core::fmt::write::hb357ae00ad9c5259 2: 0x73887edbda51 - std::io::Write::write_fmt::h13a24ddc9a1fdb00 3: 0x73887d5b4fbb - std::panicking::default_hook::{{closure}}::he90538c5db987e04 4: 0x73887d5b4c2e - std::panicking::default_hook::ha1a531e9b99fa317 5: 0x73887c747ba9 - std[6cb574a7e0954fac]::panicking::update_hook::>::{closure#0} 6: 0x73887d5b58d7 - std::panicking::rust_panic_with_hook::h13cac42622f97635 7: 0x73887c781f11 - std[6cb574a7e0954fac]::panicking::begin_panic::::{closure#0} 8: 0x73887c774f56 - std[6cb574a7e0954fac]::sys::backtrace::__rust_end_short_backtrace::::{closure#0}, !> 9: 0x73887c770336 - std[6cb574a7e0954fac]::panicking::begin_panic:: 10: 0x73887c78aef1 - ::emit_producing_guarantee 11: 0x73887cd4e994 - rustc_middle[c3682ad5e92f3c6c]::util::bug::opt_span_bug_fmt::::{closure#0} 12: 0x73887cd345aa - rustc_middle[c3682ad5e92f3c6c]::ty::context::tls::with_opt::::{closure#0}, !>::{closure#0} 13: 0x73887cd3445b - rustc_middle[c3682ad5e92f3c6c]::ty::context::tls::with_context_opt::::{closure#0}, !>::{closure#0}, !> 14: 0x73887a823c10 - rustc_middle[c3682ad5e92f3c6c]::util::bug::bug_fmt 15: 0x73887b2a73e4 - rustc_hir_analysis[25b7da8f6fe9ad06]::collect::type_of::type_of 16: 0x73887de37530 - rustc_query_impl[f86d883d92ecf329]::plumbing::__rust_begin_short_backtrace::> 17: 0x73887de361e7 - rustc_query_system[bd3380b77d0fd58]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[f86d883d92ecf329]::plumbing::QueryCtxt, false> 18: 0x73887de35da7 - rustc_query_impl[f86d883d92ecf329]::query_impl::type_of::get_query_non_incr::__rust_end_short_backtrace 19: 0x73887e2cab11 - rustc_middle[c3682ad5e92f3c6c]::query::plumbing::query_get_at::>> 20: 0x73887ca8d083 - ::suggest_traits_to_import 21: 0x73887ca7a19a - ::report_no_match_method_error 22: 0x73887caae2ba - ::report_method_error 23: 0x73887e848e90 - ::check_expr_path 24: 0x73887e7db898 - ::check_expr_with_expectation_and_args 25: 0x73887e7dcfcd - ::check_expr_with_expectation_and_args 26: 0x73887e7ddaea - ::check_expr_with_expectation_and_args 27: 0x73887e7da304 - ::check_decl 28: 0x73887e7d7581 - ::check_block_with_expected 29: 0x73887e7dda88 - ::check_expr_with_expectation_and_args 30: 0x73887e03a521 - rustc_hir_typeck[12bf866448a1086e]::check::check_fn 31: 0x73887e16b41f - rustc_hir_typeck[12bf866448a1086e]::typeck 32: 0x73887e16ae73 - rustc_query_impl[f86d883d92ecf329]::plumbing::__rust_begin_short_backtrace::> 33: 0x73887e0cb039 - rustc_query_system[bd3380b77d0fd58]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[f86d883d92ecf329]::plumbing::QueryCtxt, false> 34: 0x73887e0ca255 - rustc_query_impl[f86d883d92ecf329]::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace 35: 0x73887e0c9edb - ::par_body_owners::::{closure#0} 36: 0x73887e0c7c24 - rustc_hir_analysis[25b7da8f6fe9ad06]::check_crate 37: 0x73887e9279ff - rustc_interface[63d22841a2327cf2]::passes::run_required_analyses 38: 0x73887e95dc9e - rustc_interface[63d22841a2327cf2]::passes::analysis 39: 0x73887e95dc71 - rustc_query_impl[f86d883d92ecf329]::plumbing::__rust_begin_short_backtrace::> 40: 0x73887ed873ae - rustc_query_system[bd3380b77d0fd58]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[f86d883d92ecf329]::plumbing::QueryCtxt, false> 41: 0x73887ed8710f - rustc_query_impl[f86d883d92ecf329]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace 42: 0x73887ebfa56a - rustc_interface[63d22841a2327cf2]::interface::run_compiler::, rustc_driver_impl[8771d5e726c45cf8]::run_compiler::{closure#0}>::{closure#1} 43: 0x73887eb13690 - std[6cb574a7e0954fac]::sys::backtrace::__rust_begin_short_backtrace::, rustc_driver_impl[8771d5e726c45cf8]::run_compiler::{closure#0}>::{closure#1}, core[7c75989f65d16f38]::result::Result<(), rustc_span[5d62fad87722a712]::ErrorGuaranteed>>::{closure#0}, core[7c75989f65d16f38]::result::Result<(), rustc_span[5d62fad87722a712]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[7c75989f65d16f38]::result::Result<(), rustc_span[5d62fad87722a712]::ErrorGuaranteed>> 44: 0x73887eb13cfa - <::spawn_unchecked_, rustc_driver_impl[8771d5e726c45cf8]::run_compiler::{closure#0}>::{closure#1}, core[7c75989f65d16f38]::result::Result<(), rustc_span[5d62fad87722a712]::ErrorGuaranteed>>::{closure#0}, core[7c75989f65d16f38]::result::Result<(), rustc_span[5d62fad87722a712]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[7c75989f65d16f38]::result::Result<(), rustc_span[5d62fad87722a712]::ErrorGuaranteed>>::{closure#1} as core[7c75989f65d16f38]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} 45: 0x73887eb1406b - std::sys::pal::unix::thread::Thread::new::thread_start::h683ced0bc52e6b8c 46: 0x73888028c39d - 47: 0x73888031149c - 48: 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 (9b318d2e9 2024-08-17) running on x86_64-unknown-linux-gnu query stack during panic: #0 [type_of] computing type of `test_generic::T` #1 [typeck] type-checking `test_generic` end of query stack error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0601`. ```

matthiaskrgr commented 2 months ago

mvce:

fn x<T: Copy>() {
    T::try_from();
}
matthiaskrgr commented 2 months ago

128786 :thinking: cc @estebank

estebank commented 2 months ago