Cargo_bin! deprecated

I am very confused by this error message

Warning: use of deprecated function `assert_cmd::cargo::cargo_bin`: incompatible with a custom cargo build-dir, see instead `cargo::cargo_bin!`
 --> horned-bin/tests/test_horned_validate.rs:1:24
  |
1 | use assert_cmd::cargo::cargo_bin;
  |                        ^^^^^^^^^

I have been trying to update my code to remove a deprecation warning message.

I have previously been using Command in assert_cmd::cmd - Rust which has clearly been deprecated. So, I have updated by code to use cargo_bin! as suggested. It now looks like this:

use assert_cmd::cargo::cargo_bin;
use assert_cmd::prelude::*; // Add methods on commands
use std::process::Command; // Run programs

#[test]
fn integration_validate_ontology_rdf() -> Result<(), Box<dyn std::error::Error>> {
    let mut cmd = Command::new(cargo_bin!("horned-validate"));

    cmd.arg("../src/ont/owl-rdf/and.owl");
    cmd.assert().success();

    Ok(())
}

#[test]
fn integration_validate_ontology_xml() -> Result<(), Box<dyn std::error::Error>> {
    let mut cmd = Command::new(cargo_bin!("horned-validate"));

    cmd.arg("../src/ont/owl-xml/and.owx");
    cmd.assert().success();

    Ok(())
}

But this leaves me with the deprecation message given. But cargo_bin! isn't deprecated as far as I can see.

I am missing something obvious here but cannot see it.

This imports both the cargo_bin macro and the deprecated cargo_bin function. Try use assert_cmd::cargo and then use cargo::cargo_bin!.

Oh, I see. I had thought it was complaining about

the method, but it was complaining about

the function.

I guess that this makes the documentation wrong in the sense that their code examples are guaranteed to return warnings:

use assert_cmd::prelude::*;
use assert_cmd::cargo::cargo_bin;

use std::process::Command;

let mut cmd = Command::new(cargo_bin!())
let output = cmd.unwrap();

It's an unfortunate name clash.

Yes, I regret the name collision.

As for the documentation, the problem is that I can't write compilable doctests using cargo_bin! or cargo_bin_cmd! because the environment variable is not present, so I'm punting and using the deprecated functions to verify the rest of the examples are correct. The ones specifically for the macros, I have set to ignore.

Maybe just update the code snippet to

use assert_cmd::prelude::*;
use assert_cmd::cargo;

use std::process::Command;

let mut cmd = Command::new(cargo::cargo_bin!())
let output = cmd.unwrap();

which fixes the warnings? And perhaps update the deprecation warnings so that Command::cargo_bin and and cargo::cargo_bin are somewhat different. These were the two things that confused me -- I copied the code, then thought I was getting the same error.

Happy to send a PR in that would help.

That code snippet won't compile in the examples as I said because it reads an environment variable that doesn't exist.

For what it's worth, there's a rustc github issue about making the lint a bit smarter.

We think that the fix here (both to the duplicated-ish warnings and your issue) is to only lint on imports of deprecated items when you wouldn't get an unused import warning if the import was unused in the crate. I.e. only lint on pub uses of deprecated items.

That way you either get a warning on the actual use of the item (e.g. function call), get an unused import warning, or get a warning on the use item, but only if it's public.