@@ -33,7 +33,6 @@ use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
3333use rustc_span:: source_map:: { respan, Spanned } ;
3434use rustc_span:: symbol:: { kw, sym, Ident , Symbol } ;
3535use rustc_span:: { Span , DUMMY_SP } ;
36- use std:: cmp:: Ordering ;
3736use std:: convert:: TryFrom ;
3837use std:: fmt;
3938use std:: mem;
@@ -324,46 +323,17 @@ pub type GenericBounds = Vec<GenericBound>;
324323/// Specifies the enforced ordering for generic parameters. In the future,
325324/// if we wanted to relax this order, we could override `PartialEq` and
326325/// `PartialOrd`, to allow the kinds to be unordered.
327- #[ derive( Hash , Clone , Copy ) ]
326+ #[ derive( Hash , Clone , Copy , PartialEq , Eq , PartialOrd , Ord ) ]
328327pub enum ParamKindOrd {
329328 Lifetime ,
330- Type ,
331- Const ,
332- // `Infer` is not actually constructed directly from the AST, but is implicitly constructed
333- // during HIR lowering, and `ParamKindOrd` will implicitly order inferred variables last.
334- Infer ,
335- }
336-
337- impl Ord for ParamKindOrd {
338- fn cmp ( & self , other : & Self ) -> Ordering {
339- use ParamKindOrd :: * ;
340- let to_int = |v| match v {
341- Lifetime => 0 ,
342- Infer | Type | Const => 1 ,
343- } ;
344-
345- to_int ( * self ) . cmp ( & to_int ( * other) )
346- }
347- }
348- impl PartialOrd for ParamKindOrd {
349- fn partial_cmp ( & self , other : & Self ) -> Option < Ordering > {
350- Some ( self . cmp ( other) )
351- }
352- }
353- impl PartialEq for ParamKindOrd {
354- fn eq ( & self , other : & Self ) -> bool {
355- self . cmp ( other) == Ordering :: Equal
356- }
329+ TypeOrConst ,
357330}
358- impl Eq for ParamKindOrd { }
359331
360332impl fmt:: Display for ParamKindOrd {
361333 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
362334 match self {
363335 ParamKindOrd :: Lifetime => "lifetime" . fmt ( f) ,
364- ParamKindOrd :: Type => "type" . fmt ( f) ,
365- ParamKindOrd :: Const { .. } => "const" . fmt ( f) ,
366- ParamKindOrd :: Infer => "infer" . fmt ( f) ,
336+ ParamKindOrd :: TypeOrConst => "type and const" . fmt ( f) ,
367337 }
368338 }
369339}
0 commit comments