1
Fork 0

Handle empty where-clause better

This commit is contained in:
Michael Goulet 2022-06-05 17:37:45 -07:00
parent 8506b7d4e0
commit 9c47afe9fa
23 changed files with 78 additions and 59 deletions

View file

@ -324,7 +324,7 @@ pub trait InferCtxtExt<'tcx> {
fn predicate_constraint(generics: &hir::Generics<'_>, pred: String) -> (Span, String) {
(
generics.tail_span_for_predicate_suggestion(),
format!("{} {}", if generics.has_where_clause { "," } else { " where" }, pred,),
format!("{} {}", generics.add_where_or_trailing_comma(), pred),
)
}
@ -339,15 +339,16 @@ fn suggest_restriction<'tcx>(
fn_sig: Option<&hir::FnSig<'_>>,
projection: Option<&ty::ProjectionTy<'_>>,
trait_pred: ty::PolyTraitPredicate<'tcx>,
super_traits: Option<(&Ident, &hir::GenericBounds<'_>)>,
) {
// When we are dealing with a trait, `super_traits` will be `Some`:
// Given `trait T: A + B + C {}`
// - ^^^^^^^^^ GenericBounds
// |
// &Ident
let span = generics.span_for_predicates_or_empty_place();
if span.from_expansion() || span.desugaring_kind().is_some() {
super_traits: Option<(&Ident, &hir::GenericBounds<'_>)>,
) {
if generics.where_clause_span.from_expansion()
|| generics.where_clause_span.desugaring_kind().is_some()
{
return;
}
// Given `fn foo(t: impl Trait)` where `Trait` requires assoc type `A`...