Skip to content

When the write! macro's result is chained stability warnings show up, and the expansion site is not reported #22013

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
renato-zannon opened this issue Feb 6, 2015 · 4 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)

Comments

@renato-zannon
Copy link
Contributor

Example:

fn main() {
    let mut buffer = Vec::new();
    writeln!(&mut buffer, "foo").unwrap();
}

This errors as:

<std macros>:2:20: 2:66 warning: use of unstable library feature 'io'
<std macros>:2 ( & mut * $ dst ) . write_fmt ( format_args ! ( $ ( $ arg ) * ) ) )
                                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<std macros>:2:20: 2:66 help: add #![feature(io)] to the crate attributes to silence this warning
<std macros>:2 ( & mut * $ dst ) . write_fmt ( format_args ! ( $ ( $ arg ) * ) ) )
                                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Contrast that with the error when the .unwrap() is removed:

<std macros>:2:1: 2:66 warning: unused result which must be used, #[warn(unused_must_use)] on by default
<std macros>:2 ( & mut * $ dst ) . write_fmt ( format_args ! ( $ ( $ arg ) * ) ) )
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<std macros>:1:1: 2:68 note: in expansion of write!
<std macros>:2:1: 2:46 note: expansion site
<std macros>:1:1: 4:66 note: in expansion of writeln!
src/main.rs:3:5: 3:34 note: expansion site

This can be pretty hairy to find if the project has many crates (my project euler repo, which is where I observed this, has 60+ executables).

@kmcallister kmcallister added A-diagnostics Area: Messages for errors, warnings, and lints A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) labels Feb 6, 2015
@rprichard
Copy link
Contributor

Related to #23459

@gbersac
Copy link

gbersac commented Sep 16, 2015

Still a problem with the 1.2 rustc compiler.

@pmarcelll
Copy link
Contributor

Triage: we have nice error messages now.

@petrochenkov
Copy link
Contributor

Current diagnostics:

rustc 1.17.0-nightly (b1e31766d 2017-03-03)
error: no method named `write_fmt` found for type `&mut std::vec::Vec<_>` in the current scope
 --> <anon>:3:5
  |
3 |     writeln!(&mut buffer, "foo").unwrap();
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = help: items from traits can only be used if the trait is in scope; the following trait is implemented but not in scope, perhaps add a `use` for it:
  = help: candidate #1: `use std::io::Write;`
  = note: this error originates in a macro outside of the current crate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)
Projects
None yet
Development

No branches or pull requests

6 participants