-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle str literals written with '
lexed as lifetime
#122217
Changes from 1 commit
982918f
4a10b01
999a0dc
6f388ef
ea1883d
f4d30b1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -698,13 +698,17 @@ impl<'psess, 'src> StringReader<'psess, 'src> { | |
let expn_data = prefix_span.ctxt().outer_expn_data(); | ||
|
||
if expn_data.edition >= Edition::Edition2021 { | ||
let mut silence = false; | ||
// In Rust 2021, this is a hard error. | ||
let sugg = if prefix == "rb" { | ||
Some(errors::UnknownPrefixSugg::UseBr(prefix_span)) | ||
} else if expn_data.is_root() { | ||
if self.cursor.first() == '\'' | ||
&& let Some(start) = self.last_lifetime | ||
&& self.cursor.third() != '\'' | ||
{ | ||
// An "unclosed `char`" error will be emitted already, silence redundant error. | ||
silence = true; | ||
Some(errors::UnknownPrefixSugg::MeantStr { | ||
start, | ||
end: self.mk_sp(self.pos, self.pos + BytePos(1)), | ||
|
@@ -715,7 +719,12 @@ impl<'psess, 'src> StringReader<'psess, 'src> { | |
} else { | ||
None | ||
}; | ||
self.dcx().emit_err(errors::UnknownPrefix { span: prefix_span, prefix, sugg }); | ||
let err = errors::UnknownPrefix { span: prefix_span, prefix, sugg }; | ||
if silence { | ||
self.dcx().create_err(err).delay_as_bug(); | ||
} else { | ||
self.dcx().emit_err(err); | ||
} | ||
Comment on lines
+722
to
+727
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would probably structure it a bit differently, namely |
||
} else { | ||
// Before Rust 2021, only emit a lint for migration. | ||
self.psess.buffer_lint_with_diagnostic( | ||
|
estebank marked this conversation as resolved.
Show resolved
Hide resolved
estebank marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -4,5 +4,4 @@ | |||||
fn main() { | ||||||
println!('hello world'); | ||||||
//[rust2015,rust2018,rust2021]~^ ERROR unterminated character literal | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could be simplified to
Suggested change
but not blocking. |
||||||
//[rust2021]~^^ ERROR prefix `world` is unknown | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since
second
andthird
are exclusively used in the error path if I'm not mistaken (haven't double-checked), perf shouldn't matter that much and we can maybe avoid introducing those helpers? Idk, do we have access toself.chars
in the parser? If so, we could just use.clone().nth(N)
, right?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.chars
is private to the lexer. I initially made it public, but given it is used only in one place it felt better to introduce the method. But then we could instead just have annth
method that expands to.clone().nth(N)
instead.