Closed
Description
fn foo(bar: str) {}
Errors:
Compiling playground v0.0.1 (/playground)
error[E0277]: the size for values of type `str` cannot be known at compilation time
--> src/lib.rs:1:8
|
1 | fn foo(bar: 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 foo(&bar: str) {}
| ^
error: aborting due to previous error
Applying the suggestion leads to yet more errors. The new errors do suggest using &str
, but they still suggest invalid code:
error[E0308]: mismatched types
--> src/lib.rs:1:8
|
1 | fn foo(&bar: str) {}
| ^^^^-----
| | |
| | expected due to this
| expected `str`, found reference
| help: did you mean `bar`: `&str`
|
= note: expected type `str`
found reference `&_`
error[E0277]: the size for values of type `str` cannot be known at compilation time
--> src/lib.rs:1:8
|
1 | fn foo(&bar: 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 foo(&bar: &str) {}
| ^
error: aborting due to 2 previous errors
After applying the new suggestions, I get:
error[E0277]: the size for values of type `str` cannot be known at compilation time
--> src/lib.rs:1:9
|
1 | fn foo(&bar: &str) {}
| ^^^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `str`
= note: all local variables must have a statically known size
= help: unsized locals are gated as an unstable feature
error: aborting due to previous error
This seems likely to send new users in circles.
Metadata
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsArea: Suggestions generated by the compiler applied by `cargo fix`Category: This is a bug.Diagnostics: A diagnostic that is giving misleading or incorrect information.Diagnostics: A structured suggestion resulting in incorrect code.Diagnostics: Confusing error or lint; hard to understand for new users.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.Medium priorityRelevant to the compiler team, which will review and decide on the PR/issue.