-
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
Provide suggestion to dereference closure tail if appropriate #122213
Conversation
These commits modify the If this was unintentional then you should revert the changes before this PR is merged. |
The checks to verify that the value can indeed be dereferenced and it will continue to satisfy the trait bounds from the method are a bit much, and we could remove them in favor of a more approximate check ("when closure return value, always suggest dereference"?). The logic as written will not work for a case where a single level of dereferencing would work with the existing lifetimes. |
This comment has been minimized.
This comment has been minimized.
When encoutnering a case like ```rust //@ run-rustfix use std::collections::HashMap; fn main() { let vs = vec![0, 0, 1, 1, 3, 4, 5, 6, 3, 3, 3]; let mut counts = HashMap::new(); for num in vs { let count = counts.entry(num).or_insert(0); *count += 1; } let _ = counts.iter().max_by_key(|(_, v)| v); ``` produce the following suggestion ``` error: lifetime may not live long enough --> $DIR/return-value-lifetime-error.rs:13:47 | LL | let _ = counts.iter().max_by_key(|(_, v)| v); | ------- ^ returning this value requires that `'1` must outlive `'2` | | | | | return type of closure is &'2 &i32 | has type `&'1 (&i32, &i32)` | help: dereference the return value | LL | let _ = counts.iter().max_by_key(|(_, v)| **v); | ++ ``` Fix rust-lang#50195.
Stop exporting `TypeckRootCtxt` and `FnCtxt`. While they have many convenient APIs, it is better to expose dedicated functions for them noticed in rust-lang#122213
Rollup merge of rust-lang#123625 - oli-obk:private_fnctxt, r=fee1-dead Stop exporting `TypeckRootCtxt` and `FnCtxt`. While they have many convenient APIs, it is better to expose dedicated functions for them noticed in rust-lang#122213
Sorry it took so long to review, but the hack just felt like something the compiler should be able to answer for us. It now does so |
@bors r=oli-obk,estebank |
…bank Provide suggestion to dereference closure tail if appropriate When encoutnering a case like ```rust use std::collections::HashMap; fn main() { let vs = vec![0, 0, 1, 1, 3, 4, 5, 6, 3, 3, 3]; let mut counts = HashMap::new(); for num in vs { let count = counts.entry(num).or_insert(0); *count += 1; } let _ = counts.iter().max_by_key(|(_, v)| v); ``` produce the following suggestion ``` error: lifetime may not live long enough --> $DIR/return-value-lifetime-error.rs:13:47 | LL | let _ = counts.iter().max_by_key(|(_, v)| v); | ------- ^ returning this value requires that `'1` must outlive `'2` | | | | | return type of closure is &'2 &i32 | has type `&'1 (&i32, &i32)` | help: dereference the return value | LL | let _ = counts.iter().max_by_key(|(_, v)| **v); | ++ ``` Fix rust-lang#50195.
💔 Test failed - checks-actions |
@bors retry |
☀️ Test successful - checks-actions |
Finished benchmarking commit (0827378): comparison URL. Overall result: ✅ improvements - no action needed@rustbot label: -perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)This benchmark run did not return any relevant results for this metric. CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 675.519s -> 676.971s (0.21%) |
…t-deref, r=oli-obk Make `suggest_deref_closure_return` more idiomatic/easier to understand The only functional change here really is just making it not use a fresh type variable for upvars. I'll point that out in the code. The rest of the changes are just stylistic, because reading this code was really confusing me (variable names were vague, ways of accessing types were unidiomatic, order of operations was kind of strange, etc). This is stacked on rust-lang#123989. r? oli-obk since you approved rust-lang#122213
Rollup merge of rust-lang#123990 - compiler-errors:suggest-closure-ret-deref, r=oli-obk Make `suggest_deref_closure_return` more idiomatic/easier to understand The only functional change here really is just making it not use a fresh type variable for upvars. I'll point that out in the code. The rest of the changes are just stylistic, because reading this code was really confusing me (variable names were vague, ways of accessing types were unidiomatic, order of operations was kind of strange, etc). This is stacked on rust-lang#123989. r? oli-obk since you approved rust-lang#122213
Stop exporting `TypeckRootCtxt` and `FnCtxt`. While they have many convenient APIs, it is better to expose dedicated functions for them noticed in rust-lang#122213
When encoutnering a case like
produce the following suggestion
Fix #50195.