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

Compiler warnings are not raised for code enclosed in macros #16360

Closed
cskr opened this issue Aug 8, 2014 · 4 comments · Fixed by #22127
Closed

Compiler warnings are not raised for code enclosed in macros #16360

cskr opened this issue Aug 8, 2014 · 4 comments · Fixed by #22127
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)

Comments

@cskr
Copy link

cskr commented Aug 8, 2014

When deprecated API usage is enclosed in a macro like try!, no warning is raised. However, using it directly in match does.

Below is an example using the deprecated url crate from rust nightly distribution. A warning is raised only in the use_match function.

extern crate url;

use url::Url;

fn main() {
    println!("Host: {}", use_try("http://localhost").unwrap())
    println!("Host: {}", use_match("http://localhost").unwrap())
}

fn use_try(s: &str) -> Result<String, String> {
    let u = try!(Url::parse(s));
    Ok(u.host)
}

fn use_match(s: &str) -> Result<String, String> {
    return match Url::parse(s) {
        Ok(u) => Ok(u.host),
        Err(e) => Err(e)
    }
}
@huonw
Copy link
Member

huonw commented Aug 8, 2014

cc @aturon (I think this is probably related to squashing stability warnings for macro generated code, it apparently includes arguments passed in).

@aturon
Copy link
Member

aturon commented Aug 8, 2014

Thanks for the heads up. Right now all expanded code is ignored. It might be possible, at least for macros-by-example, to track the "provenance" of code being produced and warn on code that was supplied by the macro user. I have no idea how hard that would be to do, though.

@cskr
Copy link
Author

cskr commented Aug 9, 2014

@aturon What are "macros-by-example"?

@huonw
Copy link
Member

huonw commented Aug 9, 2014

@tuxychandru macros declared with macro_rules! ... { ... }.

@huonw huonw added the A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) label Jan 14, 2015
alexcrichton added a commit to alexcrichton/rust that referenced this issue Feb 11, 2015
There are a number of holes that the stability lint did not previously cover,
including:

* Types
* Bounds on type parameters on functions and impls
* Where clauses
* Imports
* Patterns (structs and enums)

These holes have all been fixed by overriding the `visit_path` function on the
AST visitor instead of a few specialized cases. This change also necessitated a
few stability changes:

* The `collections::fmt` module is now stable (it was already supposed to be).
* The `thread_local::imp::Key` type is now stable (it was already supposed to
  be).
* The `std::rt::{begin_unwind, begin_unwind_fmt}` functions are now stable.
  These are required via the `panic!` macro.
* The `std::old_io::stdio::{println, println_args}` functions are now stable.
  These are required by the `print!` and `println!` macros.
* The `ops::{FnOnce, FnMut, Fn}` traits are now `#[stable]`. This is required to
  make bounds with these traits stable. Note that manual implementations of
  these traits are still gated by default, this stability only allows bounds
  such as `F: FnOnce()`.

Additionally, the compiler now has special logic to ignore its own generated
`__test` module for the `--test` harness in terms of stability.

Closes rust-lang#8962
Closes rust-lang#16360
Closes rust-lang#20327

[breaking-change]
alexcrichton added a commit to alexcrichton/rust that referenced this issue Feb 11, 2015
There are a number of holes that the stability lint did not previously cover,
including:

* Types
* Bounds on type parameters on functions and impls
* Where clauses
* Imports
* Patterns (structs and enums)

These holes have all been fixed by overriding the `visit_path` function on the
AST visitor instead of a few specialized cases. This change also necessitated a
few stability changes:

* The `collections::fmt` module is now stable (it was already supposed to be).
* The `thread_local::imp::Key` type is now stable (it was already supposed to
  be).
* The `std::rt::{begin_unwind, begin_unwind_fmt}` functions are now stable.
  These are required via the `panic!` macro.
* The `std::old_io::stdio::{println, println_args}` functions are now stable.
  These are required by the `print!` and `println!` macros.
* The `ops::{FnOnce, FnMut, Fn}` traits are now `#[stable]`. This is required to
  make bounds with these traits stable. Note that manual implementations of
  these traits are still gated by default, this stability only allows bounds
  such as `F: FnOnce()`.

Closes rust-lang#8962
Closes rust-lang#16360
Closes rust-lang#20327
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants