Commit 926f6f862226c28a9730ac2bbb33bd2f7bd894aa

Golmote 2018-03-07T21:23:21

Rust: Add support for lifetime-annotation and => operator. Fix #1339

diff --git a/components/prism-rust.js b/components/prism-rust.js
index 5a1e75d..bfdda91 100644
--- a/components/prism-rust.js
+++ b/components/prism-rust.js
@@ -22,10 +22,18 @@ Prism.languages.rust = {
 			greedy: true
 		},
 		{
-			pattern: /b?("|')(?:\\.|(?!\1)[^\\\r\n])*\1/,
+			pattern: /b?"(?:\\.|[^\\\r\n"])*"/,
 			greedy: true
 		}
 	],
+	'lifetime-annotation': {
+		pattern: /'[^\s>']+(?!')/,
+		alias: 'symbol'
+	},
+	'char': {
+		pattern: /'(?:\\.|[^\\\r\n'])*'/,
+		alias: 'string'
+	},
 	'keyword': /\b(?:abstract|alignof|as|be|box|break|const|continue|crate|do|else|enum|extern|false|final|fn|for|if|impl|in|let|loop|match|mod|move|mut|offsetof|once|override|priv|pub|pure|ref|return|sizeof|static|self|struct|super|true|trait|type|typeof|unsafe|unsized|use|virtual|where|while|yield)\b/,
 
 	'attribute': {
@@ -56,5 +64,5 @@ Prism.languages.rust = {
 		}
 	},
 	'punctuation': /[{}[\];(),:]|\.+|->/,
-	'operator': /[-+*\/%!^=]=?|@|&[&=]?|\|[|=]?|<<?=?|>>?=?/
+	'operator': /[-+*\/%!^]=?|=[=>]?|@|&[&=]?|\|[|=]?|<<?=?|>>?=?/
 };
\ No newline at end of file
diff --git a/components/prism-rust.min.js b/components/prism-rust.min.js
index 47e66dc..e6a6a01 100644
--- a/components/prism-rust.min.js
+++ b/components/prism-rust.min.js
@@ -1 +1 @@
-Prism.languages.rust={comment:[{pattern:/(^|[^\\])\/\*[\s\S]*?\*\//,lookbehind:!0},{pattern:/(^|[^\\:])\/\/.*/,lookbehind:!0}],string:[{pattern:/b?r(#*)"(?:\\.|(?!"\1)[^\\\r\n])*"\1/,greedy:!0},{pattern:/b?("|')(?:\\.|(?!\1)[^\\\r\n])*\1/,greedy:!0}],keyword:/\b(?:abstract|alignof|as|be|box|break|const|continue|crate|do|else|enum|extern|false|final|fn|for|if|impl|in|let|loop|match|mod|move|mut|offsetof|once|override|priv|pub|pure|ref|return|sizeof|static|self|struct|super|true|trait|type|typeof|unsafe|unsized|use|virtual|where|while|yield)\b/,attribute:{pattern:/#!?\[.+?\]/,greedy:!0,alias:"attr-name"},"function":[/\w+(?=\s*\()/,/\w+!(?=\s*\(|\[)/],"macro-rules":{pattern:/\w+!/,alias:"function"},number:/\b-?(?:0x[\dA-Fa-f](?:_?[\dA-Fa-f])*|0o[0-7](?:_?[0-7])*|0b[01](?:_?[01])*|(\d(?:_?\d)*)?\.?\d(?:_?\d)*(?:[Ee][+-]?\d+)?)(?:_?(?:[iu](?:8|16|32|64)?|f32|f64))?\b/,"closure-params":{pattern:/\|[^|]*\|(?=\s*[{-])/,inside:{punctuation:/[|:,]/,operator:/[&*]/}},punctuation:/[{}[\];(),:]|\.+|->/,operator:/[-+*\/%!^=]=?|@|&[&=]?|\|[|=]?|<<?=?|>>?=?/};
\ No newline at end of file
+Prism.languages.rust={comment:[{pattern:/(^|[^\\])\/\*[\s\S]*?\*\//,lookbehind:!0},{pattern:/(^|[^\\:])\/\/.*/,lookbehind:!0}],string:[{pattern:/b?r(#*)"(?:\\.|(?!"\1)[^\\\r\n])*"\1/,greedy:!0},{pattern:/b?"(?:\\.|[^\\\r\n"])*"/,greedy:!0}],"lifetime-annotation":{pattern:/'[^\s>']+(?!')/,alias:"symbol"},"char":{pattern:/'(?:\\.|[^\\\r\n'])*'/,alias:"string"},keyword:/\b(?:abstract|alignof|as|be|box|break|const|continue|crate|do|else|enum|extern|false|final|fn|for|if|impl|in|let|loop|match|mod|move|mut|offsetof|once|override|priv|pub|pure|ref|return|sizeof|static|self|struct|super|true|trait|type|typeof|unsafe|unsized|use|virtual|where|while|yield)\b/,attribute:{pattern:/#!?\[.+?\]/,greedy:!0,alias:"attr-name"},"function":[/\w+(?=\s*\()/,/\w+!(?=\s*\(|\[)/],"macro-rules":{pattern:/\w+!/,alias:"function"},number:/\b-?(?:0x[\dA-Fa-f](?:_?[\dA-Fa-f])*|0o[0-7](?:_?[0-7])*|0b[01](?:_?[01])*|(\d(?:_?\d)*)?\.?\d(?:_?\d)*(?:[Ee][+-]?\d+)?)(?:_?(?:[iu](?:8|16|32|64)?|f32|f64))?\b/,"closure-params":{pattern:/\|[^|]*\|(?=\s*[{-])/,inside:{punctuation:/[|:,]/,operator:/[&*]/}},punctuation:/[{}[\];(),:]|\.+|->/,operator:/[-+*\/%!^]=?|=[=>]?|@|&[&=]?|\|[|=]?|<<?=?|>>?=?/};
\ No newline at end of file
diff --git a/tests/languages/rust/char_feature.test b/tests/languages/rust/char_feature.test
new file mode 100644
index 0000000..9a19484
--- /dev/null
+++ b/tests/languages/rust/char_feature.test
@@ -0,0 +1,13 @@
+'a'
+'स'
+
+----------------------------------------------------
+
+[
+	["char", "'a'"],
+	["char", "'स'"]
+]
+
+----------------------------------------------------
+
+Checks for chars.
\ No newline at end of file
diff --git a/tests/languages/rust/issue1339.test b/tests/languages/rust/issue1339.test
new file mode 100644
index 0000000..1dd3208
--- /dev/null
+++ b/tests/languages/rust/issue1339.test
@@ -0,0 +1,49 @@
+const ALL_CARDS: &'static [&'static char] = &["2"]
+fn foo<'a> (first: &'a str, second: &'a str) => () { }
+
+----------------------------------------------------
+
+[
+	["keyword", "const"],
+	" ALL_CARDS",
+	["punctuation", ":"],
+	["operator", "&"],
+	["lifetime-annotation", "'static"],
+	["punctuation", "["],
+	["operator", "&"],
+	["lifetime-annotation", "'static"],
+	" char",
+	["punctuation", "]"],
+	["operator", "="],
+	["operator", "&"],
+	["punctuation", "["],
+	["string", "\"2\""],
+	["punctuation", "]"],
+	["keyword", "fn"],
+	" foo",
+	["operator", "<"],
+	["lifetime-annotation", "'a"],
+	["operator", ">"],
+	["punctuation", "("],
+	"first",
+	["punctuation", ":"],
+	["operator", "&"],
+	["lifetime-annotation", "'a"],
+	" str",
+	["punctuation", ","],
+	" second",
+	["punctuation", ":"],
+	["operator", "&"],
+	["lifetime-annotation", "'a"],
+	" str",
+	["punctuation", ")"],
+	["operator", "=>"],
+	["punctuation", "("],
+	["punctuation", ")"],
+	["punctuation", "{"],
+	["punctuation", "}"]
+]
+
+----------------------------------------------------
+
+Checks for lifetime annotations in real-world examples. See #1339.
\ No newline at end of file
diff --git a/tests/languages/rust/lifetime-annotation_feature.test b/tests/languages/rust/lifetime-annotation_feature.test
new file mode 100644
index 0000000..02c813d
--- /dev/null
+++ b/tests/languages/rust/lifetime-annotation_feature.test
@@ -0,0 +1,15 @@
+'foo
+'a
+<'a>
+
+----------------------------------------------------
+
+[
+	["lifetime-annotation", "'foo"],
+	["lifetime-annotation", "'a"],
+	["operator", "<"], ["lifetime-annotation", "'a"], ["operator", ">"]
+]
+
+----------------------------------------------------
+
+Checks for lifetime annotations.
\ No newline at end of file
diff --git a/tests/languages/rust/operator_feature.test b/tests/languages/rust/operator_feature.test
index a6e0892..5295bdb 100644
--- a/tests/languages/rust/operator_feature.test
+++ b/tests/languages/rust/operator_feature.test
@@ -5,7 +5,7 @@
 % %=
 ! !=
 ^ ^=
-= ==
+= == =>
 & && &=
 | || |=
 < << <= <<=
@@ -22,7 +22,7 @@
 	["operator", "%"], ["operator", "%="],
 	["operator", "!"], ["operator", "!="],
 	["operator", "^"], ["operator", "^="],
-	["operator", "="], ["operator", "=="],
+	["operator", "="], ["operator", "=="], ["operator", "=>"],
 	["operator", "&"], ["operator", "&&"], ["operator", "&="],
 	["operator", "|"], ["operator", "||"], ["operator", "|="],
 	["operator", "<"], ["operator", "<<"], ["operator", "<="], ["operator", "<<="],
diff --git a/tests/languages/rust/string_feature.test b/tests/languages/rust/string_feature.test
index 0928252..c0667e2 100644
--- a/tests/languages/rust/string_feature.test
+++ b/tests/languages/rust/string_feature.test
@@ -1,12 +1,8 @@
 ""
 "fo\"obar"
-''
-'fo\'obar'
 
 b""
 b"fo\"obar"
-b''
-b'fo\'obar'
 
 r#""#
 r#"fo"obar"#
@@ -21,13 +17,9 @@ br###"foo#bar"###
 [
 	["string", "\"\""],
 	["string", "\"fo\\\"obar\""],
-	["string", "''"],
-	["string", "'fo\\'obar'"],
 
 	["string", "b\"\""],
 	["string", "b\"fo\\\"obar\""],
-	["string", "b''"],
-	["string", "b'fo\\'obar'"],
 
 	["string", "r#\"\"#"],
 	["string", "r#\"fo\"obar\"#"],