Skip to content

Commit 089f353

Browse files
authored
Merge branch 'main' into redsun82/cargo-upgrade-3
2 parents 5b4c566 + 9605eb0 commit 089f353

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

rust/extractor/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ impl<'a> Extractor<'a> {
103103
}
104104
}
105105
translator.emit_source_file(&ast);
106+
translator.emit_truncated_diagnostics_message();
106107
translator.trap.commit().unwrap_or_else(|err| {
107108
error!(
108109
"Failed to write trap file for: {}: {}",

rust/extractor/src/translate/base.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,14 @@ pub struct Translator<'a> {
127127
resolve_paths: bool,
128128
source_kind: SourceKind,
129129
pub(crate) macro_context_depth: usize,
130+
diagnostic_count: usize,
130131
}
131132

132133
const UNKNOWN_LOCATION: (LineCol, LineCol) =
133134
(LineCol { line: 0, col: 0 }, LineCol { line: 0, col: 0 });
134135

136+
const DIAGNOSTIC_LIMIT_PER_FILE: usize = 100;
137+
135138
impl<'a> Translator<'a> {
136139
pub fn new(
137140
trap: TrapFile,
@@ -152,6 +155,7 @@ impl<'a> Translator<'a> {
152155
resolve_paths: resolve_paths == ResolvePaths::Yes,
153156
source_kind,
154157
macro_context_depth: 0,
158+
diagnostic_count: 0,
155159
}
156160
}
157161
fn location(&self, range: TextRange) -> Option<(LineCol, LineCol)> {
@@ -238,6 +242,36 @@ impl<'a> Translator<'a> {
238242
} else {
239243
severity
240244
};
245+
if severity > DiagnosticSeverity::Debug {
246+
self.diagnostic_count += 1;
247+
if self.diagnostic_count > DIAGNOSTIC_LIMIT_PER_FILE {
248+
return;
249+
}
250+
}
251+
self.emit_diagnostic_unchecked(severity, tag, message, full_message, location);
252+
}
253+
pub fn emit_truncated_diagnostics_message(&mut self) {
254+
if self.diagnostic_count > DIAGNOSTIC_LIMIT_PER_FILE {
255+
let count = self.diagnostic_count - DIAGNOSTIC_LIMIT_PER_FILE;
256+
self.emit_diagnostic_unchecked(
257+
DiagnosticSeverity::Warning,
258+
"diagnostics".to_owned(),
259+
"Too many diagnostic messages".to_owned(),
260+
format!(
261+
"Too many diagnostic messages, {count} diagnostic messages were suppressed"
262+
),
263+
UNKNOWN_LOCATION,
264+
);
265+
}
266+
}
267+
fn emit_diagnostic_unchecked(
268+
&mut self,
269+
severity: DiagnosticSeverity,
270+
tag: String,
271+
message: String,
272+
full_message: String,
273+
location: (LineCol, LineCol),
274+
) {
241275
let (start, end) = location;
242276
dispatch_to_tracing!(
243277
severity,

0 commit comments

Comments
 (0)