Skip to content

Commit 93e6358

Browse files
committed
fix(rust) fix regression with string matching
1 parent 40883e1 commit 93e6358

File tree

4 files changed

+69
-4
lines changed

4 files changed

+69
-4
lines changed

CHANGES.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## Version 11.11.1
2+
3+
- Fixes regression with Rust grammar.
4+
5+
16
## Version 11.11.0
27

38
CAVEATS / POTENTIALLY BREAKING CHANGES

src/languages/rust.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,10 @@ export default function(hljs) {
198198
begin: /b?"/,
199199
illegal: null
200200
}),
201+
{
202+
className: 'symbol',
203+
begin: /'[a-zA-Z_][a-zA-Z0-9_]*/
204+
},
201205
{
202206
scope: 'string',
203207
variants: [
@@ -214,10 +218,6 @@ export default function(hljs) {
214218
}
215219
]
216220
},
217-
{
218-
className: 'symbol',
219-
begin: /'[a-zA-Z_][a-zA-Z0-9_]*/
220-
},
221221
{
222222
className: 'number',
223223
variants: [

test/markup/rust/sample1.expect.txt

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<span class="hljs-keyword">use</span> std::fmt::<span class="hljs-built_in">Debug</span>; <span class="hljs-comment">// Trait to bound with.</span>
2+
3+
<span class="hljs-meta">#[derive(Debug)]</span>
4+
<span class="hljs-keyword">struct</span> <span class="hljs-title class_">Ref</span>&lt;<span class="hljs-symbol">&#x27;a</span>, T: <span class="hljs-symbol">&#x27;a</span>&gt;(&amp;<span class="hljs-symbol">&#x27;a</span> T);
5+
<span class="hljs-comment">// `Ref` contains a reference to a generic type `T` that has</span>
6+
<span class="hljs-comment">// some lifetime `&#x27;a` unknown by `Ref`. `T` is bounded such that any</span>
7+
<span class="hljs-comment">// *references* in `T` must outlive `&#x27;a`. Additionally, the lifetime</span>
8+
<span class="hljs-comment">// of `Ref` may not exceed `&#x27;a`.</span>
9+
10+
<span class="hljs-comment">// A generic function which prints using the `Debug` trait.</span>
11+
<span class="hljs-keyword">fn</span> <span class="hljs-title function_">print</span>&lt;T&gt;(t: T) <span class="hljs-keyword">where</span>
12+
T: <span class="hljs-built_in">Debug</span> {
13+
<span class="hljs-built_in">println!</span>(<span class="hljs-string">&quot;`print`: t is {:?}&quot;</span>, t);
14+
}
15+
16+
<span class="hljs-comment">// Here a reference to `T` is taken where `T` implements</span>
17+
<span class="hljs-comment">// `Debug` and all *references* in `T` outlive `&#x27;a`. In</span>
18+
<span class="hljs-comment">// addition, `&#x27;a` must outlive the function.</span>
19+
<span class="hljs-keyword">fn</span> <span class="hljs-title function_">print_ref</span>&lt;<span class="hljs-symbol">&#x27;a</span>, T&gt;(t: &amp;<span class="hljs-symbol">&#x27;a</span> T) <span class="hljs-keyword">where</span>
20+
T: <span class="hljs-built_in">Debug</span> + <span class="hljs-symbol">&#x27;a</span> {
21+
<span class="hljs-built_in">println!</span>(<span class="hljs-string">&quot;`print_ref`: t is {:?}&quot;</span>, t);
22+
}
23+
24+
<span class="hljs-keyword">fn</span> <span class="hljs-title function_">main</span>() {
25+
<span class="hljs-keyword">let</span> <span class="hljs-variable">x</span> = <span class="hljs-number">7</span>;
26+
<span class="hljs-keyword">let</span> <span class="hljs-variable">ref_x</span> = <span class="hljs-title function_ invoke__">Ref</span>(&amp;x);
27+
28+
<span class="hljs-title function_ invoke__">print_ref</span>(&amp;ref_x);
29+
<span class="hljs-title function_ invoke__">print</span>(ref_x);
30+
}

test/markup/rust/sample1.txt

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
use std::fmt::Debug; // Trait to bound with.
2+
3+
#[derive(Debug)]
4+
struct Ref<'a, T: 'a>(&'a T);
5+
// `Ref` contains a reference to a generic type `T` that has
6+
// some lifetime `'a` unknown by `Ref`. `T` is bounded such that any
7+
// *references* in `T` must outlive `'a`. Additionally, the lifetime
8+
// of `Ref` may not exceed `'a`.
9+
10+
// A generic function which prints using the `Debug` trait.
11+
fn print<T>(t: T) where
12+
T: Debug {
13+
println!("`print`: t is {:?}", t);
14+
}
15+
16+
// Here a reference to `T` is taken where `T` implements
17+
// `Debug` and all *references* in `T` outlive `'a`. In
18+
// addition, `'a` must outlive the function.
19+
fn print_ref<'a, T>(t: &'a T) where
20+
T: Debug + 'a {
21+
println!("`print_ref`: t is {:?}", t);
22+
}
23+
24+
fn main() {
25+
let x = 7;
26+
let ref_x = Ref(&x);
27+
28+
print_ref(&ref_x);
29+
print(ref_x);
30+
}

0 commit comments

Comments
 (0)