Repository navigation
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`C-bugCategory: This is a bug.Category: This is a bug.D-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.Diagnostics: A diagnostic that is giving misleading or incorrect information.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.Diagnostics: A structured suggestion resulting in incorrect code.D-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.Diagnostics: Confusing error or lint; hard to understand for new users.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.P-mediumMedium priorityMedium priorityT-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
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.
Reacted by Henry Boisdequin and Marcel Hellwig
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`C-bugCategory: This is a bug.Category: This is a bug.D-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.Diagnostics: A diagnostic that is giving misleading or incorrect information.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.Diagnostics: A structured suggestion resulting in incorrect code.D-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.Diagnostics: Confusing error or lint; hard to understand for new users.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.P-mediumMedium priorityMedium priorityT-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.
Activity
camelid commentedon Mar 6, 2021
Assigning
P-mediumand removingI-prioritizeas discussed in the prioritization working group.apiraino commentedon Mar 6, 2021
I've bisected to this nightly range:
+nightly-2020-07-12-x86_64-unknown-linux-gnu
346aec9b0=> old error msg+nightly-2020-07-26-x86_64-unknown-linux-gnu
d6953df14=> new error message(I cannot bisect further because in between of that range I cannot install nightlies 🤷♂️ )
hellow554 commentedon Apr 28, 2021
Funny enough, when using
_as variable name, the suggestion will get displayed correctly:hellow554 commentedon Apr 28, 2021
This seems to be fixed on nighlty, but not on beta...
somewhere between 5a4ab26...9d9c2c9
Fixed in 9d9c2c9
Fixed by #84313
So this can be closed @camelid 🎉
hellow554 commentedon Apr 28, 2021
But, as a sidenote: How could this ever be commited to master? I mean, it's obviosly wrong so say
&a: str:/I hope, that in the future the review process can be improved to detect such errors early on.
The error was introduced in #78152, where the test has been adapted to match the wrong syntax, but nobody has seen this :( Let's hope in the future it will get noticed right away 😊
camelid commentedon Apr 29, 2021
It looks like that PR caused a bunch of small diagnostics changes, so the reviewers probably just missed that bug.
camelid commentedon Apr 29, 2021
Assigning myself for adding a test. @rustbot claim
Rollup merge of rust-lang#84728 - camelid:sized-param-sugg-test, r=Ma…