From 0e30f07abc76587f676e91770b7630ac9727b2cb Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Tue, 1 Apr 2014 18:31:04 +0200 Subject: [PATCH] Guard variance inference for params bound in non-variance context. Before adding a variance constrant for a given early-bound param, check if it was meant to be inferred. To support the above, added `fn is_to_be_inferred` to `variance::ConstraintContext`. --- src/librustc/middle/typeck/variance.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/librustc/middle/typeck/variance.rs b/src/librustc/middle/typeck/variance.rs index c6c79608f6c..b008e59d510 100644 --- a/src/librustc/middle/typeck/variance.rs +++ b/src/librustc/middle/typeck/variance.rs @@ -533,6 +533,10 @@ impl<'a> ConstraintContext<'a> { } } + fn is_to_be_inferred(&self, param_id: ast::NodeId) -> bool { + self.terms_cx.inferred_map.contains_key(¶m_id) + } + fn declared_variance(&self, param_def_id: ast::DefId, item_def_id: ast::DefId, @@ -788,8 +792,10 @@ impl<'a> ConstraintContext<'a> { variance: VarianceTermPtr<'a>) { match region { ty::ReEarlyBound(param_id, _, _) => { - let index = self.inferred_index(param_id); - self.add_constraint(index, variance); + if self.is_to_be_inferred(param_id) { + let index = self.inferred_index(param_id); + self.add_constraint(index, variance); + } } ty::ReStatic => { }