Rollup merge of #131150 - bvanjoi:issue-128327, r=chenyukang

only query `params_in_repr` if def kind is adt

Fixes #128327

`params_in_repr` was only stored in `encode_info_for_adt`, so we only query it when the def kind belongs to them.

9e3e517446/compiler/rustc_metadata/src/rmeta/encoder.rs (L1566-L1567)
This commit is contained in:
Matthias Krüger 2024-10-02 17:10:45 +02:00 committed by GitHub
commit 2e0db79f0b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 45 additions and 6 deletions

View File

@ -358,7 +358,7 @@ fn find_item_ty_spans(
match ty.kind { match ty.kind {
hir::TyKind::Path(hir::QPath::Resolved(_, path)) => { hir::TyKind::Path(hir::QPath::Resolved(_, path)) => {
if let Res::Def(kind, def_id) = path.res 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| { let check_params = def_id.as_local().map_or(true, |def_id| {
if def_id == needle { 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 struct W<T>(T);
pub type Wrapper<T> = W<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`.