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

ICE: None in unused_io_amount #12366

Closed
matthiaskrgr opened this issue Feb 27, 2024 · 6 comments
Closed

ICE: None in unused_io_amount #12366

matthiaskrgr opened this issue Feb 27, 2024 · 6 comments
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

Summary

//@ error-pattern unable to turn pointer into raw bytes
//@ normalize-stderr-test: "alloc[0-9]+\+0x[a-z0-9]+" -> "ALLOC"

const C: () = unsafe {
    let foo = Some(&42 as *mut libc::c_void);
    let one_and_a_half_pointers = std::mem::size_of::<*const i32>()/2*3;
    (&foo as *const _ as *const u8).add(one_and_a_half_pointers).read();
};

fn main() {
}

Version

rustc 1.78.0-nightly (fc3800f65 2024-02-26)
binary: rustc
commit-hash: fc3800f65777a365b5125706d60f97e4d0675efe
commit-date: 2024-02-26
host: x86_64-unknown-linux-gnu
release: 1.78.0-nightly
LLVM version: 18.1.0

Error output

Backtrace

warning: constant `C` is never used
--> 4AB6F9BAC060E0ACA013D96EC05D093566920A235B14218D6FD712C122C232ED.rs:4:7
|
4 | const C: () = unsafe {
|       ^
|
= note: `#[warn(dead_code)]` on by default

thread 'rustc' panicked at src/tools/clippy/clippy_utils/src/lib.rs:301:73:
called `Option::unwrap()` on a `None` value
stack backtrace:
 0:     0x7fc5809cca06 - std::backtrace_rs::backtrace::libunwind::trace::h897f614a5c54abf5
                             at /rustc/fc3800f65777a365b5125706d60f97e4d0675efe/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5
 1:     0x7fc5809cca06 - std::backtrace_rs::backtrace::trace_unsynchronized::ha07ca3e1f9b9accd
                             at /rustc/fc3800f65777a365b5125706d60f97e4d0675efe/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
 2:     0x7fc5809cca06 - std::sys_common::backtrace::_print_fmt::h9057a2c67e4a571a
                             at /rustc/fc3800f65777a365b5125706d60f97e4d0675efe/library/std/src/sys_common/backtrace.rs:68:5
 3:     0x7fc5809cca06 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h8ce9754c70d092cc
                             at /rustc/fc3800f65777a365b5125706d60f97e4d0675efe/library/std/src/sys_common/backtrace.rs:44:22
 4:     0x7fc580a1d98c - core::fmt::rt::Argument::fmt::hf09070140e87d7cb
                             at /rustc/fc3800f65777a365b5125706d60f97e4d0675efe/library/core/src/fmt/rt.rs:142:9
 5:     0x7fc580a1d98c - core::fmt::write::h7464ab53ee519c5a
                             at /rustc/fc3800f65777a365b5125706d60f97e4d0675efe/library/core/src/fmt/mod.rs:1120:17
 6:     0x7fc5809c133f - std::io::Write::write_fmt::hb6c369e265d2f778
                             at /rustc/fc3800f65777a365b5125706d60f97e4d0675efe/library/std/src/io/mod.rs:1846:15
 7:     0x7fc5809cc7b4 - std::sys_common::backtrace::_print::h3df17c44fc2056b0
                             at /rustc/fc3800f65777a365b5125706d60f97e4d0675efe/library/std/src/sys_common/backtrace.rs:47:5
 8:     0x7fc5809cc7b4 - std::sys_common::backtrace::print::hb6b87ad25037aca8
                             at /rustc/fc3800f65777a365b5125706d60f97e4d0675efe/library/std/src/sys_common/backtrace.rs:34:9
 9:     0x7fc5809cf4fb - std::panicking::default_hook::{{closure}}::he18ee206e433f0ce
10:     0x7fc5809cf249 - std::panicking::default_hook::h03bf843f6389163a
                             at /rustc/fc3800f65777a365b5125706d60f97e4d0675efe/library/std/src/panicking.rs:292:9
11:     0x7fc57d69edfc - std[f92a88bd87681e23]::panicking::update_hook::<alloc[343fb8d002b75d60]::boxed::Box<rustc_driver_impl[e646bc2c37d34ca8]::install_ice_hook::{closure#0}>>::{closure#0}
12:     0x7fc5809cfc60 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h714c50999bd84945
                             at /rustc/fc3800f65777a365b5125706d60f97e4d0675efe/library/alloc/src/boxed.rs:2030:9
13:     0x7fc5809cfc60 - std::panicking::rust_panic_with_hook::h9a60490ac66caebe
                             at /rustc/fc3800f65777a365b5125706d60f97e4d0675efe/library/std/src/panicking.rs:783:13
14:     0x7fc5809cf969 - std::panicking::begin_panic_handler::{{closure}}::h14f915860bd5f3ee
                             at /rustc/fc3800f65777a365b5125706d60f97e4d0675efe/library/std/src/panicking.rs:649:13
15:     0x7fc5809ccee6 - std::sys_common::backtrace::__rust_end_short_backtrace::h016a8d075a8ae4f4
                             at /rustc/fc3800f65777a365b5125706d60f97e4d0675efe/library/std/src/sys_common/backtrace.rs:171:18
16:     0x7fc5809cf6d4 - rust_begin_unwind
                             at /rustc/fc3800f65777a365b5125706d60f97e4d0675efe/library/std/src/panicking.rs:645:5
17:     0x7fc580a19ea5 - core::panicking::panic_fmt::h15d004aec4496bae
                             at /rustc/fc3800f65777a365b5125706d60f97e4d0675efe/library/core/src/panicking.rs:72:14
18:     0x7fc580a19f63 - core::panicking::panic::hb5f4783d62415430
                             at /rustc/fc3800f65777a365b5125706d60f97e4d0675efe/library/core/src/panicking.rs:144:5
19:     0x7fc580a19c36 - core::option::unwrap_failed::h104f93f0c64baff9
                             at /rustc/fc3800f65777a365b5125706d60f97e4d0675efe/library/core/src/option.rs:1985:5
20:     0x55b06861bdb4 - clippy_utils[ffc41e989f5f4331]::match_trait_method
21:     0x55b068507209 - clippy_lints[73405db306e832e1]::unused_io_amount::should_lint
22:     0x55b068506ecd - clippy_lints[73405db306e832e1]::unused_io_amount::check_expr
23:     0x55b068506b3d - <clippy_lints[73405db306e832e1]::unused_io_amount::UnusedIoAmount as rustc_lint[81ead70ad2ae47db]::passes::LateLintPass>::check_block
24:     0x7fc57da2bd38 - <rustc_lint[81ead70ad2ae47db]::late::LateContextAndPass<rustc_lint[81ead70ad2ae47db]::late::RuntimeCombinedLateLintPass> as rustc_hir[37bd1212b186212f]::intravisit::Visitor>::visit_block
25:     0x7fc57da2b724 - <rustc_lint[81ead70ad2ae47db]::late::LateContextAndPass<rustc_lint[81ead70ad2ae47db]::late::RuntimeCombinedLateLintPass> as rustc_hir[37bd1212b186212f]::intravisit::Visitor>::visit_expr::{closure#0}
26:     0x7fc57da2b118 - <rustc_lint[81ead70ad2ae47db]::late::LateContextAndPass<rustc_lint[81ead70ad2ae47db]::late::RuntimeCombinedLateLintPass> as rustc_hir[37bd1212b186212f]::intravisit::Visitor>::visit_expr
27:     0x7fc57da2b018 - <rustc_lint[81ead70ad2ae47db]::late::LateContextAndPass<rustc_lint[81ead70ad2ae47db]::late::RuntimeCombinedLateLintPass> as rustc_hir[37bd1212b186212f]::intravisit::Visitor>::visit_nested_body
28:     0x7fc57da1b2e2 - <rustc_lint[81ead70ad2ae47db]::late::LateContextAndPass<rustc_lint[81ead70ad2ae47db]::late::RuntimeCombinedLateLintPass> as rustc_hir[37bd1212b186212f]::intravisit::Visitor>::visit_nested_item
29:     0x7fc57f56a8fd - rustc_lint[81ead70ad2ae47db]::late::check_crate::{closure#0}
30:     0x7fc57f56ab51 - rustc_lint[81ead70ad2ae47db]::late::check_crate
31:     0x7fc57f564a65 - rustc_interface[6aee5a19bc2b6d64]::passes::analysis
32:     0x7fc57f563759 - rustc_query_impl[ec3b69200ec3e59f]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[ec3b69200ec3e59f]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[9bf74739d8164068]::query::erase::Erased<[u8; 1usize]>>
33:     0x7fc57f736325 - rustc_query_system[14bfac5267aee8ee]::query::plumbing::try_execute_query::<rustc_query_impl[ec3b69200ec3e59f]::DynamicConfig<rustc_query_system[14bfac5267aee8ee]::query::caches::SingleCache<rustc_middle[9bf74739d8164068]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[ec3b69200ec3e59f]::plumbing::QueryCtxt, false>
34:     0x7fc57f736089 - rustc_query_impl[ec3b69200ec3e59f]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
35:     0x7fc57f73dc16 - rustc_interface[6aee5a19bc2b6d64]::interface::run_compiler::<core[cf0ab25acd46a93d]::result::Result<(), rustc_span[214fbc2545e6984b]::ErrorGuaranteed>, rustc_driver_impl[e646bc2c37d34ca8]::run_compiler::{closure#0}>::{closure#0}
36:     0x7fc57f9e3c45 - std[f92a88bd87681e23]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[6aee5a19bc2b6d64]::util::run_in_thread_with_globals<rustc_interface[6aee5a19bc2b6d64]::util::run_in_thread_pool_with_globals<rustc_interface[6aee5a19bc2b6d64]::interface::run_compiler<core[cf0ab25acd46a93d]::result::Result<(), rustc_span[214fbc2545e6984b]::ErrorGuaranteed>, rustc_driver_impl[e646bc2c37d34ca8]::run_compiler::{closure#0}>::{closure#0}, core[cf0ab25acd46a93d]::result::Result<(), rustc_span[214fbc2545e6984b]::ErrorGuaranteed>>::{closure#0}, core[cf0ab25acd46a93d]::result::Result<(), rustc_span[214fbc2545e6984b]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[cf0ab25acd46a93d]::result::Result<(), rustc_span[214fbc2545e6984b]::ErrorGuaranteed>>
37:     0x7fc57f9e3a72 - <<std[f92a88bd87681e23]::thread::Builder>::spawn_unchecked_<rustc_interface[6aee5a19bc2b6d64]::util::run_in_thread_with_globals<rustc_interface[6aee5a19bc2b6d64]::util::run_in_thread_pool_with_globals<rustc_interface[6aee5a19bc2b6d64]::interface::run_compiler<core[cf0ab25acd46a93d]::result::Result<(), rustc_span[214fbc2545e6984b]::ErrorGuaranteed>, rustc_driver_impl[e646bc2c37d34ca8]::run_compiler::{closure#0}>::{closure#0}, core[cf0ab25acd46a93d]::result::Result<(), rustc_span[214fbc2545e6984b]::ErrorGuaranteed>>::{closure#0}, core[cf0ab25acd46a93d]::result::Result<(), rustc_span[214fbc2545e6984b]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[cf0ab25acd46a93d]::result::Result<(), rustc_span[214fbc2545e6984b]::ErrorGuaranteed>>::{closure#1} as core[cf0ab25acd46a93d]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
38:     0x7fc5809d9635 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::ha1695fe0be816259
                             at /rustc/fc3800f65777a365b5125706d60f97e4d0675efe/library/alloc/src/boxed.rs:2016:9
39:     0x7fc5809d9635 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::ha64e49f73fb4b1b4
                             at /rustc/fc3800f65777a365b5125706d60f97e4d0675efe/library/alloc/src/boxed.rs:2016:9
40:     0x7fc5809d9635 - std::sys::pal::unix::thread::Thread::new::thread_start::h2ecaeb7829e7ce39
                             at /rustc/fc3800f65777a365b5125706d60f97e4d0675efe/library/std/src/sys/pal/unix/thread.rs:108:17
41:     0x7fc57a55e55a - <unknown>
42:     0x7fc57a5dba3c - <unknown>
43:                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 `/tmp/im/rustc-ice-2024-02-27T16_49_46-3925471.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.78 (fc3800f 2024-02-26)

error[E0433]: failed to resolve: use of undeclared crate or module `libc`
--> 4AB6F9BAC060E0ACA013D96EC05D093566920A235B14218D6FD712C122C232ED.rs:5:32
|
5 |     let foo = Some(&42 as *mut libc::c_void);
|                                ^^^^ use of undeclared crate or module `libc`

error: aborting due to 1 previous error; 1 warning emitted

For more information about this error, try `rustc --explain E0433`.

@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 Feb 27, 2024
@GuillaumeGomez
Copy link
Member

Your code doesn't seem to compile, even with:

const C: () = unsafe {
    let foo = Some(&42 as *const _ as *const libc::c_void);
    let one_and_a_half_pointers = std::mem::size_of::<*const i32>()/2*3;
    (&foo as *const _ as *const u8).add(one_and_a_half_pointers).read();
};

Did I miss something?

@matthiaskrgr
Copy link
Member Author

What do you think you're missing? 😅

@GuillaumeGomez
Copy link
Member

No clue, hence why I'm asking. 😆

@m-rph
Copy link
Contributor

m-rph commented Mar 23, 2024

I tried compiling this

#![feature(rustc_private)]
extern crate libc;

const C: () = unsafe {
    let foo = Some(&42 as *mut libc::c_void);
    let one_and_a_half_pointers = std::mem::size_of::<*const i32>()/2*3;
    (&foo as *const _ as *const u8).add(one_and_a_half_pointers).read();
};

and well, it didn't work:

error[E0606]: casting `&i32` as `*mut libc::c_void` is invalid
  --> tests/ui/unused_io_amount.rs:284:20
   |
LL |     let foo = Some(&42 as *mut libc::c_void);
   |                    ^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0606`.

As for the underlying unwrap on a None causing an ICE. That's straight forward to resolve, but I am curious if the issue is a bad assumption at the lint level on top of explicit unwrap.

@rustbot label +needs-mcve

@rustbot
Copy link
Collaborator

rustbot commented Mar 23, 2024

Error: Label needs-mcve can only be set by Rust team members

Please file an issue on GitHub at triagebot if there's a problem with this bot, or reach out on #t-infra on Zulip.

@Jarcho
Copy link
Contributor

Jarcho commented Mar 24, 2024

Doesn't reproduce on nightly. Lints shouldn't have even run due to E0433.

@Jarcho Jarcho closed this as completed Mar 24, 2024
bors added a commit that referenced this issue Mar 25, 2024
Remove `unwrap` from `match_trait_method`

Unused_IO_amount relies on `match_trait_method` in order to match trait methods that exist in Tokio traits as the corresponding symbols don't exist.

With this commit we remove the unwrap that caused #12366.
Note: author (`@m-rph)` and `@GuillaumeGomez` couldn't replicate #12366.

r? `@blyxyas`
bors added a commit that referenced this issue Mar 25, 2024
Remove `unwrap` from `match_trait_method`

Unused_IO_amount relies on `match_trait_method` in order to match trait methods that exist in Tokio traits as the corresponding symbols don't exist.

With this commit we remove the unwrap that caused #12366.
Note: author (`@m-rph)` and `@GuillaumeGomez` couldn't replicate #12366.

changelog:none

r? `@blyxyas`
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
Development

No branches or pull requests

5 participants