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 function calls inside of macros don't warn #17185

Closed
sfackler opened this issue Sep 12, 2014 · 7 comments · Fixed by #17286
Closed

Deprecated function calls inside of macros don't warn #17185

sfackler opened this issue Sep 12, 2014 · 7 comments · Fixed by #17286
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut.

Comments

@sfackler
Copy link
Member

This does not generate a deprecation warning, but will if the try! call is removed.

extern crate url;

fn foo() -> Result<(), ()> {
    try!(url::decode_component("sdf").map_err(|_| ()));
    Ok(())
}
@sfackler sfackler added the A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. label Sep 12, 2014
@sfackler
Copy link
Member Author

cc @aturon

@elinorbgr
Copy link
Contributor

I'm looking into this, if no-one is doing it yet.

@aturon
Copy link
Member

aturon commented Sep 15, 2014

@vberger Please do!

For reference, the stability lint (which includes deprecation) is currently coded to ignore any output from macros. This was done to solve the opposite problem: macros that use unstable/deprecated items in their definition should not cause warnings for macro users.

Getting this right is going to be tricky, because you'd need to distinguish which parts of a macro's output came from its definition, versus client-supplied code. While that's plausible for macro rules, doing it for syntax extensions seems difficult if not impossible.

See #15728, #15703, and #15726

@elinorbgr
Copy link
Contributor

@aturon Thanks for the links! Currently, my approach was indeed to try to ignore code that was generated by the macro, marking for lint only nodes declared outside of macro invocation, using expn_info to discriminate them.

I managed to have the example in this issue running, but encountered issues with fail! (using it in a deprecated function marked it's internal static variable as deprecated as well, and raised a warning because it was used). It is indeed trickier than I first expected.

@sfackler
Copy link
Member Author

You may also be able to use the hygiene machinery to figure out what was passed in.

bors added a commit that referenced this issue Sep 22, 2014
Closes #17185.

The stability lint will now check code generated by macro expansion. It will allow to detect :
- arguments passed to macros using deprecated (and others) items
- macro expansion generating code using deprecated items due to its arguments (hence the second commit, fixing such issue found in libcollections)

Checking is still done at expansion, but it will also detect a macro explicitly using a deprecated item in its definition.
@elinorbgr
Copy link
Contributor

@aturon In fact, I realized my fix doesn't completely close it. There is one case where the checking is not done: when the argument of the macro is directly passed to an other macro and not used otherwise, like for println!() which passes all to format_args!().

I'm looking into this.

@aturon aturon reopened this Sep 23, 2014
@aturon
Copy link
Member

aturon commented Sep 23, 2014

@vberger Thanks for the heads-up. I've reopened the issue.

@bors bors closed this as completed in dd55c80 Oct 21, 2014
lnicola pushed a commit to lnicola/rust that referenced this issue May 19, 2024
fix: keep parentheses when the precedence of inner expr is lower than the outer one

fix rust-lang#17185

Additionally, this PR simplifies some code in `apply_demorgan`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants