From 94a0819fe3a0d679c3042a77bfe6a2afc505daea Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:11:28 +0200 Subject: Adding upstream version 1.66.0+dfsg1. Signed-off-by: Daniel Baumann --- .../rustc_lint/src/hidden_unicode_codepoints.rs | 98 +++++++++++----------- 1 file changed, 51 insertions(+), 47 deletions(-) (limited to 'compiler/rustc_lint/src/hidden_unicode_codepoints.rs') diff --git a/compiler/rustc_lint/src/hidden_unicode_codepoints.rs b/compiler/rustc_lint/src/hidden_unicode_codepoints.rs index fe2712525..7e884e990 100644 --- a/compiler/rustc_lint/src/hidden_unicode_codepoints.rs +++ b/compiler/rustc_lint/src/hidden_unicode_codepoints.rs @@ -60,52 +60,56 @@ impl HiddenUnicodeCodepoints { }) .collect(); - cx.struct_span_lint(TEXT_DIRECTION_CODEPOINT_IN_LITERAL, span, |lint| { - let mut err = lint.build(fluent::lint::hidden_unicode_codepoints); - err.set_arg("label", label); - err.set_arg("count", spans.len()); - err.span_label(span, fluent::lint::label); - err.note(fluent::lint::note); - if point_at_inner_spans { - for (c, span) in &spans { - err.span_label(*span, format!("{:?}", c)); + cx.struct_span_lint( + TEXT_DIRECTION_CODEPOINT_IN_LITERAL, + span, + fluent::lint_hidden_unicode_codepoints, + |lint| { + lint.set_arg("label", label); + lint.set_arg("count", spans.len()); + lint.span_label(span, fluent::label); + lint.note(fluent::note); + if point_at_inner_spans { + for (c, span) in &spans { + lint.span_label(*span, format!("{:?}", c)); + } } - } - if point_at_inner_spans && !spans.is_empty() { - err.multipart_suggestion_with_style( - fluent::lint::suggestion_remove, - spans.iter().map(|(_, span)| (*span, "".to_string())).collect(), - Applicability::MachineApplicable, - SuggestionStyle::HideCodeAlways, - ); - err.multipart_suggestion( - fluent::lint::suggestion_escape, - spans - .into_iter() - .map(|(c, span)| { - let c = format!("{:?}", c); - (span, c[1..c.len() - 1].to_string()) - }) - .collect(), - Applicability::MachineApplicable, - ); - } else { - // FIXME: in other suggestions we've reversed the inner spans of doc comments. We - // should do the same here to provide the same good suggestions as we do for - // literals above. - err.set_arg( - "escaped", - spans - .into_iter() - .map(|(c, _)| format!("{:?}", c)) - .collect::>() - .join(", "), - ); - err.note(fluent::lint::suggestion_remove); - err.note(fluent::lint::no_suggestion_note_escape); - } - err.emit(); - }); + if point_at_inner_spans && !spans.is_empty() { + lint.multipart_suggestion_with_style( + fluent::suggestion_remove, + spans.iter().map(|(_, span)| (*span, "".to_string())).collect(), + Applicability::MachineApplicable, + SuggestionStyle::HideCodeAlways, + ); + lint.multipart_suggestion( + fluent::suggestion_escape, + spans + .into_iter() + .map(|(c, span)| { + let c = format!("{:?}", c); + (span, c[1..c.len() - 1].to_string()) + }) + .collect(), + Applicability::MachineApplicable, + ); + } else { + // FIXME: in other suggestions we've reversed the inner spans of doc comments. We + // should do the same here to provide the same good suggestions as we do for + // literals above. + lint.set_arg( + "escaped", + spans + .into_iter() + .map(|(c, _)| format!("{:?}", c)) + .collect::>() + .join(", "), + ); + lint.note(fluent::suggestion_remove); + lint.note(fluent::no_suggestion_note_escape); + } + lint + }, + ); } } impl EarlyLintPass for HiddenUnicodeCodepoints { @@ -120,8 +124,8 @@ impl EarlyLintPass for HiddenUnicodeCodepoints { fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &ast::Expr) { // byte strings are already handled well enough by `EscapeError::NonAsciiCharInByteString` let (text, span, padding) = match &expr.kind { - ast::ExprKind::Lit(ast::Lit { token, kind, span }) => { - let text = token.symbol; + ast::ExprKind::Lit(ast::Lit { token_lit, kind, span }) => { + let text = token_lit.symbol; if !contains_text_flow_control_chars(text.as_str()) { return; } -- cgit v1.2.3