Skip to content

Commit 0442d24

Browse files
committed
Rust: drop tracing:: qualifiers
1 parent c602e82 commit 0442d24

File tree

3 files changed

+25
-35
lines changed

3 files changed

+25
-35
lines changed

rust/extractor/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use std::{
1515
collections::HashMap,
1616
path::{Path, PathBuf},
1717
};
18-
use tracing::{info, warn};
18+
use tracing::{error, info, warn};
1919
use tracing_subscriber::layer::SubscriberExt;
2020
use tracing_subscriber::util::SubscriberInitExt;
2121

@@ -87,7 +87,7 @@ impl<'a> Extractor<'a> {
8787
}
8888
translator.emit_source_file(ast);
8989
translator.trap.commit().unwrap_or_else(|err| {
90-
tracing::error!(
90+
error!(
9191
"Failed to write trap file for: {}: {}",
9292
display_path,
9393
err.to_string()

rust/extractor/src/rust_analyzer.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use std::collections::{HashMap, HashSet};
2121
use std::fs;
2222
use std::path::{Path, PathBuf};
2323
use std::rc::Rc;
24-
use tracing::{debug, error, info, warn};
24+
use tracing::{debug, error, info, trace, warn};
2525
use triomphe::Arc;
2626

2727
pub enum RustAnalyzer<'a> {
@@ -51,7 +51,7 @@ impl<'a> RustAnalyzer<'a> {
5151
project: &ProjectManifest,
5252
config: &CargoConfig,
5353
) -> Option<(RootDatabase, Vfs)> {
54-
let progress = |t| (tracing::trace!("progress: {}", t));
54+
let progress = |t| (trace!("progress: {}", t));
5555
let load_config = LoadCargoConfig {
5656
load_out_dirs_from_check: true,
5757
with_proc_macro_server: ProcMacroServerChoice::Sysroot,
@@ -62,7 +62,7 @@ impl<'a> RustAnalyzer<'a> {
6262
match load_workspace_at(manifest.as_ref(), config, &load_config, &progress) {
6363
Ok((db, vfs, _macro_server)) => Some((db, vfs)),
6464
Err(err) => {
65-
tracing::error!("failed to load workspace for {}: {}", manifest, err);
65+
error!("failed to load workspace for {}: {}", manifest, err);
6666
None
6767
}
6868
}

rust/extractor/src/translate/base.rs

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,18 @@ macro_rules! emit_detached {
7171
($($_:tt)*) => {};
7272
}
7373

74+
// see https://github.com/tokio-rs/tracing/issues/2730
75+
macro_rules! dispatch_to_tracing {
76+
($lvl:ident, $($arg:tt)+) => {
77+
match $lvl {
78+
DiagnosticSeverity::Debug => ::tracing::debug!($($arg)+),
79+
DiagnosticSeverity::Info => ::tracing::info!($($arg)+),
80+
DiagnosticSeverity::Warning => ::tracing::warn!($($arg)+),
81+
DiagnosticSeverity::Error => ::tracing::error!($($arg)+),
82+
}
83+
};
84+
}
85+
7486
pub struct Translator<'a> {
7587
pub trap: TrapFile,
7688
path: &'a str,
@@ -169,36 +181,14 @@ impl<'a> Translator<'a> {
169181
location: (LineCol, LineCol),
170182
) {
171183
let (start, end) = location;
172-
match severity {
173-
DiagnosticSeverity::Debug => tracing::debug!(
174-
"{}:{}:{}: {}",
175-
self.path,
176-
start.line + 1,
177-
start.col + 1,
178-
&full_message
179-
),
180-
DiagnosticSeverity::Info => tracing::info!(
181-
"{}:{}:{}: {}",
182-
self.path,
183-
start.line + 1,
184-
start.col + 1,
185-
&full_message
186-
),
187-
DiagnosticSeverity::Warning => tracing::warn!(
188-
"{}:{}:{}: {}",
189-
self.path,
190-
start.line + 1,
191-
start.col + 1,
192-
&full_message
193-
),
194-
DiagnosticSeverity::Error => tracing::error!(
195-
"{}:{}:{}: {}",
196-
self.path,
197-
start.line + 1,
198-
start.col + 1,
199-
&full_message
200-
),
201-
};
184+
dispatch_to_tracing!(
185+
severity,
186+
"{}:{}:{}: {}",
187+
self.path,
188+
start.line + 1,
189+
start.col + 1,
190+
&full_message,
191+
);
202192

203193
if severity > DiagnosticSeverity::Debug {
204194
let location = self.trap.emit_location_label(self.label, start, end);

0 commit comments

Comments
 (0)