diff options
| author | Dylan DPC <99973273+Dylan-DPC@users.noreply.github.com> | 2022-09-09 22:02:18 +0530 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-09-09 22:02:18 +0530 |
| commit | ae4973281bee496f107ed9db5c3ff1487981af4e (patch) | |
| tree | 99cf005ab7563587fe6018f388e70b7006f15e82 /compiler/rustc_ast/src | |
| parent | fcdd5016c518c3ac3e46183933c65dc23c9f5f51 (diff) | |
| parent | 5db69074988b0edf6751192336398d0673ee81a2 (diff) | |
| download | rust-ae4973281bee496f107ed9db5c3ff1487981af4e.tar.gz rust-ae4973281bee496f107ed9db5c3ff1487981af4e.zip | |
Rollup merge of #101573 - lcnr:param-kind-ord, r=BoxyUwU
update `ParamKindOrd` https://github.com/rust-lang/rust/pull/90207#discussion_r767160854 :grin: writing comments "for future prs" sure works well :3 r? `@BoxyUwU`
Diffstat (limited to 'compiler/rustc_ast/src')
| -rw-r--r-- | compiler/rustc_ast/src/ast.rs | 36 |
1 files changed, 3 insertions, 33 deletions
diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index c07ba88ae20..3f4911c4ecf 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -33,7 +33,6 @@ use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; use rustc_span::source_map::{respan, Spanned}; use rustc_span::symbol::{kw, sym, Ident, Symbol}; use rustc_span::{Span, DUMMY_SP}; -use std::cmp::Ordering; use std::convert::TryFrom; use std::fmt; use std::mem; @@ -324,46 +323,17 @@ pub type GenericBounds = Vec<GenericBound>; /// Specifies the enforced ordering for generic parameters. In the future, /// if we wanted to relax this order, we could override `PartialEq` and /// `PartialOrd`, to allow the kinds to be unordered. -#[derive(Hash, Clone, Copy)] +#[derive(Hash, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] pub enum ParamKindOrd { Lifetime, - Type, - Const, - // `Infer` is not actually constructed directly from the AST, but is implicitly constructed - // during HIR lowering, and `ParamKindOrd` will implicitly order inferred variables last. - Infer, -} - -impl Ord for ParamKindOrd { - fn cmp(&self, other: &Self) -> Ordering { - use ParamKindOrd::*; - let to_int = |v| match v { - Lifetime => 0, - Infer | Type | Const => 1, - }; - - to_int(*self).cmp(&to_int(*other)) - } -} -impl PartialOrd for ParamKindOrd { - fn partial_cmp(&self, other: &Self) -> Option<Ordering> { - Some(self.cmp(other)) - } -} -impl PartialEq for ParamKindOrd { - fn eq(&self, other: &Self) -> bool { - self.cmp(other) == Ordering::Equal - } + TypeOrConst, } -impl Eq for ParamKindOrd {} impl fmt::Display for ParamKindOrd { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { ParamKindOrd::Lifetime => "lifetime".fmt(f), - ParamKindOrd::Type => "type".fmt(f), - ParamKindOrd::Const { .. } => "const".fmt(f), - ParamKindOrd::Infer => "infer".fmt(f), + ParamKindOrd::TypeOrConst => "type and const".fmt(f), } } } |
