Skip to content

Commit 7ef610c

Browse files
committed
lint: port drop trait/glue diagnostics
Signed-off-by: David Wood <david.wood@huawei.com>
1 parent 8e83656 commit 7ef610c

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

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

+6
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,9 @@ lint-redundant-semicolons =
141141
[true] these semicolons
142142
*[false] this semicolon
143143
}
144+
145+
lint-drop-trait-constraints =
146+
bounds on `{$predicate}` are most likely incorrect, consider instead using `{$needs_drop}` to detect whether a type can be trivially dropped
147+
148+
lint-drop-glue =
149+
types that do not implement `Drop` can still have drop glue, consider instead using `{$needs_drop}` to detect whether a type is trivially dropped

compiler/rustc_lint/src/traits.rs

+8-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::LateContext;
22
use crate::LateLintPass;
33
use crate::LintContext;
4+
use rustc_errors::fluent;
45
use rustc_hir as hir;
56
use rustc_span::symbol::sym;
67

@@ -103,13 +104,10 @@ impl<'tcx> LateLintPass<'tcx> for DropTraitConstraints {
103104
let Some(needs_drop) = cx.tcx.get_diagnostic_item(sym::needs_drop) else {
104105
return
105106
};
106-
let msg = format!(
107-
"bounds on `{}` are most likely incorrect, consider instead \
108-
using `{}` to detect whether a type can be trivially dropped",
109-
predicate,
110-
cx.tcx.def_path_str(needs_drop)
111-
);
112-
lint.build(&msg).emit();
107+
lint.build(fluent::lint::drop_trait_constraints)
108+
.set_arg("predicate", predicate)
109+
.set_arg("needs_drop", cx.tcx.def_path_str(needs_drop))
110+
.emit();
113111
});
114112
}
115113
}
@@ -126,12 +124,9 @@ impl<'tcx> LateLintPass<'tcx> for DropTraitConstraints {
126124
let Some(needs_drop) = cx.tcx.get_diagnostic_item(sym::needs_drop) else {
127125
return
128126
};
129-
let msg = format!(
130-
"types that do not implement `Drop` can still have drop glue, consider \
131-
instead using `{}` to detect whether a type is trivially dropped",
132-
cx.tcx.def_path_str(needs_drop)
133-
);
134-
lint.build(&msg).emit();
127+
lint.build(fluent::lint::drop_glue)
128+
.set_arg("needs_drop", cx.tcx.def_path_str(needs_drop))
129+
.emit();
135130
});
136131
}
137132
}

compiler/rustc_middle/src/ty/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,12 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for Predicate<'tcx> {
611611
}
612612
}
613613

614+
impl rustc_errors::IntoDiagnosticArg for Predicate<'_> {
615+
fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue<'static> {
616+
rustc_errors::DiagnosticArgValue::Str(std::borrow::Cow::Owned(self.to_string()))
617+
}
618+
}
619+
614620
#[derive(Clone, Copy, PartialEq, Eq, Hash, TyEncodable, TyDecodable)]
615621
#[derive(HashStable, TypeFoldable)]
616622
pub enum PredicateKind<'tcx> {

0 commit comments

Comments
 (0)