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

#[deprecated] attribute not working "as expected" on pub use library crate exports #85388

Closed
d-e-s-o opened this issue May 16, 2021 · 4 comments
Labels
C-bug Category: This is a bug.

Comments

@d-e-s-o
Copy link
Contributor

d-e-s-o commented May 16, 2021

Perhaps I don't have the right mental model, but I find it extremely confusing that #[deprecated] does not do what it's supposed to do on a pub use statement (in a lib.rs, for example). Consider:

# foolib/src/lib.rs
mod foobar {
  pub struct Foo {
    pub i: u64,
  }
}

#[deprecated(note = "no longer needed")]
pub use foobar::Foo;
# fooapp/src/main.rs
use foolib::Foo;

fn main() {
    let foo = Foo {
      i: 42,
    };
    println!("Foo.i = {}", foo.i);
}

When compiling, no deprecation warning is emitted.

Instead, I am forced to use:

--- foolib/src/lib.rs
+++ foolib/src/lib.rs
@@ -1,8 +1,8 @@
 mod foobar {
+  #[deprecated(note = "no longer needed")]
   pub struct Foo {
     pub i: u64,
   }
 }

-#[deprecated(note = "no longer needed")]
 pub use foobar::Foo;

That in turn, now causes a deprecation warning to be emitted in the library crate itself.

Furthermore, no warning is emitted for the first version (#[deprecated] on the pub use statement) that it does not do what (clearly?) the user intends.

Meta

$ rustc --version --verbose
rustc 1.51.0 (gentoo)
binary: rustc
commit-hash: unknown
commit-date: unknown
host: x86_64-unknown-linux-gnu
release: 1.51.0
LLVM version: 11.1.0
@d-e-s-o d-e-s-o added the C-bug Category: This is a bug. label May 16, 2021
@d-e-s-o
Copy link
Contributor Author

d-e-s-o commented May 16, 2021

Reproduction case: foo.tar.gz

@d-e-s-o
Copy link
Contributor Author

d-e-s-o commented May 16, 2021

Also FWIW, the attribute documentation https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-deprecated-attribute does not explicitly say that it does not work on pub use statements (I am not that familiar with the grammar to say with confidence whether it should work on it). In any event, if it intentionally does not work, I'd at the very least expect a warning, more likely an error. Silently not doing the right thing is something I'd expect in other languages ;-)

@ehuss
Copy link
Contributor

ehuss commented May 17, 2021

Thanks for the report! I do believe that it is intended to work, but it is a known bug. This has been reported a few times, see #84584, #47236, #30827, #23937.

@d-e-s-o
Copy link
Contributor Author

d-e-s-o commented May 17, 2021

Ah, thanks for the pointer. #84584 I found (but then forgot to mention as related), but deemed slightly different. #30827 seems to be about exactly the same issue. Closing then.

@d-e-s-o d-e-s-o closed this as completed May 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

2 participants