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

Crash in use_self: LateContext::typeck_results called outside of body #7423

Closed
dtolnay opened this issue Jul 3, 2021 · 10 comments
Closed

Crash in use_self: LateContext::typeck_results called outside of body #7423

dtolnay opened this issue Jul 3, 2021 · 10 comments
Assignees
Labels
C-bug Category: Clippy is not doing the correct thing I-ICE Issue: Clippy panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@dtolnay
Copy link
Member

dtolnay commented Jul 3, 2021

Code

pub trait Trait {
    fn f();
}

macro_rules! repro {
    ($ty:ty) => {
        impl Trait for $ty {
            fn f() {
                extern "C" {
                    fn _f() -> $ty;
                }
            }
        }
    };
}

repro!(usize);

Meta

  • cargo clippy -V: clippy 0.1.55 (798baeb 2021-07-02)
  • rustc -Vv:
    rustc 1.55.0-nightly (798baebde 2021-07-02)
    binary: rustc
    commit-hash: 798baebde1fe77e5a660490ec64e727a5d79970d
    commit-date: 2021-07-02
    host: x86_64-unknown-linux-gnu
    release: 1.55.0-nightly
    LLVM version: 12.0.1
    

Error output

thread 'rustc' panicked at '`LateContext::typeck_results` called outside of body', src/tools/clippy/clippy_lints/src/use_self.rs:213:20
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

error: internal compiler error: unexpected panic

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

query stack during panic:
#0 [analysis] running analysis passes on this crate
end of query stack
Backtrace

 0: rust_begin_unwind
           at /rustc/798baebde1fe77e5a660490ec64e727a5d79970d/library/std/src/panicking.rs:515:5
 1: core::panicking::panic_fmt
           at /rustc/798baebde1fe77e5a660490ec64e727a5d79970d/library/core/src/panicking.rs:92:14
 2: core::option::expect_failed
           at /rustc/798baebde1fe77e5a660490ec64e727a5d79970d/library/core/src/option.rs:1243:5
 3: rustc_lint::context::LateContext::typeck_results
 4: <clippy_lints::use_self::UseSelf as rustc_lint::passes::LateLintPass>::check_ty
 5: <rustc_lint::late::LateLintPassObjects as rustc_lint::passes::LateLintPass>::check_ty
 6: <rustc_lint::late::LateContextAndPass<T> as rustc_hir::intravisit::Visitor>::visit_ty
 7: rustc_hir::intravisit::walk_foreign_item
 8: rustc_hir::intravisit::Visitor::visit_nested_foreign_item
 9: rustc_hir::intravisit::walk_foreign_item_ref
10: rustc_hir::intravisit::walk_item
11: rustc_hir::intravisit::Visitor::visit_nested_item
12: <rustc_lint::late::LateContextAndPass<T> as rustc_hir::intravisit::Visitor>::visit_stmt
13: rustc_hir::intravisit::walk_block
14: <rustc_lint::late::LateContextAndPass<T> as rustc_hir::intravisit::Visitor>::visit_block
15: <rustc_lint::late::LateContextAndPass<T> as rustc_hir::intravisit::Visitor>::visit_expr
16: <rustc_lint::late::LateContextAndPass<T> as rustc_hir::intravisit::Visitor>::visit_nested_body
17: <rustc_lint::late::LateContextAndPass<T> as rustc_hir::intravisit::Visitor>::visit_fn
18: rustc_hir::intravisit::walk_impl_item
19: rustc_hir::intravisit::Visitor::visit_nested_impl_item
20: rustc_hir::intravisit::walk_impl_item_ref
21: rustc_hir::intravisit::walk_item
22: rustc_hir::intravisit::Visitor::visit_nested_item
23: rustc_hir::intravisit::walk_mod
24: <rustc_lint::late::LateContextAndPass<T> as rustc_hir::intravisit::Visitor>::visit_mod
25: rustc_hir::intravisit::walk_crate
26: rustc_lint::late::late_lint_pass_crate
27: rustc_lint::late::late_lint_crate
28: rustc_data_structures::sync::join
29: <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
30: rustc_session::utils::<impl rustc_session::session::Session>::time
31: rustc_interface::passes::analysis
32: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
33: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
34: rustc_query_system::dep_graph::graph::DepGraph<K>::with_eval_always_task
35: rustc_data_structures::stack::ensure_sufficient_stack
36: rustc_query_system::query::plumbing::force_query_with_job
37: rustc_query_system::query::plumbing::get_query_impl
38: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::analysis
39: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
40: rustc_span::with_source_map
41: rustc_interface::interface::create_compiler_and_run
42: scoped_tls::ScopedKey<T>::set

Mentioning @camsteffen @flip1995 who touched this lint recently in #7411.

@dtolnay dtolnay added C-bug Category: Clippy is not doing the correct thing I-ICE Issue: Clippy panicked, giving an Internal Compilation Error (ICE) ❄️ labels Jul 3, 2021
dtolnay added a commit to dtolnay/cxx that referenced this issue Jul 3, 2021
Clippy crash: rust-lang/rust-clippy#7423

    thread 'rustc' panicked at '`LateContext::typeck_results` called outside of body', src/tools/clippy/clippy_lints/src/use_self.rs:213:20
    note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

    error: internal compiler error: unexpected panic

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

    query stack during panic:
    #0 [analysis] running analysis passes on this crate
    end of query stack
@camsteffen camsteffen self-assigned this Jul 3, 2021
@camsteffen
Copy link
Contributor

So much for making it less fragile 😭

@camsteffen
Copy link
Contributor

@dtolnay Do you have any projects that would be good for Clippy integration tests?

@dtolnay
Copy link
Member Author

dtolnay commented Jul 3, 2021

@dtolnay Do you have any projects that would be good for Clippy integration tests?

I already have a bunch of crates in lintcheck_crates.toml, but they seem to often get hit by false positives anyway. The project affected by this crash is already in there:

cxx = {name = "cxx", versions = ['1.0.32']}

Many of the projects affected by #7422 and #7421 are already in there too.

@flip1995
Copy link
Member

flip1995 commented Jul 3, 2021

Wait, I got an error from cxx, but the lintcheck tool didn't display that an ICE occurred. In that case that was totally my fault. Now I know to be more careful interpreting the lintcheck output in the future.

@camsteffen
Copy link
Contributor

Does lintcheck need to be louder when ICE occurs? Also we have integration tests that are separate from the lintcheck list, right? cxx seems like a good candidate for that.

bors added a commit that referenced this issue Jul 3, 2021
Fix use_self ICE

changelog: Fix ICE #7423

r? `@flip1995`
@flip1995
Copy link
Member

flip1995 commented Jul 3, 2021

Fixed in #7428

Does lintcheck need to be louder when ICE occurs?

I guess so? We should also make it easier to use, or rather use it more often.

@flip1995 flip1995 closed this as completed Jul 3, 2021
@QuantumEntangledAndy
Copy link

Sorry to bother you but I am currently getting this issue with Clippy 0.1.55 (8853999 2021-07-06), given the date (2021-07-06) I believe I am using the version with the fix merged in. Am I reading the version wrong (and should wait for a version bump) or is this still not completely resolved.

I do not have the trait macro pattern described in the original post but still get the following error

thread 'rustc' panicked at '`LateContext::typeck_results` called outside of body', src/tools/clippy/clippy_lints/src/use_self.rs:213:20
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

error: internal compiler error: unexpected panic

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

note: we would appreciate a bug report: https://github.com/rust-lang/rust-clippy/issues/new

note: Clippy version: clippy 0.1.55 (88539999 2021-07-06)

query stack during panic:
#0 [analysis] running analysis passes on this crate
end of query stack

Please let me know if any more details would be required

@dtolnay
Copy link
Member Author

dtolnay commented Jul 7, 2021

@QuantumEntangledAndy
Copy link

Thanks for the info :). Sorry about that

@flip1995
Copy link
Member

flip1995 commented Jul 7, 2021

I haven't gotten to sync it to nightly yet. Our next regular sync is in 8 days, so I guess I won't do an out-of-cycle sync now. This will definitely not hit beta/stable.

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

4 participants