about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorTaylor Yu <tlyu@mit.edu>2021-06-18 14:13:12 -0500
committerTaylor Yu <tlyu@mit.edu>2021-11-15 22:31:55 -0600
commitc9fcbda389adfffd72405905de67be1aa444820f (patch)
treeb3967d4f2483fac5be51a5ca302e9ebeee2a2c9b /compiler
parentb0535508474fb4353a3b83ef79df87817f028a71 (diff)
downloadrust-c9fcbda389adfffd72405905de67be1aa444820f.tar.gz
rust-c9fcbda389adfffd72405905de67be1aa444820f.zip
check where clause before suggesting unsized
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs19
1 files changed, 19 insertions, 0 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs
index 79194718d1e..305af6db298 100644
--- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs
+++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs
@@ -14,6 +14,7 @@ use crate::infer::{self, InferCtxt, TyCtxtInferExt};
 use rustc_data_structures::fx::FxHashMap;
 use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder, ErrorReported};
 use rustc_hir as hir;
+use rustc_hir::def::{DefKind, Res};
 use rustc_hir::def_id::DefId;
 use rustc_hir::intravisit::Visitor;
 use rustc_hir::GenericParam;
@@ -2009,6 +2010,24 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
             Some(param) => param,
             _ => return,
         };
+        let param_def_id = self.tcx.hir().local_def_id(param.hir_id).to_def_id();
+        let preds = generics.where_clause.predicates.iter();
+        let explicitly_sized = preds
+            .filter_map(|pred| match pred {
+                hir::WherePredicate::BoundPredicate(bp) => Some(bp),
+                _ => None,
+            })
+            .flat_map(|bp| match bp.bounded_ty.kind {
+                hir::TyKind::Path(hir::QPath::Resolved(
+                    None,
+                    &hir::Path { res: Res::Def(DefKind::TyParam, def_id), .. },
+                )) if def_id == param_def_id => bp.bounds,
+                _ => &[][..],
+            })
+            .any(|bound| bound.trait_ref().and_then(|tr| tr.trait_def_id()) == sized_trait);
+        if explicitly_sized {
+            return;
+        }
         debug!("maybe_suggest_unsized_generics: param={:?}", param);
         match node {
             hir::Node::Item(