Change <
interpreted as generic arg start warning
``` warning: `<` 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); ```
This commit is contained in:
parent
5fcfa08e98
commit
46a6af12aa
@ -42,7 +42,7 @@ use ast::RangeEnd;
|
|||||||
use {ast, attr};
|
use {ast, attr};
|
||||||
use codemap::{self, CodeMap, Spanned, respan};
|
use codemap::{self, CodeMap, Spanned, respan};
|
||||||
use syntax_pos::{self, Span, BytePos};
|
use syntax_pos::{self, Span, BytePos};
|
||||||
use errors::{self, DiagnosticBuilder, Level};
|
use errors::{self, DiagnosticBuilder};
|
||||||
use parse::{self, classify, token};
|
use parse::{self, classify, token};
|
||||||
use parse::common::SeqSep;
|
use parse::common::SeqSep;
|
||||||
use parse::lexer::TokenAndSpan;
|
use parse::lexer::TokenAndSpan;
|
||||||
@ -441,7 +441,14 @@ fn dummy_arg(span: Span) -> Arg {
|
|||||||
Arg { ty: P(ty), pat: pat, id: ast::DUMMY_NODE_ID }
|
Arg { ty: P(ty), pat: pat, id: ast::DUMMY_NODE_ID }
|
||||||
}
|
}
|
||||||
|
|
||||||
type RewindPoint = (token::Token, Span, Option<Span>, Span, TokenCursor, Vec<TokenType>);
|
struct RewindPoint {
|
||||||
|
token: token::Token,
|
||||||
|
span: Span,
|
||||||
|
meta_var_span: Option<Span>,
|
||||||
|
prev_span: Span,
|
||||||
|
token_cursor: TokenCursor,
|
||||||
|
expected_tokens: Vec<TokenType>,
|
||||||
|
}
|
||||||
|
|
||||||
impl<'a> Parser<'a> {
|
impl<'a> Parser<'a> {
|
||||||
pub fn new(sess: &'a ParseSess,
|
pub fn new(sess: &'a ParseSess,
|
||||||
@ -2835,11 +2842,13 @@ impl<'a> Parser<'a> {
|
|||||||
// Rewind to before attempting to parse the type with generics, to get
|
// Rewind to before attempting to parse the type with generics, to get
|
||||||
// arround #22644.
|
// arround #22644.
|
||||||
let rp_err = self.get_rewind_point();
|
let rp_err = self.get_rewind_point();
|
||||||
|
let sp = rp_err.span.clone();
|
||||||
self.rewind(rp);
|
self.rewind(rp);
|
||||||
let lo = self.span;
|
let lo = self.span;
|
||||||
let path = match self.parse_path_without_generics(PathStyle::Type) {
|
let path = match self.parse_path_without_generics(PathStyle::Type) {
|
||||||
Ok(path) => {
|
Ok(path) => {
|
||||||
// Successfully parsed the type leaving a `<` yet to parse
|
// Successfully parsed the type leaving a `<` yet to parse
|
||||||
|
err.cancel();
|
||||||
let codemap = self.sess.codemap();
|
let codemap = self.sess.codemap();
|
||||||
let suggestion_span = lhs_span.to(self.prev_span);
|
let suggestion_span = lhs_span.to(self.prev_span);
|
||||||
let suggestion = match codemap.span_to_snippet(suggestion_span) {
|
let suggestion = match codemap.span_to_snippet(suggestion_span) {
|
||||||
@ -2850,15 +2859,17 @@ impl<'a> Parser<'a> {
|
|||||||
Ok(lstring) => format!("`{}`", lstring),
|
Ok(lstring) => format!("`{}`", lstring),
|
||||||
_ => "a type".to_string(),
|
_ => "a type".to_string(),
|
||||||
};
|
};
|
||||||
err.span_suggestion(suggestion_span,
|
let msg = format!("`<` is interpreted as a start of generic \
|
||||||
|
arguments for {}, not a comparison",
|
||||||
|
warn_message);
|
||||||
|
let mut warn = self.sess.span_diagnostic.struct_span_warn(sp, &msg);
|
||||||
|
warn.span_label(sp, "interpreted as generic argument");
|
||||||
|
warn.span_label(self.span, "not interpreted as comparison");
|
||||||
|
warn.span_suggestion(suggestion_span,
|
||||||
"if you want to compare the casted value \
|
"if you want to compare the casted value \
|
||||||
then write:",
|
then write:",
|
||||||
suggestion);
|
suggestion);
|
||||||
err.level = Level::Warning;
|
warn.emit();
|
||||||
err.set_message(&format!("`<` is interpreted as a start of generic \
|
|
||||||
arguments for {}, not a comparison",
|
|
||||||
warn_message));
|
|
||||||
err.emit();
|
|
||||||
path
|
path
|
||||||
}
|
}
|
||||||
Err(mut path_err) => {
|
Err(mut path_err) => {
|
||||||
@ -6255,23 +6266,22 @@ impl<'a> Parser<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_rewind_point(&mut self) -> RewindPoint {
|
fn get_rewind_point(&mut self) -> RewindPoint {
|
||||||
(
|
RewindPoint {
|
||||||
self.token.clone(),
|
token: self.token.clone(),
|
||||||
self.span,
|
span: self.span,
|
||||||
self.meta_var_span,
|
meta_var_span: self.meta_var_span,
|
||||||
self.prev_span,
|
prev_span: self.prev_span,
|
||||||
self.token_cursor.clone(),
|
token_cursor: self.token_cursor.clone(),
|
||||||
self.expected_tokens.clone(),
|
expected_tokens: self.expected_tokens.clone(),
|
||||||
)
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn rewind(&mut self, rp: RewindPoint) {
|
fn rewind(&mut self, rp: RewindPoint) {
|
||||||
let (token, span, meta_var_span, prev_span, token_cursor, expected_tokens,) = rp;
|
self.token = rp.token;
|
||||||
self.token = token;
|
self.span = rp.span;
|
||||||
self.span = span;
|
self.meta_var_span = rp.meta_var_span;
|
||||||
self.meta_var_span = meta_var_span;
|
self.prev_span = rp.prev_span;
|
||||||
self.prev_span = prev_span;
|
self.token_cursor = rp.token_cursor;
|
||||||
self.token_cursor = token_cursor;
|
self.expected_tokens = rp.expected_tokens;
|
||||||
self.expected_tokens = expected_tokens;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,9 @@ warning: `<` is interpreted as a start of generic arguments for `usize`, not a c
|
|||||||
--> $DIR/issue-22644.rs:16:33
|
--> $DIR/issue-22644.rs:16:33
|
||||||
|
|
|
|
||||||
16 | println!("{}", a as usize < b);
|
16 | println!("{}", a as usize < b);
|
||||||
| ^ expected one of `!`, `(`, `+`, `,`, `::`, or `>` here
|
| - ^ interpreted as generic argument
|
||||||
|
| |
|
||||||
|
| not interpreted as comparison
|
||||||
|
|
|
|
||||||
help: if you want to compare the casted value then write:
|
help: if you want to compare the casted value then write:
|
||||||
| println!("{}", (a as usize) < b);
|
| println!("{}", (a as usize) < b);
|
||||||
@ -11,9 +13,9 @@ warning: `<` is interpreted as a start of generic arguments for `usize`, not a c
|
|||||||
--> $DIR/issue-22644.rs:17:33
|
--> $DIR/issue-22644.rs:17:33
|
||||||
|
|
|
|
||||||
17 | println!("{}", a as usize < 4);
|
17 | println!("{}", a as usize < 4);
|
||||||
| -^ unexpected token
|
| - ^ interpreted as generic argument
|
||||||
| |
|
| |
|
||||||
| expected one of `>`, identifier, lifetime, or type here
|
| not interpreted as comparison
|
||||||
|
|
|
|
||||||
help: if you want to compare the casted value then write:
|
help: if you want to compare the casted value then write:
|
||||||
| println!("{}", (a as usize) < 4);
|
| println!("{}", (a as usize) < 4);
|
||||||
|
Loading…
Reference in New Issue
Block a user