Skip to content

let_underscore_drop: weird "+" in output? #113894

Closed

Description

@matthiaskrgr

Code

#![allow(unused_must_use)]
use std::thread;

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

macro_rules! spawn {
    ($($code: tt)*) => {
        expr!(thread::spawn(move|| {$($code)*}).join())
    }
}

pub fn main() {
    spawn! {
        println!("expr");
    };
    let _ = spawn! {
        println!("expr");
    };
}

Current output

warning: non-binding let on a type that implements `Drop`
  --> 2B8C38DE2265366FC40C9872C2EB2C8B37BDA99B72B47C43B03BF5A58936ABCC.rs:16:5
   |
16 | /     let _ = spawn! {
17 | |         println!("expr");
18 | |     };
   | |______^
   |
   = note: requested on the command line with `-W let-underscore-drop`
help: consider binding to an unused variable to avoid immediately dropping the value
   |
16 |     let _unused = spawn! {
   |         ~~~~~~~
help: consider immediately dropping the value
   |
8  |         expr!(drop())
   |               ~~~~~                                   +

warning: 1 warning emitted

This free-standing "+" looks very weird, not sure what this is supposed to point at?
Maybe the macros messed something up here?

Activity

  1. added
    A-diagnosticsArea: Messages for errors, warnings, and lints
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Jul 20, 2023
  2. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Jul 20, 2023
  3. clubby789 commented on Jul 21, 2023

    @clubby789
    Contributor

    While reducing this

    #![allow(unused_must_use)]
    #![warn(let_underscore_drop)]
    use std::thread;
    
    struct DropMe;
    impl Drop for DropMe {
        fn drop(&mut self) {}
    }
    
    macro_rules! spawn {
        ($code: tt) => {
            $code
        }
    }
    
    pub fn main() {
        let _ = spawn!(DropMe);
    }

    ICEs with

    thread 'rustc' panicked at 'assertion failed: `(left == right)`
      left: `Some([SubstitutionPart { span: poc.rs:12:9: 17:5 (#0), snippet: "drop(" }, SubstitutionPart { span: poc.rs:12:14: 12:14 (#0), snippet: ")" }])`,
     right: `None`: suggestion must not have overlapping parts'
    

    Filing that here as I suspect it's part of the same issue

    EDIT: The issue here is that the span associated with the drop( suggestion is from the start of local.span (which covers the whole let _ = ... line) up until the start of init.span, which is the span of $code inside the macro definition.

  4. added
    C-bugCategory: This is a bug.
    and removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Jul 23, 2023
  5. added
    A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)
    A-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`
    D-diagnostic-infraDiagnostics: Issues that affect all diagnostics, or relate to the diagnostic machinery itself.
    on Jul 28, 2023
  6. self-assigned this
    on May 15, 2024
  7. chenyukang commented on May 15, 2024

    @chenyukang
    Member

    While reducing this

    #![allow(unused_must_use)]
    #![warn(let_underscore_drop)]
    use std::thread;
    
    struct DropMe;
    impl Drop for DropMe {
        fn drop(&mut self) {}
    }
    
    macro_rules! spawn {
        ($code: tt) => {
            $code
        }
    }
    
    pub fn main() {
        let _ = spawn!(DropMe);
    }

    ICEs with

    thread 'rustc' panicked at 'assertion failed: `(left == right)`
      left: `Some([SubstitutionPart { span: poc.rs:12:9: 17:5 (#0), snippet: "drop(" }, SubstitutionPart { span: poc.rs:12:14: 12:14 (#0), snippet: ")" }])`,
     right: `None`: suggestion must not have overlapping parts'
    

    Filing that here as I suspect it's part of the same issue

    EDIT: The issue here is that the span associated with the drop( suggestion is from the start of local.span (which covers the whole let _ = ... line) up until the start of init.span, which is the span of $code inside the macro definition.

    The ice dispear now:

    warning: unused import: `std::thread`
     --> ./t/t4.rs:3:5
      |
    3 | use std::thread;
      |     ^^^^^^^^^^^
      |
      = note: `#[warn(unused_imports)]` on by default
    
    warning: non-binding let on a type that implements `Drop`
      --> ./t/t4.rs:17:5
       |
    17 |     let _ = spawn!(DropMe);
       |     ^^^^^^^^^^^^^^^^^^^^^^^
       |
    note: the lint level is defined here
      --> ./t/t4.rs:2:9
       |
    2  | #![warn(let_underscore_drop)]
       |         ^^^^^^^^^^^^^^^^^^^
    help: consider binding to an unused variable to avoid immediately dropping the value
       |
    17 |     let _unused = spawn!(DropMe);
       |         ~~~~~~~
    help: consider immediately dropping the value
       |
    17 |     drop(DropMe));
       |     ~~~~~      +
    
    warning: 2 warnings emitted
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)A-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-bugCategory: This is a bug.D-diagnostic-infraDiagnostics: Issues that affect all diagnostics, or relate to the diagnostic machinery itself.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions