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 when using #[clippy::author] #11651

Closed
AneesHl opened this issue Oct 9, 2023 · 2 comments
Closed

ICE when using #[clippy::author] #11651

AneesHl opened this issue Oct 9, 2023 · 2 comments
Labels
C-bug Category: Clippy is not doing the correct thing I-ICE Issue: Clippy panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@AneesHl
Copy link

AneesHl commented Oct 9, 2023

Summary

fn main() {
    let x = "world";

    #[clippy::author]
    let print_text = |y| println!("Hello {}!", y);
    print_text(x);
}

Version

rustc 1.73.0 (cc66ad468 2023-10-03)
binary: rustc
commit-hash: cc66ad468955717ab92600c770da8c1601a4ff33
commit-date: 2023-10-03
host: x86_64-apple-darwin
release: 1.73.0
LLVM version: 17.0.2

Error output

Backtrace

if let StmtKind::Local(local) = stmt.kind
  && let Some(init) = local.init
  && let ExprKind::Closure(CaptureBy::Ref, fn_decl, body_id, _, None) = init.kind
  && let FnRetTy::DefaultReturn(_) = fn_decl.output
  && expr = &cx.tcx.hir().body(body_id).value
  && let ExprKind::Block(block, None) = expr.kind
  && block.stmts.len() == 1
  && let StmtKind::Semi(e) = block.stmts[0].kind
  && let ExprKind::Call(func, args) = e.kind
  && let ExprKind::Path(ref qpath) = func.kind
  && match_qpath(qpath, &["$crate", "io", "_print"])
  && args.len() == 1
  && let ExprKind::Call(func1, args1) = args[0].kind
  && let ExprKind::Path(ref qpath1) = func1.kind
thread 'rustc' panicked at src/tools/clippy/clippy_lints/src/utils/author.rs:760:36:
path_to_string: called for lang item qpath
stack backtrace:
 0: _rust_begin_unwind
 1: core::panicking::panic_fmt
 2: clippy_lints::utils::author::path_to_string::inner
 3: clippy_lints::utils::author::path_to_string::inner
 4: <clippy_lints::utils::author::PrintVisitor>::qpath
 5: <clippy_lints::utils::author::PrintVisitor>::expr
 6: <clippy_lints::utils::author::PrintVisitor>::expr
 7: <clippy_lints::utils::author::PrintVisitor>::slice::<rustc_hir::hir::Expr, <clippy_lints::utils::author::PrintVisitor>::expr::{closure#2}>
 8: <clippy_lints::utils::author::PrintVisitor>::expr
 9: <clippy_lints::utils::author::PrintVisitor>::stmt
10: <clippy_lints::utils::author::PrintVisitor>::block
11: <clippy_lints::utils::author::PrintVisitor>::expr
12: <clippy_lints::utils::author::PrintVisitor>::body
13: <clippy_lints::utils::author::PrintVisitor>::expr
14: <clippy_lints::utils::author::PrintVisitor>::stmt
15: <clippy_lints::utils::author::Author as rustc_lint::passes::LateLintPass>::check_stmt
16: <rustc_lint::late::LateContextAndPass<rustc_lint::late::RuntimeCombinedLateLintPass> as rustc_hir::intravisit::Visitor>::visit_stmt
17: rustc_hir::intravisit::walk_block::<rustc_lint::late::LateContextAndPass<rustc_lint::late::RuntimeCombinedLateLintPass>>
18: rustc_hir::intravisit::walk_expr::<rustc_lint::late::LateContextAndPass<rustc_lint::late::RuntimeCombinedLateLintPass>>
19: <rustc_lint::late::LateContextAndPass<rustc_lint::late::RuntimeCombinedLateLintPass> as rustc_hir::intravisit::Visitor>::visit_expr::{closure#0}
20: <rustc_lint::late::LateContextAndPass<rustc_lint::late::RuntimeCombinedLateLintPass> as rustc_hir::intravisit::Visitor>::visit_nested_body
21: rustc_hir::intravisit::walk_item::<rustc_lint::late::LateContextAndPass<rustc_lint::late::RuntimeCombinedLateLintPass>>
22: <rustc_lint::late::LateContextAndPass<rustc_lint::late::RuntimeCombinedLateLintPass> as rustc_hir::intravisit::Visitor>::visit_nested_item
23: <rustc_session::session::Session>::time::<(), rustc_lint::late::check_crate::{closure#0}::{closure#0}>
24: <core::panic::unwind_safe::AssertUnwindSafe<rustc_interface::passes::analysis::{closure#5}::{closure#1}::{closure#2}> as core::ops::function::FnOnce<()>>::call_once
25: <core::panic::unwind_safe::AssertUnwindSafe<rustc_interface::passes::analysis::{closure#5}::{closure#1}> as core::ops::function::FnOnce<()>>::call_once
26: <rustc_session::session::Session>::time::<(), rustc_interface::passes::analysis::{closure#5}>
27: rustc_interface::passes::analysis
    [... omitted 2 frames ...]
28: <rustc_middle::ty::context::GlobalCtxt>::enter::<rustc_driver_impl::run_compiler::{closure#1}::{closure#2}::{closure#6}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
29: <rustc_interface::interface::Compiler>::enter::<rustc_driver_impl::run_compiler::{closure#1}::{closure#2}, core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_span::ErrorGuaranteed>>
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

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: rustc 1.73.0 (cc66ad468 2023-10-03) running on x86_64-apple-darwin

note: compiler flags: --crate-type bin -C embed-bitcode=no -C debuginfo=2 -C split-debuginfo=unpacked -C incremental=[REDACTED]

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [analysis] running analysis passes on this crate
end of query stack
note: Clippy version: clippy 0.1.73 (cc66ad46 2023-10-03)

error: could not compile `demo_bug` (bin "demo_bug")

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

y21 commented Oct 9, 2023

Looks like a duplicate of #11134

@AneesHl
Copy link
Author

AneesHl commented Oct 9, 2023

You're right, I think the problem in both issues is in the combination of using #[clippy::author] and the println! (or print!) macro inside a closure or for-loop.

@koka831 koka831 mentioned this issue Oct 13, 2023
bors added a commit that referenced this issue Oct 13, 2023
Fix/11134

Fix #11134

Hir of `qpath` will be `TypeRelative(Ty { kind: Path(LangItem...` when a closure contains macro (e.g. #11651) and #11134, it causes panic.
This PR avoids panicking and emitting incomplete path string when `qpath` contains `LangItem`.

changelog: none
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

3 participants