Skip to content

Commit 601e5b5

Browse files
committed
Move remaining early buffered lints for rustc_parse to dyn lint diagnostics
1 parent 08de25c commit 601e5b5

File tree

8 files changed

+157
-219
lines changed

8 files changed

+157
-219
lines changed

compiler/rustc_lint/messages.ftl

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@ lint_bad_attribute_argument = bad attribute argument
4444
4545
lint_bad_opt_access = {$msg}
4646
47-
lint_break_with_label_and_loop = this labeled break expression is easy to confuse with an unlabeled break with a labeled value expression
48-
.suggestion = wrap this expression in parentheses
49-
5047
lint_builtin_allow_internal_unsafe =
5148
`allow_internal_unsafe` allows defining macros using unsafe without triggering the `unsafe_code` lint at their call site
5249
@@ -765,11 +762,6 @@ lint_range_endpoint_out_of_range = range endpoint is out of range for `{$ty}`
765762
766763
lint_range_use_inclusive_range = use an inclusive range instead
767764
768-
769-
lint_raw_prefix = prefix `'r` is reserved
770-
.label = reserved prefix
771-
.suggestion = insert whitespace here to avoid this being parsed as a prefix in Rust 2021
772-
773765
lint_reason_must_be_string_literal = reason must be a string literal
774766
775767
lint_reason_must_come_last = reason in lint attribute must come last
@@ -801,16 +793,6 @@ lint_renamed_lint = lint `{$name}` has been renamed to `{$replace}`
801793
802794
lint_requested_level = requested on the command line with `{$level} {$lint_name}`
803795
804-
lint_reserved_multihash = reserved token in Rust 2024
805-
.suggestion = insert whitespace here to avoid this being parsed as a forbidden token in Rust 2024
806-
807-
lint_reserved_prefix = prefix `{$prefix}` is unknown
808-
.label = unknown prefix
809-
.suggestion = insert whitespace here to avoid this being parsed as a prefix in Rust 2021
810-
811-
lint_reserved_string = will be parsed as a guarded string in Rust 2024
812-
.suggestion = insert whitespace here to avoid this being parsed as a guarded string in Rust 2024
813-
814796
lint_shadowed_into_iter =
815797
this method call resolves to `<&{$target} as IntoIterator>::into_iter` (due to backwards compatibility), but will resolve to `<{$target} as IntoIterator>::into_iter` in Rust {$edition}
816798
.use_iter_suggestion = use `.iter()` instead of `.into_iter()` to avoid ambiguity
@@ -927,16 +909,6 @@ lint_unexpected_cfg_value_specify_value = specify a config value
927909
lint_ungated_async_fn_track_caller = `#[track_caller]` on async functions is a no-op
928910
.label = this function will not propagate the caller location
929911
930-
lint_unicode_text_flow = unicode codepoint changing visible direction of text present in comment
931-
.label = {$num_codepoints ->
932-
[1] this comment contains an invisible unicode text flow control codepoint
933-
*[other] this comment contains invisible unicode text flow control codepoints
934-
}
935-
.note = these kind of unicode codepoints change the way text flows on applications that support them, but can cause confusion because they change the order of characters on the screen
936-
.suggestion = if their presence wasn't intentional, you can remove them
937-
.label_comment_char = {$c_debug}
938-
939-
940912
lint_unit_bindings = binding has unit type `()`
941913
.label = this pattern is inferred to be the unit type `()`
942914

compiler/rustc_lint/src/early/diagnostics.rs

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use std::borrow::Cow;
22

3-
use rustc_ast::util::unicode::TEXT_FLOW_CONTROL_CHARS;
43
use rustc_errors::{
54
Applicability, Diag, DiagArgValue, LintDiagnostic, elided_lifetime_in_path_suggestion,
65
};
@@ -9,7 +8,6 @@ use rustc_middle::middle::stability;
98
use rustc_middle::ty::TyCtxt;
109
use rustc_session::Session;
1110
use rustc_session::lint::BuiltinLintDiag;
12-
use rustc_span::BytePos;
1311
use tracing::debug;
1412

1513
use crate::lints;
@@ -23,32 +21,6 @@ pub fn decorate_builtin_lint(
2321
diag: &mut Diag<'_, ()>,
2422
) {
2523
match diagnostic {
26-
BuiltinLintDiag::UnicodeTextFlow(comment_span, content) => {
27-
let spans: Vec<_> = content
28-
.char_indices()
29-
.filter_map(|(i, c)| {
30-
TEXT_FLOW_CONTROL_CHARS.contains(&c).then(|| {
31-
let lo = comment_span.lo() + BytePos(2 + i as u32);
32-
(c, comment_span.with_lo(lo).with_hi(lo + BytePos(c.len_utf8() as u32)))
33-
})
34-
})
35-
.collect();
36-
let characters = spans
37-
.iter()
38-
.map(|&(c, span)| lints::UnicodeCharNoteSub { span, c_debug: format!("{c:?}") })
39-
.collect();
40-
let suggestions = (!spans.is_empty()).then_some(lints::UnicodeTextFlowSuggestion {
41-
spans: spans.iter().map(|(_c, span)| *span).collect(),
42-
});
43-
44-
lints::UnicodeTextFlow {
45-
comment_span,
46-
characters,
47-
suggestions,
48-
num_codepoints: spans.len(),
49-
}
50-
.decorate_lint(diag);
51-
}
5224
BuiltinLintDiag::AbsPathWithModule(mod_span) => {
5325
let (replacement, applicability) = match sess.source_map().span_to_snippet(mod_span) {
5426
Ok(ref s) => {
@@ -141,34 +113,6 @@ pub fn decorate_builtin_lint(
141113
}
142114
.decorate_lint(diag);
143115
}
144-
BuiltinLintDiag::ReservedPrefix(label_span, prefix) => {
145-
lints::ReservedPrefix {
146-
label: label_span,
147-
suggestion: label_span.shrink_to_hi(),
148-
prefix,
149-
}
150-
.decorate_lint(diag);
151-
}
152-
BuiltinLintDiag::RawPrefix(label_span) => {
153-
lints::RawPrefix { label: label_span, suggestion: label_span.shrink_to_hi() }
154-
.decorate_lint(diag);
155-
}
156-
BuiltinLintDiag::ReservedString { is_string, suggestion } => {
157-
if is_string {
158-
lints::ReservedString { suggestion }.decorate_lint(diag);
159-
} else {
160-
lints::ReservedMultihash { suggestion }.decorate_lint(diag);
161-
}
162-
}
163-
BuiltinLintDiag::BreakWithLabelAndLoop(sugg_span) => {
164-
lints::BreakWithLabelAndLoop {
165-
sub: lints::BreakWithLabelAndLoopSub {
166-
left: sugg_span.shrink_to_lo(),
167-
right: sugg_span.shrink_to_hi(),
168-
},
169-
}
170-
.decorate_lint(diag);
171-
}
172116
BuiltinLintDiag::DeprecatedWhereclauseLocation(left_sp, sugg) => {
173117
let suggestion = match sugg {
174118
Some((right_sp, sugg)) => lints::DeprecatedWhereClauseLocationSugg::MoveToEnd {

compiler/rustc_lint/src/lints.rs

Lines changed: 0 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -2604,35 +2604,6 @@ pub(crate) struct IllFormedAttributeInput {
26042604
pub docs: &'static str,
26052605
}
26062606

2607-
#[derive(LintDiagnostic)]
2608-
#[diag(lint_unicode_text_flow)]
2609-
#[note]
2610-
pub(crate) struct UnicodeTextFlow {
2611-
#[label]
2612-
pub comment_span: Span,
2613-
#[subdiagnostic]
2614-
pub characters: Vec<UnicodeCharNoteSub>,
2615-
#[subdiagnostic]
2616-
pub suggestions: Option<UnicodeTextFlowSuggestion>,
2617-
2618-
pub num_codepoints: usize,
2619-
}
2620-
2621-
#[derive(Subdiagnostic)]
2622-
#[label(lint_label_comment_char)]
2623-
pub(crate) struct UnicodeCharNoteSub {
2624-
#[primary_span]
2625-
pub span: Span,
2626-
pub c_debug: String,
2627-
}
2628-
2629-
#[derive(Subdiagnostic)]
2630-
#[multipart_suggestion(lint_suggestion, applicability = "machine-applicable", style = "hidden")]
2631-
pub(crate) struct UnicodeTextFlowSuggestion {
2632-
#[suggestion_part(code = "")]
2633-
pub spans: Vec<Span>,
2634-
}
2635-
26362607
#[derive(LintDiagnostic)]
26372608
#[diag(lint_abs_path_with_module)]
26382609
pub(crate) struct AbsPathWithModule {
@@ -2737,42 +2708,6 @@ pub(crate) struct PatternsInFnsWithoutBodySub {
27372708
pub ident: Ident,
27382709
}
27392710

2740-
#[derive(LintDiagnostic)]
2741-
#[diag(lint_reserved_prefix)]
2742-
pub(crate) struct ReservedPrefix {
2743-
#[label]
2744-
pub label: Span,
2745-
#[suggestion(code = " ", applicability = "machine-applicable")]
2746-
pub suggestion: Span,
2747-
2748-
pub prefix: String,
2749-
}
2750-
2751-
#[derive(LintDiagnostic)]
2752-
#[diag(lint_raw_prefix)]
2753-
pub(crate) struct RawPrefix {
2754-
#[label]
2755-
pub label: Span,
2756-
#[suggestion(code = " ", applicability = "machine-applicable")]
2757-
pub suggestion: Span,
2758-
}
2759-
2760-
#[derive(LintDiagnostic)]
2761-
#[diag(lint_break_with_label_and_loop)]
2762-
pub(crate) struct BreakWithLabelAndLoop {
2763-
#[subdiagnostic]
2764-
pub sub: BreakWithLabelAndLoopSub,
2765-
}
2766-
2767-
#[derive(Subdiagnostic)]
2768-
#[multipart_suggestion(lint_suggestion, applicability = "machine-applicable")]
2769-
pub(crate) struct BreakWithLabelAndLoopSub {
2770-
#[suggestion_part(code = "(")]
2771-
pub left: Span,
2772-
#[suggestion_part(code = ")")]
2773-
pub right: Span,
2774-
}
2775-
27762711
#[derive(LintDiagnostic)]
27772712
#[diag(lint_deprecated_where_clause_location)]
27782713
#[note]
@@ -2927,20 +2862,6 @@ pub(crate) enum MutRefSugg {
29272862
#[diag(lint_unqualified_local_imports)]
29282863
pub(crate) struct UnqualifiedLocalImportsDiag {}
29292864

2930-
#[derive(LintDiagnostic)]
2931-
#[diag(lint_reserved_string)]
2932-
pub(crate) struct ReservedString {
2933-
#[suggestion(code = " ", applicability = "machine-applicable")]
2934-
pub suggestion: Span,
2935-
}
2936-
2937-
#[derive(LintDiagnostic)]
2938-
#[diag(lint_reserved_multihash)]
2939-
pub(crate) struct ReservedMultihash {
2940-
#[suggestion(code = " ", applicability = "machine-applicable")]
2941-
pub suggestion: Span,
2942-
}
2943-
29442865
#[derive(LintDiagnostic)]
29452866
#[diag(lint_function_casts_as_integer)]
29462867
pub(crate) struct FunctionCastsAsIntegerDiag<'tcx> {

compiler/rustc_lint_defs/src/lib.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -678,16 +678,6 @@ pub enum BuiltinLintDiag {
678678
ident: Ident,
679679
is_foreign: bool,
680680
},
681-
ReservedPrefix(Span, String),
682-
/// `'r#` in edition < 2021.
683-
RawPrefix(Span),
684-
/// `##` or `#"` in edition < 2024.
685-
ReservedString {
686-
is_string: bool,
687-
suggestion: Span,
688-
},
689-
BreakWithLabelAndLoop(Span),
690-
UnicodeTextFlow(Span, String),
691681
DeprecatedWhereclauseLocation(Span, Option<(Span, String)>),
692682
SingleUseLifetime {
693683
/// Span of the parameter which declares this lifetime.

compiler/rustc_parse/messages.ftl

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ parse_box_not_pat = expected pattern, found {$descr}
115115
parse_box_syntax_removed = `box_syntax` has been removed
116116
parse_box_syntax_removed_suggestion = use `Box::new()` instead
117117
118+
parse_break_with_label_and_loop = this labeled break expression is easy to confuse with an unlabeled break with a labeled value expression
119+
.suggestion = wrap this expression in parentheses
120+
118121
parse_cannot_be_raw_ident = `{$ident}` cannot be a raw identifier
119122
120123
parse_cannot_be_raw_lifetime = `{$ident}` cannot be a raw lifetime
@@ -773,6 +776,10 @@ parse_question_mark_in_type = invalid `?` in type
773776
.label = `?` is only allowed on expressions, not types
774777
.suggestion = if you meant to express that the type might not contain a value, use the `Option` wrapper type
775778
779+
parse_raw_prefix = prefix `'r` is reserved
780+
.label = reserved prefix
781+
.suggestion = insert whitespace here to avoid this being parsed as a prefix in Rust 2021
782+
776783
parse_recover_import_as_use = expected item, found {$token_name}
777784
.suggestion = items are imported using the `use` keyword
778785
@@ -787,13 +794,23 @@ parse_require_colon_after_labeled_expression = labeled expression must be follow
787794
.label = the label
788795
.suggestion = add `:` after the label
789796
797+
parse_reserved_guarded_string = invalid string literal
798+
.note = unprefixed guarded string literals are reserved for future use since Rust 2024
799+
.suggestion = consider inserting whitespace here
800+
801+
parse_reserved_guarded_string_lint = will be parsed as a guarded string in Rust 2024
802+
.suggestion = insert whitespace here to avoid this being parsed as a guarded string in Rust 2024
803+
790804
parse_reserved_multihash = reserved multi-hash token is forbidden
791805
.note = sequences of two or more # are reserved for future use since Rust 2024
792-
.suggestion_whitespace = consider inserting whitespace here
806+
.suggestion = consider inserting whitespace here
793807
794-
parse_reserved_string = invalid string literal
795-
.note = unprefixed guarded string literals are reserved for future use since Rust 2024
796-
.suggestion_whitespace = consider inserting whitespace here
808+
parse_reserved_multihash_lint = reserved token in Rust 2024
809+
.suggestion = insert whitespace here to avoid this being parsed as a forbidden token in Rust 2024
810+
811+
parse_reserved_prefix = prefix `{$prefix}` is unknown
812+
.label = unknown prefix
813+
.suggestion = insert whitespace here to avoid this being parsed as a prefix in Rust 2021
797814
798815
parse_return_types_use_thin_arrow = return types are denoted using `->`
799816
.suggestion = use `->` instead
@@ -951,6 +968,14 @@ parse_unicode_escape_in_byte = unicode escape in byte string
951968
.label = {parse_unicode_escape_in_byte}
952969
.help = unicode escape sequences cannot be used as a byte or in a byte string
953970
971+
parse_unicode_text_flow = unicode codepoint changing visible direction of text present in comment
972+
.label = {$num_codepoints ->
973+
[1] this comment contains an invisible unicode text flow control codepoint
974+
*[other] this comment contains invisible unicode text flow control codepoints
975+
}
976+
.note = these kind of unicode codepoints change the way text flows on applications that support them, but can cause confusion because they change the order of characters on the screen
977+
.suggestion = if their presence wasn't intentional, you can remove them
978+
954979
parse_unknown_builtin_construct = unknown `builtin #` construct `{$name}`
955980
956981
parse_unknown_prefix = prefix `{$prefix}` is unknown

0 commit comments

Comments
 (0)