mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-29 18:23:49 +00:00
migrate: traits.rs
This commit is contained in:
parent
e5ae9d019c
commit
a42afa0444
@ -1,11 +1,39 @@
|
||||
use rustc_errors::{fluent, AddSubdiagnostic, Applicability, DecorateLint, EmissionGuarantee};
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_macros::{LintDiagnostic, SessionSubdiagnostic};
|
||||
use rustc_middle::ty::Ty;
|
||||
use rustc_middle::ty::{Predicate, Ty, TyCtxt};
|
||||
use rustc_span::{Span, Symbol};
|
||||
|
||||
use crate::LateContext;
|
||||
|
||||
pub struct DropTraitConstraintsDiag<'a> {
|
||||
pub predicate: Predicate<'a>,
|
||||
pub tcx: TyCtxt<'a>,
|
||||
pub def_id: DefId,
|
||||
}
|
||||
|
||||
impl<'a, G: EmissionGuarantee> DecorateLint<'_, G> for DropTraitConstraintsDiag<'a> {
|
||||
fn decorate_lint(self, diag: rustc_errors::LintDiagnosticBuilder<'_, G>) {
|
||||
let mut diag = diag.build(fluent::lint_drop_trait_constraints);
|
||||
diag.set_arg("predicate", self.predicate);
|
||||
diag.set_arg("needs_drop", self.tcx.def_path_str(self.def_id));
|
||||
diag.emit();
|
||||
}
|
||||
}
|
||||
|
||||
pub struct DropGlue<'a> {
|
||||
pub tcx: TyCtxt<'a>,
|
||||
pub def_id: DefId,
|
||||
}
|
||||
|
||||
impl<'a, G: EmissionGuarantee> DecorateLint<'_, G> for DropGlue<'a> {
|
||||
fn decorate_lint(self, diag: rustc_errors::LintDiagnosticBuilder<'_, G>) {
|
||||
let mut diag = diag.build(fluent::lint_drop_glue);
|
||||
diag.set_arg("needs_drop", self.tcx.def_path_str(self.def_id));
|
||||
diag.emit();
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(LintDiagnostic)]
|
||||
#[diag(lint_range_endpoint_out_of_range)]
|
||||
pub struct RangeEndpointOutOfRange<'a> {
|
||||
|
@ -1,7 +1,9 @@
|
||||
#![deny(rustc::untranslatable_diagnostic)]
|
||||
#![deny(rustc::diagnostic_outside_of_impl)]
|
||||
use crate::lints::{DropGlue, DropTraitConstraintsDiag};
|
||||
use crate::LateContext;
|
||||
use crate::LateLintPass;
|
||||
use crate::LintContext;
|
||||
use rustc_errors::fluent;
|
||||
use rustc_hir as hir;
|
||||
use rustc_span::symbol::sym;
|
||||
|
||||
@ -101,17 +103,13 @@ impl<'tcx> LateLintPass<'tcx> for DropTraitConstraints {
|
||||
if trait_predicate.trait_ref.self_ty().is_impl_trait() {
|
||||
continue;
|
||||
}
|
||||
let Some(needs_drop) = cx.tcx.get_diagnostic_item(sym::needs_drop) else {
|
||||
continue;
|
||||
let Some(def_id) = cx.tcx.get_diagnostic_item(sym::needs_drop) else {
|
||||
return
|
||||
};
|
||||
cx.struct_span_lint(
|
||||
cx.emit_spanned_lint(
|
||||
DROP_BOUNDS,
|
||||
span,
|
||||
fluent::lint_drop_trait_constraints,
|
||||
|lint| {
|
||||
lint.set_arg("predicate", predicate)
|
||||
.set_arg("needs_drop", cx.tcx.def_path_str(needs_drop))
|
||||
},
|
||||
DropTraitConstraintsDiag { predicate, tcx: cx.tcx, def_id },
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -123,12 +121,11 @@ impl<'tcx> LateLintPass<'tcx> for DropTraitConstraints {
|
||||
};
|
||||
for bound in &bounds[..] {
|
||||
let def_id = bound.trait_ref.trait_def_id();
|
||||
if cx.tcx.lang_items().drop_trait() == def_id
|
||||
&& let Some(needs_drop) = cx.tcx.get_diagnostic_item(sym::needs_drop)
|
||||
{
|
||||
cx.struct_span_lint(DYN_DROP, bound.span, fluent::lint_drop_glue, |lint| {
|
||||
lint.set_arg("needs_drop", cx.tcx.def_path_str(needs_drop))
|
||||
});
|
||||
if cx.tcx.lang_items().drop_trait() == def_id {
|
||||
let Some(def_id) = cx.tcx.get_diagnostic_item(sym::needs_drop) else {
|
||||
return
|
||||
};
|
||||
cx.emit_spanned_lint(DYN_DROP, bound.span, DropGlue { tcx: cx.tcx, def_id });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user