diff options
| author | Ashley Mannix <kodraus@hey.com> | 2021-01-18 21:53:26 +1000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-01-18 21:53:26 +1000 |
| commit | d3ff9ac8e8899f06a32e85d9d1a8ec7b2abd6765 (patch) | |
| tree | 55e544cdfe8291bb0be9f0986f2360ad2268f084 | |
| parent | c7ca540da279406e055f71f58feb6427314322ab (diff) | |
| parent | 84b056d5970b3f91073de0414a03d613ecc1009f (diff) | |
| download | rust-d3ff9ac8e8899f06a32e85d9d1a8ec7b2abd6765.tar.gz rust-d3ff9ac8e8899f06a32e85d9d1a8ec7b2abd6765.zip | |
Rollup merge of #81100 - lcnr:encode_with_shorthand, r=oli-obk
prevent potential bug in `encode_with_shorthand`. see https://rust-lang.zulipchat.com/#narrow/stream/233931-t-compiler.2Fmajor-changes/topic/Remove.20PredicateKind.20in.20favor.20of.20only.20Bin.E2.80.A6.20compiler-team.23397/near/223012169
| -rw-r--r-- | compiler/rustc_middle/src/ty/codec.rs | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/compiler/rustc_middle/src/ty/codec.rs b/compiler/rustc_middle/src/ty/codec.rs index a7b0ff45b97..0dad5df4855 100644 --- a/compiler/rustc_middle/src/ty/codec.rs +++ b/compiler/rustc_middle/src/ty/codec.rs @@ -18,7 +18,6 @@ use rustc_data_structures::fx::FxHashMap; use rustc_hir::def_id::{CrateNum, DefId}; use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; use rustc_span::Span; -use std::convert::{TryFrom, TryInto}; use std::hash::Hash; use std::intrinsics; use std::marker::DiscriminantKind; @@ -81,7 +80,8 @@ where E: TyEncoder<'tcx>, M: for<'b> Fn(&'b mut E) -> &'b mut FxHashMap<T, usize>, T: EncodableWithShorthand<'tcx, E>, - <T::Variant as DiscriminantKind>::Discriminant: Ord + TryFrom<usize>, + // The discriminant and shorthand must have the same size. + T::Variant: DiscriminantKind<Discriminant = isize>, { let existing_shorthand = cache(encoder).get(value).copied(); if let Some(shorthand) = existing_shorthand { @@ -97,7 +97,7 @@ where // The shorthand encoding uses the same usize as the // discriminant, with an offset so they can't conflict. let discriminant = intrinsics::discriminant_value(variant); - assert!(discriminant < SHORTHAND_OFFSET.try_into().ok().unwrap()); + assert!(SHORTHAND_OFFSET > discriminant as usize); let shorthand = start + SHORTHAND_OFFSET; |
