diff --git a/src/librustc_error_codes/error_codes.rs b/src/librustc_error_codes/error_codes.rs index 00c072e1b04a1..f687221d78e03 100644 --- a/src/librustc_error_codes/error_codes.rs +++ b/src/librustc_error_codes/error_codes.rs @@ -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 diff --git a/src/librustc_error_codes/error_codes/E0768.md b/src/librustc_error_codes/error_codes/E0768.md new file mode 100644 index 0000000000000..24169ef512efb --- /dev/null +++ b/src/librustc_error_codes/error_codes/E0768.md @@ -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! +``` diff --git a/src/librustc_parse/lexer/mod.rs b/src/librustc_parse/lexer/mod.rs index 5050f03bea9b2..2b0e637c74e5a 100644 --- a/src/librustc_parse/lexer/mod.rs +++ b/src/librustc_parse/lexer/mod.rs @@ -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); diff --git a/src/test/ui/parser/issue-1802-1.stderr b/src/test/ui/parser/issue-1802-1.stderr index b7d003df56b71..954cc0beeef3e 100644 --- a/src/test/ui/parser/issue-1802-1.stderr +++ b/src/test/ui/parser/issue-1802-1.stderr @@ -1,4 +1,4 @@ -error: no valid digits found for number +error[E0768]: no valid digits found for number --> $DIR/issue-1802-1.rs:5:16 | LL | log(error, 0b); @@ -6,3 +6,4 @@ LL | log(error, 0b); error: aborting due to previous error +For more information about this error, try `rustc --explain E0768`. diff --git a/src/test/ui/parser/issue-1802-2.stderr b/src/test/ui/parser/issue-1802-2.stderr index 8491dd07cb788..49043d07b35eb 100644 --- a/src/test/ui/parser/issue-1802-2.stderr +++ b/src/test/ui/parser/issue-1802-2.stderr @@ -1,4 +1,4 @@ -error: no valid digits found for number +error[E0768]: no valid digits found for number --> $DIR/issue-1802-2.rs:5:16 | LL | log(error, 0b); @@ -6,3 +6,4 @@ LL | log(error, 0b); error: aborting due to previous error +For more information about this error, try `rustc --explain E0768`. diff --git a/src/test/ui/parser/lex-bad-numeric-literals.stderr b/src/test/ui/parser/lex-bad-numeric-literals.stderr index 151480dd012a3..f05d61603023c 100644 --- a/src/test/ui/parser/lex-bad-numeric-literals.stderr +++ b/src/test/ui/parser/lex-bad-numeric-literals.stderr @@ -46,7 +46,7 @@ error: hexadecimal float literal is not supported LL | 0x9.0e-9; | ^^^^^^^^ -error: no valid digits found for number +error[E0768]: no valid digits found for number --> $DIR/lex-bad-numeric-literals.rs:11:5 | LL | 0o; @@ -64,31 +64,31 @@ error: hexadecimal float literal is not supported LL | 0x539.0; | ^^^^^^^ -error: no valid digits found for number +error[E0768]: no valid digits found for number --> $DIR/lex-bad-numeric-literals.rs:18:5 | LL | 0x; | ^^ -error: no valid digits found for number +error[E0768]: no valid digits found for number --> $DIR/lex-bad-numeric-literals.rs:19:5 | LL | 0xu32; | ^^ -error: no valid digits found for number +error[E0768]: no valid digits found for number --> $DIR/lex-bad-numeric-literals.rs:20:5 | LL | 0ou32; | ^^ -error: no valid digits found for number +error[E0768]: no valid digits found for number --> $DIR/lex-bad-numeric-literals.rs:21:5 | LL | 0bu32; | ^^ -error: no valid digits found for number +error[E0768]: no valid digits found for number --> $DIR/lex-bad-numeric-literals.rs:22:5 | LL | 0b; @@ -138,3 +138,4 @@ LL | 0b101f64; error: aborting due to 23 previous errors +For more information about this error, try `rustc --explain E0768`.