Skip to content

Recursive types in a Vec<T> with generic parameters gives ambiguous error #110466

Closed
@Kjolnyr

Description

@Kjolnyr

I tried this code:

struct Foo<T> { v: Vec<Bar<T>> }
struct Bar<T> { f: Foo<T> }

I expected to see this happen:

error[[E0072]](https://doc.rust-lang.org/stable/error_codes/E0072.html): recursive types `Foo` and `Bar` have infinite size
 --> src/lib.rs:1:1
  |
1 | struct Foo<T> { v: Bar<T> }
  | ^^^^^^^^^^^^^      ------ recursive without indirection
2 | struct Bar<T> { f: Foo<T> }
  | ^^^^^^^^^^^^^      ------ recursive without indirection
  |
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle

OR actually compiling.

Instead, this happened: not compiling

error[E0392]: parameter `T` is never used
 --> src/main.rs:2:12
  |
2 | struct Foo<T> { v: Vec<Bar<T>> }
  |            ^ unused parameter
  |
  = help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData`
  = help: if you intended `T` to be a const parameter, use `const T: usize` instead

error[E0392]: parameter `T` is never used
 --> src/main.rs:3:12
  |
3 | struct Bar<T> { f: Foo<T> }
  |            ^ unused parameter
  |
  = help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData`
  = help: if you intended `T` to be a const parameter, use `const T: usize` instead

For more information about this error, try `rustc --explain E0392`.

Meta

rustc --version --verbose:

rustc 1.70.0-nightly (db0cbc48d 2023-03-26)
binary: rustc
commit-hash: db0cbc48d4aaa300713a95d9b317a365a474490c
commit-date: 2023-03-26
host: x86_64-pc-windows-msvc
release: 1.70.0-nightly
LLVM version: 16.0.0

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-varianceArea: Variance (https://doc.rust-lang.org/nomicon/subtyping.html)D-confusingDiagnostics: Confusing error or lint that should be reworked.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions