Code
use std::any::Any;
pub trait Foo: Any {}
impl Foo for Box<dyn Foo> {}
impl dyn Foo {
#[expect(dead_code)]
fn downcast_ref<T: 'static>(&self) -> Option<&T> {
let this = self as &dyn Any;
if let Some(boxed) = this.downcast_ref::<Box<dyn Foo>>() {
boxed.downcast_ref::<T>()
} else {
this.downcast_ref::<T>()
}
}
}
Current output
warning: this lint expectation is unfulfilled
--> src/main.rs:8:14
|
8 | #[expect(dead_code)]
| ^^^^^^^^^
|
= note: `#[warn(unfulfilled_lint_expectations)]` on by default
Desired output
Rationale and extra context
This function is unused and it is reported as unused without the #[expect] attribute. My expectation would be that adding the #[expect] attribute suppresses the warning
Playground link
Other cases
use std::any::Any;
pub trait Foo: Any {}
impl Foo for Box<dyn Foo> {}
impl dyn Foo {
fn downcast_ref<T: 'static>(&self) -> Option<&T> {
let this = self as &dyn Any;
if let Some(boxed) = this.downcast_ref::<Box<dyn Foo>>() {
boxed.downcast_ref::<T>()
} else {
this.downcast_ref::<T>()
}
}
}
reports
warning: method `downcast_ref` is never used
--> src/main.rs:9:8
|
7 | impl dyn Foo {
| ------------ method in this implementation
8 | //#[expect(dead_code)]
9 | fn downcast_ref<T: 'static>(&self) -> Option<&T> {
| ^^^^^^^^^^^^
|
= note: `#[warn(dead_code)]` (part of `#[warn(unused)]`) on by default
Rust Version
1.93.0-nightly (2025-11-11 25d319a0f656ee8faa7a)
Anything else?
No response
Code
Current output
Desired output
Rationale and extra context
This function is unused and it is reported as unused without the
#[expect]attribute. My expectation would be that adding the#[expect]attribute suppresses the warningPlayground link
Other cases
reports
Rust Version
Anything else?
No response