Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rust highlighting doesn't handle lifetime parameters correctly #347

Open
GoogleCodeExporter opened this issue Feb 20, 2016 · 2 comments
Open

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem?

The highlighting for Rust does not properly handle lifetimes. It treats the 
lifetime sigil ' as the start of a string instead (even though Rust doesn't 
support single-quoted strings). This causes bad rendering.

This causes a problem on StackOverflow, when people post questions about Rust. 
For example, in a question asked 19 hours ago 
(http://stackoverflow.com/questions/24855830/how-convert-a-string-in-str-in-impl
-block-in-rust), the first code block contains a struct definition with a field 
`title: &'static str`. The rest of the code block from the ' is colored red, as 
if it were a string, when in fact 'static is a lifetime specifier.

In Rust, the ' token is either used to start a character literal, or a 
lifetime. if the ' is followed by a single unicode character (or a single 
escape, such as \n, \t, \u2022), and then another ', then it is a character 
literal. Otherwise, if it's followed by a single identifier that meets the 
identifier rules, the ' with the identifier are considered a lifetime 
(otherwise, it's assumed to be an unterminated character literal).

Original issue reported on code.google.com by [email protected] on 21 Jul 2014 at 6:35

@GoogleCodeExporter
Copy link
Author

I actually don't even see a lang-rust.js file anywhere, which leads me to 
believe that SO is just using some other arbitrary language to highlight Rust 
code.

I've filed an issue in the Rust repo to implement proper Rust highlighting 
support (https://github.com/rust-lang/rust/issues/18931).

Original comment by [email protected] on 13 Nov 2014 at 7:12

@GoogleCodeExporter
Copy link
Author

I removed the generic references to rust from prettify.js and added a separate 
lang-rust.js file to provide better highlighting for rust.

Please review the attached diff and let me know if I need to make any further 
changes.

Original comment by [email protected] on 10 Dec 2014 at 6:19

Attachments:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant