rust-lang / cargo

The Rust package manager
https://doc.rust-lang.org/cargo
Apache License 2.0
12.82k stars 2.43k forks source link

Use cargo fix command not check [dependencies] crate code #11096

Open baoyachi opened 2 years ago

baoyachi commented 2 years ago

Problem

when use cargo fix command, does cargo ignore check dependencies crate code ,just fix check current repository code

error detail


➜  odbc-api-helper git:(main) rustc -V
rustc 1.63.0 (4b91a6ea7 2022-08-08)
➜  odbc-api-helper git:(main) rustup default 1.61.0
info: using existing install for '1.61.0-x86_64-apple-darwin'
info: default toolchain set to '1.61.0-x86_64-apple-darwin'

  1.61.0-x86_64-apple-darwin unchanged - rustc 1.61.0 (fe5b13d68 2022-05-18)

➜  odbc-api-helper git:(main) cargo fix
   Compiling libc v0.2.132
   Compiling proc-macro2 v1.0.43
   Compiling unicode-ident v1.0.3
   Compiling quote v1.0.21
   Compiling memchr v2.5.0
   Compiling syn v1.0.99
    Checking cfg-if v1.0.0
   Compiling autocfg v1.1.0
   Compiling version_check v0.9.4
   Compiling serde_derive v1.0.144
   Compiling typenum v1.15.0
   ...
    Checking miette v5.3.0
error[E0658]: use of unstable library feature 'bool_to_option'
   --> /Users/baoyachi/.cargo/registry/src/github.com-1ecc6299db9ec823/odbc-api-0.49.0/src/cursor.rs:572:24
    |
572 |             Ok(has_row.then_some(&self.buffer))
    |                        ^^^^^^^^^
    |
    = note: see issue #80967 <https://github.com/rust-lang/rust/issues/80967> for more information

error[E0658]: use of unstable library feature 'bool_to_option'
   --> /Users/baoyachi/.cargo/registry/src/github.com-1ecc6299db9ec823/odbc-api-0.49.0/src/cursor.rs:429:24
    |
429 |             Ok(has_row.then_some(&self.buffer))
    |                        ^^^^^^^^^
    |
    = note: see issue #80967 <https://github.com/rust-lang/rust/issues/80967> for more information

error[E0658]: use of unstable library feature 'bool_to_option'
   --> /Users/baoyachi/.cargo/registry/src/github.com-1ecc6299db9ec823/odbc-api-0.49.0/src/handles/environment.rs:228:24
    |
228 |         .map(|res| res.then_some((length_description, length_attributes)))
    |                        ^^^^^^^^^
    |
    = note: see issue #80967 <https://github.com/rust-lang/rust/issues/80967> for more information

error[E0658]: use of unstable library feature 'bool_to_option'
   --> /Users/baoyachi/.cargo/registry/src/github.com-1ecc6299db9ec823/odbc-api-0.49.0/src/handles/environment.rs:270:24
    |
270 |         .map(|res| res.then_some((length_name, length_description)))
    |                        ^^^^^^^^^
    |
    = note: see issue #80967 <https://github.com/rust-lang/rust/issues/80967> for more information

For more information about this error, try `rustc --explain E0658`.
error: could not compile `odbc-api` due to 4 previous errors
warning: build failed, waiting for other jobs to finish...
➜  odbc-api-helper git:(main) 

Proposed Solution

just cargo fix check current repository code,and fix

Notes

No response

weihanglo commented 2 years ago

Thanks for the report. I believe this is the default behaviour for all compilation commands in Cargo.

Those errors you saw were actually non-fixable with cargo fix. Cargo fix does its job by taking rustc's diagnostic suggestions and apply them to your source code. Without succeeding to compile dependencies, cargo cannot proceed to "fix" your crate. You will get the same errors when performing a cargo build as well.

One way to improve the error message is the author of odbc-api adding rust-version field in Cargo.toml. The rust-version field would be checked upfront, so you won't get those detailed error messages from dependencies.

error: package `foo v0.0.1 (/projects/foo)` cannot be built 
because it requires rustc 1.9876.0 or newer, 
while the currently active rustc version is 1.63.0

I am not sure how Cargo can improve at this moment. Do you have any further suggestion?