-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't suggest adding 'static lifetime to function arguments #69350
Comments
How should I go to avoid this error? |
This error in practice means references are forbidden, so don't use references. Usually you'll want to use This issue is about development of the Rust compiler. Please ask Rust programming questions on https://users.rust-lang.org/ |
Just ran into this incredibly useless compiler message and had to spend some time digging. I agree that this "help" message does more harm than good and it would probably be better to have no help than this suggestion. |
Another case of a user stuck, because the compiler told them to have https://users.rust-lang.org/t/how-to-solve-this-lifetime-problem/54129 |
Thanks for the answer. This needs to be fixed asap |
…dtwco Don't suggest adding `'static` lifetime to arguments Fixes rust-lang#69350 This is almost always the wrong this to do
Fixes rust-lang#73159 This is similar to rust-lang#69350 - if the user didn't initially write out a 'static lifetime, adding 'static in response to a lifetime error is usually the wrong thing to do.
…tsakis Don't suggest replacing region with 'static in NLL Fixes rust-lang#73159 This is similar to rust-lang#69350 - if the user didn't initially write out a 'static lifetime, adding 'static in response to a lifetime error is usually the wrong thing to do.
…tsakis Don't suggest replacing region with 'static in NLL Fixes rust-lang#73159 This is similar to rust-lang#69350 - if the user didn't initially write out a 'static lifetime, adding 'static in response to a lifetime error is usually the wrong thing to do.
When using a temporary reference in a context where temporary references are not allowed, rustc gives a technically-correct suggestion that in practice is most often misleading and makes beginners stuck trying to solve a wrong problem:
This suggestion is very unlikely to be useful in a real program. If the function is changed to require arguments with a
'static
lifetime, it generally just causes more borrow checking errors at the call sites of the function, causing inexperienced users dig deeper in the wrong direction.My suggestions:
Don't make code change suggestions for
'static
lifetime outside of globals. In this case no suggestion at all would be better than a misleading code change.Because the correct solution is most likely not to use a reference at all, don't focus the message on the (unusual) kind of reference that would work, but explain that most (i.e. non-
'static
) references won't work.I suggest changing "lifetime
'static
required" say something along the lines of "temporary references are not allowed".The text was updated successfully, but these errors were encountered: