Auto merge of #13045 - J-ZhengLi:missing_const_for_fn_FP, r=blyxyas

[`missing_const_for_fn`]: fix FP when arg ty is impl trait alias ty

closes: #13009

---

changelog: [`missing_const_for_fn`]: fix FP when arg ty is impl trait alias ty
This commit is contained in:
bors 2024-07-08 14:39:12 +00:00
commit 2ad8cdc81b
5 changed files with 68 additions and 1 deletions

View file

@ -7,6 +7,7 @@
#![warn(clippy::missing_const_for_fn)]
#![feature(start)]
#![feature(type_alias_impl_trait)]
extern crate helper;
extern crate proc_macros;
@ -190,3 +191,11 @@ mod with_extern {
extern "system" fn system() {}
extern "system-unwind" fn system_unwind() {}
}
mod with_ty_alias {
type Foo = impl std::fmt::Debug;
fn foo(_: Foo) {
let _: Foo = 1;
}
}

View file

@ -186,3 +186,18 @@ mod issue12677 {
}
}
}
mod with_ty_alias {
trait FooTrait {
type Foo: std::fmt::Debug;
fn bar(_: Self::Foo) {}
}
impl FooTrait for () {
type Foo = i32;
}
// NOTE: When checking the type of a function param, make sure it is not an alias with
// `AliasTyKind::Projection` before calling `TyCtxt::type_of` to find out what the actual type
// is. Because the associate ty could have no default, therefore would cause ICE, as demostrated
// in this test.
const fn alias_ty_is_projection(bar: <() as FooTrait>::Foo) {}
}

View file

@ -186,3 +186,18 @@ mod issue12677 {
}
}
}
mod with_ty_alias {
trait FooTrait {
type Foo: std::fmt::Debug;
fn bar(_: Self::Foo) {}
}
impl FooTrait for () {
type Foo = i32;
}
// NOTE: When checking the type of a function param, make sure it is not an alias with
// `AliasTyKind::Projection` before calling `TyCtxt::type_of` to find out what the actual type
// is. Because the associate ty could have no default, therefore would cause ICE, as demostrated
// in this test.
fn alias_ty_is_projection(bar: <() as FooTrait>::Foo) {}
}

View file

@ -261,5 +261,16 @@ help: make the function `const`
LL | pub const fn new(text: String) -> Self {
| +++++
error: aborting due to 19 previous errors
error: this could be a `const fn`
--> tests/ui/missing_const_for_fn/could_be_const.rs:202:5
|
LL | fn alias_ty_is_projection(bar: <() as FooTrait>::Foo) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: make the function `const`
|
LL | const fn alias_ty_is_projection(bar: <() as FooTrait>::Foo) {}
| +++++
error: aborting due to 20 previous errors