From a4f6d3e5c27e09f9fab591c19391b53a4175b666 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Mon, 30 Aug 2021 19:01:34 +0200 Subject: [PATCH] Fix lifetime generics in >::try_from suggestion. --- .../src/check/method/prelude2021.rs | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/compiler/rustc_typeck/src/check/method/prelude2021.rs b/compiler/rustc_typeck/src/check/method/prelude2021.rs index b5bc9d3599ac..0ab64170e4c2 100644 --- a/compiler/rustc_typeck/src/check/method/prelude2021.rs +++ b/compiler/rustc_typeck/src/check/method/prelude2021.rs @@ -239,16 +239,23 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let trait_path = self.trait_path_or_bare_name(span, expr_id, pick.item.container.id()); let trait_generics = self.tcx.generics_of(pick.item.container.id()); - let parameter_count = trait_generics.count() - (trait_generics.has_self as usize); - let trait_name = if parameter_count == 0 { - trait_path - } else { - format!( - "{}<{}>", - trait_path, - std::iter::repeat("_").take(parameter_count).collect::>().join(", ") - ) - }; + let trait_name = + if trait_generics.params.len() <= trait_generics.has_self as usize { + trait_path + } else { + let counts = trait_generics.own_counts(); + format!( + "{}<{}>", + trait_path, + std::iter::repeat("'_") + .take(counts.lifetimes) + .chain(std::iter::repeat("_").take( + counts.types + counts.consts - trait_generics.has_self as usize + )) + .collect::>() + .join(", ") + ) + }; let mut lint = lint.build(&format!( "trait-associated function `{}` will become ambiguous in Rust 2021",