|
| 1 | +use serde::{self, Deserialize}; |
| 2 | +use std::collections::HashSet; |
| 3 | +use std::process::Command; |
| 4 | +const TRANSLATABLE_LIMIT: usize = 902; |
| 5 | + |
| 6 | +#[derive(Deserialize)] |
| 7 | +struct CompilerMessage { |
| 8 | + message: CompilerMessageMessage, |
| 9 | +} |
| 10 | + |
| 11 | +#[derive(Deserialize)] |
| 12 | +struct CompilerMessageMessage { |
| 13 | + spans: Vec<Span>, |
| 14 | +} |
| 15 | + |
| 16 | +#[derive(Deserialize)] |
| 17 | +struct Span { |
| 18 | + expansion: Option<Box<Expansion>>, |
| 19 | + file_name: String, |
| 20 | + line_start: usize, |
| 21 | +} |
| 22 | + |
| 23 | +#[derive(Deserialize)] |
| 24 | +struct Expansion { |
| 25 | + span: Span, |
| 26 | +} |
| 27 | + |
| 28 | +fn main() { |
| 29 | + let Some(x_path) = std::env::args().skip(1).next() else { |
| 30 | + panic!("Usage: translatable-limits <x.py path>") |
| 31 | + }; |
| 32 | + let output = Command::new(x_path) |
| 33 | + .args(["check", "compiler", "--json-output", "--warnings", "warn"]) |
| 34 | + .env("RUSTFLAGS_BOOTSTRAP", "-Wrustc::untranslatable_diagnostic") |
| 35 | + .output() |
| 36 | + .expect("executing rustc") |
| 37 | + .stdout; |
| 38 | + let stdout = String::from_utf8(output).expect("non-utf8 output"); |
| 39 | + let messages = stdout |
| 40 | + .lines() |
| 41 | + .filter(|l| l.starts_with('{')) |
| 42 | + .filter_map(|msg| serde_json::from_str::<CompilerMessage>(&msg).ok()) |
| 43 | + .filter_map(|msg| { |
| 44 | + let mut sp = msg.message.spans.get(0)?; |
| 45 | + if let Some(exp) = &sp.expansion { |
| 46 | + sp = &exp.span |
| 47 | + } |
| 48 | + Some((sp.file_name.clone(), sp.line_start)) |
| 49 | + }) |
| 50 | + .collect::<HashSet<_>>(); |
| 51 | + |
| 52 | + assert!(messages.len() <= TRANSLATABLE_LIMIT, "Newly added diagnostics should be translatable"); |
| 53 | + if messages.len() < TRANSLATABLE_LIMIT { |
| 54 | + println!("Limit can be lowered to {}", messages.len()); |
| 55 | + } |
| 56 | +} |
0 commit comments