only query params_in_repr if def kind is adt

This commit is contained in:
bohan 2024-10-02 17:36:31 +08:00
parent 9e3e517446
commit e9b2d09ad7
5 changed files with 45 additions and 6 deletions

View File

@ -358,7 +358,7 @@ fn find_item_ty_spans(
match ty.kind {
hir::TyKind::Path(hir::QPath::Resolved(_, path)) => {
if let Res::Def(kind, def_id) = path.res
&& !matches!(kind, DefKind::TyAlias)
&& matches!(kind, DefKind::Enum | DefKind::Struct | DefKind::Union)
{
let check_params = def_id.as_local().map_or(true, |def_id| {
if def_id == needle {

View File

@ -1,5 +0,0 @@
//@ known-bug: rust-lang/rust#128327
use std::ops::Deref;
struct Apple((Apple, <&'static [f64] as Deref>::Target(Banana ? Citron)));
fn main(){}

View File

@ -1,2 +1,5 @@
pub struct W<T>(T);
pub type Wrapper<T> = W<T>;
pub trait Trait {
type T;
}

View File

@ -0,0 +1,16 @@
//@ aux-build: alias.rs
// issue#128327
extern crate alias;
use alias::Trait;
struct S;
impl Trait for S {
type T = ();
}
struct A((A, <S as Trait>::T<NOT_EXIST?>));
//~^ ERROR: invalid `?` in type
//~| ERROR: recursive type `A` has infinite size
fn main() {}

View File

@ -0,0 +1,25 @@
error: invalid `?` in type
--> $DIR/infinite-assoc.rs:12:39
|
LL | struct A((A, <S as Trait>::T<NOT_EXIST?>));
| ^ `?` is only allowed on expressions, not types
|
help: if you meant to express that the type might not contain a value, use the `Option` wrapper type
|
LL | struct A((A, <S as Trait>::T<Option<NOT_EXIST>>));
| +++++++ ~
error[E0072]: recursive type `A` has infinite size
--> $DIR/infinite-assoc.rs:12:1
|
LL | struct A((A, <S as Trait>::T<NOT_EXIST?>));
| ^^^^^^^^ - recursive without indirection
|
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
|
LL | struct A((Box<A>, <S as Trait>::T<NOT_EXIST?>));
| ++++ +
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0072`.