12

Recover on invalid operators `<>` and `<=>` by r00ster91 · Pull Requ...

 2 years ago
source link: https://github.com/rust-lang/rust/pull/91597
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Copy link

Contributor

Author

r00ster91 commented on Dec 6, 2021

edited

@leonardo-m

In the end rustc will understand (and refuse) the syntax of most other languages... :-)

Right, so you are saying something along the lines of "it doesn't make much sense to add this if we don't suggest a match for a switch etc." right? Yeah I get your logic/point and I tend to agree but then I wonder why suggestions exist for !== and ===:

if (op.node == AssocOp::Equal || op.node == AssocOp::NotEqual)

&& self.token.kind == token::Eq

&& self.prev_token.span.hi() == self.token.span.lo()

{

// Look for JS' `===` and `!==` and recover 😇

let sp = op.span.to(self.token.span);

let sugg = match op.node {

AssocOp::Equal => "==",

AssocOp::NotEqual => "!=",

_ => unreachable!(),

};

self.struct_span_err(sp, &format!("invalid comparison operator `{}=`", sugg))

.span_suggestion_short(

sp,

&format!("`{s}=` is not a valid comparison operator, use `{s}`", s = sugg),

sugg.to_string(),

Applicability::MachineApplicable,

)

.emit();

self.bump();

}

Should these be removed too?


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK