From 58797b01f1b0925095986e4f42b839cdb2a99ac8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Tue, 12 May 2020 11:56:11 -0700 Subject: [PATCH] review comments --- .../traits/error_reporting/suggestions.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/librustc_trait_selection/traits/error_reporting/suggestions.rs b/src/librustc_trait_selection/traits/error_reporting/suggestions.rs index c9eb2ee6c5a33..5c4ba40bf38e3 100644 --- a/src/librustc_trait_selection/traits/error_reporting/suggestions.rs +++ b/src/librustc_trait_selection/traits/error_reporting/suggestions.rs @@ -175,6 +175,11 @@ fn suggest_restriction( trait_ref: ty::PolyTraitRef<'_>, 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.where_clause.span_for_predicates_or_empty_place(); if span.from_expansion() || span.desugaring_kind().is_some() { return; @@ -311,7 +316,8 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { ident, kind: hir::ItemKind::Trait(_, _, generics, bounds, _), .. - }) if param_ty && self_ty == self.tcx.types.self_param => { + }) if self_ty == self.tcx.types.self_param => { + assert!(param_ty); // Restricting `Self` for a single method. suggest_restriction( &generics, @@ -329,7 +335,8 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { generics, kind: hir::TraitItemKind::Fn(..), .. - }) if param_ty && self_ty == self.tcx.types.self_param => { + }) if self_ty == self.tcx.types.self_param => { + assert!(param_ty); // Restricting `Self` for a single method. suggest_restriction( &generics, "`Self`", err, None, projection, trait_ref, None,