Skip to content

Using an unsized value from slicing incorrectly should give a more helpful error message #20848

Closed
@huonw

Description

@huonw
fn main() {
    let y = "foo";
    let x = y[1..2];
}
<anon>:3:9: 3:10 error: the trait `core::marker::Sized` is not implemented for the type `str`
<anon>:3     let x = y[1..2];
                 ^

The fix is to write let x = &y[1..2]; but it's not the first thing that springs to mind given that error message, especially for a beginner.

cc #20783

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.WG-diagnosticsWorking group: Diagnostics

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions