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

redundant-closure-for-method-calls suggests <dyn trait>::fn which does not compile #10446

Open
matthiaskrgr opened this issue Mar 4, 2023 · 0 comments
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied

Comments

@matthiaskrgr
Copy link
Member

Summary

.

Lint Name

redundant-closure-for-method-calls

Reproducer

I tried this code:

#![feature(error_generic_member_access, provide_any)]

use std::backtrace::{Backtrace};
use std::error::Error;

const _: fn(&dyn Error) -> Option<&Backtrace> = |err| err.request_ref::<Backtrace>();

pub fn main() {}

I saw this happen:

warning: redundant closure
 --> src/main.rs:6:49
  |
6 | const _: fn(&dyn Error) -> Option<&Backtrace> = |err| err.request_ref::<Backtrace>();
  |                                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `<dyn std::error::Error>::request_ref`
  |

Suggested code does not compile

The following errors were reported:
error[E0308]: mismatched types
 --> src/main.rs:6:49
  |
6 | const _: fn(&dyn Error) -> Option<&Backtrace> = <dyn std::error::Error>::request_ref;
  |                                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
  |
  = note: expected fn pointer `for<'a> fn(&'a (dyn std::error::Error + 'a)) -> std::option::Option<&'a std::backtrace::Backtrace>`
                found fn item `fn(&dyn std::error::Error) -> std::option::Option<&_> {<dyn std::error::Error>::request_ref::<_>}`

Version

rustc 1.69.0-nightly (b1719530f 2023-03-04)
binary: rustc
commit-hash: b1719530f44e3c8ec903f76020a52bd8764d5d10
commit-date: 2023-03-04
host: x86_64-unknown-linux-gnu
release: 1.69.0-nightly
LLVM version: 15.0.7

Additional Labels

No response

@matthiaskrgr matthiaskrgr added C-bug Category: Clippy is not doing the correct thing I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied I-false-positive Issue: The lint was triggered on code it shouldn't have labels Mar 4, 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-false-positive Issue: The lint was triggered on code it shouldn't have I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied
Projects
None yet
Development

No branches or pull requests

1 participant