Skip to content

Commit e9e85e8

Browse files
committed
Rollup merge of #33218 - oli-obk:interned_str_cmp, r=nikomatsakis
allow InternedString to be compared to &str directly
2 parents 98c91e0 + 6343f26 commit e9e85e8

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

src/libsyntax/attr.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -333,11 +333,11 @@ pub enum InlineAttr {
333333
pub fn find_inline_attr(diagnostic: Option<&Handler>, attrs: &[Attribute]) -> InlineAttr {
334334
attrs.iter().fold(InlineAttr::None, |ia,attr| {
335335
match attr.node.value.node {
336-
MetaItemKind::Word(ref n) if *n == "inline" => {
336+
MetaItemKind::Word(ref n) if n == "inline" => {
337337
mark_used(attr);
338338
InlineAttr::Hint
339339
}
340-
MetaItemKind::List(ref n, ref items) if *n == "inline" => {
340+
MetaItemKind::List(ref n, ref items) if n == "inline" => {
341341
mark_used(attr);
342342
if items.len() != 1 {
343343
diagnostic.map(|d|{ d.span_err(attr.span, "expected one argument"); });
@@ -711,7 +711,7 @@ pub fn require_unique_names(diagnostic: &Handler, metas: &[P<MetaItem>]) {
711711
pub fn find_repr_attrs(diagnostic: &Handler, attr: &Attribute) -> Vec<ReprAttr> {
712712
let mut acc = Vec::new();
713713
match attr.node.value.node {
714-
ast::MetaItemKind::List(ref s, ref items) if *s == "repr" => {
714+
ast::MetaItemKind::List(ref s, ref items) if s == "repr" => {
715715
mark_used(attr);
716716
for item in items {
717717
match item.node {

src/libsyntax/parse/token.rs

+22
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,28 @@ impl<'a> PartialEq<InternedString> for &'a str {
566566
}
567567
}
568568

569+
impl PartialEq<str> for InternedString {
570+
#[inline(always)]
571+
fn eq(&self, other: &str) -> bool {
572+
PartialEq::eq(&self.string[..], other)
573+
}
574+
#[inline(always)]
575+
fn ne(&self, other: &str) -> bool {
576+
PartialEq::ne(&self.string[..], other)
577+
}
578+
}
579+
580+
impl PartialEq<InternedString> for str {
581+
#[inline(always)]
582+
fn eq(&self, other: &InternedString) -> bool {
583+
PartialEq::eq(self, &other.string[..])
584+
}
585+
#[inline(always)]
586+
fn ne(&self, other: &InternedString) -> bool {
587+
PartialEq::ne(self, &other.string[..])
588+
}
589+
}
590+
569591
impl Decodable for InternedString {
570592
fn decode<D: Decoder>(d: &mut D) -> Result<InternedString, D::Error> {
571593
Ok(intern(d.read_str()?.as_ref()).as_str())

0 commit comments

Comments
 (0)