Skip to content

Commit 8dad1c6

Browse files
authored
Merge pull request #1099 from micahscopes/no-print
Don't print to stdio/stderr; use tracing
2 parents 416234a + 4c2adc9 commit 8dad1c6

File tree

22 files changed

+137
-439
lines changed

22 files changed

+137
-439
lines changed

Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ coverage:
7979

8080
.PHONY: clippy
8181
clippy:
82-
cargo clippy --workspace --all-targets --all-features -- -D warnings -A clippy::upper-case-acronyms -A clippy::large-enum-variant
82+
cargo clippy --workspace --all-targets --all-features -- -D warnings -A clippy::upper-case-acronyms -A clippy::large-enum-variant -W clippy::print_stdout -W clippy::print_stderr
8383

8484
.PHONY: rustfmt
8585
rustfmt:

crates/bench/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ parser.workspace = true
1414
common.workspace = true
1515
camino.workspace = true
1616
url.workspace = true
17+
tracing.workspace = true
1718

1819
[[bench]]
1920
name = "analysis"

crates/bench/src/main.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use tracing::error;
2+
13
fn main() {
2-
eprintln!("run `cargo bench`");
4+
error!("run `cargo bench`");
35
}

crates/driver/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ resolver.workspace = true
2121
url.workspace = true
2222
smol_str.workspace = true
2323
test-utils.workspace = true
24+
tracing.workspace = true

crates/driver/src/db.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ impl DiagnosticsCollection<'_> {
7171
term::emit(&mut buffer, &config, &CsDbWrapper(db), &diag.to_cs(db)).unwrap();
7272
}
7373

74-
eprintln!("{}", std::str::from_utf8(buffer.as_slice()).unwrap());
74+
writer
75+
.print(&buffer)
76+
.expect("Failed to write diagnostics to stderr");
7577
}
7678

7779
/// Format the accumulated diagnostics to a string.

crates/driver/src/lib.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ use resolver::{
1414
ingot::{source_files::SourceFiles, Ingot, IngotResolver},
1515
Resolver,
1616
};
17+
use tracing::error;
1718
use url::Url;
1819

1920
pub fn run(opts: &Options) {
2021
match &opts.command {
21-
Command::Build => eprintln!("`fe build` doesn't work at the moment"),
22+
Command::Build => error!("`fe build` doesn't work at the moment"),
2223
Command::Check { path, core } => {
2324
let mut db = DriverDataBase::default();
2425
let mut ingot_resolver = IngotResolver::default();
@@ -36,9 +37,9 @@ pub fn run(opts: &Options) {
3637
let core_base_url = Url::parse("core-ingot:///").unwrap();
3738
let diagnostics = ingot_resolver.take_diagnostics();
3839
if !diagnostics.is_empty() {
39-
eprintln!("an error was encountered while resolving `{core_path}`");
40+
error!("an error was encountered while resolving `{core_path}`");
4041
for diagnostic in diagnostics {
41-
eprintln!("{diagnostic}")
42+
error!("{diagnostic}")
4243
}
4344
std::process::exit(2)
4445
}
@@ -61,19 +62,19 @@ pub fn run(opts: &Options) {
6162
core_base_url
6263
}
6364
Ok(Ingot::SingleFile { .. }) => {
64-
eprintln!("standalone core ingot not supported");
65+
error!("standalone core ingot not supported");
6566
std::process::exit(2)
6667
}
6768
Ok(_) => {
68-
eprintln!("an error was encountered while resolving `{core_path}`");
69+
error!("an error was encountered while resolving `{core_path}`");
6970
for diagnostic in ingot_resolver.take_diagnostics() {
70-
eprintln!("{diagnostic}")
71+
error!("{diagnostic}")
7172
}
7273
std::process::exit(2)
7374
}
7475
Err(error) => {
75-
eprintln!("an error was encountered while resolving `{core_path}`");
76-
eprintln!("{error}");
76+
error!("an error was encountered while resolving `{core_path}`");
77+
error!("{error}");
7778
std::process::exit(2)
7879
}
7980
}
@@ -95,9 +96,9 @@ pub fn run(opts: &Options) {
9596

9697
let diagnostics = ingot_resolver.take_diagnostics();
9798
if !diagnostics.is_empty() {
98-
eprintln!("an error was encountered while resolving `{path}`");
99+
error!("an error was encountered while resolving `{path}`");
99100
for diagnostic in diagnostics {
100-
eprintln!("{diagnostic}")
101+
error!("{diagnostic}")
101102
}
102103
std::process::exit(2)
103104
}
@@ -124,12 +125,12 @@ pub fn run(opts: &Options) {
124125
}
125126
Ok(_) => {
126127
for diagnostic in ingot_resolver.take_diagnostics() {
127-
eprintln!("{diagnostic}")
128+
error!("{diagnostic}")
128129
}
129130
std::process::exit(2)
130131
}
131132
Err(error) => {
132-
eprintln!("{error}: {path}");
133+
error!("{error}: {path}");
133134
std::process::exit(2)
134135
}
135136
};
@@ -144,7 +145,7 @@ pub fn run(opts: &Options) {
144145
std::process::exit(1);
145146
}
146147
}
147-
Command::New => eprintln!("`fe new` doesn't work at the moment"),
148+
Command::New => error!("`fe new` doesn't work at the moment"),
148149
}
149150
}
150151

crates/fe/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ edition = "2021"
66
[dependencies]
77
clap.workspace = true
88
driver.workspace = true
9+
tracing.workspace = true
10+
tracing-subscriber.workspace = true

crates/fe/src/main.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,14 @@ use driver::Options;
33

44
fn main() {
55
let opts = Options::parse();
6+
7+
// Initialize tracing with ERROR as default level
8+
tracing_subscriber::fmt()
9+
.with_env_filter(
10+
tracing_subscriber::EnvFilter::try_from_default_env()
11+
.unwrap_or_else(|_| tracing_subscriber::EnvFilter::new("error")),
12+
)
13+
.init();
14+
615
driver::run(&opts);
716
}

crates/hir-analysis/tests/test_db.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use hir::{
3030
};
3131
use rustc_hash::FxHashMap;
3232
use test_utils::url_utils::UrlExt;
33+
use tracing::error;
3334
use url::Url;
3435

3536
type CodeSpanFileId = usize;
@@ -81,7 +82,7 @@ impl HirAnalysisTestDb {
8182
let cs_diag = &diag.to_cs(self);
8283
term::emit(&mut buffer, &config, &CsDbWrapper(self), cs_diag).unwrap();
8384
}
84-
eprintln!("{}", std::str::from_utf8(buffer.as_slice()).unwrap());
85+
error!("{}", std::str::from_utf8(buffer.as_slice()).unwrap());
8586

8687
panic!("this module contains errors");
8788
}

0 commit comments

Comments
 (0)