about summary refs log tree commit diff
path: root/src/libsyntax_pos
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2017-12-07 21:05:49 +0000
committerbors <bors@rust-lang.org>2017-12-07 21:05:49 +0000
commitc8ddf28527119a06a9f5da9bd34c97ae97afe531 (patch)
tree458cdc07ce837e57058f2613e8e92e036d5251da /src/libsyntax_pos
parent9c49f401fecd8c5ef42a33a070a61daa2b911b47 (diff)
parent29e268060209765e5a9efb4c0941765d064e13ea (diff)
downloadrust-c8ddf28527119a06a9f5da9bd34c97ae97afe531.tar.gz
rust-c8ddf28527119a06a9f5da9bd34c97ae97afe531.zip
Auto merge of #46497 - AgustinCB:issue-46311, r=petrochenkov
Modify message for keyword as identifier name

This is a temporary solution to #46311.

The message is generic enough to cover both cases and is probably a fine enough solution to the specific problem described in the task. However, the underlying reason for this to be wrong is that `next_token_inner` returns `Lifetime` even if the token is a label. That's not simple, as the syntax for both can be quite similar and it may need to take a look to the next token to make a decision. I'm not sure I have enough knowledge about the project to be able to solve that (yet!), so I thought I'll fix the immediate problem first.
Diffstat (limited to 'src/libsyntax_pos')
-rw-r--r--src/libsyntax_pos/symbol.rs10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/libsyntax_pos/symbol.rs b/src/libsyntax_pos/symbol.rs
index 72760360711..aafdd696b74 100644
--- a/src/libsyntax_pos/symbol.rs
+++ b/src/libsyntax_pos/symbol.rs
@@ -35,6 +35,10 @@ impl Ident {
         Ident::with_empty_ctxt(Symbol::intern(string))
     }
 
+    pub fn without_first_quote(&self) -> Ident {
+        Ident { name: Symbol::from(self.name.as_str().trim_left_matches('\'')), ctxt: self.ctxt }
+    }
+
     pub fn modern(self) -> Ident {
         Ident { name: self.name, ctxt: self.ctxt.modern() }
     }
@@ -437,4 +441,10 @@ mod tests {
         // gensym of *existing* string gets new number:
         assert_eq!(i.gensym("dog"), Symbol(4294967293));
     }
+
+    #[test]
+    fn without_first_quote_test() {
+        let i = Ident::from_str("'break");
+        assert_eq!(i.without_first_quote().name, keywords::Break.name());
+    }
 }