Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit d44ccaa

Browse files
committed
migrate: types.rs
1 parent 5a90537 commit d44ccaa

File tree

2 files changed

+248
-154
lines changed

2 files changed

+248
-154
lines changed

compiler/rustc_lint/src/lints.rs

Lines changed: 139 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,142 @@
1-
use rustc_macros::LintDiagnostic;
2-
use rustc_span::{Symbol, Span};
1+
use rustc_errors::{fluent, AddSubdiagnostic, DecorateLint, EmissionGuarantee};
2+
use rustc_macros::{LintDiagnostic, SessionSubdiagnostic};
3+
use rustc_span::{Span, Symbol};
4+
5+
#[derive(LintDiagnostic)]
6+
#[diag(lint_range_endpoint_out_of_range)]
7+
pub struct RangeEndpointOutOfRange<'a> {
8+
pub ty: &'a str,
9+
#[suggestion(code = "{start}..={literal}{suffix}", applicability = "machine-applicable")]
10+
pub suggestion: Span,
11+
pub start: String,
12+
pub literal: u128,
13+
pub suffix: &'a str,
14+
}
15+
16+
#[derive(LintDiagnostic)]
17+
#[diag(lint_overflowing_bin_hex)]
18+
pub struct OverflowingBinHex<'a> {
19+
pub ty: &'a str,
20+
pub lit: String,
21+
pub dec: u128,
22+
pub actually: String,
23+
#[subdiagnostic]
24+
pub sign: OverflowingBinHexSign,
25+
#[subdiagnostic]
26+
pub sub: Option<OverflowingBinHexSub<'a>>,
27+
}
28+
29+
pub enum OverflowingBinHexSign {
30+
Positive,
31+
Negative,
32+
}
33+
34+
impl AddSubdiagnostic for OverflowingBinHexSign {
35+
fn add_to_diagnostic(self, diag: &mut rustc_errors::Diagnostic) {
36+
match self {
37+
OverflowingBinHexSign::Positive => {
38+
diag.note(fluent::positive_note);
39+
}
40+
OverflowingBinHexSign::Negative => {
41+
diag.note(fluent::negative_note);
42+
diag.note(fluent::negative_becomes_note);
43+
}
44+
}
45+
}
46+
}
47+
48+
#[derive(SessionSubdiagnostic)]
49+
pub enum OverflowingBinHexSub<'a> {
50+
#[suggestion(
51+
suggestion,
52+
code = "{sans_suffix}{suggestion_ty}",
53+
applicability = "machine-applicable"
54+
)]
55+
Suggestion {
56+
#[primary_span]
57+
span: Span,
58+
suggestion_ty: &'a str,
59+
sans_suffix: &'a str,
60+
},
61+
#[help(help)]
62+
Help { suggestion_ty: &'a str },
63+
}
64+
65+
pub struct OverflowingInt<'a> {
66+
pub ty: &'a str,
67+
pub lit: String,
68+
pub min: i128,
69+
pub max: u128,
70+
pub suggestion_ty: Option<&'a str>,
71+
}
72+
73+
// FIXME: refactor with `Option<&'a str>` in macro
74+
impl<'a, G: EmissionGuarantee> DecorateLint<'_, G> for OverflowingInt<'a> {
75+
fn decorate_lint(self, diag: rustc_errors::LintDiagnosticBuilder<'_, G>) {
76+
let mut diag = diag.build(fluent::lint_overflowing_int);
77+
diag.set_arg("ty", self.ty);
78+
diag.set_arg("lit", self.lit);
79+
diag.set_arg("min", self.min);
80+
diag.set_arg("max", self.max);
81+
diag.note(fluent::note);
82+
if let Some(suggestion_ty) = self.suggestion_ty {
83+
diag.set_arg("suggestion_ty", suggestion_ty);
84+
diag.help(fluent::help);
85+
}
86+
diag.emit();
87+
}
88+
}
89+
90+
#[derive(LintDiagnostic)]
91+
#[diag(lint_only_cast_u8_to_char)]
92+
pub struct OnlyCastu8ToChar {
93+
#[suggestion(code = "'\\u{{{literal:X}}}'", applicability = "machine-applicable")]
94+
pub span: Span,
95+
pub literal: u128,
96+
}
97+
98+
#[derive(LintDiagnostic)]
99+
#[diag(lint_overflowing_uint)]
100+
#[note]
101+
pub struct OverflowingUInt<'a> {
102+
pub ty: &'a str,
103+
pub lit: String,
104+
pub min: u128,
105+
pub max: u128,
106+
}
107+
108+
#[derive(LintDiagnostic)]
109+
#[diag(lint_overflowing_literal)]
110+
#[note]
111+
pub struct OverflowingLiteral<'a> {
112+
pub ty: &'a str,
113+
pub lit: String,
114+
}
115+
116+
#[derive(LintDiagnostic)]
117+
#[diag(lint_unused_comparisons)]
118+
pub struct UnusedComparisons;
119+
120+
#[derive(LintDiagnostic)]
121+
#[diag(lint_variant_size_differences)]
122+
pub struct VariantSizeDifferencesDiag {
123+
pub largest: u64,
124+
}
125+
126+
#[derive(LintDiagnostic)]
127+
#[diag(lint_atomic_ordering_load)]
128+
#[help]
129+
pub struct AtomicOrderingLoad;
130+
131+
#[derive(LintDiagnostic)]
132+
#[diag(lint_atomic_ordering_store)]
133+
#[help]
134+
pub struct AtomicOrderingStore;
135+
136+
#[derive(LintDiagnostic)]
137+
#[diag(lint_atomic_ordering_fence)]
138+
#[help]
139+
pub struct AtomicOrderingFence;
3140

4141
#[derive(LintDiagnostic)]
5142
#[diag(lint_atomic_ordering_invalid)]

0 commit comments

Comments
 (0)