Skip to content

Commit 95d3e0c

Browse files
committed
migrate: methods.rs
1 parent 3f69c1b commit 95d3e0c

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

compiler/rustc_lint/src/lints.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ use rustc_span::{symbol::Ident, Span, Symbol};
66

77
use crate::LateContext;
88

9+
#[derive(LintDiagnostic)]
10+
#[diag(lint_cstring_ptr)]
11+
#[note]
12+
#[help]
13+
pub struct CStringPtr {
14+
#[label(as_ptr_label)]
15+
pub as_ptr: Span,
16+
#[label(unwrap_label)]
17+
pub unwrap: Span,
18+
}
919
#[derive(LintDiagnostic)]
1020
#[diag(lint_identifier_non_ascii_char)]
1121
pub struct IdentifierNonAsciiChar;

compiler/rustc_lint/src/methods.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
#![deny(rustc::untranslatable_diagnostic)]
2+
#![deny(rustc::diagnostic_outside_of_impl)]
3+
use crate::lints::CStringPtr;
14
use crate::LateContext;
25
use crate::LateLintPass;
36
use crate::LintContext;
4-
use rustc_errors::fluent;
57
use rustc_hir::{Expr, ExprKind, PathSegment};
68
use rustc_middle::ty;
79
use rustc_span::{symbol::sym, ExpnKind, Span};
@@ -90,16 +92,10 @@ fn lint_cstring_as_ptr(
9092
if cx.tcx.is_diagnostic_item(sym::Result, def.did()) {
9193
if let ty::Adt(adt, _) = substs.type_at(0).kind() {
9294
if cx.tcx.is_diagnostic_item(sym::cstring_type, adt.did()) {
93-
cx.struct_span_lint(
95+
cx.emit_spanned_lint(
9496
TEMPORARY_CSTRING_AS_PTR,
9597
as_ptr_span,
96-
fluent::lint_cstring_ptr,
97-
|diag| {
98-
diag.span_label(as_ptr_span, fluent::as_ptr_label)
99-
.span_label(unwrap.span, fluent::unwrap_label)
100-
.note(fluent::note)
101-
.help(fluent::help)
102-
},
98+
CStringPtr { as_ptr: as_ptr_span, unwrap: unwrap.span },
10399
);
104100
}
105101
}

0 commit comments

Comments
 (0)