diff --git a/src/ops/info.rs b/src/ops/info.rs index 85b07fd..668d49a 100644 --- a/src/ops/info.rs +++ b/src/ops/info.rs @@ -36,6 +36,7 @@ pub fn info( let ws = nearest_manifest_path .as_ref() .and_then(|root| Workspace::new(root, gctx).ok()); + validate_locked_and_frozen_options(ws.is_some(), gctx)?; let nearest_package = ws.as_ref().and_then(|ws| { nearest_manifest_path .as_ref() @@ -48,8 +49,6 @@ pub fn info( package_id = None; } - validate_locked_and_frozen_options(package_id, gctx)?; - let msrv_from_nearest_manifest_path_or_ws = try_get_msrv_from_nearest_manifest_or_ws(nearest_package, ws.as_ref()); // If the workspace does not have a specific Rust version, @@ -364,12 +363,11 @@ fn api_registry( } fn validate_locked_and_frozen_options( - package_id: Option, + in_workspace: bool, gctx: &GlobalContext, ) -> Result<(), anyhow::Error> { - let from_workspace = package_id.is_some(); // Only in workspace, we can use --frozen or --locked. - if !from_workspace { + if !in_workspace { if gctx.locked() { anyhow::bail!("the option `--locked` can only be used within a workspace"); } diff --git a/tests/testsuite/cargo_information/with_frozen_within_ws/stderr.log b/tests/testsuite/cargo_information/with_frozen_within_ws/stderr.log index 55fff25..c96d52b 100644 --- a/tests/testsuite/cargo_information/with_frozen_within_ws/stderr.log +++ b/tests/testsuite/cargo_information/with_frozen_within_ws/stderr.log @@ -1 +1 @@ -error: the option `--frozen` can only be used within a workspace +error: could not find `unknown` in registry `[ROOTURL]/registry` diff --git a/tests/testsuite/cargo_information/with_locked_within_ws/stderr.log b/tests/testsuite/cargo_information/with_locked_within_ws/stderr.log index 83c0352..7cea0f7 100644 --- a/tests/testsuite/cargo_information/with_locked_within_ws/stderr.log +++ b/tests/testsuite/cargo_information/with_locked_within_ws/stderr.log @@ -1,2 +1,2 @@ Updating `dummy-registry` index -error: the option `--locked` can only be used within a workspace +error: could not find `unknown` in registry `[ROOTURL]/registry`