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] does not work for in-crate usages of items #16409

Closed
brendanzab opened this issue Aug 11, 2014 · 7 comments
Closed

#[deprecated] does not work for in-crate usages of items #16409

brendanzab opened this issue Aug 11, 2014 · 7 comments

Comments

@brendanzab
Copy link
Member

This compiles:

#![forbid(deprecated)]

#[deprecated]
fn foo() {}

fn main() {
    foo();
}

http://is.gd/bQE1W1

More extensive example from @chrismorgan: http://is.gd/eRBKUc

This is annoying because I would love to use it to purge old stuff from my own codebase, rather than deferring it until the removal time, and risking usages creep back in with other PRs.

@brendanzab brendanzab changed the title #[deprecated] does not work for in-crate usages #[deprecated] does not work for in-crate usages of items Aug 11, 2014
@lilyball
Copy link
Contributor

In librustc/lint/builtin.rs:

        // stability attributes are promises made across crates; do not
        // check anything for crate-local usage.
        if ast_util::is_local(id) { return }

This makes sense for stable/unstable/experimental/whatnot. But I agree that deprecated is a bit different and it would be useful to be able to use it to clean up your own code instead of only using it cross-crate.

@brendanzab
Copy link
Member Author

I kinda wish we could have: #[allow(experimental = foo::bar)] - then it we would be able to get rid of the crate-local rule altogether. But I'm guessing macro path-resolution is an issue there?

@huonw
Copy link
Member

huonw commented Aug 11, 2014

Stability attributes are lints, not macros, and lints have access to the full resolution information so that's not a problem. I believe @aturon is thinking about (and may be implementing) pathed stability attributes; he and I have certainly discussed in passing previously.

@brendanzab
Copy link
Member Author

Oooh!! Exciting!!

@aturon
Copy link
Member

aturon commented Aug 11, 2014

This is a good point; I will change the lint to warn on deprecated within your own crate.

@aturon
Copy link
Member

aturon commented Aug 11, 2014

Unsurprisingly, turning this on is revealing a bunch of deprecated usage in libstd...

@brendanzab
Copy link
Member Author

Awesome, thanks!

bors added a commit that referenced this issue Aug 12, 2014
Previously the stability lint considered cross-crate items only. That's appropriate for unstable and experimental levels, but not for deprecation.

In addition to changing the lint, this PR takes care of the fallout: a number of deprecated items that were being used throughout libstd.

Closes #16409

Due to deny(deprecated), this is a:

[breaking-change]
@aturon aturon closed this as completed in 0b5204f Aug 12, 2014
lnicola pushed a commit to lnicola/rust that referenced this issue Jan 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants