mirror of
https://github.com/rust-lang/rust-clippy
synced 2025-02-17 06:28:42 +00:00
Fix cast_lossless false positive in impl const fn
Fixes https://github.com/rust-lang/rust-clippy/issues/3656#issuecomment-526387382
This commit is contained in:
parent
28a8a6a483
commit
fb1ae1747f
5 changed files with 48 additions and 0 deletions
|
@ -88,6 +88,10 @@ pub fn in_constant(cx: &LateContext<'_, '_>, id: HirId) -> bool {
|
|||
node: ItemKind::Fn(_, header, ..),
|
||||
..
|
||||
}) => header.constness == Constness::Const,
|
||||
Node::ImplItem(&ImplItem {
|
||||
node: ImplItemKind::Method(ref sig, _),
|
||||
..
|
||||
}) => sig.header.constness == Constness::Const,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,3 +32,14 @@ fn main() {
|
|||
const fn abc(input: f32) -> f64 {
|
||||
input as f64
|
||||
}
|
||||
|
||||
// Same as the above issue. We can't suggest `::from` in const fns in impls
|
||||
mod cast_lossless_in_impl {
|
||||
struct A;
|
||||
|
||||
impl A {
|
||||
pub const fn convert(x: f32) -> f64 {
|
||||
x as f64
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,3 +32,14 @@ fn main() {
|
|||
const fn abc(input: f32) -> f64 {
|
||||
input as f64
|
||||
}
|
||||
|
||||
// Same as the above issue. We can't suggest `::from` in const fns in impls
|
||||
mod cast_lossless_in_impl {
|
||||
struct A;
|
||||
|
||||
impl A {
|
||||
pub const fn convert(x: f32) -> f64 {
|
||||
x as f64
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,3 +34,14 @@ fn main() {
|
|||
const fn abc(input: u16) -> u32 {
|
||||
input as u32
|
||||
}
|
||||
|
||||
// Same as the above issue. We can't suggest `::from` in const fns in impls
|
||||
mod cast_lossless_in_impl {
|
||||
struct A;
|
||||
|
||||
impl A {
|
||||
pub const fn convert(x: u32) -> u64 {
|
||||
x as u64
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,3 +34,14 @@ fn main() {
|
|||
const fn abc(input: u16) -> u32 {
|
||||
input as u32
|
||||
}
|
||||
|
||||
// Same as the above issue. We can't suggest `::from` in const fns in impls
|
||||
mod cast_lossless_in_impl {
|
||||
struct A;
|
||||
|
||||
impl A {
|
||||
pub const fn convert(x: u32) -> u64 {
|
||||
x as u64
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue