diff options
| author | Mara Bos <m-ou.se@m-ou.se> | 2021-08-30 19:01:34 +0200 |
|---|---|---|
| committer | Mara Bos <m-ou.se@m-ou.se> | 2021-08-30 19:01:34 +0200 |
| commit | a4f6d3e5c27e09f9fab591c19391b53a4175b666 (patch) | |
| tree | a698bad7cb61f42934f6c214992f5bd151157059 | |
| parent | 13edc17f65bcad7fe9046720a16fc192e810970e (diff) | |
| download | rust-a4f6d3e5c27e09f9fab591c19391b53a4175b666.tar.gz rust-a4f6d3e5c27e09f9fab591c19391b53a4175b666.zip | |
Fix lifetime generics in <T as Trait<..>>::try_from suggestion.
| -rw-r--r-- | compiler/rustc_typeck/src/check/method/prelude2021.rs | 27 |
1 files 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 b5bc9d3599a..0ab64170e4c 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::<Vec<_>>().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::<Vec<_>>() + .join(", ") + ) + }; let mut lint = lint.build(&format!( "trait-associated function `{}` will become ambiguous in Rust 2021", |
