From 6fb3a38f9b27b328c6209147793602545d291b85 Mon Sep 17 00:00:00 2001 From: Rejyr Date: Mon, 5 Sep 2022 12:38:55 -0400 Subject: [PATCH] migrate: `pass_by_value.rs` --- compiler/rustc_lint/src/lints.rs | 8 ++++++++ compiler/rustc_lint/src/pass_by_value.rs | 19 ++++++------------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/compiler/rustc_lint/src/lints.rs b/compiler/rustc_lint/src/lints.rs index 077ee3fb671..fd68af572ff 100644 --- a/compiler/rustc_lint/src/lints.rs +++ b/compiler/rustc_lint/src/lints.rs @@ -6,6 +6,14 @@ use rustc_span::{Span, Symbol}; use crate::LateContext; +#[derive(LintDiagnostic)] +#[diag(lint_pass_by_value)] +pub struct PassByValueDiag { + pub ty: String, + #[suggestion(code = "{ty}", applicability = "maybe-incorrect")] + pub suggestion: Span, +} + #[derive(LintDiagnostic)] #[diag(lint_redundant_semicolons)] pub struct RedundantSemicolonsDiag { diff --git a/compiler/rustc_lint/src/pass_by_value.rs b/compiler/rustc_lint/src/pass_by_value.rs index 22caadfab17..3df0fc38595 100644 --- a/compiler/rustc_lint/src/pass_by_value.rs +++ b/compiler/rustc_lint/src/pass_by_value.rs @@ -1,5 +1,7 @@ +#![deny(rustc::untranslatable_diagnostic)] +#![deny(rustc::diagnostic_outside_of_impl)] +use crate::lints::PassByValueDiag; use crate::{LateContext, LateLintPass, LintContext}; -use rustc_errors::{fluent, Applicability}; use rustc_hir as hir; use rustc_hir::def::Res; use rustc_hir::{GenericArg, PathSegment, QPath, TyKind}; @@ -29,20 +31,11 @@ impl<'tcx> LateLintPass<'tcx> for PassByValue { } } if let Some(t) = path_for_pass_by_value(cx, &inner_ty) { - cx.struct_span_lint( + cx.emit_spanned_lint( PASS_BY_VALUE, ty.span, - fluent::lint_pass_by_value, - |lint| { - lint.set_arg("ty", t.clone()).span_suggestion( - ty.span, - fluent::suggestion, - t, - // Changing type of function argument - Applicability::MaybeIncorrect, - ) - }, - ) + PassByValueDiag { ty: t.clone(), suggestion: ty.span }, + ); } } _ => {}