Skip to content

compiler errors sometimes made nugatory (closures, struct derive?) #60

@ijackson

Description

@ijackson

Hi. Thanks again for this excellent package.

To reproduce:

#[allow(unused_imports)]
use fehler::throws;

fn parse_args(_f: &dyn Fn(&mut ())) { }

#[throws(std::io::Error)]
fn main() 
{
    #[derive(Default,Debug)]
    struct Args { }
    let args = parse_args(&|ma|{ });
    let spec = 42;
}

And run cargo build, with fehler="1" in your dependencies.

Actual output:

warning: unused variable: `ma`
  |
  = note: `#[warn(unused_variables)]` on by default

warning: unused variable: `args`

warning: unused variable: `spec`

warning: 3 warnings emitted

    Finished dev [unoptimized + debuginfo] target(s) in 0.01s

Note the very unhelpful error messages, with no location information and no suggestions.

Expected output:


warning: unused variable: `ma`
  --> src/bin/report.rs:11:29
   |
11 |     let args = parse_args(&|ma|{ });
   |                             ^^ help: if this is intentional, prefix it with an underscore: `_ma`
   |
   = note: `#[warn(unused_variables)]` on by default

warning: unused variable: `args`
  --> src/bin/report.rs:11:9
   |
11 |     let args = parse_args(&|ma|{ });
   |         ^^^^ help: if this is intentional, prefix it with an underscore: `_args`

warning: unused variable: `spec`
  --> src/bin/report.rs:12:9
   |
12 |     let spec = 42;
   |         ^^^^ help: if this is intentional, prefix it with an underscore: `_spec`

warning: 3 warnings emitted

    Finished dev [unoptimized + debuginfo] target(s) in 0.17s

This rather odd test case was minimised from a more complicated program. Empirically, the issue goes away if I remove any of (a) #[throws] (b) the #[derive] on the struct (c) the closure. The problem can occur with errors as well as warnings. In one particular version of my actual program I got the very unhelpful output type annotations needed without any indication of where!

Thanks for your attention.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions