Skip to content

Commit 1ce5f04

Browse files
authored
Merge pull request #485 from dtolnay/fallbackident
Make parser's fallback Ident symmetric with Group and Literal
2 parents 56c3e31 + 75d0818 commit 1ce5f04

File tree

3 files changed

+19
-18
lines changed

3 files changed

+19
-18
lines changed

src/lib.rs

+7
Original file line numberDiff line numberDiff line change
@@ -971,6 +971,13 @@ impl Ident {
971971
}
972972
}
973973

974+
fn _new_fallback(inner: fallback::Ident) -> Self {
975+
Ident {
976+
inner: imp::Ident::from(inner),
977+
_marker: MARKER,
978+
}
979+
}
980+
974981
/// Creates a new `Ident` with the given `string` as well as the specified
975982
/// `span`.
976983
///

src/parse.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::fallback::{
2-
self, is_ident_continue, is_ident_start, Group, LexError, Literal, Span, TokenStream,
2+
self, is_ident_continue, is_ident_start, Group, Ident, LexError, Literal, Span, TokenStream,
33
TokenStreamBuilder,
44
};
55
use crate::{Delimiter, Punct, Spacing, TokenTree};
@@ -300,10 +300,8 @@ fn ident_any(input: Cursor) -> PResult<crate::Ident> {
300300
let (rest, sym) = ident_not_raw(rest)?;
301301

302302
if !raw {
303-
let ident = crate::Ident::_new(crate::imp::Ident::new_unchecked(
304-
sym,
305-
fallback::Span::call_site(),
306-
));
303+
let ident =
304+
crate::Ident::_new_fallback(Ident::new_unchecked(sym, fallback::Span::call_site()));
307305
return Ok((rest, ident));
308306
}
309307

@@ -312,10 +310,8 @@ fn ident_any(input: Cursor) -> PResult<crate::Ident> {
312310
_ => {}
313311
}
314312

315-
let ident = crate::Ident::_new(crate::imp::Ident::new_raw_unchecked(
316-
sym,
317-
fallback::Span::call_site(),
318-
));
313+
let ident =
314+
crate::Ident::_new_fallback(Ident::new_raw_unchecked(sym, fallback::Span::call_site()));
319315
Ok((rest, ident))
320316
}
321317

@@ -941,7 +937,7 @@ fn doc_comment<'a>(input: Cursor<'a>, trees: &mut TokenStreamBuilder) -> PResult
941937
trees.push_token_from_parser(TokenTree::Punct(bang));
942938
}
943939

944-
let doc_ident = crate::Ident::_new(crate::imp::Ident::new_unchecked("doc", fallback_span));
940+
let doc_ident = crate::Ident::_new_fallback(Ident::new_unchecked("doc", fallback_span));
945941
let mut equal = Punct::new('=', Spacing::Alone);
946942
equal.set_span(span);
947943
let mut literal = crate::Literal::_new_fallback(Literal::string(comment));

src/wrapper.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -693,10 +693,6 @@ impl Ident {
693693
}
694694
}
695695

696-
pub(crate) fn new_unchecked(string: &str, span: fallback::Span) -> Self {
697-
Ident::Fallback(fallback::Ident::new_unchecked(string, span))
698-
}
699-
700696
#[track_caller]
701697
pub(crate) fn new_raw_checked(string: &str, span: Span) -> Self {
702698
match span {
@@ -705,10 +701,6 @@ impl Ident {
705701
}
706702
}
707703

708-
pub(crate) fn new_raw_unchecked(string: &str, span: fallback::Span) -> Self {
709-
Ident::Fallback(fallback::Ident::new_raw_unchecked(string, span))
710-
}
711-
712704
pub(crate) fn span(&self) -> Span {
713705
match self {
714706
Ident::Compiler(t) => Span::Compiler(t.span()),
@@ -733,6 +725,12 @@ impl Ident {
733725
}
734726
}
735727

728+
impl From<fallback::Ident> for Ident {
729+
fn from(inner: fallback::Ident) -> Self {
730+
Ident::Fallback(inner)
731+
}
732+
}
733+
736734
impl PartialEq for Ident {
737735
fn eq(&self, other: &Ident) -> bool {
738736
match (self, other) {

0 commit comments

Comments
 (0)