- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`Area: Suggestions generated by the compiler applied by `cargo fix`D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.Diagnostics: A structured suggestion resulting in incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Code
fn main() {
    struct StructA<A, B = A> {
        _marker: std::marker::PhantomData<fn() -> (A, B)>,
    }
    struct StructB {
        a: StructA<isize, [u8]>,
    }
}Current output
error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
 --> src\main.rs:7:12
  |
7 |         a: StructA<isize, [u8]>,
  |            ^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
  |
  = help: the trait `Sized` is not implemented for `[u8]`
note: required by a bound in `StructA`
 --> src\main.rs:2:23
  |
2 |     struct StructA<A, B = A> {
  |                       ^^^^^ required by this bound in `StructA`
help: consider relaxing the implicit `Sized` restriction
  |
2 |     struct StructA<A, B = A: ?Sized> {
  |                            ++++++++Desired output
error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
 --> src\main.rs:7:12
  |
7 |         a: StructA<isize, [u8]>,
  |            ^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
  |
  = help: the trait `Sized` is not implemented for `[u8]`
note: required by a bound in `StructA`
 --> src\main.rs:2:23
  |
2 |     struct StructA<A, B = A> {
  |                       ^^^^^ required by this bound in `StructA`
help: consider relaxing the implicit `Sized` restriction
  |
2 |     struct StructA<A, B: ?Sized = A> {
  |                            ++++++++Rationale and extra context
No response
Other cases
No response
Rust Version
$ rustc --version --verbose
rustc 1.76.0 (07dca489a 2024-02-04)
binary: rustc
commit-hash: 07dca489ac2d933c78d3c5158e3f43beefeb02ce
commit-date: 2024-02-04
host: x86_64-pc-windows-msvc
release: 1.76.0
LLVM version: 17.0.6Anything else?
No response
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`Area: Suggestions generated by the compiler applied by `cargo fix`D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.Diagnostics: A structured suggestion resulting in incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.