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

clippy fails to check project but no error shown, due to doc comment #6022

Closed
matthiaskrgr opened this issue Sep 9, 2020 · 14 comments · Fixed by #6458
Closed

clippy fails to check project but no error shown, due to doc comment #6022

matthiaskrgr opened this issue Sep 9, 2020 · 14 comments · Fixed by #6458
Labels
C-bug Category: Clippy is not doing the correct thing

Comments

@matthiaskrgr
Copy link
Member

matthiaskrgr commented Sep 9, 2020

EDIT: reduced even further by @keiichiw

/// ```
/// 'a()'
/// ```
fn main() {}

git clone https://github.com/rust-lang/cargo
cd cargo
git checkout 875e0123259b0b6299903fe4aea0a12ecde9324f
cargo check --all-features --all-targets
find . | grep \.rs$ | xargs touch
cargo clippy --all-features --all-targets

This throws an error on my machine but it does not say what the actual problem is, as if something was eating the error message:

    Checking cargo-test-support v0.1.0 (/home/matthias/vcs/github/cargo/crates/cargo-test-support)
warning: calling `push_str()` using a single-character string literal
   --> src/bin/cargo/cli.rs:121:5
    |
121 |     version_string.push_str("\n");
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `push` with a character literal: `version_string.push('\n')`
    |
    = note: `#[warn(clippy::single_char_push_str)]` on by default
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_char_push_str

warning: 1 warning emitted

warning: unneeded `return` statement
   --> crates/cargo-test-support/src/cross_compile.rs:219:13
    |
219 |             return true;
    |             ^^^^^^^^^^^^ help: remove `return`: `true`
    |
    = note: `#[warn(clippy::needless_return)]` on by default
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return

warning: unneeded `return` statement
   --> crates/cargo-test-support/src/cross_compile.rs:222:13
    |
222 |             return false;
    |             ^^^^^^^^^^^^^ help: remove `return`: `false`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return

warning: unneeded `return` statement
   --> crates/cargo-test-support/src/cross_compile.rs:226:9
    |
226 |         return true;
    |         ^^^^^^^^^^^^ help: remove `return`: `true`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return

warning: 3 warnings emitted

error: could not compile `cargo-test-support`.

I tried cargo check but that seems to work and does not throw any errors.

Meta

clippy 0.0.212 (5099914 2020-09-08)


rustc 1.48.0-nightly (5099914a1 2020-09-08)
binary: rustc
commit-hash: 5099914a16a215794ad243df0cc7a05d91d168e0
commit-date: 2020-09-08
host: x86_64-unknown-linux-gnu
release: 1.48.0-nightly
LLVM version: 11.0
@matthiaskrgr matthiaskrgr added the C-bug Category: Clippy is not doing the correct thing label Sep 9, 2020
@matthiaskrgr
Copy link
Member Author

I tried to poke around with some debug prints but I'm still not sure what causes this...

diff --git a/src/main.rs b/src/main.rs
index ea0674339..05b5abfeb 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -53,7 +53,7 @@ pub fn main() {
         return;
     }

-    if let Err(code) = process(env::args().skip(2)) {
+if let Err(code) = dbg!(process(env::args().skip(2))) {
         process::exit(code);
     }
 }
@@ -157,12 +157,12 @@ impl ClippyCmd {
             .collect();

         cmd.env(self.path_env(), Self::path())
-            .envs(ClippyCmd::target_dir())
-            .env("CLIPPY_ARGS", clippy_args)
-            .arg(self.cargo_subcommand)
+            .envs(dbg!(ClippyCmd::target_dir()))
+            .env("CLIPPY_ARGS", dbg!(clippy_args))
+            .arg(dbg!(self.cargo_subcommand))
             .args(&self.args);

-        cmd
+        dbg!(cmd)
     }
 }

@@ -172,7 +172,7 @@ where
 {
     let cmd = ClippyCmd::new(old_args);

-    let mut cmd = cmd.into_std_cmd();
+    let mut cmd = dbg!(cmd.into_std_cmd());

     let exit_status = cmd
         .spawn()
@@ -180,6 +180,8 @@ where
         .wait()
         .expect("failed to wait for cargo?");

+    dbg!(exit_status);
+
     if exit_status.success() {
         Ok(())
     } else {

cargo-clippy --verbose -j 1 --all-targets

[src/main.rs:160] ClippyCmd::target_dir() = None
[src/main.rs:161] clippy_args = ""
[src/main.rs:162] self.cargo_subcommand = "check"
[src/main.rs:165] cmd = "cargo" "check" "-j" "1" "--all-targets"
[src/main.rs:175] cmd.into_std_cmd() = "cargo" "check" "-j" "1" "--all-targets"
* clippy warnings *
[src/main.rs:183] exit_status = ExitStatus(
    ExitStatus(
        25856,
    ),
)
[src/main.rs:56] process(env::args().skip(2)) = Err(
    101,
)

@matthiaskrgr
Copy link
Member Author

Hmm, happens major release stable-x86_64-unknown-linux-gnu unchanged - rustc 1.48.0 (7eac88abb 2020-11-16)

@phansch
Copy link
Member

phansch commented Dec 12, 2020

Someone encountered the same exit code in cargo here: rust-lang/cargo#7147

Maybe this is caused by our cargo tests?

@matthiaskrgr
Copy link
Member Author

Maybe this is caused by our cargo tests?

I would be very surprised since clippy should not execute cargo tests. I also don't understand why cargo should lock the cargo_home for clippy, hm...

For the record I wondered if cargo clippy -Zunstable-options could be a culprint but it was added in cargo 1.44 and not in cargo 1.48.

@phansch
Copy link
Member

phansch commented Dec 13, 2020

Oh wait, I meant cargo lints not tests 😅

@matthiaskrgr
Copy link
Member Author

cargo_common_metadata fires on the crate if it is enabled (it's allow by default) but I could not find any other culprints :/

@ghost
Copy link

ghost commented Dec 14, 2020

Isn't this because cargo has a feature to deny warnings? You were running with --all-features.

@matthiaskrgr
Copy link
Member Author

I don't think this is the cause.
The mysterious error also happens when I check the cargo-test-support crate directly and it does not have any features and does not seem to deny warnings.

@matthiaskrgr
Copy link
Member Author

So, I spent a some time reducing the issue and came down to this (as main.rs):

/// Adds a platform-specific dependency. Example:
/// ```
/// [target.'cfg(windows)'.dependencies]
/// foo = {version = "1.0"}
/// ```
fn main() {
    println!("Hello, world!");
}

The problem seems to be the doc comment.

@matthiaskrgr matthiaskrgr changed the title clippy fails to check project but no error message is shown clippy fails to check project but no error shown, due to doc comment Dec 14, 2020
@keiichiw
Copy link

I made it a bit smaller.

/// ```
/// 'a()'
/// ```
fn main() {}

@flip1995
Copy link
Member

flip1995 commented Dec 15, 2020

I tested this a bit more, and it seems, that something with the string parsing/lexing in doc comments goes wrong. This happens when a string is not properly enclosed, like

r#"hi"
"a
"
'

All of this produces an error without a message when put in the doc comment.

The example by @keiichiw is kind of an outlier. IIUC it parses 'a as a lifetime, () as the unit type (?), and then trips over the trailing '. The error goes away if only [a-zA-Z0-9_] are used between the single quotes (aka chars allowed in an ident).

Maybe a bug in pulldown_cmark?

@ebroto
Copy link
Member

ebroto commented Dec 15, 2020

We're interpreting the fenced code block as rust code (there's no label), and the parser chokes, so there's a panic.

I'll see what would be the best way to recover from this later.

Backtrace
0  std::panicking::rust_panic () at library/std/src/panicking.rs:640
1  0x00007ffff32b9ae2 in std::panicking::rust_panic_without_hook () at library/std/src/panicking.rs:630
2  0x00007ffff32ae136 in std::panic::resume_unwind () at library/std/src/panic.rs:426
3  0x00007ffff6e79673 in rustc_span::fatal_error::FatalError::raise ()
   from /home/ebroto/.rustup/toolchains/nightly-2020-12-14-x86_64-unknown-linux-gnu/lib/librustc_driver-17b8b01089c6566b.so
4  0x00007ffff5e32dc0 in rustc_parse::lexer::StringReader::report_unterminated_raw_string ()
   from /home/ebroto/.rustup/toolchains/nightly-2020-12-14-x86_64-unknown-linux-gnu/lib/librustc_driver-17b8b01089c6566b.so
5  0x00007ffff5e31e4f in rustc_parse::lexer::StringReader::next_token ()
   from /home/ebroto/.rustup/toolchains/nightly-2020-12-14-x86_64-unknown-linux-gnu/lib/librustc_driver-17b8b01089c6566b.so
6  0x00007ffff5de6712 in rustc_parse::lexer::tokentrees::TokenTreesReader::parse_all_token_trees ()
   from /home/ebroto/.rustup/toolchains/nightly-2020-12-14-x86_64-unknown-linux-gnu/lib/librustc_driver-17b8b01089c6566b.so
7  0x00007ffff5e2fe9a in rustc_parse::lexer::parse_token_trees () from /home/ebroto/.rustup/toolchains/nightly-2020-12-14-x86_64-unknown-linux-gnu/lib/librustc_driver-17b8b01089c6566b.so
8  0x00007ffff5e2bec9 in rustc_parse::maybe_file_to_stream () from /home/ebroto/.rustup/toolchains/nightly-2020-12-14-x86_64-unknown-linux-gnu/lib/librustc_driver-17b8b01089c6566b.so
9  0x00007ffff5e2bb18 in rustc_parse::maybe_source_file_to_parser () from /home/ebroto/.rustup/toolchains/nightly-2020-12-14-x86_64-unknown-linux-gnu/lib/librustc_driver-17b8b01089c6566b.so
10 0x00007ffff5e2b6e7 in rustc_parse::maybe_new_parser_from_source_str ()
   from /home/ebroto/.rustup/toolchains/nightly-2020-12-14-x86_64-unknown-linux-gnu/lib/librustc_driver-17b8b01089c6566b.so
11 0x00005555559b327f in clippy_lints::doc::check_code::has_needless_main (code=...) at clippy_lints/src/doc.rs:462
12 0x00005555559b2f12 in clippy_lints::doc::check_code (cx=0x7fffee43d9f0, text=..., span=...) at clippy_lints/src/doc.rs:513
13 0x0000555555b682be in clippy_lints::doc::check_doc (cx=0x7fffee43d9f0, valid_idents=0x7fffe82ce160, events=..., spans=...) at clippy_lints/src/doc.rs:439
14 0x00005555559b2d93 in clippy_lints::doc::check_attrs (cx=0x7fffee43d9f0, valid_idents=0x7fffe82ce160, attrs=...) at clippy_lints/src/doc.rs:377
15 0x00005555559b158d in <clippy_lints::doc::DocMarkdown as rustc_lint::passes::LateLintPass>::check_item (self=0x7fffe82ce160, cx=0x7fffee43d9f0, item=0x7fffe8211698)
    at clippy_lints/src/doc.rs:175
16 0x00007ffff5f3d5b0 in <rustc_lint::late::LateLintPassObjects as rustc_lint::passes::LateLintPass>::check_item ()
   from /home/ebroto/.rustup/toolchains/nightly-2020-12-14-x86_64-unknown-linux-gnu/lib/librustc_driver-17b8b01089c6566b.so
17 0x00007ffff3da215c in rustc_hir::intravisit::Visitor::visit_nested_item ()
   from /home/ebroto/.rustup/toolchains/nightly-2020-12-14-x86_64-unknown-linux-gnu/lib/librustc_driver-17b8b01089c6566b.so
18 0x00007ffff3d1e4de in rustc_hir::intravisit::walk_crate () from /home/ebroto/.rustup/toolchains/nightly-2020-12-14-x86_64-unknown-linux-gnu/lib/librustc_driver-17b8b01089c6566b.so
19 0x00007ffff3d88bbc in rustc_lint::late::late_lint_pass_crate () from /home/ebroto/.rustup/toolchains/nightly-2020-12-14-x86_64-unknown-linux-gnu/lib/librustc_driver-17b8b01089c6566b.so
20 0x00007ffff3d8f9e1 in rustc_session::utils::<impl rustc_session::session::Session>::time ()
   from /home/ebroto/.rustup/toolchains/nightly-2020-12-14-x86_64-unknown-linux-gnu/lib/librustc_driver-17b8b01089c6566b.so
21 0x00007ffff3db56c8 in <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once ()
   from /home/ebroto/.rustup/toolchains/nightly-2020-12-14-x86_64-unknown-linux-gnu/lib/librustc_driver-17b8b01089c6566b.so
22 0x00007ffff3d91758 in rustc_session::utils::<impl rustc_session::session::Session>::time ()
   from /home/ebroto/.rustup/toolchains/nightly-2020-12-14-x86_64-unknown-linux-gnu/lib/librustc_driver-17b8b01089c6566b.so
23 0x00007ffff3dd3920 in rustc_interface::passes::analysis () from /home/ebroto/.rustup/toolchains/nightly-2020-12-14-x86_64-unknown-linux-gnu/lib/librustc_driver-17b8b01089c6566b.so
24 0x00007ffff3bde27b in rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::analysis>::compute () from /home/ebroto/.rustup/toolchains/nightly-2020-12-14-x86_64-unknown-linux-gnu/lib/librustc_driver-17b8b01089c6566b.so
25 0x00007ffff3bbc396 in rustc_query_system::dep_graph::graph::DepGraph<K>::with_eval_always_task ()
   from /home/ebroto/.rustup/toolchains/nightly-2020-12-14-x86_64-unknown-linux-gnu/lib/librustc_driver-17b8b01089c6566b.so
26 0x00007ffff3bcf8f6 in rustc_data_structures::stack::ensure_sufficient_stack ()
   from /home/ebroto/.rustup/toolchains/nightly-2020-12-14-x86_64-unknown-linux-gnu/lib/librustc_driver-17b8b01089c6566b.so
27 0x00007ffff3b5f685 in rustc_query_system::query::plumbing::get_query_impl ()
   from /home/ebroto/.rustup/toolchains/nightly-2020-12-14-x86_64-unknown-linux-gnu/lib/librustc_driver-17b8b01089c6566b.so
28 0x00007ffff3be118f in rustc_interface::passes::QueryContext::enter ()
   from /home/ebroto/.rustup/toolchains/nightly-2020-12-14-x86_64-unknown-linux-gnu/lib/librustc_driver-17b8b01089c6566b.so
29 0x00007ffff3b1b355 in rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter ()
   from /home/ebroto/.rustup/toolchains/nightly-2020-12-14-x86_64-unknown-linux-gnu/lib/librustc_driver-17b8b01089c6566b.so
30 0x00007ffff3b9c297 in rustc_span::with_source_map () from /home/ebroto/.rustup/toolchains/nightly-2020-12-14-x86_64-unknown-linux-gnu/lib/librustc_driver-17b8b01089c6566b.so
31 0x00007ffff3b1caab in rustc_interface::interface::create_compiler_and_run ()
   from /home/ebroto/.rustup/toolchains/nightly-2020-12-14-x86_64-unknown-linux-gnu/lib/librustc_driver-17b8b01089c6566b.so
32 0x00007ffff3bc92e0 in scoped_tls::ScopedKey<T>::set () from /home/ebroto/.rustup/toolchains/nightly-2020-12-14-x86_64-unknown-linux-gnu/lib/librustc_driver-17b8b01089c6566b.so
33 0x00007ffff3bd01a6 in std::sys_common::backtrace::__rust_begin_short_backtrace ()
   from /home/ebroto/.rustup/toolchains/nightly-2020-12-14-x86_64-unknown-linux-gnu/lib/librustc_driver-17b8b01089c6566b.so
34 0x00007ffff3b23f4a in core::ops::function::FnOnce::call_once{{vtable-shim}} ()
   from /home/ebroto/.rustup/toolchains/nightly-2020-12-14-x86_64-unknown-linux-gnu/lib/librustc_driver-17b8b01089c6566b.so
35 0x00007ffff32c947a in <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once () at /rustc/803c60218ffac3384b0063c1b87ae7944163bba7/library/alloc/src/boxed.rs:1328
36 <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once () at /rustc/803c60218ffac3384b0063c1b87ae7944163bba7/library/alloc/src/boxed.rs:1328
37 std::sys::unix::thread::Thread::new::thread_start () at library/std/src/sys/unix/thread.rs:71
38 0x00007ffff31cafb7 in start_thread (arg=<optimized out>) at pthread_create.c:486
39 0x00007ffff2fb72cf in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

dgreid pushed a commit to dgreid/crosvm that referenced this issue Dec 15, 2020
clippy 1.48.0 has a bug in string parsing in doc comments.
rust-lang/rust-clippy#6022

To avoid this issue, update to use double-quotation instead of single-quotation
inside a code block in a doc comment.

Also, this fixes wrong examples of commands there at the same time.

BUG=none
TEST=bin/clippy

Change-Id: I90e5699f6d4e839304f9d4e05e5c7b21467744cd
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2592001
Tested-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
@matthiaskrgr
Copy link
Member Author

Do you know why clippy did not properly panic here?
The fact that it only threw a bad exit status without giving details is a bit scary imo.

@ebroto
Copy link
Member

ebroto commented Dec 15, 2020

@matthiaskrgr yep, that happened because of two reasons:

  1. When parsing doctests, we throw away any diagnostic emitted by the parser. This makes sense as we only care about valid Rust code, but...
  2. When a fatal error is raised when parsing, a panic starts unwinding the stack unti we reach rustc_driver::catch_with_exit_code. There, if the panic was started by a fatal error, it is assumed the message was printed and that it's not an ICE, so the panic hook is not executed.

The PR adds a call to rustc_driver::catch_fatal_errors to avoid propagating the panic until catch_with_exit_code in driver.rs.

Note that stack unwinding is used during "normal operation", a fatal error is not an ICE.

@bors bors closed this as completed in 88323e8 Dec 18, 2020
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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants