rust-marker / marker

An experimental linting interface for Rust. Let's make custom lints a reality
https://rust-marker.github.io/marker/
Other
144 stars 11 forks source link

[Bug]: Marker panics when the item identifier from macro expansion is debug-printed. #300

Open Veetaha opened 1 year ago

Veetaha commented 1 year ago

Reproducer

  1. Take this code for the lint
use marker_api::prelude::*;
use marker_api::{LintPass, LintPassInfo, LintPassInfoBuilder};

#[derive(Default)]
struct MyLintPass {}
marker_api::export_lint_pass!(MyLintPass);

marker_api::declare_lint! {
    /// # What it does
    /// Breaks marker.
    MY_LINT,
    Deny,
}

impl LintPass for MyLintPass {
    fn info(&self) -> LintPassInfo {
        LintPassInfoBuilder::new(Box::new([MY_LINT])).build()
    }

    fn check_item<'ast>(&mut self, ctx: &'ast MarkerContext<'ast>, item: ast::ItemKind<'ast>) {
        let _ = dbg!(item.ident());
    }
}
  1. Take this code that is linted
fn main() {}
  1. Run cargo marker

Version

cargo-marker 0.3.0

Logs


      Marker compiling lints
   Compiling veetaha-lints v0.1.0 (/home/veetaha/sandbox/rust/crates/veetaha-lints)
warning: unused variable: `ctx`
  --> crates/veetaha-lints/src/lib.rs:20:36
   |
20 |     fn check_item<'ast>(&mut self, ctx: &'ast MarkerContext<'ast>, item: ast::ItemKind<'ast>) {
   |                                    ^^^ help: if this is intentional, prefix it with an underscore: `_ctx`
   |
   = note: `#[warn(unused_variables)]` on by default

warning: `veetaha-lints` (lib) generated 1 warning (run `cargo fix --lib -p veetaha-lints` to apply 1 suggestion)
    Finished release [optimized] target(s) in 0.23s

      Marker linting
    Checking scratch v0.1.0 (/home/veetaha/sandbox/rust/crates/scratch)
[crates/veetaha-lints/src/lib.rs:25] item.ident() = Some(
    Ident {
        name: "",
        span: crates/scratch/src/main.rs:1:1 - 1:1,
    },
)
[crates/veetaha-lints/src/lib.rs:25] item.ident() = Some(
    Ident {
        name: "std",
        span: thread 'rustc' panicked at marker_rustc_driver/src/conversion/marker/span.rs:59:48:
filled, because this belongs to a macro
stack backtrace:
   0:     0x7fd71a20333c - std::backtrace_rs::backtrace::libunwind::trace::h910709f6ac8bdc9f
                               at /rustc/249595b7523fc07a99c1adee90b1947739ca0e5b/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7fd71a20333c - std::backtrace_rs::backtrace::trace_unsynchronized::h66c1b9aae6144841
                               at /rustc/249595b7523fc07a99c1adee90b1947739ca0e5b/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7fd71a20333c - std::sys_common::backtrace::_print_fmt::h225f965e4a6dd062
                               at /rustc/249595b7523fc07a99c1adee90b1947739ca0e5b/library/std/src/sys_common/backtrace.rs:67:5
   3:     0x7fd71a20333c - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h4f4e7c60db66a770
                               at /rustc/249595b7523fc07a99c1adee90b1947739ca0e5b/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7fd71a2694cc - core::fmt::rt::Argument::fmt::h87caa0a583b068c8
                               at /rustc/249595b7523fc07a99c1adee90b1947739ca0e5b/library/core/src/fmt/rt.rs:138:9
   5:     0x7fd71a2694cc - core::fmt::write::h3b600a18a82b19f5
                               at /rustc/249595b7523fc07a99c1adee90b1947739ca0e5b/library/core/src/fmt/mod.rs:1094:21
   6:     0x7fd71a1f5d6e - std::io::Write::write_fmt::h02208d7956f2653b
                               at /rustc/249595b7523fc07a99c1adee90b1947739ca0e5b/library/std/src/io/mod.rs:1714:15
   7:     0x7fd71a203124 - std::sys_common::backtrace::_print::h3aea4dd9a94d323a
                               at /rustc/249595b7523fc07a99c1adee90b1947739ca0e5b/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7fd71a203124 - std::sys_common::backtrace::print::hbf8b71196d492872
                               at /rustc/249595b7523fc07a99c1adee90b1947739ca0e5b/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7fd71a20621a - std::panicking::panic_hook_with_disk_dump::{{closure}}::h6a8880f6e8234529
                               at /rustc/249595b7523fc07a99c1adee90b1947739ca0e5b/library/std/src/panicking.rs:278:22
  10:     0x7fd71a205f07 - std::panicking::panic_hook_with_disk_dump::h8ea3bdb613c8c8a5
                               at /rustc/249595b7523fc07a99c1adee90b1947739ca0e5b/library/std/src/panicking.rs:312:9
  11:     0x7fd71d3c5969 - <rustc_driver_impl[8d3f86e83538be5d]::install_ice_hook::{closure#0} as core[328660574c6e17ab]::ops::function::FnOnce<(&core[328660574c6e17ab]::panic::panic_info::PanicInfo,)>>::call_once::{shim:vtable#0}
  12:     0x7fd71a206ac0 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h21e710b40303a14c
                               at /rustc/249595b7523fc07a99c1adee90b1947739ca0e5b/library/alloc/src/boxed.rs:2021:9
  13:     0x7fd71a206ac0 - std::panicking::rust_panic_with_hook::h006994873154b18b
                               at /rustc/249595b7523fc07a99c1adee90b1947739ca0e5b/library/std/src/panicking.rs:733:13
  14:     0x7fd71a206847 - std::panicking::begin_panic_handler::{{closure}}::hcca9a8f2a8a2254b
                               at /rustc/249595b7523fc07a99c1adee90b1947739ca0e5b/library/std/src/panicking.rs:621:13
  15:     0x7fd71a203866 - std::sys_common::backtrace::__rust_end_short_backtrace::ha419d4c6c0af0a51
                               at /rustc/249595b7523fc07a99c1adee90b1947739ca0e5b/library/std/src/sys_common/backtrace.rs:170:18
  16:     0x7fd71a206592 - rust_begin_unwind
                               at /rustc/249595b7523fc07a99c1adee90b1947739ca0e5b/library/std/src/panicking.rs:617:5
  17:     0x7fd71a2658d3 - core::panicking::panic_fmt::h1243a42fc81a0e60
                               at /rustc/249595b7523fc07a99c1adee90b1947739ca0e5b/library/core/src/panicking.rs:67:14
  18:     0x7fd71a26562a - core::panicking::panic_display::h90db6bb08c15aa65
                               at /rustc/249595b7523fc07a99c1adee90b1947739ca0e5b/library/core/src/panicking.rs:150:5
  19:     0x7fd71a26562a - core::panicking::panic_str::h1232b217758d4212
                               at /rustc/249595b7523fc07a99c1adee90b1947739ca0e5b/library/core/src/panicking.rs:134:5
  20:     0x7fd71a26562a - core::option::expect_failed::h7fef9d7681984e5c
                               at /rustc/249595b7523fc07a99c1adee90b1947739ca0e5b/library/core/src/option.rs:1988:5
  21:     0x55b48b4b02ef - <marker_rustc_driver::context::RustcContext as marker_adapter::context::MarkerContextDriver>::span_source::hbdba057a108ca367
  22:     0x55b48b4c749e - marker_adapter::context::span_source::hee52503a9bf1c81c
  23:     0x7fd719e2d596 - marker_api::context::with_cx::hbe74c59b5e355405
  24:     0x7fd719e2d74a - <marker_api::span::Span as core::fmt::Debug>::fmt::h7dc1d40f5b346e21
  25:     0x7fd719e68685 - core::fmt::builders::DebugStruct::field::{{closure}}::hf55b1049da32da64
                               at /rustc/249595b7523fc07a99c1adee90b1947739ca0e5b/library/core/src/fmt/builders.rs:134:17
  26:     0x7fd719e68685 - core::result::Result<T,E>::and_then::hd944f176260d54b9
                               at /rustc/249595b7523fc07a99c1adee90b1947739ca0e5b/library/core/src/result.rs:1320:22
  27:     0x7fd719e68685 - core::fmt::builders::DebugStruct::field::h76de08c93bb42fbb
                               at /rustc/249595b7523fc07a99c1adee90b1947739ca0e5b/library/core/src/fmt/builders.rs:124:35
  28:     0x7fd719e2dd8c - <marker_api::span::Ident as core::fmt::Debug>::fmt::hff3f55c42f166675
  29:     0x7fd719e6883d - core::fmt::builders::DebugTuple::field::{{closure}}::h7db531e92f547a4c
                               at /rustc/249595b7523fc07a99c1adee90b1947739ca0e5b/library/core/src/fmt/builders.rs:317:17
  30:     0x7fd719e6883d - core::result::Result<T,E>::and_then::h79f12efade5734f1
                               at /rustc/249595b7523fc07a99c1adee90b1947739ca0e5b/library/core/src/result.rs:1320:22
  31:     0x7fd719e6883d - core::fmt::builders::DebugTuple::field::hcbf54de13280125c
                               at /rustc/249595b7523fc07a99c1adee90b1947739ca0e5b/library/core/src/fmt/builders.rs:309:35
  32:     0x7fd719e6966b - core::fmt::Formatter::debug_tuple_field1_finish::h43b44f668d1dd03a
                               at /rustc/249595b7523fc07a99c1adee90b1947739ca0e5b/library/core/src/fmt/mod.rs:2035:9
  33:     0x7fd719e2ce50 - <&T as core::fmt::Debug>::fmt::h925a20d5b5dbf0a1
  34:     0x7fd719e68dbe - core::fmt::rt::Argument::fmt::h87caa0a583b068c8
                               at /rustc/249595b7523fc07a99c1adee90b1947739ca0e5b/library/core/src/fmt/rt.rs:138:9
  35:     0x7fd719e68dbe - core::fmt::run::h86a30f58899e1cd0
                               at /rustc/249595b7523fc07a99c1adee90b1947739ca0e5b/library/core/src/fmt/mod.rs:1142:11
  36:     0x7fd719e68dbe - core::fmt::write::h3b600a18a82b19f5
                               at /rustc/249595b7523fc07a99c1adee90b1947739ca0e5b/library/core/src/fmt/mod.rs:1110:26
  37:     0x7fd719e461c6 - std::io::Write::write_fmt::h653ff5e1a734eac5
                               at /rustc/249595b7523fc07a99c1adee90b1947739ca0e5b/library/std/src/io/mod.rs:1714:15
  38:     0x7fd719e461c6 - <&std::io::stdio::Stderr as std::io::Write>::write_fmt::he3916c2967156893
                               at /rustc/249595b7523fc07a99c1adee90b1947739ca0e5b/library/std/src/io/stdio.rs:945:9
  39:     0x7fd719e4654a - <std::io::stdio::Stderr as std::io::Write>::write_fmt::h87570fc367244edb
                               at /rustc/249595b7523fc07a99c1adee90b1947739ca0e5b/library/std/src/io/stdio.rs:919:9
  40:     0x7fd719e4654a - std::io::stdio::print_to::hf92873194822865d
                               at /rustc/249595b7523fc07a99c1adee90b1947739ca0e5b/library/std/src/io/stdio.rs:1018:21
  41:     0x7fd719e4654a - std::io::stdio::_eprint::ha1e5afe14e7adc27
                               at /rustc/249595b7523fc07a99c1adee90b1947739ca0e5b/library/std/src/io/stdio.rs:1106:5
  42:     0x7fd719e2d103 - veetaha_lints::__marker_todo::marker_lint_crate_bindings::check_item::hc3fd13d42da5365d
  43:     0x55b48b4c79fe - marker_utils::visitor::traverse_item::h6e6864935b44afca
  44:     0x55b48b4c1360 - <marker_rustc_driver::lint_pass::RustcLintPass as rustc_lint::passes::LateLintPass>::check_crate::hc24059d54fd29dcb
  45:     0x7fd71c5dacc7 - <rustc_session[b6932d4e5e79a3c2]::session::Session>::time::<(), rustc_lint[e0df64bfbaf459ee]::late::check_crate::{closure#0}::{closure#0}>
  46:     0x7fd71c5d9999 - <core[328660574c6e17ab]::panic::unwind_safe::AssertUnwindSafe<rustc_interface[5749929743a7739d]::passes::analysis::{closure#5}::{closure#1}::{closure#2}> as core[328660574c6e17ab]::ops::function::FnOnce<()>>::call_once
  47:     0x7fd71c5d970f - <core[328660574c6e17ab]::panic::unwind_safe::AssertUnwindSafe<rustc_interface[5749929743a7739d]::passes::analysis::{closure#5}::{closure#1}> as core[328660574c6e17ab]::ops::function::FnOnce<()>>::call_once
  48:     0x7fd71c5d9138 - <rustc_session[b6932d4e5e79a3c2]::session::Session>::time::<(), rustc_interface[5749929743a7739d]::passes::analysis::{closure#5}>
  49:     0x7fd71c5d6eb7 - rustc_interface[5749929743a7739d]::passes::analysis
  50:     0x7fd71c8e21fa - rustc_query_impl[54fb8ce76ffe27d7]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[54fb8ce76ffe27d7]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[4d497bf664395237]::query::erase::Erased<[u8; 1usize]>>
  51:     0x7fd71c8e21e9 - <rustc_query_impl[54fb8ce76ffe27d7]::query_impl::analysis::dynamic_query::{closure#2} as core[328660574c6e17ab]::ops::function::FnOnce<(rustc_middle[4d497bf664395237]::ty::context::TyCtxt, ())>>::call_once
  52:     0x7fd71cbc3018 - rustc_query_system[c8323b2e3373b6b6]::query::plumbing::try_execute_query::<rustc_query_impl[54fb8ce76ffe27d7]::DynamicConfig<rustc_query_system[c8323b2e3373b6b6]::query::caches::SingleCache<rustc_middle[4d497bf664395237]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[54fb8ce76ffe27d7]::plumbing::QueryCtxt, true>
  53:     0x7fd71cbc2b74 - rustc_query_impl[54fb8ce76ffe27d7]::query_impl::analysis::get_query_incr::__rust_end_short_backtrace
  54:     0x7fd71c6801e3 - <rustc_interface[5749929743a7739d]::queries::QueryResult<&rustc_middle[4d497bf664395237]::ty::context::GlobalCtxt>>::enter::<core[328660574c6e17ab]::result::Result<(), rustc_span[498346d9655021fc]::ErrorGuaranteed>, rustc_driver_impl[8d3f86e83538be5d]::run_compiler::{closure#1}::{closure#2}::{closure#6}>
  55:     0x7fd71c67f1ba - <rustc_interface[5749929743a7739d]::interface::Compiler>::enter::<rustc_driver_impl[8d3f86e83538be5d]::run_compiler::{closure#1}::{closure#2}, core[328660574c6e17ab]::result::Result<core[328660574c6e17ab]::option::Option<rustc_interface[5749929743a7739d]::queries::Linker>, rustc_span[498346d9655021fc]::ErrorGuaranteed>>
  56:     0x7fd71c67c4e8 - std[3de2780fbf87294b]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[5749929743a7739d]::util::run_in_thread_pool_with_globals<rustc_interface[5749929743a7739d]::interface::run_compiler<core[328660574c6e17ab]::result::Result<(), rustc_span[498346d9655021fc]::ErrorGuaranteed>, rustc_driver_impl[8d3f86e83538be5d]::run_compiler::{closure#1}>::{closure#0}, core[328660574c6e17ab]::result::Result<(), rustc_span[498346d9655021fc]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[328660574c6e17ab]::result::Result<(), rustc_span[498346d9655021fc]::ErrorGuaranteed>>
  57:     0x7fd71c67bc75 - <<std[3de2780fbf87294b]::thread::Builder>::spawn_unchecked_<rustc_interface[5749929743a7739d]::util::run_in_thread_pool_with_globals<rustc_interface[5749929743a7739d]::interface::run_compiler<core[328660574c6e17ab]::result::Result<(), rustc_span[498346d9655021fc]::ErrorGuaranteed>, rustc_driver_impl[8d3f86e83538be5d]::run_compiler::{closure#1}>::{closure#0}, core[328660574c6e17ab]::result::Result<(), rustc_span[498346d9655021fc]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[328660574c6e17ab]::result::Result<(), rustc_span[498346d9655021fc]::ErrorGuaranteed>>::{closure#1} as core[328660574c6e17ab]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  58:     0x7fd71a211425 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h07273d00f835f9f4
                               at /rustc/249595b7523fc07a99c1adee90b1947739ca0e5b/library/alloc/src/boxed.rs:2007:9
  59:     0x7fd71a211425 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hfd47bb1abc348520
                               at /rustc/249595b7523fc07a99c1adee90b1947739ca0e5b/library/alloc/src/boxed.rs:2007:9
  60:     0x7fd71a211425 - std::sys::unix::thread::Thread::new::thread_start::h98e1ddafb85f3672
                               at /rustc/249595b7523fc07a99c1adee90b1947739ca0e5b/library/std/src/sys/unix/thread.rs:108:17
  61:     0x7fd719f3cac3 - start_thread
                               at ./nptl/pthread_create.c:442:8
  62:     0x7fd719fcea40 - clone3
                               at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:81
  63:                0x0 - <unknown>

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

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

note: please attach the file at `/home/veetaha/sandbox/rust/rustc-ice-2023-10-22T01:36:17.256473866Z-2178294.txt` to your bug report

note: compiler flags: --crate-type bin -C embed-bitcode=no -C debuginfo=2 -C linker=clang -C incremental=[REDACTED] -C link-arg=-fuse-ld=/home/veetaha/apps/bin/mold

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: marker_rustc_driver 0.3.0 (76e7f1f 2023-10-05)

note: Achievement Unlocked: [Free Ice Cream]

error: could not compile `scratch` (bin "scratch")
  × linting finished with an error