Auto merge of #122213 - estebank:issue-50195, r=oli-obk,estebank
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 #50195.
This commit is contained in:
commit
08273780d8
8 changed files with 241 additions and 5 deletions
|
@ -983,6 +983,9 @@ rustc_queries! {
|
|||
query diagnostic_only_typeck(key: LocalDefId) -> &'tcx ty::TypeckResults<'tcx> {
|
||||
desc { |tcx| "type-checking `{}`", tcx.def_path_str(key) }
|
||||
}
|
||||
query lookup_method_for_diagnostic((def_id, hir_id): (LocalDefId, hir::HirId)) -> Option<DefId> {
|
||||
desc { |tcx| "lookup_method_for_diagnostics `{}`", tcx.def_path_str(def_id) }
|
||||
}
|
||||
|
||||
query used_trait_imports(key: LocalDefId) -> &'tcx UnordSet<LocalDefId> {
|
||||
desc { |tcx| "finding used_trait_imports `{}`", tcx.def_path_str(key) }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue