Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implied_bounds_in_impl ice #11422

Closed
matthiaskrgr opened this issue Aug 29, 2023 · 2 comments · Fixed by #11437
Closed

implied_bounds_in_impl ice #11422

matthiaskrgr opened this issue Aug 29, 2023 · 2 comments · Fixed by #11437
Assignees
Labels
C-bug Category: Clippy is not doing the correct thing I-ICE Issue: Clippy panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@matthiaskrgr
Copy link
Member

matthiaskrgr commented Aug 29, 2023

Summary

since rust-lang/rust#115183 from rustc
./tests/ui/impl-trait/issues/issue-49376.rs

// check-pass

// Tests for nested self-reference which caused a stack overflow.

use std::fmt::Debug;
use std::ops::*;

fn gen() -> impl PartialOrd + PartialEq + Debug { }

struct Bar {}
trait Foo<T = Self> {}
trait FooNested<T = Option<Self>> {}
impl Foo for Bar {}
impl FooNested for Bar {}

fn foo() -> impl Foo + FooNested {
    Bar {}
}

fn test_impl_ops() -> impl Add + Sub + Mul + Div { 1 }
fn test_impl_assign_ops() -> impl AddAssign + SubAssign + MulAssign + DivAssign { 1 }

fn main() {}

Version

rustc 1.74.0-nightly (b2515fa74 2023-08-29)
binary: rustc
commit-hash: b2515fa741eea89b82a2c94048f934bbcbd3bd48
commit-date: 2023-08-29
host: x86_64-unknown-linux-gnu
release: 1.74.0-nightly
LLVM version: 17.0.0

Error output

Backtrace

warning: function `gen` is never used
--> ./tests/ui/impl-trait/issues/issue-49376.rs:8:4
|
8 | fn gen() -> impl PartialOrd + PartialEq + Debug { }
|    ^^^
|
= note: `#[warn(dead_code)]` on by default

warning: function `foo` is never used
--> ./tests/ui/impl-trait/issues/issue-49376.rs:16:4
 |
16 | fn foo() -> impl Foo + FooNested {
 |    ^^^

warning: function `test_impl_ops` is never used
--> ./tests/ui/impl-trait/issues/issue-49376.rs:20:4
 |
20 | fn test_impl_ops() -> impl Add + Sub + Mul + Div { 1 }
 |    ^^^^^^^^^^^^^

warning: function `test_impl_assign_ops` is never used
--> ./tests/ui/impl-trait/issues/issue-49376.rs:21:4
 |
21 | fn test_impl_assign_ops() -> impl AddAssign + SubAssign + MulAssign + DivAssign { 1 }
 |    ^^^^^^^^^^^^^^^^^^^^

thread 'rustc' panicked at src/tools/clippy/clippy_lints/src/implied_bounds_in_impls.rs:90:49:
index out of bounds: the len is 0 but the index is 0
stack backtrace:
 0:     0x7f239236316c - std::backtrace_rs::backtrace::libunwind::trace::h436c8e524cde9e19
                             at /rustc/b2515fa741eea89b82a2c94048f934bbcbd3bd48/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
 1:     0x7f239236316c - std::backtrace_rs::backtrace::trace_unsynchronized::h23af15dda014f863
                             at /rustc/b2515fa741eea89b82a2c94048f934bbcbd3bd48/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
 2:     0x7f239236316c - std::sys_common::backtrace::_print_fmt::h366b8b1240af736d
                             at /rustc/b2515fa741eea89b82a2c94048f934bbcbd3bd48/library/std/src/sys_common/backtrace.rs:67:5
 3:     0x7f239236316c - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h4c76a6c9a9d27949
                             at /rustc/b2515fa741eea89b82a2c94048f934bbcbd3bd48/library/std/src/sys_common/backtrace.rs:44:22
 4:     0x7f23923c941c - core::fmt::rt::Argument::fmt::hdcec6912fddde237
                             at /rustc/b2515fa741eea89b82a2c94048f934bbcbd3bd48/library/core/src/fmt/rt.rs:138:9
 5:     0x7f23923c941c - core::fmt::write::h3c8408a9c1ca2b88
                             at /rustc/b2515fa741eea89b82a2c94048f934bbcbd3bd48/library/core/src/fmt/mod.rs:1094:21
 6:     0x7f2392355d7e - std::io::Write::write_fmt::h49f73e56bc6178eb
                             at /rustc/b2515fa741eea89b82a2c94048f934bbcbd3bd48/library/std/src/io/mod.rs:1714:15
 7:     0x7f2392362f54 - std::sys_common::backtrace::_print::hc978fdff27b3702f
                             at /rustc/b2515fa741eea89b82a2c94048f934bbcbd3bd48/library/std/src/sys_common/backtrace.rs:47:5
 8:     0x7f2392362f54 - std::sys_common::backtrace::print::h6d8605d3f6a732cf
                             at /rustc/b2515fa741eea89b82a2c94048f934bbcbd3bd48/library/std/src/sys_common/backtrace.rs:34:9
 9:     0x7f239236604a - std::panicking::panic_hook_with_disk_dump::{{closure}}::h5ba21bec50652e99
                             at /rustc/b2515fa741eea89b82a2c94048f934bbcbd3bd48/library/std/src/panicking.rs:280:22
10:     0x7f2392365d45 - std::panicking::panic_hook_with_disk_dump::h06e78b9adc4953c8
                             at /rustc/b2515fa741eea89b82a2c94048f934bbcbd3bd48/library/std/src/panicking.rs:314:9
11:     0x7f239553b2a9 - <rustc_driver_impl[9c0b0eae858fb9ed]::install_ice_hook::{closure#0} as core[f4d78fc37b1271ab]::ops::function::FnOnce<(&core[f4d78fc37b1271ab]::panic::panic_info::PanicInfo,)>>::call_once::{shim:vtable#0}
12:     0x7f2392366913 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h5e9d6c842a587ade
                             at /rustc/b2515fa741eea89b82a2c94048f934bbcbd3bd48/library/alloc/src/boxed.rs:2021:9
13:     0x7f2392366913 - std::panicking::rust_panic_with_hook::h731d1fd1d7057f0e
                             at /rustc/b2515fa741eea89b82a2c94048f934bbcbd3bd48/library/std/src/panicking.rs:757:13
14:     0x7f2392366681 - std::panicking::begin_panic_handler::{{closure}}::h6d854330c70238b5
                             at /rustc/b2515fa741eea89b82a2c94048f934bbcbd3bd48/library/std/src/panicking.rs:631:13
15:     0x7f2392363696 - std::sys_common::backtrace::__rust_end_short_backtrace::hc13992967e8ee37d
                             at /rustc/b2515fa741eea89b82a2c94048f934bbcbd3bd48/library/std/src/sys_common/backtrace.rs:170:18
16:     0x7f23923663c2 - rust_begin_unwind
                             at /rustc/b2515fa741eea89b82a2c94048f934bbcbd3bd48/library/std/src/panicking.rs:619:5
17:     0x7f23923c57a5 - core::panicking::panic_fmt::h55890f00e6462e9a
                             at /rustc/b2515fa741eea89b82a2c94048f934bbcbd3bd48/library/core/src/panicking.rs:72:14
18:     0x7f23923c5959 - core::panicking::panic_bounds_check::he2dd890af437804e
                             at /rustc/b2515fa741eea89b82a2c94048f934bbcbd3bd48/library/core/src/panicking.rs:180:5
19:     0x55cc1a7ae702 - clippy_lints[32b6a0893c936af6]::implied_bounds_in_impls::check
20:     0x7f239593d125 - <rustc_lint[7c029eba3f723c1c]::late::LateContextAndPass<rustc_lint[7c029eba3f723c1c]::late::RuntimeCombinedLateLintPass> as rustc_hir[c8736cc5ad551095]::intravisit::Visitor>::visit_fn
21:     0x7f2395946e9d - rustc_hir[c8736cc5ad551095]::intravisit::walk_item::<rustc_lint[7c029eba3f723c1c]::late::LateContextAndPass<rustc_lint[7c029eba3f723c1c]::late::RuntimeCombinedLateLintPass>>
22:     0x7f239593ad7b - <rustc_lint[7c029eba3f723c1c]::late::LateContextAndPass<rustc_lint[7c029eba3f723c1c]::late::RuntimeCombinedLateLintPass> as rustc_hir[c8736cc5ad551095]::intravisit::Visitor>::visit_nested_item
23:     0x7f2395945c0a - rustc_hir[c8736cc5ad551095]::intravisit::walk_mod::<rustc_lint[7c029eba3f723c1c]::late::LateContextAndPass<rustc_lint[7c029eba3f723c1c]::late::RuntimeCombinedLateLintPass>>
24:     0x7f2394bba7db - <rustc_session[227a7b0182a81de4]::session::Session>::time::<(), rustc_lint[7c029eba3f723c1c]::late::check_crate::{closure#0}::{closure#0}>
25:     0x7f2394bb9f99 - <core[f4d78fc37b1271ab]::panic::unwind_safe::AssertUnwindSafe<rustc_interface[86525c5fafa2c3a]::passes::analysis::{closure#6}::{closure#1}::{closure#2}> as core[f4d78fc37b1271ab]::ops::function::FnOnce<()>>::call_once
26:     0x7f2394bb159f - <core[f4d78fc37b1271ab]::panic::unwind_safe::AssertUnwindSafe<rustc_interface[86525c5fafa2c3a]::passes::analysis::{closure#6}::{closure#1}> as core[f4d78fc37b1271ab]::ops::function::FnOnce<()>>::call_once
27:     0x7f2394472aa8 - <rustc_session[227a7b0182a81de4]::session::Session>::time::<(), rustc_interface[86525c5fafa2c3a]::passes::analysis::{closure#6}>
28:     0x7f2394470e31 - rustc_interface[86525c5fafa2c3a]::passes::analysis
29:     0x7f2394a5572a - rustc_query_impl[75df7bf25f38779]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[75df7bf25f38779]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[6f8d83f57f417709]::query::erase::Erased<[u8; 1usize]>>
30:     0x7f2394a55719 - <rustc_query_impl[75df7bf25f38779]::query_impl::analysis::dynamic_query::{closure#2} as core[f4d78fc37b1271ab]::ops::function::FnOnce<(rustc_middle[6f8d83f57f417709]::ty::context::TyCtxt, ())>>::call_once
31:     0x7f2394bdd8ca - rustc_query_system[9ff6dc27fa3386b9]::query::plumbing::try_execute_query::<rustc_query_impl[75df7bf25f38779]::DynamicConfig<rustc_query_system[9ff6dc27fa3386b9]::query::caches::SingleCache<rustc_middle[6f8d83f57f417709]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[75df7bf25f38779]::plumbing::QueryCtxt, false>
32:     0x7f2394bdd649 - rustc_query_impl[75df7bf25f38779]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
33:     0x7f239484a8f6 - <rustc_middle[6f8d83f57f417709]::ty::context::GlobalCtxt>::enter::<rustc_driver_impl[9c0b0eae858fb9ed]::run_compiler::{closure#1}::{closure#2}::{closure#6}, core[f4d78fc37b1271ab]::result::Result<(), rustc_span[9b50d41fcb69953]::ErrorGuaranteed>>
34:     0x7f2394849d3d - <rustc_interface[86525c5fafa2c3a]::interface::Compiler>::enter::<rustc_driver_impl[9c0b0eae858fb9ed]::run_compiler::{closure#1}::{closure#2}, core[f4d78fc37b1271ab]::result::Result<core[f4d78fc37b1271ab]::option::Option<rustc_interface[86525c5fafa2c3a]::queries::Linker>, rustc_span[9b50d41fcb69953]::ErrorGuaranteed>>
35:     0x7f2394847058 - std[dba048ab42cdd2b]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[86525c5fafa2c3a]::util::run_in_thread_pool_with_globals<rustc_interface[86525c5fafa2c3a]::interface::run_compiler<core[f4d78fc37b1271ab]::result::Result<(), rustc_span[9b50d41fcb69953]::ErrorGuaranteed>, rustc_driver_impl[9c0b0eae858fb9ed]::run_compiler::{closure#1}>::{closure#0}, core[f4d78fc37b1271ab]::result::Result<(), rustc_span[9b50d41fcb69953]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[f4d78fc37b1271ab]::result::Result<(), rustc_span[9b50d41fcb69953]::ErrorGuaranteed>>
36:     0x7f23948467ce - <<std[dba048ab42cdd2b]::thread::Builder>::spawn_unchecked_<rustc_interface[86525c5fafa2c3a]::util::run_in_thread_pool_with_globals<rustc_interface[86525c5fafa2c3a]::interface::run_compiler<core[f4d78fc37b1271ab]::result::Result<(), rustc_span[9b50d41fcb69953]::ErrorGuaranteed>, rustc_driver_impl[9c0b0eae858fb9ed]::run_compiler::{closure#1}>::{closure#0}, core[f4d78fc37b1271ab]::result::Result<(), rustc_span[9b50d41fcb69953]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[f4d78fc37b1271ab]::result::Result<(), rustc_span[9b50d41fcb69953]::ErrorGuaranteed>>::{closure#1} as core[f4d78fc37b1271ab]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
37:     0x7f2392371375 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h7334712f13dfb18e
                             at /rustc/b2515fa741eea89b82a2c94048f934bbcbd3bd48/library/alloc/src/boxed.rs:2007:9
38:     0x7f2392371375 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hcc12b515e1513e84
                             at /rustc/b2515fa741eea89b82a2c94048f934bbcbd3bd48/library/alloc/src/boxed.rs:2007:9
39:     0x7f2392371375 - std::sys::unix::thread::Thread::new::thread_start::h103bf550e93c21c5
                             at /rustc/b2515fa741eea89b82a2c94048f934bbcbd3bd48/library/std/src/sys/unix/thread.rs:108:17
40:     0x7f2391e8c9eb - <unknown>
41:     0x7f2391f10ebc - <unknown>
42:                0x0 - <unknown>

error: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust-clippy/issues/new?template=ice.yml

note: please attach the file at `/home/matthias/vcs/github/rust/rustc-ice-2023-08-29T20:09:43.815254478Z-2767745.txt` to your bug report

query stack during panic:
#0 [analysis] running analysis passes on this crate
end of query stack
note: Clippy version: clippy 0.1.74 (b2515fa 2023-08-29)

warning: 4 warnings emitted

@matthiaskrgr matthiaskrgr added C-bug Category: Clippy is not doing the correct thing I-ICE Issue: Clippy panicked, giving an Internal Compilation Error (ICE) ❄️ labels Aug 29, 2023
@y21
Copy link
Member

y21 commented Aug 29, 2023

This line causes the ICE:

fn gen() -> impl PartialOrd + PartialEq {}

It looks like the issue here is that we're trying to get the Rhs generic type parameter from PartialOrd and PartialEq to check if the generic args are the same, and incorrectly assuming that all generic parameters defined on the trait will be specified in the trait bound, but the Rhs is not explicitly specified here. It should probably use the default type if there is no type at that index.

@y21
Copy link
Member

y21 commented Aug 30, 2023

@rustbot claim

I have a fix for this locally that fixes this ICE as well as another somewhat similar one. I've found a few other issues with this lint (mostly just suggestion-causes-error ones), so I think it's better if we move this into nursery for now... I can do that in the same PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-ICE Issue: Clippy panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
2 participants