Skip to content

borrowed_box lint and Any #1884

Closed
Closed
@stanislav-tkach

Description

@stanislav-tkach

I'm not sure that this is an issue, but it can be a little confusing.

I have the following situation: there is a function that works with panic::catch_unwind error (Box<Any + Send + 'static>):

fn foo(e: &Box<Any + Send>) {
    if let Some(s) = e.as_ref().downcast_ref::<&str>() { ... }
    ...
}

Clippy suggests the following:

warning: you seem to be trying to use `&Box<T>`. Consider using just `&T`
 --> src/main.rs:4:11
  |
4 | fn foo(e: &Box<Any + Send>) {
  |           ^^^^^^^^^^^^^^^^ help: try `&Any + Send`

Functions becomes more generic, that for sure, but Any is a specific type: foo call site must be updated otherwise instead of Any that contains a panic error it will take Any that contains Box<Any + Send>.

Probably borrowed_box lint should be disabled for Any type?

Metadata

Metadata

Labels

C-enhancementCategory: Enhancement of lints, like adding more cases or adding help messagesE-mediumCall for participation: Medium difficulty level problem and requires some initial experience.T-middleType: Probably requires verifiying types

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions