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

cargo check does not see missing functions #11765

Closed
Mingun opened this issue Feb 24, 2023 · 4 comments
Closed

cargo check does not see missing functions #11765

Mingun opened this issue Feb 24, 2023 · 4 comments
Labels
C-bug Category: bug

Comments

@Mingun
Copy link

Mingun commented Feb 24, 2023

Problem

I found this when tried to reproduce user bug report, as I initially described here: #11762

I found that cargo minimal-versions check (which in the end calls cargo check) does not report the obvious error, but cargo minimal-versions build (which in the end calls cargo build) reports it.

Because functions memchr2 and memchr3 that used by quick-xml was added only in memchr v2.1 (see tafia/quick-xml#562), both commands should definitely fail. According to the description of the cargo check, only code generation step is omitted and missing function is obviously should be detected on early step of compilation.

Steps

  1. Install tools:
    cargo install cargo-hack
    cargo install cargo-versions
  2. Checkout tafia/quick-xml@f0b3420
  3. Apply the patch:
    diff --git a/Cargo.toml b/Cargo.toml
    index 872da6ba..61a41d84 100644
    --- a/Cargo.toml
    +++ b/Cargo.toml
    @@ -17,17 +17,13 @@ include = ["src/*", "LICENSE-MIT.md", "README.md"]
     document-features = { version = "0.2", optional = true }
     encoding_rs = { version = "0.8", optional = true }
     serde = { version = "1.0.100", optional = true }
    -tokio = { version = "1.0", optional = true, default-features = false, features = ["io-util"] }
     memchr = "2.0"
    
     [dev-dependencies]
    -criterion = "0.4"
     pretty_assertions = "1.3"
     regex = "1"
     serde = { version = "1.0", features = ["derive"] }
     serde-value = "0.7"
    -tokio = { version = "1.21", default-features = false, features = ["macros", "rt"] }
    -tokio-test = "0.4"
    
     [lib]
     bench = false
    @@ -49,7 +45,6 @@ default = []
     ## [reading events] from types implementing [`tokio::io::AsyncBufRead`].
     ##
     ## [reading events]: crate::reader::Reader::read_event_into_async
    -async-tokio = ["tokio"]
    
     ## Enables support of non-UTF-8 encoded documents. Encoding will be inferred from
     ## the XML declaration if it will be found, otherwise UTF-8 is assumed.
  4. Run cargo minimal-versions check -- no errors:
    PS D:\Projects\quick-xml> cargo minimal-versions check
    info: running `cargo update -Z minimal-versions`
        Updating crates.io index
        Removing aho-corasick v0.7.20
        Removing autocfg v1.1.0
        Updating cfg-if v1.0.0 -> v0.1.0
        Removing ctor v0.1.26
        Removing diff v0.1.13
        Updating document-features v0.2.7 -> v0.2.0
        Updating encoding_rs v0.8.32 -> v0.8.0
          Adding libc v0.2.18
        Removing litrs v0.2.3
        Updating memchr v2.5.0 -> v2.0.0
        Removing num-traits v0.2.15
        Removing ordered-float v2.10.0
        Removing output_vt100 v0.1.3
        Removing pretty_assertions v1.3.0
        Removing proc-macro2 v1.0.51
        Updating quote v1.0.23 -> v0.3.8
        Removing regex v1.7.1
        Removing regex-syntax v0.6.28
        Updating serde v1.0.152 -> v1.0.100
        Removing serde-value v0.7.0
        Updating serde_derive v1.0.152 -> v1.0.0
          Adding serde_derive_internals v0.15.0
        Updating syn v1.0.109 -> v0.11.10
          Adding synom v0.11.0
        Removing unicode-ident v1.0.6
          Adding unicode-xid v0.0.4
        Removing winapi v0.3.9
        Removing winapi-i686-pc-windows-gnu v0.4.0
        Removing winapi-x86_64-pc-windows-gnu v0.4.0
        Removing yansi v0.5.1
    info: running `cargo hack check`
    info: running `cargo check` on quick-xml (1/1)
        Finished dev [unoptimized + debuginfo] target(s) in 0.02s
    PS D:\Projects\quick-xml>
  5. Run cargo minimal-versions build -- see errors:
    PS D:\Projects\quick-xml> cargo minimal-versions build
    info: running `cargo update -Z minimal-versions`
        Updating crates.io index
        Removing aho-corasick v0.7.20
        Removing autocfg v1.1.0
        Updating cfg-if v1.0.0 -> v0.1.0
        Removing ctor v0.1.26
        Removing diff v0.1.13
        Updating document-features v0.2.7 -> v0.2.0
        Updating encoding_rs v0.8.32 -> v0.8.0
          Adding libc v0.2.18
        Removing litrs v0.2.3
        Updating memchr v2.5.0 -> v2.0.0
        Removing num-traits v0.2.15
        Removing ordered-float v2.10.0
        Removing output_vt100 v0.1.3
        Removing pretty_assertions v1.3.0
        Removing proc-macro2 v1.0.51
        Updating quote v1.0.23 -> v0.3.8
        Removing regex v1.7.1
        Removing regex-syntax v0.6.28
        Updating serde v1.0.152 -> v1.0.100
        Removing serde-value v0.7.0
        Updating serde_derive v1.0.152 -> v1.0.0
          Adding serde_derive_internals v0.15.0
        Updating syn v1.0.109 -> v0.11.10
          Adding synom v0.11.0
        Removing unicode-ident v1.0.6
          Adding unicode-xid v0.0.4
        Removing winapi v0.3.9
        Removing winapi-i686-pc-windows-gnu v0.4.0
        Removing winapi-x86_64-pc-windows-gnu v0.4.0
        Removing yansi v0.5.1
    info: running `cargo hack build`
    info: running `cargo build` on quick-xml (1/1)
       Compiling libc v0.2.18
       Compiling memchr v2.0.0
       Compiling quick-xml v0.27.1 (D:\Projects\quick-xml)
    error[E0432]: unresolved import `memchr::memchr2_iter`
     --> src\escapei.rs:3:5
      |
    3 | use memchr::memchr2_iter;
      |     ^^^^^^^^^^^^^^^^^^^^ no `memchr2_iter` in the root
    
    error[E0425]: cannot find function `memchr_iter` in crate `memchr`
      --> src\reader\parser.rs:96:46
       |
    96 |                     if let Some(p) = memchr::memchr_iter(b'-', &buf[3..len - 2])
       |                                              ^^^^^^^^^^^ not found in `memchr`
    
    error[E0425]: cannot find function `memchr_iter` in crate `memchr`
       --> src\reader\mod.rs:773:26
        |
    773 |         for i in memchr::memchr_iter(b'>', chunk) {
        |                          ^^^^^^^^^^^ not found in `memchr`
    
    error[E0425]: cannot find function `memchr2_iter` in crate `memchr`
       --> src\reader\mod.rs:815:43
        |
    815 |                     let balance = memchr::memchr2_iter(b'<', b'>', content)
        |                                           ^^^^^^^^^^^^ not found in `memchr`
    
    error[E0425]: cannot find function `memchr3_iter` in crate `memchr`
       --> src\reader\mod.rs:853:26
        |
    853 |         for i in memchr::memchr3_iter(b'>', b'\'', b'"', chunk) {
        |                          ^^^^^^^^^^^^ not found in `memchr`
    
    Some errors have detailed explanations: E0425, E0432.
    For more information about an error, try `rustc --explain E0425`.
    error: could not compile `quick-xml` due to 5 previous errors
    error: process didn't exit successfully: `\\?\D:\Users\mingun\.rustup\toolchains\nightly-x86_64-pc-windows-gnu\bin\cargo.exe build --manifest-path Cargo.toml` (exit code: 101)
    error: process didn't exit successfully: `\\?\D:\Users\mingun\.rustup\toolchains\nightly-x86_64-pc-windows-gnu\bin\cargo.exe hack build` (exit code: 1)
    PS D:\Projects\quick-xml>

Possible Solution(s)

No response

Notes

No response

Version

cargo 1.69.0-nightly (9d5b32f50 2023-02-22)
release: 1.69.0-nightly
commit-hash: 9d5b32f503fc099c4064298465add14d4bce11e6
commit-date: 2023-02-22
host: x86_64-pc-windows-gnu
libgit2: 1.5.0 (sys:0.16.0 vendored)
libcurl: 7.86.0-DEV (sys:0.4.59+curl-7.86.0 vendored ssl:Schannel)
os: Windows 6.1.7601 (Windows 7 Professional) [64-bit]
@Mingun Mingun added the C-bug Category: bug label Feb 24, 2023
@Mingun Mingun changed the title cargo check seems to not respect crate versions? cargo check does not see missing functions Feb 24, 2023
@epage
Copy link
Contributor

epage commented Feb 24, 2023

Can you reproduce this directly, without using a wrapper around cargo? You shouldn't even need the unstable feature for this but a repro repo with a Cargo.lock file.

@Mingun
Copy link
Author

Mingun commented Feb 24, 2023

Probably I found the cause. I run all commands from VSCode integrated terminal, and of course I have working rust-analyzer LSP. It seems that LSP overrides the Cargo.lock file each time when I tried to run cargo minimal-versions check and the updated file (with the latest versions of dependencies) is used when cargo-minimal-versions runs cargo check. So the timeline seems the follow:

  • I run cargo minimal-versions check
  • cargo-minimal-versions runs cargo update -Z minimal-versions
  • Cargo.lock is updated to contain minimal versions
  • rust-analyzer see the changes and updates project. Cargo.lock is updated again to the latest versions
  • cargo-minimal-versions runs cargo check
  • Check is performed using versions from Cargo.lock

When I close VSCode and tried to reproduce my case from console, error is always generated. Seems this is the error in cargo-minimal-versions, which should lock file until testing is done, but I'm unsure could this prevent it from doing it's work (if cargo check will require to lock file that is already locked...). So if this is the problem for cargo-minimal-versions I suggest to convert this issue to the issue for fixing that problem, if some actions is required from cargo side. Feel free to close if you don't like such approach.

@Mingun
Copy link
Author

Mingun commented Feb 24, 2023

I'm not sure, however, how it is possible, that Cargo.lock is updated without explicit user command. After all, its goal is precisely that such random updates do not come?

@taiki-e, could you look at this, is that possible scenario, that Cargo.lock could be unintentionally updated during cargo-minimal-versions work? The @rust-analyzer team also could be interested to check if that is possible.

@epage
Copy link
Contributor

epage commented Feb 24, 2023

As this doesn't sound like a bug in cargo, I'm going to go ahead and close.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

2 participants