I still don't understand "cargo upgrade"

My rough understanding was, that cargo update does a compatible update of Cargo.toml, cargo upgrades is looking for available updates, and finally cargo upgrade makes all upgrades, but might ask for a flag for incompatible versions.

But what I typically get is

stefan@hx90 /tmp/xilem-chess $ cat Cargo.toml 
[package]
name = "xilem-chess"
version = "0.5.0"
edition = "2024"

[dependencies]
num-traits = "0.2.19"
tokio = "1.49.0"
winit = "0.30.12"

#xilem   = { git = "https://github.com/linebender/xilem.git", rev = "5281ffb308732b00f42e0755c6095b6ae234ae16" }
#xilem_core = { git = "https://github.com/linebender/xilem.git", rev = "5281ffb308732b00f42e0755c6095b6ae234ae16" }
#masonry = { git = "https://github.com/linebender/xilem.git", rev = "5281ffb308732b00f42e0755c6095b6ae234ae16" }
#masonry_winit = { git = "https://github.com/linebender/xilem.git", rev = "5281ffb308732b00f42e0755c6095b6ae234ae16" }

xilem   = { git = "https://github.com/linebender/xilem.git"}
xilem_core = { git = "https://github.com/linebender/xilem.git"}
masonry = { git = "https://github.com/linebender/xilem.git"}
masonry_winit = { git = "https://github.com/linebender/xilem.git"}

[profile.dev]
opt-level = 2

[profile.release]
opt-level = 2
#codegen-units = 1
strip = true  # Automatically strip symbols from the binary.
lto = false
panic = "abort"

[features]
salewskiChessDebug = []

stefan@hx90 /tmp/xilem-chess $ cargo upgrades
All dependencies match up-to-date releases.
Run `cargo update` to update to latest release.
stefan@hx90 /tmp/xilem-chess $ cargo update
    Updating git repository `https://github.com/linebender/xilem.git`
    Updating crates.io index
     Locking 0 packages to latest Rust 1.94.0 compatible versions
stefan@hx90 /tmp/xilem-chess $ cargo upgrade
    Checking xilem-chess's dependencies
name  old req compatible latest  new req
====  ======= ========== ======  =======
tokio 1.49.0  1.50.0     1.50.0  1.50.0 
winit 0.30.12 0.30.13    0.30.13 0.30.13
   Upgrading git dependencies
     Locking 0 packages to latest Rust 1.94.0 compatible versions
   Upgrading recursive dependencies
     Locking 0 packages to latest Rust 1.94.0 compatible versions
note: Re-run with `--verbose` to show more dependencies
  git: 4 packages
  latest: num-traits
stefan@hx90 /tmp/xilem-chess $ cat Cargo.toml 
[package]
name = "xilem-chess"
version = "0.5.0"
edition = "2024"

[dependencies]
num-traits = "0.2.19"
tokio = "1.50.0"
winit = "0.30.13"

#xilem   = { git = "https://github.com/linebender/xilem.git", rev = "5281ffb308732b00f42e0755c6095b6ae234ae16" }
#xilem_core = { git = "https://github.com/linebender/xilem.git", rev = "5281ffb308732b00f42e0755c6095b6ae234ae16" }
#masonry = { git = "https://github.com/linebender/xilem.git", rev = "5281ffb308732b00f42e0755c6095b6ae234ae16" }
#masonry_winit = { git = "https://github.com/linebender/xilem.git", rev = "5281ffb308732b00f42e0755c6095b6ae234ae16" }

xilem   = { git = "https://github.com/linebender/xilem.git"}
xilem_core = { git = "https://github.com/linebender/xilem.git"}
masonry = { git = "https://github.com/linebender/xilem.git"}
masonry_winit = { git = "https://github.com/linebender/xilem.git"}

[profile.dev]
opt-level = 2

[profile.release]
opt-level = 2
#codegen-units = 1
strip = true  # Automatically strip symbols from the binary.
lto = false
panic = "abort"

[features]
salewskiChessDebug = []

stefan@hx90 /tmp/xilem-chess $ 

So often cargo upgrades tells me there is nothing to do. But then cargo upgrade still is able to do upgrades.

From quickly glancing at the source code of cargo-upgrades, it looks to me like the version requirement declaration from your manifest is checked against the latest version of the dependency and only if the latest version isn't covered by the declaration does cargo upgrades tell you to upgrade your version requirement. cargo upgrade seemingly doesn't follow the same rule, upgrading version requirements even if the latest version would be covered by the existing requirement declaration.

1 Like