diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-10-02 17:10:45 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-10-02 17:10:45 +0200 |
| commit | 2e0db79f0b6ef4248d22b50b090c42fc77122cd0 (patch) | |
| tree | 07985f73c10f4cebb89156bd08149891beb89711 | |
| parent | 49f17ff74e0abe51daadaff37f796ccc68e2ed50 (diff) | |
| parent | e9b2d09ad7905c51e7795730147f8d2303fb4bbd (diff) | |
| download | rust-2e0db79f0b6ef4248d22b50b090c42fc77122cd0.tar.gz rust-2e0db79f0b6ef4248d22b50b090c42fc77122cd0.zip | |
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. https://github.com/rust-lang/rust/blob/9e3e5174462afaf6c3b9db9b35c6d1934521848a/compiler/rustc_metadata/src/rmeta/encoder.rs#L1566-L1567
| -rw-r--r-- | compiler/rustc_middle/src/values.rs | 2 | ||||
| -rw-r--r-- | tests/crashes/128327.rs | 5 | ||||
| -rw-r--r-- | tests/ui/infinite/auxiliary/alias.rs | 3 | ||||
| -rw-r--r-- | tests/ui/infinite/infinite-assoc.rs | 16 | ||||
| -rw-r--r-- | tests/ui/infinite/infinite-assoc.stderr | 25 |
5 files changed, 45 insertions, 6 deletions
diff --git a/compiler/rustc_middle/src/values.rs b/compiler/rustc_middle/src/values.rs index c98d88e22d4..48ca38344cf 100644 --- a/compiler/rustc_middle/src/values.rs +++ b/compiler/rustc_middle/src/values.rs @@ -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 { diff --git a/tests/crashes/128327.rs b/tests/crashes/128327.rs deleted file mode 100644 index a63f758c317..00000000000 --- a/tests/crashes/128327.rs +++ /dev/null @@ -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(){} diff --git a/tests/ui/infinite/auxiliary/alias.rs b/tests/ui/infinite/auxiliary/alias.rs index 59add7eb18b..5ae124e8aba 100644 --- a/tests/ui/infinite/auxiliary/alias.rs +++ b/tests/ui/infinite/auxiliary/alias.rs @@ -1,2 +1,5 @@ pub struct W<T>(T); pub type Wrapper<T> = W<T>; +pub trait Trait { + type T; +} diff --git a/tests/ui/infinite/infinite-assoc.rs b/tests/ui/infinite/infinite-assoc.rs new file mode 100644 index 00000000000..d128a7e0d2d --- /dev/null +++ b/tests/ui/infinite/infinite-assoc.rs @@ -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() {} diff --git a/tests/ui/infinite/infinite-assoc.stderr b/tests/ui/infinite/infinite-assoc.stderr new file mode 100644 index 00000000000..e6b91f13241 --- /dev/null +++ b/tests/ui/infinite/infinite-assoc.stderr @@ -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`. |
