Skip to content

Commit bfffe40

Browse files
committed
Auto merge of #101138 - Rejyr:diagnostic-migration-rustc-lint-pt2, r=davidtwco
Migrate `rustc_lint` lint diagnostics Part 2 of [Migrate `rustc_lint` errors to `SessionDiagnostic`](#100776) r? `@davidtwco` # TODO - [x] Refactor some lints manually implementing `DecorateLint` to use `Option<Subdiagnostic>`. - [x] Add `#[rustc_lint_diagnostics]` to lint functions in `context.rs`. - [x] Migrate `hidden_unicode_codepoints.rs`. - [x] Migrate `UnsafeCode` in `builtin.rs`. - [x] Migrate the rest of `builtin.rs`.
2 parents 86ad69d + 88e5dd2 commit bfffe40

26 files changed

+2295
-1374
lines changed

compiler/rustc_error_messages/locales/en-US/lint.ftl

+59-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,43 @@ lint_enum_intrinsics_mem_variant =
1515
1616
lint_expectation = this lint expectation is unfulfilled
1717
.note = the `unfulfilled_lint_expectations` lint can't be expected and will always produce this message
18+
.rationale = {$rationale}
19+
20+
lint_for_loops_over_fallibles =
21+
for loop over {$article} `{$ty}`. This is more readably written as an `if let` statement
22+
.suggestion = consider using `if let` to clear intent
23+
.remove_next = to iterate over `{$recv_snip}` remove the call to `next`
24+
.use_while_let = to check pattern in a loop use `while let`
25+
.use_question_mark = consider unwrapping the `Result` with `?` to iterate over its contents
26+
27+
lint_non_binding_let_on_sync_lock =
28+
non-binding let on a synchronization lock
29+
30+
lint_non_binding_let_on_drop_type =
31+
non-binding let on a type that implements `Drop`
32+
33+
lint_non_binding_let_suggestion =
34+
consider binding to an unused variable to avoid immediately dropping the value
35+
36+
lint_non_binding_let_multi_suggestion =
37+
consider immediately dropping the value
38+
39+
lint_deprecated_lint_name =
40+
lint name `{$name}` is deprecated and may not have an effect in the future.
41+
.suggestion = change it to
42+
43+
lint_renamed_or_removed_lint = {$msg}
44+
.suggestion = use the new name
45+
46+
lint_unknown_lint =
47+
unknown lint: `{$name}`
48+
.suggestion = did you mean
49+
50+
lint_ignored_unless_crate_specified = {$level}({$name}) is ignored unless specified at crate level
51+
52+
lint_unknown_gated_lint =
53+
unknown lint: `{$name}`
54+
.note = the `{$name}` lint is unstable
1855
1956
lint_hidden_unicode_codepoints = unicode codepoint changing visible direction of text present in {$label}
2057
.label = this {$label} contains {$count ->
@@ -55,6 +92,8 @@ lint_diag_out_of_impl =
5592
5693
lint_untranslatable_diag = diagnostics should be created using translatable messages
5794
95+
lint_bad_opt_access = {$msg}
96+
5897
lint_cstring_ptr = getting the inner pointer of a temporary `CString`
5998
.as_ptr_label = this pointer will be invalid
6099
.unwrap_label = this `CString` is deallocated at the end of the statement, bind it to a variable to extend its lifetime
@@ -331,6 +370,8 @@ lint_builtin_anonymous_params = anonymous parameters are deprecated and will be
331370
.suggestion = try naming the parameter or explicitly ignoring it
332371
333372
lint_builtin_deprecated_attr_link = use of deprecated attribute `{$name}`: {$reason}. See {$link}
373+
.msg_suggestion = {$msg}
374+
.default_suggestion = remove this attribute
334375
lint_builtin_deprecated_attr_used = use of deprecated attribute `{$name}`: no longer used.
335376
lint_builtin_deprecated_attr_default_suggestion = remove this attribute
336377
@@ -391,10 +432,16 @@ lint_builtin_incomplete_features = the feature `{$name}` is incomplete and may n
391432
.note = see issue #{$n} <https://github.com/rust-lang/rust/issues/{$n}> for more information
392433
.help = consider using `min_{$name}` instead, which is more stable and complete
393434
394-
lint_builtin_clashing_extern_same_name = `{$this_fi}` redeclared with a different signature
435+
lint_builtin_unpermitted_type_init_zeroed = the type `{$ty}` does not permit zero-initialization
436+
lint_builtin_unpermitted_type_init_unint = the type `{$ty}` does not permit being left uninitialized
437+
438+
lint_builtin_unpermitted_type_init_label = this code causes undefined behavior when executed
439+
lint_builtin_unpermitted_type_init_label_suggestion = help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
440+
441+
lint_builtin_clashing_extern_same_name = `{$this}` redeclared with a different signature
395442
.previous_decl_label = `{$orig}` previously declared here
396443
.mismatch_label = this signature doesn't match the previous declaration
397-
lint_builtin_clashing_extern_diff_name = `{$this_fi}` redeclares `{$orig}` with a different signature
444+
lint_builtin_clashing_extern_diff_name = `{$this}` redeclares `{$orig}` with a different signature
398445
.previous_decl_label = `{$orig}` previously declared here
399446
.mismatch_label = this signature doesn't match the previous declaration
400447
@@ -403,6 +450,16 @@ lint_builtin_deref_nullptr = dereferencing a null pointer
403450
404451
lint_builtin_asm_labels = avoid using named labels in inline assembly
405452
453+
lint_builtin_special_module_name_used_lib = found module declaration for lib.rs
454+
.note = lib.rs is the root of this crate's library target
455+
.help = to refer to it from other targets, use the library's name as the path
456+
457+
lint_builtin_special_module_name_used_main = found module declaration for main.rs
458+
.note = a binary crate cannot be used as library
459+
460+
lint_supertrait_as_deref_target = `{$t}` implements `Deref` with supertrait `{$target_principal}` as target
461+
.label = target type is set here
462+
406463
lint_overruled_attribute = {$lint_level}({$lint_source}) incompatible with previous forbid
407464
.label = overruled by previous forbid
408465

compiler/rustc_lint/src/array_into_iter.rs

+16-34
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
use crate::lints::{ArrayIntoIterDiag, ArrayIntoIterDiagSub};
12
use crate::{LateContext, LateLintPass, LintContext};
2-
use rustc_errors::{fluent, Applicability};
33
use rustc_hir as hir;
44
use rustc_middle::ty;
55
use rustc_middle::ty::adjustment::{Adjust, Adjustment};
@@ -118,41 +118,23 @@ impl<'tcx> LateLintPass<'tcx> for ArrayIntoIter {
118118
// to an array or to a slice.
119119
_ => bug!("array type coerced to something other than array or slice"),
120120
};
121-
cx.struct_span_lint(
121+
let sub = if self.for_expr_span == expr.span {
122+
Some(ArrayIntoIterDiagSub::RemoveIntoIter {
123+
span: receiver_arg.span.shrink_to_hi().to(expr.span.shrink_to_hi()),
124+
})
125+
} else if receiver_ty.is_array() {
126+
Some(ArrayIntoIterDiagSub::UseExplicitIntoIter {
127+
start_span: expr.span.shrink_to_lo(),
128+
end_span: receiver_arg.span.shrink_to_hi().to(expr.span.shrink_to_hi()),
129+
})
130+
} else {
131+
None
132+
};
133+
cx.emit_spanned_lint(
122134
ARRAY_INTO_ITER,
123135
call.ident.span,
124-
fluent::lint_array_into_iter,
125-
|diag| {
126-
diag.set_arg("target", target);
127-
diag.span_suggestion(
128-
call.ident.span,
129-
fluent::use_iter_suggestion,
130-
"iter",
131-
Applicability::MachineApplicable,
132-
);
133-
if self.for_expr_span == expr.span {
134-
diag.span_suggestion(
135-
receiver_arg.span.shrink_to_hi().to(expr.span.shrink_to_hi()),
136-
fluent::remove_into_iter_suggestion,
137-
"",
138-
Applicability::MaybeIncorrect,
139-
);
140-
} else if receiver_ty.is_array() {
141-
diag.multipart_suggestion(
142-
fluent::use_explicit_into_iter_suggestion,
143-
vec![
144-
(expr.span.shrink_to_lo(), "IntoIterator::into_iter(".into()),
145-
(
146-
receiver_arg.span.shrink_to_hi().to(expr.span.shrink_to_hi()),
147-
")".into(),
148-
),
149-
],
150-
Applicability::MaybeIncorrect,
151-
);
152-
}
153-
diag
154-
},
155-
)
136+
ArrayIntoIterDiag { target, suggestion: call.ident.span, sub },
137+
);
156138
}
157139
}
158140
}

0 commit comments

Comments
 (0)