-
Notifications
You must be signed in to change notification settings - Fork 14k
Open
Labels
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.Category: This is a bug.L-dead_codeLint: dead_codeLint: dead_codeS-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueStatus: A Minimal Complete and Verifiable Example has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
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 defaultDesired output
No warningRationale 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
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
SwishSwushPow
Metadata
Metadata
Assignees
Labels
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.Category: This is a bug.L-dead_codeLint: dead_codeLint: dead_codeS-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueStatus: A Minimal Complete and Verifiable Example has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.