Skip to content
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

Migrate rustc_lint lint diagnostics #101138

Merged
merged 33 commits into from
Jan 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
5a90537
add: `lints.rs`
Rejyr Aug 28, 2022
d44ccaa
migrate: `types.rs`
Rejyr Aug 28, 2022
e5ae9d0
migrate: `unused.rs`
Rejyr Sep 4, 2022
a42afa0
migrate: `traits.rs`
Rejyr Sep 5, 2022
c3a6801
migrate: `redundant_semicolon.rs`
Rejyr Sep 5, 2022
6fb3a38
migrate: `pass_by_value.rs`
Rejyr Sep 5, 2022
56fc66d
migrate: `noop_method_call.rs`
Rejyr Sep 5, 2022
a9bbe31
migrate: `nonstandard_style.rs`
Rejyr Sep 5, 2022
384010b
migrate: `non_fmt_panic.rs`
Rejyr Sep 5, 2022
3f69c1b
migrate: `non_ascii_idents.rs`
Rejyr Sep 5, 2022
95d3e0c
migrate: `methods.rs`
Rejyr Sep 5, 2022
c63ba52
migrate: `array_into_iter.rs`
Rejyr Sep 18, 2022
8b897bb
migrate: `early.rs` and `enum_intrinsics_non_enums.rs`
Rejyr Sep 18, 2022
e3bb2eb
add: `lints` for `errors.rs`
Rejyr Sep 22, 2022
dc00aa3
update: `lints.rs` for renamed traits
Rejyr Sep 22, 2022
a0614ec
fix: merge conflict
Rejyr Oct 4, 2022
f9289c3
refactor: comment about lint location
Rejyr Oct 4, 2022
ab66ea6
add: `emit{,_spanned}_lint` for `LintLevelsBuilder`
Rejyr Oct 5, 2022
80df25e
migrate: `levels.rs`
Rejyr Oct 7, 2022
e610047
migrate: `let_underscore.rs`
Rejyr Oct 7, 2022
5ffaae7
migrate: `ImproperCTypes`
Rejyr Oct 7, 2022
0b19227
migrate: `internal.rs`
Rejyr Oct 22, 2022
6ffecd2
migrate(wip): `builtin.rs`
Rejyr Oct 23, 2022
3c1a1f3
migrate: `expect.rs`
Rejyr Nov 9, 2022
ca7df9a
migrate: `for_loops_over_fallibles.rs`
Rejyr Nov 10, 2022
78fce79
refactor: refactor to derive for some lints.
Rejyr Nov 11, 2022
ce72f94
add: `#[rustc_lint_diagnostics]` for more `context.rs` functions.
Rejyr Nov 11, 2022
c06a242
migrate: `hidden_unicode_codepoints.rs`
Rejyr Nov 12, 2022
587d497
migrate: `UnsafeCode` in `builtin.rs`
Rejyr Nov 13, 2022
758140e
migrate: rest of `builtin.rs` without `builtin_asm_labels`
Rejyr Nov 13, 2022
f38db48
add: allow lints in `lints.rs`
Rejyr Nov 13, 2022
fe09291
migrate: `deref_into_dyn_supertrait.rs`
Rejyr Nov 25, 2022
88e5dd2
refactor: cleanup
Rejyr Nov 23, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 59 additions & 2 deletions compiler/rustc_error_messages/locales/en-US/lint.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,43 @@ lint_enum_intrinsics_mem_variant =

lint_expectation = this lint expectation is unfulfilled
.note = the `unfulfilled_lint_expectations` lint can't be expected and will always produce this message
.rationale = {$rationale}

lint_for_loops_over_fallibles =
for loop over {$article} `{$ty}`. This is more readably written as an `if let` statement
.suggestion = consider using `if let` to clear intent
.remove_next = to iterate over `{$recv_snip}` remove the call to `next`
.use_while_let = to check pattern in a loop use `while let`
.use_question_mark = consider unwrapping the `Result` with `?` to iterate over its contents

lint_non_binding_let_on_sync_lock =
non-binding let on a synchronization lock

lint_non_binding_let_on_drop_type =
non-binding let on a type that implements `Drop`

lint_non_binding_let_suggestion =
consider binding to an unused variable to avoid immediately dropping the value

lint_non_binding_let_multi_suggestion =
consider immediately dropping the value

lint_deprecated_lint_name =
lint name `{$name}` is deprecated and may not have an effect in the future.
.suggestion = change it to

lint_renamed_or_removed_lint = {$msg}
.suggestion = use the new name

lint_unknown_lint =
unknown lint: `{$name}`
.suggestion = did you mean

lint_ignored_unless_crate_specified = {$level}({$name}) is ignored unless specified at crate level

lint_unknown_gated_lint =
unknown lint: `{$name}`
.note = the `{$name}` lint is unstable

lint_hidden_unicode_codepoints = unicode codepoint changing visible direction of text present in {$label}
.label = this {$label} contains {$count ->
Expand Down Expand Up @@ -55,6 +92,8 @@ lint_diag_out_of_impl =

lint_untranslatable_diag = diagnostics should be created using translatable messages

lint_bad_opt_access = {$msg}

lint_cstring_ptr = getting the inner pointer of a temporary `CString`
.as_ptr_label = this pointer will be invalid
.unwrap_label = this `CString` is deallocated at the end of the statement, bind it to a variable to extend its lifetime
Expand Down Expand Up @@ -331,6 +370,8 @@ lint_builtin_anonymous_params = anonymous parameters are deprecated and will be
.suggestion = try naming the parameter or explicitly ignoring it

lint_builtin_deprecated_attr_link = use of deprecated attribute `{$name}`: {$reason}. See {$link}
.msg_suggestion = {$msg}
.default_suggestion = remove this attribute
lint_builtin_deprecated_attr_used = use of deprecated attribute `{$name}`: no longer used.
lint_builtin_deprecated_attr_default_suggestion = remove this attribute

Expand Down Expand Up @@ -391,10 +432,16 @@ lint_builtin_incomplete_features = the feature `{$name}` is incomplete and may n
.note = see issue #{$n} <https://github.com/rust-lang/rust/issues/{$n}> for more information
.help = consider using `min_{$name}` instead, which is more stable and complete

lint_builtin_clashing_extern_same_name = `{$this_fi}` redeclared with a different signature
lint_builtin_unpermitted_type_init_zeroed = the type `{$ty}` does not permit zero-initialization
lint_builtin_unpermitted_type_init_unint = the type `{$ty}` does not permit being left uninitialized

lint_builtin_unpermitted_type_init_label = this code causes undefined behavior when executed
lint_builtin_unpermitted_type_init_label_suggestion = help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done

lint_builtin_clashing_extern_same_name = `{$this}` redeclared with a different signature
.previous_decl_label = `{$orig}` previously declared here
.mismatch_label = this signature doesn't match the previous declaration
lint_builtin_clashing_extern_diff_name = `{$this_fi}` redeclares `{$orig}` with a different signature
lint_builtin_clashing_extern_diff_name = `{$this}` redeclares `{$orig}` with a different signature
.previous_decl_label = `{$orig}` previously declared here
.mismatch_label = this signature doesn't match the previous declaration

Expand All @@ -403,6 +450,16 @@ lint_builtin_deref_nullptr = dereferencing a null pointer

lint_builtin_asm_labels = avoid using named labels in inline assembly

lint_builtin_special_module_name_used_lib = found module declaration for lib.rs
.note = lib.rs is the root of this crate's library target
.help = to refer to it from other targets, use the library's name as the path

lint_builtin_special_module_name_used_main = found module declaration for main.rs
.note = a binary crate cannot be used as library

lint_supertrait_as_deref_target = `{$t}` implements `Deref` with supertrait `{$target_principal}` as target
.label = target type is set here

lint_overruled_attribute = {$lint_level}({$lint_source}) incompatible with previous forbid
.label = overruled by previous forbid

Expand Down
50 changes: 16 additions & 34 deletions compiler/rustc_lint/src/array_into_iter.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::lints::{ArrayIntoIterDiag, ArrayIntoIterDiagSub};
use crate::{LateContext, LateLintPass, LintContext};
use rustc_errors::{fluent, Applicability};
use rustc_hir as hir;
use rustc_middle::ty;
use rustc_middle::ty::adjustment::{Adjust, Adjustment};
Expand Down Expand Up @@ -118,41 +118,23 @@ impl<'tcx> LateLintPass<'tcx> for ArrayIntoIter {
// to an array or to a slice.
_ => bug!("array type coerced to something other than array or slice"),
};
cx.struct_span_lint(
let sub = if self.for_expr_span == expr.span {
Some(ArrayIntoIterDiagSub::RemoveIntoIter {
span: receiver_arg.span.shrink_to_hi().to(expr.span.shrink_to_hi()),
})
} else if receiver_ty.is_array() {
Some(ArrayIntoIterDiagSub::UseExplicitIntoIter {
start_span: expr.span.shrink_to_lo(),
end_span: receiver_arg.span.shrink_to_hi().to(expr.span.shrink_to_hi()),
})
} else {
None
};
cx.emit_spanned_lint(
ARRAY_INTO_ITER,
call.ident.span,
fluent::lint_array_into_iter,
|diag| {
diag.set_arg("target", target);
diag.span_suggestion(
call.ident.span,
fluent::use_iter_suggestion,
"iter",
Applicability::MachineApplicable,
);
if self.for_expr_span == expr.span {
diag.span_suggestion(
receiver_arg.span.shrink_to_hi().to(expr.span.shrink_to_hi()),
fluent::remove_into_iter_suggestion,
"",
Applicability::MaybeIncorrect,
);
} else if receiver_ty.is_array() {
diag.multipart_suggestion(
fluent::use_explicit_into_iter_suggestion,
vec![
(expr.span.shrink_to_lo(), "IntoIterator::into_iter(".into()),
(
receiver_arg.span.shrink_to_hi().to(expr.span.shrink_to_hi()),
")".into(),
),
],
Applicability::MaybeIncorrect,
);
}
diag
},
)
ArrayIntoIterDiag { target, suggestion: call.ident.span, sub },
);
}
}
}
Loading