Skip to content

Impossible to remove #![must_use] from a value #36675

Closed as not planned
Closed as not planned
@alexchandel

Description

@alexchandel

I want to write a macro wrapping something marked #![must_use] which doesn't spam the build output with "unused_must_use", but also doesn't destroy the result. I don't want to unwrap these values either, nor mark every single invocation with #![allow(unused_must_use)], nor allow unused_must_see for the entire program (because with this macro's one exception, it is useful): I simply want to strip this return value's compiler-spamming must_use.

This:

macro_rules! println_out(
    ($($arg:tt)*) => ( {let _ = writeln!(&mut ::std::io::stdout(), $($arg)* )} )
);

doesn't work because the result is unavailable if I need to check it, which I do on occasion.

Even this: fails to work:

macro_rules! println_err(
    ($($arg:tt)*) => ( {
        let _x = writeln!(&mut ::std::io::stderr(), $($arg)* );
        _x.is_ok();
        _x
    } )
);

because the final line can be unused in the calling context

stdout/stderr/write_ln! are used as examples here, but I need to do this generically with certain things that spam must_use.

This isn't an unsafety issue. I simply shouldn't have to be bound ubiquitously by the particular compiler-warning policy preached by a module's author. I may (and do) have valid cases where must_use is semantically wrong.

It should not be impossible to do this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-feature-requestCategory: A feature request, i.e: not implemented / a PR.T-langRelevant to the language team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions