Skip to content

Suggest adding a reference for &[str], not just str #95244

@jyn514

Description

@jyn514

Given the following code: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=0682c1798c04ce89d5780a3124a755ea

fn f(x: &[str]) {}

The current output is:

error[E0277]: the size for values of type `str` cannot be known at compilation time
 --> src/lib.rs:1:10
  |
1 | fn f(x: &[str]) {}
  |          ^^^^^ doesn't have a size known at compile-time
  |
  = help: the trait `Sized` is not implemented for `str`
  = note: slice and array elements must have `Sized` type

Ideally the output should look like:

error[E0277]: the size for values of type `str` cannot be known at compilation time
 --> src/lib.rs:1:6
  |
1 | fn f(x: &[str]) {}
  |           ^^^ doesn't have a size known at compile-time
  |
  = help: the trait `Sized` is not implemented for `str`
help: function arguments must have a statically known size, borrowed types always have a known size
  |
1 | fn f(x: &[&str]) {}
  |           +

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsD-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.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