mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-21 22:34:05 +00:00
Fix tools
This commit is contained in:
parent
5054e8cba8
commit
b6a86bee87
@ -879,7 +879,9 @@ impl<'src> Classifier<'src> {
|
||||
| TokenKind::UnknownPrefix
|
||||
| TokenKind::InvalidPrefix
|
||||
| TokenKind::InvalidIdent => Class::Ident(self.new_span(before, text)),
|
||||
TokenKind::Lifetime { .. } => Class::Lifetime,
|
||||
TokenKind::Lifetime { .. }
|
||||
| TokenKind::RawLifetime
|
||||
| TokenKind::UnknownPrefixLifetime => Class::Lifetime,
|
||||
TokenKind::Eof => panic!("Eof in advance"),
|
||||
};
|
||||
// Anything that didn't return above is the simple case where we the
|
||||
|
@ -198,6 +198,13 @@ impl<'a> Converter<'a> {
|
||||
}
|
||||
LIFETIME_IDENT
|
||||
}
|
||||
rustc_lexer::TokenKind::UnknownPrefixLifetime => {
|
||||
err = "Unknown lifetime prefix";
|
||||
LIFETIME_IDENT
|
||||
}
|
||||
rustc_lexer::TokenKind::RawLifetime => {
|
||||
LIFETIME_IDENT
|
||||
}
|
||||
|
||||
rustc_lexer::TokenKind::Semi => T![;],
|
||||
rustc_lexer::TokenKind::Comma => T![,],
|
||||
|
@ -462,7 +462,7 @@ fn rewrite_empty_block(
|
||||
return None;
|
||||
}
|
||||
|
||||
let label_str = rewrite_label(label);
|
||||
let label_str = rewrite_label(context, label);
|
||||
if attrs.map_or(false, |a| !inner_attributes(a).is_empty()) {
|
||||
return None;
|
||||
}
|
||||
@ -527,7 +527,7 @@ fn rewrite_single_line_block(
|
||||
if let Some(block_expr) = stmt::Stmt::from_simple_block(context, block, attrs) {
|
||||
let expr_shape = shape.offset_left(last_line_width(prefix))?;
|
||||
let expr_str = block_expr.rewrite(context, expr_shape)?;
|
||||
let label_str = rewrite_label(label);
|
||||
let label_str = rewrite_label(context, label);
|
||||
let result = format!("{prefix}{label_str}{{ {expr_str} }}");
|
||||
if result.len() <= shape.width && !result.contains('\n') {
|
||||
return Some(result);
|
||||
@ -562,7 +562,7 @@ pub(crate) fn rewrite_block_with_visitor(
|
||||
}
|
||||
|
||||
let inner_attrs = attrs.map(inner_attributes);
|
||||
let label_str = rewrite_label(label);
|
||||
let label_str = rewrite_label(context, label);
|
||||
visitor.visit_block(block, inner_attrs.as_deref(), has_braces);
|
||||
let visitor_context = visitor.get_context();
|
||||
context
|
||||
@ -939,7 +939,7 @@ impl<'a> ControlFlow<'a> {
|
||||
fresh_shape
|
||||
};
|
||||
|
||||
let label_string = rewrite_label(self.label);
|
||||
let label_string = rewrite_label(context, self.label);
|
||||
// 1 = space after keyword.
|
||||
let offset = self.keyword.len() + label_string.len() + 1;
|
||||
|
||||
@ -1168,9 +1168,9 @@ impl<'a> Rewrite for ControlFlow<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
fn rewrite_label(opt_label: Option<ast::Label>) -> Cow<'static, str> {
|
||||
fn rewrite_label(context: &RewriteContext<'_>, opt_label: Option<ast::Label>) -> Cow<'static, str> {
|
||||
match opt_label {
|
||||
Some(label) => Cow::from(format!("{}: ", label.ident)),
|
||||
Some(label) => Cow::from(format!("{}: ", context.snippet(label.ident.span))),
|
||||
None => Cow::from(""),
|
||||
}
|
||||
}
|
||||
|
@ -1074,7 +1074,7 @@ fn force_space_before(tok: &TokenKind) -> bool {
|
||||
fn ident_like(tok: &Token) -> bool {
|
||||
matches!(
|
||||
tok.kind,
|
||||
TokenKind::Ident(..) | TokenKind::Literal(..) | TokenKind::Lifetime(_)
|
||||
TokenKind::Ident(..) | TokenKind::Literal(..) | TokenKind::Lifetime(..)
|
||||
)
|
||||
}
|
||||
|
||||
@ -1099,7 +1099,9 @@ fn next_space(tok: &TokenKind) -> SpaceState {
|
||||
| TokenKind::OpenDelim(_)
|
||||
| TokenKind::CloseDelim(_) => SpaceState::Never,
|
||||
|
||||
TokenKind::Literal(..) | TokenKind::Ident(..) | TokenKind::Lifetime(_) => SpaceState::Ident,
|
||||
TokenKind::Literal(..) | TokenKind::Ident(..) | TokenKind::Lifetime(..) => {
|
||||
SpaceState::Ident
|
||||
}
|
||||
|
||||
_ => SpaceState::Always,
|
||||
}
|
||||
|
@ -548,7 +548,7 @@ impl Rewrite for ast::AnonConst {
|
||||
|
||||
impl Rewrite for ast::Lifetime {
|
||||
fn rewrite(&self, context: &RewriteContext<'_>, _: Shape) -> Option<String> {
|
||||
Some(rewrite_ident(context, self.ident).to_owned())
|
||||
Some(context.snippet(self.ident.span).to_owned())
|
||||
}
|
||||
}
|
||||
|
||||
|
15
src/tools/rustfmt/tests/target/raw-lifetimes.rs
Normal file
15
src/tools/rustfmt/tests/target/raw-lifetimes.rs
Normal file
@ -0,0 +1,15 @@
|
||||
// rustfmt-edition: 2021
|
||||
|
||||
// Simple idempotence test for raw lifetimes.
|
||||
|
||||
fn test<'r#gen>() -> &'r#gen () {
|
||||
// Test raw lifetimes...
|
||||
}
|
||||
|
||||
fn label() {
|
||||
'r#label: {
|
||||
// Test raw labels.
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
Loading…
Reference in New Issue
Block a user