1
Fork 0

Migrate rustc_passes to translatable diagnostics

This commit is contained in:
clubby789 2023-04-25 18:42:42 +01:00
parent 20d90b14ff
commit 6a41cfe095
11 changed files with 313 additions and 180 deletions

View file

@ -139,7 +139,6 @@ passes_doc_attr_not_crate_level =
passes_attr_crate_level = passes_attr_crate_level =
this attribute can only be applied at the crate level this attribute can only be applied at the crate level
.suggestion = to apply to the crate, use an inner attribute .suggestion = to apply to the crate, use an inner attribute
.help = to apply to the crate, use an inner attribute
.note = read <https://doc.rust-lang.org/nightly/rustdoc/the-doc-attribute.html#at-the-crate-level> for more information .note = read <https://doc.rust-lang.org/nightly/rustdoc/the-doc-attribute.html#at-the-crate-level> for more information
passes_doc_test_unknown = passes_doc_test_unknown =
@ -724,3 +723,45 @@ passes_skipping_const_checks = skipping const checks
passes_invalid_macro_export_arguments = `{$name}` isn't a valid `#[macro_export]` argument passes_invalid_macro_export_arguments = `{$name}` isn't a valid `#[macro_export]` argument
passes_invalid_macro_export_arguments_too_many_items = `#[macro_export]` can only take 1 or 0 arguments passes_invalid_macro_export_arguments_too_many_items = `#[macro_export]` can only take 1 or 0 arguments
passes_unreachable_due_to_uninhabited = unreachable {$descr}
.label = unreachable {$descr}
.label_orig = any code following this expression is unreachable
.note = this expression has type `{$ty}`, which is uninhabited
passes_unused_var_maybe_capture_ref = unused variable: `{$name}`
.help = did you mean to capture by reference instead?
passes_unused_capture_maybe_capture_ref = value captured by `{$name}` is never read
.help = did you mean to capture by reference instead?
passes_unused_var_remove_field = unused variable: `{$name}`
passes_unused_var_remove_field_suggestion = try removing the field
passes_unused_var_assigned_only = variable `{$name}` is assigned to, but never used
.note = consider using `_{$name}` instead
passes_unnecessary_stable_feature = the feature `{$feature}` has been stable since {$since} and no longer requires an attribute to enable
passes_unnecessary_partial_stable_feature = the feature `{$feature}` has been partially stabilized since {$since} and is succeeded by the feature `{$implies}`
.suggestion = if you are using features which are still unstable, change to using `{$implies}`
.suggestion_remove = if you are using features which are now stable, remove this line
passes_ineffective_unstable_impl = an `#[unstable]` annotation here has no effect
.note = see issue #55436 <https://github.com/rust-lang/rust/issues/55436> for more information
passes_unused_assign = value assigned to `{$name}` is never read
.help = maybe it is overwritten before being read?
passes_unused_assign_passed = value passed to `{$name}` is never read
.help = maybe it is overwritten before being read?
passes_maybe_string_interpolation = you might have meant to use string interpolation in this string literal
passes_string_interpolation_only_works = string interpolation only works in `format!` invocations
passes_unused_variable_try_prefix = unused variable: `{$name}`
.label = unused variable
.suggestion = if this is intentional, prefix it with an underscore
passes_unused_variable_try_ignore = unused variable: `{$name}`
.suggestion = try ignoring the field

View file

@ -29,7 +29,7 @@ use rustc_session::lint::builtin::{
}; };
use rustc_session::parse::feature_err; use rustc_session::parse::feature_err;
use rustc_span::symbol::{kw, sym, Symbol}; use rustc_span::symbol::{kw, sym, Symbol};
use rustc_span::{Span, DUMMY_SP}; use rustc_span::{BytePos, Span, DUMMY_SP};
use rustc_target::spec::abi::Abi; use rustc_target::spec::abi::Abi;
use rustc_trait_selection::infer::{TyCtxtInferExt, ValuePairs}; use rustc_trait_selection::infer::{TyCtxtInferExt, ValuePairs};
use rustc_trait_selection::traits::error_reporting::TypeErrCtxtExt; use rustc_trait_selection::traits::error_reporting::TypeErrCtxtExt;
@ -927,30 +927,18 @@ impl CheckAttrVisitor<'_> {
hir_id: HirId, hir_id: HirId,
) -> bool { ) -> bool {
if hir_id != CRATE_HIR_ID { if hir_id != CRATE_HIR_ID {
self.tcx.struct_span_lint_hir( // insert a bang between `#` and `[...`
let bang_span = attr.span.lo() + BytePos(1);
let sugg = (attr.style == AttrStyle::Outer
&& self.tcx.hir().get_parent_item(hir_id) == CRATE_OWNER_ID)
.then_some(errors::AttrCrateLevelOnlySugg {
attr: attr.span.with_lo(bang_span).with_hi(bang_span),
});
self.tcx.emit_spanned_lint(
INVALID_DOC_ATTRIBUTES, INVALID_DOC_ATTRIBUTES,
hir_id, hir_id,
meta.span(), meta.span(),
fluent::passes_attr_crate_level, errors::AttrCrateLevelOnly { sugg },
|err| {
if attr.style == AttrStyle::Outer
&& self.tcx.hir().get_parent_item(hir_id) == CRATE_OWNER_ID
{
if let Ok(mut src) = self.tcx.sess.source_map().span_to_snippet(attr.span) {
src.insert(1, '!');
err.span_suggestion_verbose(
attr.span,
fluent::passes_suggestion,
src,
Applicability::MaybeIncorrect,
);
} else {
err.span_help(attr.span, fluent::passes_help);
}
}
err.note(fluent::passes_note);
err
},
); );
return false; return false;
} }

View file

@ -6,7 +6,8 @@ use std::{
use crate::fluent_generated as fluent; use crate::fluent_generated as fluent;
use rustc_ast::Label; use rustc_ast::Label;
use rustc_errors::{ use rustc_errors::{
error_code, Applicability, DiagnosticSymbolList, ErrorGuaranteed, IntoDiagnostic, MultiSpan, error_code, AddToDiagnostic, Applicability, Diagnostic, DiagnosticSymbolList, ErrorGuaranteed,
IntoDiagnostic, MultiSpan,
}; };
use rustc_hir::{self as hir, ExprKind, Target}; use rustc_hir::{self as hir, ExprKind, Target};
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic}; use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
@ -1555,3 +1556,160 @@ pub struct SkippingConstChecks {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(LintDiagnostic)]
#[diag(passes_unreachable_due_to_uninhabited)]
pub struct UnreachableDueToUninhabited<'desc, 'tcx> {
pub descr: &'desc str,
#[label]
pub expr: Span,
#[label(passes_label_orig)]
#[note]
pub orig: Span,
pub ty: Ty<'tcx>,
}
#[derive(LintDiagnostic)]
#[diag(passes_unused_var_maybe_capture_ref)]
#[help]
pub struct UnusedVarMaybeCaptureRef {
pub name: String,
}
#[derive(LintDiagnostic)]
#[diag(passes_unused_capture_maybe_capture_ref)]
#[help]
pub struct UnusedCaptureMaybeCaptureRef {
pub name: String,
}
#[derive(LintDiagnostic)]
#[diag(passes_unused_var_remove_field)]
pub struct UnusedVarRemoveField {
pub name: String,
#[subdiagnostic]
pub sugg: UnusedVarRemoveFieldSugg,
}
#[derive(Subdiagnostic)]
#[multipart_suggestion(
passes_unused_var_remove_field_suggestion,
applicability = "machine-applicable"
)]
pub struct UnusedVarRemoveFieldSugg {
#[suggestion_part(code = "")]
pub spans: Vec<Span>,
}
#[derive(LintDiagnostic)]
#[diag(passes_unused_var_assigned_only)]
#[note]
pub struct UnusedVarAssignedOnly {
pub name: String,
}
#[derive(LintDiagnostic)]
#[diag(passes_unnecessary_stable_feature)]
pub struct UnnecessaryStableFeature {
pub feature: Symbol,
pub since: Symbol,
}
#[derive(LintDiagnostic)]
#[diag(passes_unnecessary_partial_stable_feature)]
pub struct UnnecessaryPartialStableFeature {
#[suggestion(code = "{implies}", applicability = "maybe-incorrect")]
pub span: Span,
#[suggestion(passes_suggestion_remove, code = "", applicability = "maybe-incorrect")]
pub line: Span,
pub feature: Symbol,
pub since: Symbol,
pub implies: Symbol,
}
#[derive(LintDiagnostic)]
#[diag(passes_ineffective_unstable_impl)]
#[note]
pub struct IneffectiveUnstableImpl;
#[derive(LintDiagnostic)]
#[diag(passes_unused_assign)]
#[help]
pub struct UnusedAssign {
pub name: String,
}
#[derive(LintDiagnostic)]
#[diag(passes_unused_assign_passed)]
#[help]
pub struct UnusedAssignPassed {
pub name: String,
}
#[derive(LintDiagnostic)]
#[diag(passes_unused_variable_try_prefix)]
pub struct UnusedVariableTryPrefix {
#[label]
pub label: Option<Span>,
#[subdiagnostic]
pub string_interp: Vec<UnusedVariableStringInterp>,
#[subdiagnostic]
pub sugg: UnusedVariableTryPrefixSugg,
}
#[derive(Subdiagnostic)]
#[multipart_suggestion(passes_suggestion, applicability = "machine-applicable")]
pub struct UnusedVariableTryPrefixSugg {
#[suggestion_part(code = "_{name}")]
pub spans: Vec<Span>,
pub name: String,
}
pub struct UnusedVariableStringInterp {
pub lit: Span,
pub lo: Span,
pub hi: Span,
}
impl AddToDiagnostic for UnusedVariableStringInterp {
fn add_to_diagnostic_with<F>(self, diag: &mut Diagnostic, _: F) {
diag.span_label(self.lit, crate::fluent_generated::passes_maybe_string_interpolation);
diag.multipart_suggestion(
crate::fluent_generated::passes_string_interpolation_only_works,
vec![(self.lo, String::from("format!(")), (self.hi, String::from(")"))],
Applicability::MachineApplicable,
);
}
}
#[derive(LintDiagnostic)]
#[diag(passes_unused_variable_try_ignore)]
pub struct UnusedVarTryIgnore {
#[subdiagnostic]
pub sugg: UnusedVarTryIgnoreSugg,
}
#[derive(Subdiagnostic)]
#[multipart_suggestion(passes_suggestion, applicability = "machine-applicable")]
pub struct UnusedVarTryIgnoreSugg {
#[suggestion_part(code = "{name}: _")]
pub shorthands: Vec<Span>,
#[suggestion_part(code = "_")]
pub non_shorthands: Vec<Span>,
pub name: String,
}
#[derive(LintDiagnostic)]
#[diag(passes_attr_crate_level)]
#[note]
pub struct AttrCrateLevelOnly {
#[subdiagnostic]
pub sugg: Option<AttrCrateLevelOnlySugg>,
}
#[derive(Subdiagnostic)]
#[suggestion(passes_suggestion, applicability = "maybe-incorrect", code = "!", style = "verbose")]
pub struct AttrCrateLevelOnlySugg {
#[primary_span]
pub attr: Span,
}

View file

@ -12,6 +12,8 @@
#![feature(min_specialization)] #![feature(min_specialization)]
#![feature(try_blocks)] #![feature(try_blocks)]
#![recursion_limit = "256"] #![recursion_limit = "256"]
#![deny(rustc::untranslatable_diagnostic)]
#![deny(rustc::diagnostic_outside_of_impl)]
#[macro_use] #[macro_use]
extern crate rustc_middle; extern crate rustc_middle;

View file

@ -81,13 +81,13 @@
//! We generate various special nodes for various, well, special purposes. //! We generate various special nodes for various, well, special purposes.
//! These are described in the `Liveness` struct. //! These are described in the `Liveness` struct.
use crate::errors;
use self::LiveNodeKind::*; use self::LiveNodeKind::*;
use self::VarKind::*; use self::VarKind::*;
use rustc_ast::InlineAsmOptions; use rustc_ast::InlineAsmOptions;
use rustc_data_structures::fx::FxIndexMap; use rustc_data_structures::fx::FxIndexMap;
use rustc_errors::Applicability;
use rustc_errors::Diagnostic;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def::*; use rustc_hir::def::*;
use rustc_hir::def_id::LocalDefId; use rustc_hir::def_id::LocalDefId;
@ -1297,13 +1297,13 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
self.exit_ln self.exit_ln
} }
fn warn_about_unreachable( fn warn_about_unreachable<'desc>(
&mut self, &mut self,
orig_span: Span, orig_span: Span,
orig_ty: Ty<'tcx>, orig_ty: Ty<'tcx>,
expr_span: Span, expr_span: Span,
expr_id: HirId, expr_id: HirId,
descr: &str, descr: &'desc str,
) { ) {
if !orig_ty.is_never() { if !orig_ty.is_never() {
// Unreachable code warnings are already emitted during type checking. // Unreachable code warnings are already emitted during type checking.
@ -1316,22 +1316,15 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
// that we do not emit the same warning twice if the uninhabited type // that we do not emit the same warning twice if the uninhabited type
// is indeed `!`. // is indeed `!`.
let msg = format!("unreachable {}", descr); self.ir.tcx.emit_spanned_lint(
self.ir.tcx.struct_span_lint_hir(
lint::builtin::UNREACHABLE_CODE, lint::builtin::UNREACHABLE_CODE,
expr_id, expr_id,
expr_span, expr_span,
&msg, errors::UnreachableDueToUninhabited {
|diag| { expr: expr_span,
diag.span_label(expr_span, &msg) orig: orig_span,
.span_label(orig_span, "any code following this expression is unreachable") descr,
.span_note( ty: orig_ty,
orig_span,
&format!(
"this expression has type `{}`, which is uninhabited",
orig_ty
),
)
}, },
); );
} }
@ -1483,23 +1476,21 @@ impl<'tcx> Liveness<'_, 'tcx> {
if self.used_on_entry(entry_ln, var) { if self.used_on_entry(entry_ln, var) {
if !self.live_on_entry(entry_ln, var) { if !self.live_on_entry(entry_ln, var) {
if let Some(name) = self.should_warn(var) { if let Some(name) = self.should_warn(var) {
self.ir.tcx.struct_span_lint_hir( self.ir.tcx.emit_spanned_lint(
lint::builtin::UNUSED_ASSIGNMENTS, lint::builtin::UNUSED_ASSIGNMENTS,
var_hir_id, var_hir_id,
vec![span], vec![span],
format!("value captured by `{}` is never read", name), errors::UnusedCaptureMaybeCaptureRef { name },
|lint| lint.help("did you mean to capture by reference instead?"),
); );
} }
} }
} else { } else {
if let Some(name) = self.should_warn(var) { if let Some(name) = self.should_warn(var) {
self.ir.tcx.struct_span_lint_hir( self.ir.tcx.emit_spanned_lint(
lint::builtin::UNUSED_VARIABLES, lint::builtin::UNUSED_VARIABLES,
var_hir_id, var_hir_id,
vec![span], vec![span],
format!("unused variable: `{}`", name), errors::UnusedVarMaybeCaptureRef { name },
|lint| lint.help("did you mean to capture by reference instead?"),
); );
} }
} }
@ -1514,11 +1505,14 @@ impl<'tcx> Liveness<'_, 'tcx> {
Some(entry_ln), Some(entry_ln),
Some(body), Some(body),
|spans, hir_id, ln, var| { |spans, hir_id, ln, var| {
if !self.live_on_entry(ln, var) { if !self.live_on_entry(ln, var)
self.report_unused_assign(hir_id, spans, var, |name| { && let Some(name) = self.should_warn(var) {
format!("value passed to `{}` is never read", name) self.ir.tcx.emit_spanned_lint(
}); lint::builtin::UNUSED_ASSIGNMENTS,
} hir_id,
spans,
errors::UnusedAssignPassed { name },
); }
}, },
); );
} }
@ -1587,26 +1581,17 @@ impl<'tcx> Liveness<'_, 'tcx> {
if ln == self.exit_ln { false } else { self.assigned_on_exit(ln, var) }; if ln == self.exit_ln { false } else { self.assigned_on_exit(ln, var) };
if is_assigned { if is_assigned {
self.ir.tcx.struct_span_lint_hir( self.ir.tcx.emit_spanned_lint(
lint::builtin::UNUSED_VARIABLES, lint::builtin::UNUSED_VARIABLES,
first_hir_id, first_hir_id,
hir_ids_and_spans hir_ids_and_spans
.into_iter() .into_iter()
.map(|(_, _, ident_span)| ident_span) .map(|(_, _, ident_span)| ident_span)
.collect::<Vec<_>>(), .collect::<Vec<_>>(),
format!("variable `{}` is assigned to, but never used", name), errors::UnusedVarAssignedOnly { name },
|lint| lint.note(&format!("consider using `_{}` instead", name)),
) )
} else if can_remove { } else if can_remove {
self.ir.tcx.struct_span_lint_hir( let spans = hir_ids_and_spans
lint::builtin::UNUSED_VARIABLES,
first_hir_id,
hir_ids_and_spans.iter().map(|(_, pat_span, _)| *pat_span).collect::<Vec<_>>(),
format!("unused variable: `{}`", name),
|lint| {
lint.multipart_suggestion(
"try removing the field",
hir_ids_and_spans
.iter() .iter()
.map(|(_, pat_span, _)| { .map(|(_, pat_span, _)| {
let span = self let span = self
@ -1615,11 +1600,16 @@ impl<'tcx> Liveness<'_, 'tcx> {
.sess .sess
.source_map() .source_map()
.span_extend_to_next_char(*pat_span, ',', true); .span_extend_to_next_char(*pat_span, ',', true);
(span.with_hi(BytePos(span.hi().0 + 1)), String::new()) span.with_hi(BytePos(span.hi().0 + 1))
}) })
.collect(), .collect();
Applicability::MachineApplicable, self.ir.tcx.emit_spanned_lint(
) lint::builtin::UNUSED_VARIABLES,
first_hir_id,
hir_ids_and_spans.iter().map(|(_, pat_span, _)| *pat_span).collect::<Vec<_>>(),
errors::UnusedVarRemoveField {
name,
sugg: errors::UnusedVarRemoveFieldSugg { spans },
}, },
); );
} else { } else {
@ -1633,55 +1623,46 @@ impl<'tcx> Liveness<'_, 'tcx> {
// the field" message, and suggest `_` for the non-shorthands. If we only // the field" message, and suggest `_` for the non-shorthands. If we only
// have non-shorthand, then prefix with an underscore instead. // have non-shorthand, then prefix with an underscore instead.
if !shorthands.is_empty() { if !shorthands.is_empty() {
let shorthands = shorthands let shorthands =
.into_iter() shorthands.into_iter().map(|(_, pat_span, _)| pat_span).collect();
.map(|(_, pat_span, _)| (pat_span, format!("{}: _", name))) let non_shorthands =
.chain( non_shorthands.into_iter().map(|(_, pat_span, _)| pat_span).collect();
non_shorthands
.into_iter()
.map(|(_, pat_span, _)| (pat_span, "_".to_string())),
)
.collect::<Vec<_>>();
self.ir.tcx.struct_span_lint_hir( self.ir.tcx.emit_spanned_lint(
lint::builtin::UNUSED_VARIABLES, lint::builtin::UNUSED_VARIABLES,
first_hir_id, first_hir_id,
hir_ids_and_spans hir_ids_and_spans
.iter() .iter()
.map(|(_, pat_span, _)| *pat_span) .map(|(_, pat_span, _)| *pat_span)
.collect::<Vec<_>>(), .collect::<Vec<_>>(),
format!("unused variable: `{}`", name), errors::UnusedVarTryIgnore {
|lint| { sugg: errors::UnusedVarTryIgnoreSugg {
lint.multipart_suggestion(
"try ignoring the field",
shorthands, shorthands,
Applicability::MachineApplicable, non_shorthands,
) name,
},
}, },
); );
} else { } else {
let non_shorthands = non_shorthands let non_shorthands = non_shorthands
.into_iter() .into_iter()
.map(|(_, _, ident_span)| (ident_span, format!("_{}", name))) .map(|(_, _, ident_span)| ident_span)
.collect::<Vec<_>>(); .collect::<Vec<_>>();
let suggestions = self.string_interp_suggestions(&name, opt_body);
self.ir.tcx.struct_span_lint_hir( self.ir.tcx.emit_spanned_lint(
lint::builtin::UNUSED_VARIABLES, lint::builtin::UNUSED_VARIABLES,
first_hir_id, first_hir_id,
hir_ids_and_spans hir_ids_and_spans
.iter() .iter()
.map(|(_, _, ident_span)| *ident_span) .map(|(_, _, ident_span)| *ident_span)
.collect::<Vec<_>>(), .collect::<Vec<_>>(),
format!("unused variable: `{}`", name), errors::UnusedVariableTryPrefix {
|lint| { label: if !suggestions.is_empty() { Some(pat.span) } else { None },
if self.has_added_lit_match_name_span(&name, opt_body, lint) { sugg: errors::UnusedVariableTryPrefixSugg {
lint.span_label(pat.span, "unused variable"); spans: non_shorthands,
} name,
lint.multipart_suggestion( },
"if this is intentional, prefix it with an underscore", string_interp: suggestions,
non_shorthands,
Applicability::MachineApplicable,
)
}, },
); );
} }
@ -1689,65 +1670,40 @@ impl<'tcx> Liveness<'_, 'tcx> {
} }
} }
fn has_added_lit_match_name_span( fn string_interp_suggestions(
&self, &self,
name: &str, name: &str,
opt_body: Option<&hir::Body<'_>>, opt_body: Option<&hir::Body<'_>>,
err: &mut Diagnostic, ) -> Vec<errors::UnusedVariableStringInterp> {
) -> bool { let mut suggs = Vec::new();
let mut has_litstring = false; let Some(opt_body) = opt_body else { return suggs; };
let Some(opt_body) = opt_body else {return false;};
let mut visitor = CollectLitsVisitor { lit_exprs: vec![] }; let mut visitor = CollectLitsVisitor { lit_exprs: vec![] };
intravisit::walk_body(&mut visitor, opt_body); intravisit::walk_body(&mut visitor, opt_body);
for lit_expr in visitor.lit_exprs { for lit_expr in visitor.lit_exprs {
let hir::ExprKind::Lit(litx) = &lit_expr.kind else { continue }; let hir::ExprKind::Lit(litx) = &lit_expr.kind else { continue };
let rustc_ast::LitKind::Str(syb, _) = litx.node else{ continue; }; let rustc_ast::LitKind::Str(syb, _) = litx.node else{ continue; };
let name_str: &str = syb.as_str(); let name_str: &str = syb.as_str();
let mut name_pa = String::from("{"); let name_pa = format!("{{{name}}}");
name_pa.push_str(&name);
name_pa.push('}');
if name_str.contains(&name_pa) { if name_str.contains(&name_pa) {
err.span_label( suggs.push(errors::UnusedVariableStringInterp {
lit_expr.span, lit: lit_expr.span,
"you might have meant to use string interpolation in this string literal", lo: lit_expr.span.shrink_to_lo(),
); hi: lit_expr.span.shrink_to_hi(),
err.multipart_suggestion(
"string interpolation only works in `format!` invocations",
vec![
(lit_expr.span.shrink_to_lo(), "format!(".to_string()),
(lit_expr.span.shrink_to_hi(), ")".to_string()),
],
Applicability::MachineApplicable,
);
has_litstring = true;
}
}
has_litstring
}
fn warn_about_dead_assign(&self, spans: Vec<Span>, hir_id: HirId, ln: LiveNode, var: Variable) {
if !self.live_on_exit(ln, var) {
self.report_unused_assign(hir_id, spans, var, |name| {
format!("value assigned to `{}` is never read", name)
}); });
} }
} }
suggs
}
fn report_unused_assign( fn warn_about_dead_assign(&self, spans: Vec<Span>, hir_id: HirId, ln: LiveNode, var: Variable) {
&self, if !self.live_on_exit(ln, var)
hir_id: HirId, && let Some(name) = self.should_warn(var) {
spans: Vec<Span>, self.ir.tcx.emit_spanned_lint(
var: Variable,
message: impl Fn(&str) -> String,
) {
if let Some(name) = self.should_warn(var) {
self.ir.tcx.struct_span_lint_hir(
lint::builtin::UNUSED_ASSIGNMENTS, lint::builtin::UNUSED_ASSIGNMENTS,
hir_id, hir_id,
spans, spans,
message(&name), errors::UnusedAssign { name },
|lint| lint.help("maybe it is overwritten before being read?"), );
)
} }
} }
} }

View file

@ -7,7 +7,6 @@ use rustc_attr::{
UnstableReason, VERSION_PLACEHOLDER, UnstableReason, VERSION_PLACEHOLDER,
}; };
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap}; use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
use rustc_errors::Applicability;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res}; use rustc_hir::def::{DefKind, Res};
use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID}; use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID};
@ -759,12 +758,11 @@ impl<'tcx> Visitor<'tcx> for Checker<'tcx> {
// do not lint when the trait isn't resolved, since resolution error should // do not lint when the trait isn't resolved, since resolution error should
// be fixed first // be fixed first
if t.path.res != Res::Err && c.fully_stable { if t.path.res != Res::Err && c.fully_stable {
self.tcx.struct_span_lint_hir( self.tcx.emit_spanned_lint(
INEFFECTIVE_UNSTABLE_TRAIT_IMPL, INEFFECTIVE_UNSTABLE_TRAIT_IMPL,
item.hir_id(), item.hir_id(),
span, span,
"an `#[unstable]` annotation here has no effect", errors::IneffectiveUnstableImpl,
|lint| lint.note("see issue #55436 <https://github.com/rust-lang/rust/issues/55436> for more information")
); );
} }
} }
@ -1095,29 +1093,16 @@ fn unnecessary_partially_stable_feature_lint(
implies: Symbol, implies: Symbol,
since: Symbol, since: Symbol,
) { ) {
tcx.struct_span_lint_hir( tcx.emit_spanned_lint(
lint::builtin::STABLE_FEATURES, lint::builtin::STABLE_FEATURES,
hir::CRATE_HIR_ID, hir::CRATE_HIR_ID,
span, span,
format!( errors::UnnecessaryPartialStableFeature {
"the feature `{feature}` has been partially stabilized since {since} and is succeeded \
by the feature `{implies}`"
),
|lint| {
lint.span_suggestion(
span, span,
&format!( line: tcx.sess.source_map().span_extend_to_line(span),
"if you are using features which are still unstable, change to using `{implies}`" feature,
), since,
implies, implies,
Applicability::MaybeIncorrect,
)
.span_suggestion(
tcx.sess.source_map().span_extend_to_line(span),
"if you are using features which are now stable, remove this line",
"",
Applicability::MaybeIncorrect,
)
}, },
); );
} }
@ -1131,7 +1116,10 @@ fn unnecessary_stable_feature_lint(
if since.as_str() == VERSION_PLACEHOLDER { if since.as_str() == VERSION_PLACEHOLDER {
since = rust_version_symbol(); since = rust_version_symbol();
} }
tcx.struct_span_lint_hir(lint::builtin::STABLE_FEATURES, hir::CRATE_HIR_ID, span, format!("the feature `{feature}` has been stable since {since} and no longer requires an attribute to enable"), |lint| { tcx.emit_spanned_lint(
lint lint::builtin::STABLE_FEATURES,
}); hir::CRATE_HIR_ID,
span,
errors::UnnecessaryStableFeature { feature, since },
);
} }

View file

@ -16,7 +16,7 @@ LL | #![deny(warnings)]
help: to apply to the crate, use an inner attribute help: to apply to the crate, use an inner attribute
| |
LL | #![doc(cfg_hide(doc))] LL | #![doc(cfg_hide(doc))]
| ~~~~~~~~~~~~~~~~~~~~~~ | +
error: `#[doc(cfg_hide(...)]` takes a list of attributes error: `#[doc(cfg_hide(...)]` takes a list of attributes
--> $DIR/doc_cfg_hide.rs:4:8 --> $DIR/doc_cfg_hide.rs:4:8

View file

@ -5,7 +5,7 @@
//~^ ERROR can only be applied at the crate level //~^ ERROR can only be applied at the crate level
//~| WARN is being phased out //~| WARN is being phased out
//~| HELP to apply to the crate, use an inner attribute //~| HELP to apply to the crate, use an inner attribute
//~| SUGGESTION #![doc(test(no_crate_inject))] //~| SUGGESTION !
#[doc(inline)] #[doc(inline)]
//~^ ERROR can only be applied to a `use` item //~^ ERROR can only be applied to a `use` item
//~| WARN is being phased out //~| WARN is being phased out

View file

@ -16,7 +16,7 @@ LL | #![deny(warnings)]
help: to apply to the crate, use an inner attribute help: to apply to the crate, use an inner attribute
| |
LL | #![doc(test(no_crate_inject))] LL | #![doc(test(no_crate_inject))]
| | +
error: this attribute can only be applied to a `use` item error: this attribute can only be applied to a `use` item
--> $DIR/invalid-doc-attr.rs:9:7 --> $DIR/invalid-doc-attr.rs:9:7

View file

@ -5,7 +5,7 @@
//~^ ERROR can only be applied at the crate level //~^ ERROR can only be applied at the crate level
//~| WARN is being phased out //~| WARN is being phased out
//~| HELP to apply to the crate, use an inner attribute //~| HELP to apply to the crate, use an inner attribute
//~| SUGGESTION #![doc(test(no_crate_inject))] //~| SUGGESTION !
#[doc(inline)] #[doc(inline)]
//~^ ERROR can only be applied to a `use` item //~^ ERROR can only be applied to a `use` item
//~| WARN is being phased out //~| WARN is being phased out

View file

@ -16,7 +16,7 @@ LL | #![deny(warnings)]
help: to apply to the crate, use an inner attribute help: to apply to the crate, use an inner attribute
| |
LL | #![doc(test(no_crate_inject))] LL | #![doc(test(no_crate_inject))]
| | +
error: this attribute can only be applied to a `use` item error: this attribute can only be applied to a `use` item
--> $DIR/invalid-doc-attr.rs:9:7 --> $DIR/invalid-doc-attr.rs:9:7