Skip to content

Commit 0e30f07

Browse files
committed
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`.
1 parent 787f415 commit 0e30f07

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/librustc/middle/typeck/variance.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,10 @@ impl<'a> ConstraintContext<'a> {
533533
}
534534
}
535535

536+
fn is_to_be_inferred(&self, param_id: ast::NodeId) -> bool {
537+
self.terms_cx.inferred_map.contains_key(&param_id)
538+
}
539+
536540
fn declared_variance(&self,
537541
param_def_id: ast::DefId,
538542
item_def_id: ast::DefId,
@@ -788,8 +792,10 @@ impl<'a> ConstraintContext<'a> {
788792
variance: VarianceTermPtr<'a>) {
789793
match region {
790794
ty::ReEarlyBound(param_id, _, _) => {
791-
let index = self.inferred_index(param_id);
792-
self.add_constraint(index, variance);
795+
if self.is_to_be_inferred(param_id) {
796+
let index = self.inferred_index(param_id);
797+
self.add_constraint(index, variance);
798+
}
793799
}
794800

795801
ty::ReStatic => { }

0 commit comments

Comments
 (0)