Skip to content

#[deprecated] fn using format_args!() triggers "use of deprecated item" warning #35128

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

Closed
shahn opened this issue Jul 30, 2016 · 5 comments · Fixed by #35317
Closed

#[deprecated] fn using format_args!() triggers "use of deprecated item" warning #35128

shahn opened this issue Jul 30, 2016 · 5 comments · Fixed by #35317

Comments

@shahn
Copy link
Contributor

shahn commented Jul 30, 2016

This code:

#[deprecated]
fn foo() {
    format_args!("bla");
}

gives this warning:

warning: use of deprecated item, #[warn(deprecated)] on by default
 --> <anon>:3:18
3 |>     format_args!("bla");
  |>                  ^^^^^
<anon>:3:5: 3:25: note: in this expansion of format_args!

in current stable and nightly

@shahn shahn changed the title #[deprecated] fn declaration triggers use of deprecated item warning #[deprecated] fn using format_args!() triggers "use of deprecated item" warning Jul 30, 2016
@cengiz-io
Copy link
Contributor

cengiz-io commented Jul 31, 2016

Hello.

What's the real issue here? Are you concerned about the extra error message?

Because when I try this in playground, I get two errors and one of them is correct behaviour.

warning: use of deprecated item, #[warn(deprecated)] on by default
 --> <anon>:3:18
3 |>     format_args!("bla");
  |>                  ^^^^^
<anon>:3:5: 3:25: note: in this expansion of format_args!

warning: use of deprecated item, #[warn(deprecated)] on by default
 --> <anon>:7:5
7 |>     foo();
  |>     ^^^

If it's so, I think you should update the title to "Deprecation warning getting incorrectly recursed into builtin macro calls" or something like that.

Cheers!

@TimNN
Copy link
Contributor

TimNN commented Jul 31, 2016

@cengizio: I believe the current title is pretty accurate:

  • only the format_args! macro is affected (as far as I can tell, stringify!, concat! and try! don't work for example)
  • the error is triggered, even if foo is never used

See: https://is.gd/ua1Lyz

@cengiz-io
Copy link
Contributor

@TimNN Thanks for clarifying that for me.

I traced source to librustc_lint/builtin.rs#L577 but can't seem to find something special for macros.

@TimNN
Copy link
Contributor

TimNN commented Jul 31, 2016

Alright, I did some more tests and basically the following happens:

  • #[deprecated] is applied recursively, so a #[deprecated] mod foo {} will deprecate anything inside that module as well.
  • format_args! (probably) expands (among other things) to something like const BLA: &'static str = "bla"; ...; do_somthing(BLA);
  • since foo is deprecated, BLA is deprecated, so using BLA in do_something(BLA) triggers a deprecation warning

Example:

#[deprecated]
fn _foo() {
    static FOO: &'static str = "abc";

    let _ = FOO; //~ WARN use of deprecated item
}

While this specific case is indeed very surprising, the more general case ("deprecated use inside of deprecated item") is already tracked at #16490.

@cengiz-io
Copy link
Contributor

@TimNN Nice catch! Here's the full expanded version

#![feature(prelude_import)]
#![no_std]
#[prelude_import]
use std::prelude::v1::*;
#[macro_use]
extern crate std as std;
#[deprecated]
fn _foo() {
    ::std::fmt::Arguments::new_v1({
                                      static __STATIC_FMTSTR: &'static [&'static str] = &["bla"];
                                      __STATIC_FMTSTR
                                  },
                                  &match () {
                                      () => [],
                                  });
}

fn main() {}

TimNN added a commit to TimNN/rust that referenced this issue Aug 4, 2016
Whenever a node whould be reported as deprecated:

- check if the parent item is also deprecated

- if it is and both were deprecated by the same attribute

- skip the deprecation warning

fixes rust-lang#35128
closes rust-lang#16490
TimNN added a commit to TimNN/rust that referenced this issue Aug 4, 2016
Whenever a node whould be reported as deprecated:

- check if the parent item is also deprecated

- if it is and both were deprecated by the same attribute

- skip the deprecation warning

fixes rust-lang#35128
closes rust-lang#16490
bors added a commit that referenced this issue Aug 5, 2016
Ignore deprecation for items deprecated by the same attribute

Whenever a node would be reported as deprecated:

- check if the parent item is also deprecated
- if it is and both were deprecated by the same attribute
- skip the deprecation warning

fixes #35128
closes #16490

r? @eddyb
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.

3 participants