Skip to content

Commit

Permalink
Create new E0768 error code for "no valid digits found for number" error
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Jul 3, 2020
1 parent f844ea1 commit d64a4b5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/librustc_error_codes/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ E0764: include_str!("./error_codes/E0764.md"),
E0765: include_str!("./error_codes/E0765.md"),
E0766: include_str!("./error_codes/E0766.md"),
E0767: include_str!("./error_codes/E0767.md"),
E0768: include_str!("./error_codes/E0768.md"),
;
// E0006, // merged with E0005
// E0008, // cannot bind by-move into a pattern guard
Expand Down
13 changes: 13 additions & 0 deletions src/librustc_error_codes/error_codes/E0768.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
A number in a non-decimal base has no digits.

Erroneous code example:

```compile_fail,E0768
let s: i32 = 0b; // error!
```

To fix this error, add the missing digits:

```
let s: i32 = 0b1; // ok!
```
9 changes: 8 additions & 1 deletion src/librustc_parse/lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,14 @@ impl<'a> StringReader<'a> {
}
rustc_lexer::LiteralKind::Int { base, empty_int } => {
return if empty_int {
self.err_span_(start, suffix_start, "no valid digits found for number");
self.sess
.span_diagnostic
.struct_span_err_with_code(
self.mk_sp(start, suffix_start),
"no valid digits found for number",
error_code!(E0768),
)
.emit();
(token::Integer, sym::integer(0))
} else {
self.validate_int_literal(base, start, suffix_start);
Expand Down

0 comments on commit d64a4b5

Please sign in to comment.