Skip to content

Commit 5d302d1

Browse files
committed
migrate: BuiltinEllipsisInclusiveRangePatterns
1 parent 7a6ae23 commit 5d302d1

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

compiler/rustc_lint/src/builtin.rs

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// #![deny(rustc::diagnostic_outside_of_impl)]
2+
// #![deny(rustc::untranslatable_diagnostic)]
3+
//
14
//! Lints in the Rust compiler.
25
//!
36
//! This contains lints which can feasibly be implemented as their own
@@ -21,6 +24,7 @@
2124
//! `late_lint_methods!` invocation in `lib.rs`.
2225
2326
use crate::{
27+
errors::BuiltinEllpisisInclusiveRangePatterns,
2428
types::{transparent_newtype_field, CItemKind},
2529
EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintContext,
2630
};
@@ -1760,18 +1764,11 @@ impl EarlyLintPass for EllipsisInclusiveRangePatterns {
17601764
None => format!("&(..={})", end),
17611765
};
17621766
if join.edition() >= Edition::Edition2021 {
1763-
let mut err = cx.sess().struct_span_err_with_code(
1764-
pat.span,
1765-
msg,
1766-
rustc_errors::error_code!(E0783),
1767-
);
1768-
err.span_suggestion(
1769-
pat.span,
1770-
suggestion,
1767+
cx.sess().emit_err(BuiltinEllpisisInclusiveRangePatterns {
1768+
span: pat.span,
1769+
suggestion: pat.span,
17711770
replace,
1772-
Applicability::MachineApplicable,
1773-
)
1774-
.emit();
1771+
});
17751772
} else {
17761773
cx.struct_span_lint(ELLIPSIS_INCLUSIVE_RANGE_PATTERNS, pat.span, |lint| {
17771774
lint.build(msg)
@@ -1787,18 +1784,11 @@ impl EarlyLintPass for EllipsisInclusiveRangePatterns {
17871784
} else {
17881785
let replace = "..=";
17891786
if join.edition() >= Edition::Edition2021 {
1790-
let mut err = cx.sess().struct_span_err_with_code(
1791-
pat.span,
1792-
msg,
1793-
rustc_errors::error_code!(E0783),
1794-
);
1795-
err.span_suggestion_short(
1796-
join,
1797-
suggestion,
1798-
replace,
1799-
Applicability::MachineApplicable,
1800-
)
1801-
.emit();
1787+
cx.sess().emit_err(BuiltinEllpisisInclusiveRangePatterns {
1788+
span: pat.span,
1789+
suggestion: join,
1790+
replace: replace.to_string(),
1791+
});
18021792
} else {
18031793
cx.struct_span_lint(ELLIPSIS_INCLUSIVE_RANGE_PATTERNS, join, |lint| {
18041794
lint.build(msg)

compiler/rustc_lint/src/errors.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,13 @@ pub struct UnknownTool {
7070
#[help]
7171
pub is_nightly_build: Option<()>,
7272
}
73+
74+
#[derive(SessionDiagnostic)]
75+
#[error(lint::builtin_ellipsis_inclusive_range_patterns, code = "E0783")]
76+
pub struct BuiltinEllpisisInclusiveRangePatterns {
77+
#[primary_span]
78+
pub span: Span,
79+
#[suggestion_short(code = "{replace}", applicability = "machine-applicable")]
80+
pub suggestion: Span,
81+
pub replace: String,
82+
}

0 commit comments

Comments
 (0)