Skip to content

Commit

Permalink
fix(rust) fix regression with string matching
Browse files Browse the repository at this point in the history
  • Loading branch information
joshgoebel committed Dec 21, 2024
1 parent 40883e1 commit 93e6358
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## Version 11.11.1

- Fixes regression with Rust grammar.


## Version 11.11.0

CAVEATS / POTENTIALLY BREAKING CHANGES
Expand Down
8 changes: 4 additions & 4 deletions src/languages/rust.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ export default function(hljs) {
begin: /b?"/,
illegal: null
}),
{
className: 'symbol',
begin: /'[a-zA-Z_][a-zA-Z0-9_]*/
},
{
scope: 'string',
variants: [
Expand All @@ -214,10 +218,6 @@ export default function(hljs) {
}
]
},
{
className: 'symbol',
begin: /'[a-zA-Z_][a-zA-Z0-9_]*/
},
{
className: 'number',
variants: [
Expand Down
30 changes: 30 additions & 0 deletions test/markup/rust/sample1.expect.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<span class="hljs-keyword">use</span> std::fmt::<span class="hljs-built_in">Debug</span>; <span class="hljs-comment">// Trait to bound with.</span>

<span class="hljs-meta">#[derive(Debug)]</span>
<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);
<span class="hljs-comment">// `Ref` contains a reference to a generic type `T` that has</span>
<span class="hljs-comment">// some lifetime `&#x27;a` unknown by `Ref`. `T` is bounded such that any</span>
<span class="hljs-comment">// *references* in `T` must outlive `&#x27;a`. Additionally, the lifetime</span>
<span class="hljs-comment">// of `Ref` may not exceed `&#x27;a`.</span>

<span class="hljs-comment">// A generic function which prints using the `Debug` trait.</span>
<span class="hljs-keyword">fn</span> <span class="hljs-title function_">print</span>&lt;T&gt;(t: T) <span class="hljs-keyword">where</span>
T: <span class="hljs-built_in">Debug</span> {
<span class="hljs-built_in">println!</span>(<span class="hljs-string">&quot;`print`: t is {:?}&quot;</span>, t);
}

<span class="hljs-comment">// Here a reference to `T` is taken where `T` implements</span>
<span class="hljs-comment">// `Debug` and all *references* in `T` outlive `&#x27;a`. In</span>
<span class="hljs-comment">// addition, `&#x27;a` must outlive the function.</span>
<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>
T: <span class="hljs-built_in">Debug</span> + <span class="hljs-symbol">&#x27;a</span> {
<span class="hljs-built_in">println!</span>(<span class="hljs-string">&quot;`print_ref`: t is {:?}&quot;</span>, t);
}

<span class="hljs-keyword">fn</span> <span class="hljs-title function_">main</span>() {
<span class="hljs-keyword">let</span> <span class="hljs-variable">x</span> = <span class="hljs-number">7</span>;
<span class="hljs-keyword">let</span> <span class="hljs-variable">ref_x</span> = <span class="hljs-title function_ invoke__">Ref</span>(&amp;x);

<span class="hljs-title function_ invoke__">print_ref</span>(&amp;ref_x);
<span class="hljs-title function_ invoke__">print</span>(ref_x);
}
30 changes: 30 additions & 0 deletions test/markup/rust/sample1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use std::fmt::Debug; // Trait to bound with.

#[derive(Debug)]
struct Ref<'a, T: 'a>(&'a T);
// `Ref` contains a reference to a generic type `T` that has
// some lifetime `'a` unknown by `Ref`. `T` is bounded such that any
// *references* in `T` must outlive `'a`. Additionally, the lifetime
// of `Ref` may not exceed `'a`.

// A generic function which prints using the `Debug` trait.
fn print<T>(t: T) where
T: Debug {
println!("`print`: t is {:?}", t);
}

// Here a reference to `T` is taken where `T` implements
// `Debug` and all *references* in `T` outlive `'a`. In
// addition, `'a` must outlive the function.
fn print_ref<'a, T>(t: &'a T) where
T: Debug + 'a {
println!("`print_ref`: t is {:?}", t);
}

fn main() {
let x = 7;
let ref_x = Ref(&x);

print_ref(&ref_x);
print(ref_x);
}

0 comments on commit 93e6358

Please sign in to comment.