-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Add lifetime-aware support for Display
impl of Ident
#143185
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
base: master
Are you sure you want to change the base?
Conversation
This comment has been minimized.
This comment has been minimized.
c9addca
to
c4edd71
Compare
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.
@rustbot ready
} | ||
return fmt::Display::fmt(&lifetime, f); | ||
} | ||
|
||
if self.is_raw { |
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.
When Ident starts with '
, the contents are printed recursively.
if self.name == kw::StaticLifetime || self.name == kw::UnderscoreLifetime { | ||
false | ||
} else if let Some(lifetime) = self.as_lifetime() { | ||
lifetime.is_raw_guess() | ||
} else { | ||
self.name.can_be_raw() && self.is_reserved() | ||
} |
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.
There are two keywords that need to be excluded here.
@@ -2176,7 +2176,7 @@ pub(crate) struct KeywordLifetime { | |||
pub(crate) struct InvalidLabel { | |||
#[primary_span] | |||
pub span: Span, | |||
pub name: Symbol, | |||
pub name: String, |
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.
The label needs to be converted to String
, otherwise the error message will call to_ident_string
, which will print 'break
as 'r#break
in the following example.
fn main() {
'break: loop { //~ ERROR invalid label name `'break`
}
}
I haven't checked to see if there are any other label-related errors yet though, there may be similar issues, but it's generally a more borderline case.
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.
(Oh interesting. 'break
is actually an invalid label but 'r#break
is only a valid label in Rust >=2021) (ignore, not relevant)
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.
Ah, you should be able to use Symbol
instead of String
here (doesn't make much of a difference here tho) (we could actually suggest escaping via r#
(if we have Rust >= 2021) here but that's for another PR)
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.
I found the implementation of Symbol
as diagnostic arguments.
rust/compiler/rustc_errors/src/diagnostic_impls.rs
Lines 165 to 169 in f191420
impl IntoDiagArg for Symbol { | |
fn into_diag_arg(self, path: &mut Option<std::path::PathBuf>) -> DiagArgValue { | |
self.to_ident_string().into_diag_arg(path) | |
} | |
} |
It will be transformed to
Ident
, so if I use Symbol
here, It prints invalid label name 'r#break
. I may have to use String
.
This comment has been minimized.
This comment has been minimized.
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
lifetime.ident
Display
impl of Ident
d6c180d
to
9306466
Compare
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
Fixes #143150
r? compiler