Skip to content

Lint against passing &Box<dyn Any> to a function accepting &dyn Any #14806

Open
@Ralith

Description

@Ralith

What it does

Functions taking &dyn Any will accept any 'static argument. Passing a &Box<dyn Any> (or other smart pointer, or upcasting another trait object that implies Any) is therefore possible, but probably not intended.

Advantage

Probably the intended effect.

Drawbacks

In rare cases someone might do this on purpose, but that's weird enough to merit explicit documentation.

Example

let x: &Box<dyn Any>;
frob(x)

Could be written as:

let x: &Box<dyn Any>;
frob(&**x)

Metadata

Metadata

Assignees

Labels

A-lintArea: New lints

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions