diff --git a/src/cargo/ops/lockfile.rs b/src/cargo/ops/lockfile.rs index 8743520ad0c..2a1b1db39dd 100644 --- a/src/cargo/ops/lockfile.rs +++ b/src/cargo/ops/lockfile.rs @@ -47,7 +47,7 @@ pub fn write_pkg_lockfile(ws: &Workspace<'_>, resolve: &mut Resolve) -> CargoRes } if !ws.config().lock_update_allowed() { - let flag = if ws.config().network_allowed() { + let flag = if ws.config().locked() { "--locked" } else { "--frozen" diff --git a/tests/testsuite/offline.rs b/tests/testsuite/offline.rs index 722f59767a5..28f2b543ded 100644 --- a/tests/testsuite/offline.rs +++ b/tests/testsuite/offline.rs @@ -700,3 +700,16 @@ remove the --frozen flag and use --offline instead. ") .run(); } + +#[cargo_test] +fn offline_and_locked_and_no_frozen() { + let p = project().file("src/lib.rs", "").build(); + p.cargo("build --locked --offline") + .with_status(101) + .with_stderr("\ +error: the lock file [ROOT]/foo/Cargo.lock needs to be updated but --locked was passed to prevent this +If you want to try to generate the lock file without accessing the network, \ +remove the --locked flag and use --offline instead. +") + .run(); +}