Skip to content

Macro error inside of file that gets included with include! yields terrible error #37719

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
jdm opened this issue Nov 11, 2016 · 5 comments
Closed
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jdm
Copy link
Contributor

jdm commented Nov 11, 2016

a.rs:

include!("b.rs")

b.rs:

fn main() {
    println!("{}");
}

Compiling a.rs yields:

error: invalid reference to argument `0` (no arguments given)
 --> a.rs:1:1
  |
1 | include!("b.rs");
  | ^^^^^^^^^^^^^^^^^
  |
  = note: this error originates in a macro from the standard library

error: aborting due to previous error
@jdm jdm added A-diagnostics Area: Messages for errors, warnings, and lints A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) labels Nov 11, 2016
@TimNN
Copy link
Contributor

TimNN commented Nov 11, 2016

Related (maybe duplicate of?) to #37663, I think.

@paulstansifer
Copy link
Contributor

I don't believe that this problem is restricted to include!. For example, I had a tough time debugging a a situation like this:

macro_rules! noop {
    ($e:expr) => {$e}
}

fn main() {
    noop!({
        // ... imagine lots of code here ...
        try!(0); // Oops!
        // ... imagine lots of code here ...
    })
}

...yields the following error:

error[E0308]: mismatched types
  --> /tmp/macro.rs:7:5
   |
7  |     noop!({
   |     ^
   |     |
   |     in this macro invocation
   |     expected integral variable, found enum `std::result::Result`
   |
   = note: expected type `{integer}`
   = note:    found type `std::result::Result<_, _>`
   = note: this error originates in a macro outside of the current crate

[more type errors with the same span elided]

@jseyfried jseyfried self-assigned this Dec 6, 2016
@steveklabnik steveklabnik added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Mar 9, 2017
@theIDinside
Copy link
Contributor

I get the exact same error, when just trying to compile this;

use std::io::prelude::*;
use std::fs::File;
fn main() {
    let mut f = try!(File::create("foo.txt"));
    try!(f.write_all(b"Hello, world!"));
    try!(f.sync_data());
}

   = note: expected type `()`
   = note:    found type `std::result::Result<_, _>`
   = note: this error originates in a macro outside of the current crate

error: aborting due to 3 previous errors

Using version 1.15.1 stable channel.

@Mark-Simulacrum Mark-Simulacrum added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jul 26, 2017
@estebank
Copy link
Contributor

estebank commented Feb 1, 2018

CC #38771.

@estebank
Copy link
Contributor

Current output for the original repro case:

error: 1 positional argument in format string, but no arguments were given
 --> b.rs:2:5
  |
2 |     println!("{}");
  |     ^^^^^^^^^^^^^^^
  |
  = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

error: aborting due to previous error

Current output for #37719 (comment) (note the repetition):

error[E0308]: mismatched types
 --> file.rs:8:9
  |
8 |         try!(0); // Oops!
  |         ^^^^^^^^ expected integral variable, found enum `std::result::Result`
  |
  = note: expected type `{integer}`
             found type `std::result::Result<_, _>`
  = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

error[E0308]: mismatched types
 --> file.rs:8:9
  |
8 |         try!(0); // Oops!
  |         ^^^^^^^^ expected integral variable, found enum `std::result::Result`
  |
  = note: expected type `{integer}`
             found type `std::result::Result<_, _>`
  = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

error[E0308]: mismatched types
 --> file.rs:8:9
  |
8 |         try!(0); // Oops!
  |         ^^^^^^^^ expected (), found enum `std::result::Result`
  |
  = note: expected type `()`
             found type `std::result::Result<_, _>`
  = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

error: aborting due to 3 previous errors

Current output for #37719 (comment):

error[E0308]: mismatched types
 --> src/main.rs:4:17
  |
4 |     let mut f = try!(File::create("foo.txt"));
  |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected (), found enum `std::result::Result`
  |
  = note: expected type `()`
             found type `std::result::Result<_, _>`
  = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

error: aborting due to previous error

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, ..) C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

8 participants