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

debug ice: needless_return suggestion removes code which isnt there inside macro #11167

Closed
matthiaskrgr opened this issue Jul 16, 2023 · 0 comments · Fixed by #11173
Closed
Labels
C-bug Category: Clippy is not doing the correct thing I-ICE Issue: Clippy panicked, giving an Internal Compilation Error (ICE) ❄️ L-suggestion Lint: Improving, adding or fixing lint suggestions

Comments

@matthiaskrgr
Copy link
Member

Summary

// run-pass

macro_rules! overly_complicated {
    ($fnname:ident, $arg:ident, $ty:ty, $body:block, $val:expr, $pat:pat, $res:path) =>
    ({
        fn $fnname($arg: $ty) -> Option<$ty> $body
        match $fnname($val) {
          Some($pat) => {
            $res
          }
          _ => { panic!(); }
        }
    })

}

macro_rules! qpath {
    (path, <$type:ty as $trait:path>::$name:ident) => {
        <$type as $trait>::$name
    };

    (ty, <$type:ty as $trait:ty>::$name:ident) => {
        <$type as $trait>::$name
    };
}

pub fn main() {
    let _: qpath!(path, <str as ToOwned>::Owned);
    let _: qpath!(ty, <str as ToOwned>::Owned);

    assert!(overly_complicated!(f, x, Option<usize>, { return Some(x); },
                               Some(8), Some(y), y) == 8)
}

see the first "help" hint:

warning: unneeded `return` statement
  --> /home/matthias/vcs/github/rust_debug_assertions/tests/ui/macros/macro-interpolation.rs:31:56
   |
31 |     assert!(overly_complicated!(f, x, Option<usize>, { return Some(x); },
   |                                                        ^^^^^^^^^^^^^^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return
   = note: `#[warn(clippy::needless_return)]` on by default
help: remove `return`
   |
6  ~         fn $fnname($arg: $ty) -> Option<$ty> $body
7  |         match $fnname($val) {
 ...
30 |
31 ~     assert!(overly_complicated!(f, x, Option<usize>, { Some(x); },
   |

warning: 1 warning emitted

Version

425726d46b637f94995ca1c95f4f16cdb903d30e

Error output

Backtrace

thread 'rustc' panicked at 'assertion failed: `(left == right)`
left: `Some(SubstitutionPart { span: /home/matthias/vcs/github/rust_debug_assertions/tests/ui/macros/macro-interpolation.rs:6:51: 6:51 (#0), snippet: "" })`,
right: `None`: Span must not be empty and have no suggestion', /home/matthias/vcs/github/rust_debug_assertions/compiler/rustc_errors/src/diagnostic.rs:623:9
stack backtrace:
 0:     0x7f4c852c3836 - std::backtrace_rs::backtrace::libunwind::trace::h30fa42aa2db88158
                             at /home/matthias/vcs/github/rust_debug_assertions/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
 1:     0x7f4c852c3836 - std::backtrace_rs::backtrace::trace_unsynchronized::h2b9cc808f86f85f7
                             at /home/matthias/vcs/github/rust_debug_assertions/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
 2:     0x7f4c852c3836 - std::sys_common::backtrace::_print_fmt::h268804fe13f30210
                             at /home/matthias/vcs/github/rust_debug_assertions/library/std/src/sys_common/backtrace.rs:65:5
 3:     0x7f4c852c3836 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h692ee2dd29cb6a32
                             at /home/matthias/vcs/github/rust_debug_assertions/library/std/src/sys_common/backtrace.rs:44:22
 4:     0x7f4c85356617 - core::fmt::rt::Argument::fmt::h1dc8855cf0be02de
                             at /home/matthias/vcs/github/rust_debug_assertions/library/core/src/fmt/rt.rs:138:9
 5:     0x7f4c85356617 - core::fmt::write::h35c6f281391d7802
                             at /home/matthias/vcs/github/rust_debug_assertions/library/core/src/fmt/mod.rs:1094:21
 6:     0x7f4c852d2445 - std::io::Write::write_fmt::h5f9eeb8695999550
                             at /home/matthias/vcs/github/rust_debug_assertions/library/std/src/io/mod.rs:1714:15
 7:     0x7f4c852c3635 - std::sys_common::backtrace::_print::h0b343769d5ca97ef
                             at /home/matthias/vcs/github/rust_debug_assertions/library/std/src/sys_common/backtrace.rs:47:5
 8:     0x7f4c852c3635 - std::sys_common::backtrace::print::h1a9dcf70c9d72f51
                             at /home/matthias/vcs/github/rust_debug_assertions/library/std/src/sys_common/backtrace.rs:34:9
 9:     0x7f4c852cce3c - std::panicking::default_hook::{{closure}}::h84517d6843a8b8eb
10:     0x7f4c852ccb0c - std::panicking::default_hook::h9d050be456d2e865
                             at /home/matthias/vcs/github/rust_debug_assertions/library/std/src/panicking.rs:288:9
11:     0x7f4c8712cd7b - <alloc[86fc1011f0da8be9]::boxed::Box<dyn for<'a, 'b> core[1cc32ee8b476061a]::ops::function::Fn<(&'a core[1cc32ee8b476061a]::panic::panic_info::PanicInfo<'b>,), Output = ()> + core[1cc32ee8b476061a]::marker::Sync + core[1cc32ee8b476061a]::marker::Send> as core[1cc32ee8b476061a]::ops::function::Fn<(&core[1cc32ee8b476061a]::panic::panic_info::PanicInfo,)>>::call
                             at /home/matthias/vcs/github/rust_debug_assertions/library/alloc/src/boxed.rs:2021:9
12:     0x7f4c8712cd7b - rustc_driver_impl[f08193399333356b]::install_ice_hook::{closure#0}
                             at /home/matthias/vcs/github/rust_debug_assertions/compiler/rustc_driver_impl/src/lib.rs:1342:13
13:     0x7f4c852cd625 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h9913b6eac17b3933
                             at /home/matthias/vcs/github/rust_debug_assertions/library/alloc/src/boxed.rs:2021:9
14:     0x7f4c852cd625 - std::panicking::rust_panic_with_hook::hd3dcfd82aa6687cf
                             at /home/matthias/vcs/github/rust_debug_assertions/library/std/src/panicking.rs:709:13
15:     0x7f4c852c41c7 - std::panicking::begin_panic_handler::{{closure}}::h30ada8e3083a8d7e
                             at /home/matthias/vcs/github/rust_debug_assertions/library/std/src/panicking.rs:597:13
16:     0x7f4c852c3a96 - std::sys_common::backtrace::__rust_end_short_backtrace::hc69fe69b4cacc2af
                             at /home/matthias/vcs/github/rust_debug_assertions/library/std/src/sys_common/backtrace.rs:151:18
17:     0x7f4c852cd192 - rust_begin_unwind
                             at /home/matthias/vcs/github/rust_debug_assertions/library/std/src/panicking.rs:593:5
18:     0x7f4c8527a303 - core::panicking::panic_fmt::h2aa9ff874ea77c22
                             at /home/matthias/vcs/github/rust_debug_assertions/library/core/src/panicking.rs:67:14
19:     0x7f4c8527a83b - core::panicking::assert_failed_inner::h4ebd8a79193f4ada
20:     0x563da0f3b9bf - core[1cc32ee8b476061a]::panicking::assert_failed::<core[1cc32ee8b476061a]::option::Option<&rustc_errors[4a72a762f26cae1d]::SubstitutionPart>, core[1cc32ee8b476061a]::option::Option<&rustc_errors[4a72a762f26cae1d]::SubstitutionPart>>
                             at /home/matthias/vcs/github/rust_debug_assertions/library/core/src/panicking.rs:229:5
21:     0x563da11d8576 - <rustc_errors[4a72a762f26cae1d]::diagnostic::Diagnostic>::multipart_suggestion_with_style::<&str>
                             at /home/matthias/vcs/github/rust_debug_assertions/compiler/rustc_errors/src/diagnostic.rs:623:9
22:     0x563da116160b - <rustc_errors[4a72a762f26cae1d]::diagnostic::Diagnostic>::multipart_suggestion_verbose::<&str>
                             at /home/matthias/vcs/github/rust_debug_assertions/compiler/rustc_errors/src/diagnostic.rs:600:9
23:     0x563da116160b - clippy_lints[6ca63caa9e712f41]::returns::emit_return_lint::{closure#0}
                             at /home/matthias/vcs/github/rust_debug_assertions/src/tools/clippy/clippy_lints/src/returns.rs:326:14
24:     0x563da116160b - clippy_utils[589fb9e96ed0da48]::diagnostics::span_lint_and_then::<rustc_lint[cbe75d113ae0540b]::context::LateContext, rustc_span[8fc2bc2477ece13]::span_encoding::Span, clippy_lints[6ca63caa9e712f41]::returns::emit_return_lint::{closure#0}>::{closure#0}
                             at /home/matthias/vcs/github/rust_debug_assertions/src/tools/clippy/clippy_utils/src/diagnostics.rs:149:9
25:     0x563da116160b - <clippy_utils[589fb9e96ed0da48]::diagnostics::span_lint_and_then<rustc_lint[cbe75d113ae0540b]::context::LateContext, rustc_span[8fc2bc2477ece13]::span_encoding::Span, clippy_lints[6ca63caa9e712f41]::returns::emit_return_lint::{closure#0}>::{closure#0} as core[1cc32ee8b476061a]::ops::function::FnOnce<(&mut rustc_errors[4a72a762f26cae1d]::diagnostic_builder::DiagnosticBuilder<()>,)>>::call_once::{shim:vtable#0}
                             at /home/matthias/vcs/github/rust_debug_assertions/library/core/src/ops/function.rs:250:5
26:     0x563da11513e8 - <alloc[86fc1011f0da8be9]::boxed::Box<dyn for<'a, 'b> core[1cc32ee8b476061a]::ops::function::FnOnce<(&'a mut rustc_errors[4a72a762f26cae1d]::diagnostic_builder::DiagnosticBuilder<'b, ()>,), Output = &'a mut rustc_errors[4a72a762f26cae1d]::diagnostic_builder::DiagnosticBuilder<'b, ()>>> as core[1cc32ee8b476061a]::ops::function::FnOnce<(&mut rustc_errors[4a72a762f26cae1d]::diagnostic_builder::DiagnosticBuilder<()>,)>>::call_once
                             at /home/matthias/vcs/github/rust_debug_assertions/library/alloc/src/boxed.rs:2007:9
27:     0x563da11513e8 - rustc_middle[6d3884defc02ee9d]::lint::struct_lint_level::struct_lint_level_impl::<alloc[86fc1011f0da8be9]::string::String>
                             at /home/matthias/vcs/github/rust_debug_assertions/compiler/rustc_middle/src/lint.rs:438:9
28:     0x563da114e60b - rustc_middle[6d3884defc02ee9d]::lint::struct_lint_level::<alloc[86fc1011f0da8be9]::string::String, clippy_utils[589fb9e96ed0da48]::diagnostics::span_lint_and_then<rustc_lint[cbe75d113ae0540b]::context::LateContext, rustc_span[8fc2bc2477ece13]::span_encoding::Span, clippy_lints[6ca63caa9e712f41]::returns::emit_return_lint::{closure#0}>::{closure#0}>
                             at /home/matthias/vcs/github/rust_debug_assertions/compiler/rustc_middle/src/lint.rs:442:5
29:     0x563da12ba88e - <rustc_middle[6d3884defc02ee9d]::ty::context::TyCtxt>::struct_span_lint_hir::<rustc_span[8fc2bc2477ece13]::span_encoding::Span, alloc[86fc1011f0da8be9]::string::String, clippy_utils[589fb9e96ed0da48]::diagnostics::span_lint_and_then<rustc_lint[cbe75d113ae0540b]::context::LateContext, rustc_span[8fc2bc2477ece13]::span_encoding::Span, clippy_lints[6ca63caa9e712f41]::returns::emit_return_lint::{closure#0}>::{closure#0}>
                             at /home/matthias/vcs/github/rust_debug_assertions/compiler/rustc_middle/src/ty/context.rs:1894:9
30:     0x563da1084238 - <rustc_lint[cbe75d113ae0540b]::context::LateContext as rustc_lint[cbe75d113ae0540b]::context::LintContext>::lookup::<rustc_span[8fc2bc2477ece13]::span_encoding::Span, alloc[86fc1011f0da8be9]::string::String, clippy_utils[589fb9e96ed0da48]::diagnostics::span_lint_and_then<rustc_lint[cbe75d113ae0540b]::context::LateContext, rustc_span[8fc2bc2477ece13]::span_encoding::Span, clippy_lints[6ca63caa9e712f41]::returns::emit_return_lint::{closure#0}>::{closure#0}>
                             at /home/matthias/vcs/github/rust_debug_assertions/compiler/rustc_lint/src/context.rs:1115:24
31:     0x563da1084238 - <rustc_lint[cbe75d113ae0540b]::context::LateContext as rustc_lint[cbe75d113ae0540b]::context::LintContext>::struct_span_lint::<rustc_span[8fc2bc2477ece13]::span_encoding::Span, alloc[86fc1011f0da8be9]::string::String, clippy_utils[589fb9e96ed0da48]::diagnostics::span_lint_and_then<rustc_lint[cbe75d113ae0540b]::context::LateContext, rustc_span[8fc2bc2477ece13]::span_encoding::Span, clippy_lints[6ca63caa9e712f41]::returns::emit_return_lint::{closure#0}>::{closure#0}>
                             at /home/matthias/vcs/github/rust_debug_assertions/compiler/rustc_lint/src/context.rs:1017:9
32:     0x563da1084238 - clippy_utils[589fb9e96ed0da48]::diagnostics::span_lint_and_then::<rustc_lint[cbe75d113ae0540b]::context::LateContext, rustc_span[8fc2bc2477ece13]::span_encoding::Span, clippy_lints[6ca63caa9e712f41]::returns::emit_return_lint::{closure#0}>
                             at /home/matthias/vcs/github/rust_debug_assertions/src/tools/clippy/clippy_utils/src/diagnostics.rs:148:5
33:     0x563da13628f8 - clippy_lints[6ca63caa9e712f41]::returns::emit_return_lint
                             at /home/matthias/vcs/github/rust_debug_assertions/src/tools/clippy/clippy_lints/src/returns.rs:321:5
34:     0x563da13628f8 - clippy_lints[6ca63caa9e712f41]::returns::check_final_expr
                             at /home/matthias/vcs/github/rust_debug_assertions/src/tools/clippy/clippy_lints/src/returns.rs:281:13
35:     0x563da1361bb0 - clippy_lints[6ca63caa9e712f41]::returns::check_block_return
36:     0x563da1361b14 - <clippy_lints[6ca63caa9e712f41]::returns::Return as rustc_lint[cbe75d113ae0540b]::passes::LateLintPass>::check_fn
                             at /home/matthias/vcs/github/rust_debug_assertions/src/tools/clippy/clippy_lints/src/returns.rs:188:17
37:     0x7f4c87c3ba46 - <rustc_lint[cbe75d113ae0540b]::late::RuntimeCombinedLateLintPass as rustc_lint[cbe75d113ae0540b]::passes::LateLintPass>::check_fn
                             at /home/matthias/vcs/github/rust_debug_assertions/compiler/rustc_lint/src/late.rs:330:21
38:     0x7f4c87c3ba46 - <rustc_lint[cbe75d113ae0540b]::late::LateContextAndPass<rustc_lint[cbe75d113ae0540b]::late::RuntimeCombinedLateLintPass> as rustc_hir[8fe631a716458333]::intravisit::Visitor>::visit_fn
                             at /home/matthias/vcs/github/rust_debug_assertions/compiler/rustc_lint/src/late.rs:192:9
39:     0x7f4c87c3ba46 - rustc_hir[8fe631a716458333]::intravisit::walk_item::<rustc_lint[cbe75d113ae0540b]::late::LateContextAndPass<rustc_lint[cbe75d113ae0540b]::late::RuntimeCombinedLateLintPass>>
                             at /home/matthias/vcs/github/rust_debug_assertions/compiler/rustc_hir/src/intravisit.rs:477:13
40:     0x7f4c87cdd886 - <rustc_lint[cbe75d113ae0540b]::late::LateContextAndPass<rustc_lint[cbe75d113ae0540b]::late::RuntimeCombinedLateLintPass> as rustc_hir[8fe631a716458333]::intravisit::Visitor>::visit_item::{closure#0}::{closure#0}
                             at /home/matthias/vcs/github/rust_debug_assertions/compiler/rustc_lint/src/late.rs:137:17
41:     0x7f4c87cdd886 - <rustc_lint[cbe75d113ae0540b]::late::LateContextAndPass<rustc_lint[cbe75d113ae0540b]::late::RuntimeCombinedLateLintPass>>::with_param_env::<<rustc_lint[cbe75d113ae0540b]::late::LateContextAndPass<rustc_lint[cbe75d113ae0540b]::late::RuntimeCombinedLateLintPass> as rustc_hir[8fe631a716458333]::intravisit::Visitor>::visit_item::{closure#0}::{closure#0}>
                             at /home/matthias/vcs/github/rust_debug_assertions/compiler/rustc_lint/src/late.rs:76:9
42:     0x7f4c87cdd886 - <rustc_lint[cbe75d113ae0540b]::late::LateContextAndPass<rustc_lint[cbe75d113ae0540b]::late::RuntimeCombinedLateLintPass> as rustc_hir[8fe631a716458333]::intravisit::Visitor>::visit_item::{closure#0}
                             at /home/matthias/vcs/github/rust_debug_assertions/compiler/rustc_lint/src/late.rs:135:13
43:     0x7f4c87cdd886 - <rustc_lint[cbe75d113ae0540b]::late::LateContextAndPass<rustc_lint[cbe75d113ae0540b]::late::RuntimeCombinedLateLintPass>>::with_lint_attrs::<<rustc_lint[cbe75d113ae0540b]::late::LateContextAndPass<rustc_lint[cbe75d113ae0540b]::late::RuntimeCombinedLateLintPass> as rustc_hir[8fe631a716458333]::intravisit::Visitor>::visit_item::{closure#0}>
                             at /home/matthias/vcs/github/rust_debug_assertions/compiler/rustc_lint/src/late.rs:64:9
44:     0x7f4c87cdd886 - <rustc_lint[cbe75d113ae0540b]::late::LateContextAndPass<rustc_lint[cbe75d113ae0540b]::late::RuntimeCombinedLateLintPass> as rustc_hir[8fe631a716458333]::intravisit::Visitor>::visit_item
                             at /home/matthias/vcs/github/rust_debug_assertions/compiler/rustc_lint/src/late.rs:134:9
45:     0x7f4c87cdd886 - <rustc_lint[cbe75d113ae0540b]::late::LateContextAndPass<rustc_lint[cbe75d113ae0540b]::late::RuntimeCombinedLateLintPass> as rustc_hir[8fe631a716458333]::intravisit::Visitor>::visit_nested_item
                             at /home/matthias/vcs/github/rust_debug_assertions/compiler/rustc_hir/src/intravisit.rs:239:13
46:     0x7f4c87cd8bb7 - rustc_hir[8fe631a716458333]::intravisit::walk_stmt::<rustc_lint[cbe75d113ae0540b]::late::LateContextAndPass<rustc_lint[cbe75d113ae0540b]::late::RuntimeCombinedLateLintPass>>
                             at /home/matthias/vcs/github/rust_debug_assertions/compiler/rustc_hir/src/intravisit.rs:607:33
...
...
...

@matthiaskrgr matthiaskrgr added C-bug Category: Clippy is not doing the correct thing I-ICE Issue: Clippy panicked, giving an Internal Compilation Error (ICE) ❄️ L-suggestion Lint: Improving, adding or fixing lint suggestions labels Jul 16, 2023
@bors bors closed this as completed in 3e0170b Jul 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-ICE Issue: Clippy panicked, giving an Internal Compilation Error (ICE) ❄️ L-suggestion Lint: Improving, adding or fixing lint suggestions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant