Skip to content
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

let_underscore_drop: weird "+" in output? #113894

Closed
matthiaskrgr opened this issue Jul 20, 2023 · 2 comments
Closed

let_underscore_drop: weird "+" in output? #113894

matthiaskrgr opened this issue Jul 20, 2023 · 2 comments
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. C-bug Category: This is a bug. D-diagnostic-infra Diagnostics: Issues that affect all diagnostics, or relate to the diagnostic machinery itself. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

matthiaskrgr commented Jul 20, 2023

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?

@matthiaskrgr matthiaskrgr added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 20, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jul 20, 2023
@clubby789
Copy link
Contributor

clubby789 commented Jul 21, 2023

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.

@saethlin saethlin added C-bug Category: This is a bug. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jul 23, 2023
@estebank estebank added A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. D-diagnostic-infra Diagnostics: Issues that affect all diagnostics, or relate to the diagnostic machinery itself. labels Jul 28, 2023
@chenyukang chenyukang self-assigned this May 15, 2024
@chenyukang
Copy link
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
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. C-bug Category: This is a bug. D-diagnostic-infra Diagnostics: Issues that affect all diagnostics, or relate to the diagnostic machinery itself. 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

6 participants