diff options
| author | bors <bors@rust-lang.org> | 2019-05-01 03:06:13 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-05-01 03:06:13 +0000 |
| commit | 834bd1959cc06bbae08e7de65f09f326d1702a95 (patch) | |
| tree | a49c75970bcecf92daaa468beb3c2ee7c2dbbb7c | |
| parent | 96ee0ba59e12f5350e799ba724a58fd488a739f2 (diff) | |
| parent | f024196dd5468aeb684ac7437dc51dbf84dab67d (diff) | |
| download | rust-834bd1959cc06bbae08e7de65f09f326d1702a95.tar.gz rust-834bd1959cc06bbae08e7de65f09f326d1702a95.zip | |
Auto merge of #60280 - varkor:const-param-invariance, r=eddyb
Fix indexing issue for const parameter invariance We were previously not taking account of the parent parameters. r? @eddyb cc @Zoxc
| -rw-r--r-- | src/librustc_typeck/variance/solve.rs | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/src/librustc_typeck/variance/solve.rs b/src/librustc_typeck/variance/solve.rs index b783bbfad16..51a1d088ddc 100644 --- a/src/librustc_typeck/variance/solve.rs +++ b/src/librustc_typeck/variance/solve.rs @@ -78,6 +78,22 @@ impl<'a, 'tcx> SolveContext<'a, 'tcx> { } } + fn enforce_const_invariance(&self, generics: &ty::Generics, variances: &mut Vec<ty::Variance>) { + let tcx = self.terms_cx.tcx; + + // Make all const parameters invariant. + for param in generics.params.iter() { + if let ty::GenericParamDefKind::Const = param.kind { + variances[param.index as usize] = ty::Invariant; + } + } + + // Make all the const parameters in the parent invariant (recursively). + if let Some(def_id) = generics.parent { + self.enforce_const_invariance(tcx.generics_of(def_id), variances); + } + } + fn create_map(&self) -> FxHashMap<DefId, Lrc<Vec<ty::Variance>>> { let tcx = self.terms_cx.tcx; @@ -91,11 +107,7 @@ impl<'a, 'tcx> SolveContext<'a, 'tcx> { debug!("id={} variances={:?}", id, variances); // Const parameters are always invariant. - for (idx, param) in generics.params.iter().enumerate() { - if let ty::GenericParamDefKind::Const = param.kind { - variances[idx] = ty::Invariant; - } - } + self.enforce_const_invariance(generics, &mut variances); // Functions are permitted to have unused generic parameters: make those invariant. if let ty::FnDef(..) = tcx.type_of(def_id).sty { |
