How to Check Rust Code for Syntax Errors
Paste or upload your Rust code
Paste a whole .rs file or a snippet, upload a .rs file, or press Sample to load a small working program. Snippets are fine as long as they are whole items (a fn, struct or impl), since that is what a Rust file is made of.
Example: a missing semicolon
fn main() {
let total = 5
println!("{}", total);
}Read the first syntax error
The check runs a moment after you stop typing. If rustc would reject the file, you see the line and column, the reason, and the line itself with a caret under the spot. For the example above, the result is the same message and line that rustc prints:
Line 2, column 18: expected `;`, found `println`
A `;` is missing at the end of this line.
let total = 5
^Only the first error is shown, because one slip (a missing brace, say) can make every line after it look wrong.
Fix it and check again
Fix that line; the result updates on its own. When the code parses, run cargo check or cargo build for types and borrowing. Copy puts the report (line, reason and the marked line) on your clipboard. Once it parses, the Rust Formatter can tidy the indentation, and cargo check takes care of everything after parsing.
Frequently Asked Questions
What does the Rust validator check?
It reads your code the way rustc does before anything else happens: first the characters (strings, chars, escapes, numbers, comments), then the brackets, then the grammar of items, types, patterns and expressions. So it catches a missing semicolon, a missing comma between struct fields or match arms, an unclosed or mismatched bracket, an unterminated string, a bad escape like \q, a reserved word used as a name, a stray semicolon after a struct, if let chains (Rust 2024 only), and similar slips. Rust 2021 rules are used.
Is this the same as cargo check?
No. cargo check goes much further: it resolves names and imports, checks types, ownership, borrowing and lifetimes, expands macros and runs lints. This page only answers the first question rustc asks, which is whether the file can be parsed at all. Code that passes here can still fail to compile, for example because a variable is used after a move or a type does not match.
Which error does it report when there are several?
The first one rustc would print, on the same line rustc points at. That is not always the earliest one in the file: rustc reports problems in the characters (a bad escape, an unknown character) before bracket problems, and bracket problems before grammar problems. For a missing semicolon it points at the end of the line that needs it, like rustc does. Fix that one and the check runs again on its own.
What about macros like println!, vec! or my own macro_rules?
Macro calls are checked only for balanced brackets, the same as rustc does before it expands them. What is inside println!("...") or a macro_rules! body is not parsed as Rust here, so a mistake inside a macro call usually shows up only when you compile.
How did you check that the results match rustc?
We ran the checker on about 3,800 real Rust files (the standard library and popular crates such as serde, syn and bytes) and on hundreds of deliberately broken copies, and compared each verdict and error line with what rustc itself reports. They agree on all of the real files. A few rare cases inside broken code can still put the error on a different line than rustc would.
Is my code uploaded anywhere?
No. The check runs in your browser, your code is not sent to a server, and nothing is kept: a reload starts with an empty editor.
Related Tools
Rust Formatter
Format and beautify Rust code with proper indentation
Cargo.toml Generator
Generate Cargo.toml files for Rust projects with dependencies
Cargo.toml Validator
Validate Cargo.toml manifest files for Rust projects
Rust Minifier
Minify Rust code by removing comments and whitespace
Rust Test Generator
Generate unit test templates for Rust functions
JSON to Rust
Convert JSON data to Rust structs with serde Serialize/Deserialize traits