From e9fb6a9ea5a4366acdb93b62f133288f98b9b03f Mon Sep 17 00:00:00 2001 From: Christopher Durham Date: Thu, 20 Oct 2022 14:49:55 -0500 Subject: [PATCH] Implement PartialOrd for Cursor --- src/buffer.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/buffer.rs b/src/buffer.rs index 161b614c80..76ee1b33db 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -14,7 +14,7 @@ use crate::proc_macro as pm; use crate::Lifetime; use proc_macro2::{Delimiter, Group, Ident, Literal, Punct, Spacing, Span, TokenStream, TokenTree}; -use std::marker::PhantomData; +use std::{cmp::Ordering, marker::PhantomData}; /// Internal type which is used instead of `TokenTree` to represent a token tree /// within a `TokenBuffer`. @@ -348,8 +348,16 @@ impl<'a> Eq for Cursor<'a> {} impl<'a> PartialEq for Cursor<'a> { fn eq(&self, other: &Self) -> bool { let Cursor { ptr, scope, marker } = self; - let _ = marker; - *ptr == other.ptr && *scope == other.scope + let _ = (scope, marker); + *ptr == other.ptr + } +} + +impl<'a> PartialOrd for Cursor<'a> { + fn partial_cmp(&self, other: &Self) -> Option { + let Cursor { ptr, scope, marker } = self; + let _ = (scope, marker); + ptr.partial_cmp(&other.ptr) } }