]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_typeck/constrained_type_params.rs
Rollup merge of #27502 - rust-lang:grammer, r=brson
[rust.git] / src / librustc_typeck / constrained_type_params.rs
index 09539931c34465f9ef78fa6922a6d8d3e71e7580..7844d71462cfccf93c2942ef5a1e3a779b8e84d3 100644 (file)
@@ -19,10 +19,21 @@ pub enum Parameter {
     Region(ty::EarlyBoundRegion),
 }
 
+/// Returns the list of parameters that are constrained by the type `ty`
+/// - i.e. the value of each parameter in the list is uniquely determined
+/// by `ty` (see RFC 447).
 pub fn parameters_for_type<'tcx>(ty: Ty<'tcx>) -> Vec<Parameter> {
-    ty.walk()
-      .flat_map(|ty| parameters_for_type_shallow(ty))
-      .collect()
+    let mut result = vec![];
+    ty.maybe_walk(|t| {
+        if let ty::TyProjection(..) = t.sty {
+            false // projections are not injective.
+        } else {
+            result.append(&mut parameters_for_type_shallow(t));
+            // non-projection type constructors are injective.
+            true
+        }
+    });
+    result
 }
 
 pub fn parameters_for_trait_ref<'tcx>(trait_ref: &ty::TraitRef<'tcx>) -> Vec<Parameter> {