Skip to content
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

NLL: suggested rewritten input types should preserve user-written lifetimes when needed #52880

Closed
pnkfelix opened this issue Jul 30, 2018 · 0 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-NLL Area: Non-lexical lifetimes (NLL) E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. NLL-diagnostics Working towards the "diagnostic parity" goal

Comments

@pnkfelix
Copy link
Member

While working on #52663, I saw a collection of cases where the .nll.stderr files shows that we are currently generating a diagnostic where we suggest the user do something like change a &-type to a &mut-type, but the problem is that in adding the mut, we seem to lose bits of the original input type that it probably needs, such as explicit lifetimes.

See for example:

LL | fn foo<'z>(&'z self) {
| -------- help: consider changing this to be a mutable reference: `&mut self`

LL | fn foo2<'a>(&'a self, other: &Z) {
| -------- help: consider changing this to be a mutable reference: `&mut self`

LL | fn foo3<'a>(self: &'a Self, other: &Z) {
| -------- help: consider changing this to be a mutable reference: `&mut Z`

LL | fn assign_field2<'a>(x: &'a Own<Point>) {
| -------------- help: consider changing this to be a mutable reference: `&mut Own<Point>`

LL | fn assign_method2<'a>(x: &'a Own<Point>) {
| -------------- help: consider changing this to be a mutable reference: `&mut Own<Point>`

LL | pub fn foo<'a>(mut a: &'a String) {
| ---------- help: consider changing this to be a mutable reference: `&mut std::string::String`

LL | fn reborrow_mut<'a>(t: &'a &'a mut i32) -> &'a mut i32 where &'a mut i32: Copy {
| --------------- help: consider changing this to be a mutable reference: `&mut &mut i32`

LL | fn copy_reborrow_mut<'a>(t: &'a &'a mut i32) -> &'a mut i32 where &'a mut i32: Copy {
| --------------- help: consider changing this to be a mutable reference: `&mut &mut i32`

@pnkfelix pnkfelix added A-NLL Area: Non-lexical lifetimes (NLL) NLL-diagnostics Working towards the "diagnostic parity" goal WG-compiler-nll labels Jul 30, 2018
@estebank estebank added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. A-diagnostics Area: Messages for errors, warnings, and lints labels Jul 30, 2018
Mark-Simulacrum added a commit to Mark-Simulacrum/rust that referenced this issue Aug 1, 2018
Include lifetime in mutability suggestion in NLL messages

Fix rust-lang#52880.
pietroalbini added a commit to pietroalbini/rust that referenced this issue Aug 1, 2018
Include lifetime in mutability suggestion in NLL messages

Fix rust-lang#52880.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-NLL Area: Non-lexical lifetimes (NLL) E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. NLL-diagnostics Working towards the "diagnostic parity" goal
Projects
None yet
Development

No branches or pull requests

2 participants