Auto merge of #42578 - estebank:recover-binop, r=nikomatsakis
Learn to parse `a as usize < b` Parsing `a as usize > b` always works, but `a as usize < b` was a parsing error because the parser would think the `<` started a generic type argument for `usize`. The parser now attempts to parse as before, and if a DiagnosticError is returned, try to parse again as a type with no generic arguments. If this fails, return the original `DiagnosticError`. Fix #22644.
This commit is contained in:
commit
44eeb2109b
5 changed files with 140 additions and 9 deletions
18
src/test/ui/issue-22644.rs
Normal file
18
src/test/ui/issue-22644.rs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
fn main() {
|
||||
let a : u32 = 0;
|
||||
let b : usize = 0;
|
||||
|
||||
println!("{}", a as usize > b);
|
||||
println!("{}", a as usize < b);
|
||||
println!("{}", a as usize < 4);
|
||||
}
|
||||
24
src/test/ui/issue-22644.stderr
Normal file
24
src/test/ui/issue-22644.stderr
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
error: `<` is interpreted as a start of generic arguments for `usize`, not a comparison
|
||||
--> $DIR/issue-22644.rs:16:33
|
||||
|
|
||||
16 | println!("{}", a as usize < b);
|
||||
| - ^ interpreted as generic argument
|
||||
| |
|
||||
| not interpreted as comparison
|
||||
|
|
||||
help: if you want to compare the casted value then write:
|
||||
| println!("{}", (a as usize) < b);
|
||||
|
||||
error: `<` is interpreted as a start of generic arguments for `usize`, not a comparison
|
||||
--> $DIR/issue-22644.rs:17:33
|
||||
|
|
||||
17 | println!("{}", a as usize < 4);
|
||||
| - ^ interpreted as generic argument
|
||||
| |
|
||||
| not interpreted as comparison
|
||||
|
|
||||
help: if you want to compare the casted value then write:
|
||||
| println!("{}", (a as usize) < 4);
|
||||
|
||||
error: aborting due to previous error(s)
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue