Skip to content

Commit 71de58d

Browse files
committed
Auto merge of #12799 - marchiore:warn_add_package_name, r=epage
feat: add package name and version to warning messages ### What does this PR try to resolve? Hi, this PR Fixes #8018, where i add the package name and version on warning messages. As this is my first contribution to the project, if anything is not in compliance in the PR let me know and I will be happy to correct it.
2 parents 90fb62f + 380719d commit 71de58d

File tree

6 files changed

+17
-14
lines changed

6 files changed

+17
-14
lines changed

src/cargo/core/compiler/job_queue/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -952,7 +952,10 @@ impl<'cfg> DrainState<'cfg> {
952952
}
953953

954954
for warning in output.warnings.iter() {
955-
bcx.config.shell().warn(warning)?;
955+
let warning_with_package =
956+
format!("{}@{}: {}", unit.pkg.name(), unit.pkg.version(), warning);
957+
958+
bcx.config.shell().warn(warning_with_package)?;
956959
}
957960

958961
if msg.is_some() {

tests/testsuite/build_script.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3778,8 +3778,8 @@ fn warnings_emitted() {
37783778
[COMPILING] foo v0.5.0 ([..])
37793779
[RUNNING] `rustc [..]`
37803780
[RUNNING] `[..]`
3781-
warning: foo
3782-
warning: bar
3781+
warning: foo@0.5.0: foo
3782+
warning: [email protected]: bar
37833783
[RUNNING] `rustc [..]`
37843784
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
37853785
",
@@ -3816,7 +3816,7 @@ fn warnings_emitted_when_build_script_panics() {
38163816
p.cargo("build")
38173817
.with_status(101)
38183818
.with_stdout("")
3819-
.with_stderr_contains("warning: foo\nwarning: bar")
3819+
.with_stderr_contains("warning: foo@0.5.0: foo\nwarning: [email protected]: bar")
38203820
.run();
38213821
}
38223822

@@ -3929,8 +3929,8 @@ fn warnings_printed_on_vv() {
39293929
[COMPILING] bar v0.1.0
39303930
[RUNNING] `[..] rustc [..]`
39313931
[RUNNING] `[..]`
3932-
warning: foo
3933-
warning: bar
3932+
warning: [email protected]: foo
3933+
warning: bar@0.1.0: bar
39343934
[RUNNING] `[..] rustc [..]`
39353935
[COMPILING] foo v0.5.0 ([..])
39363936
[RUNNING] `[..] rustc [..]`

tests/testsuite/build_script_env.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,12 @@ fn rustc_bootstrap() {
137137
// NOTE: uses RUSTC_BOOTSTRAP so it will be propagated to rustc
138138
// (this matters when tests are being run with a beta or stable cargo)
139139
.env("RUSTC_BOOTSTRAP", "1")
140-
.with_stderr_contains("warning: Cannot set `RUSTC_BOOTSTRAP=1` [..]")
140+
.with_stderr_contains("warning: [email protected]: Cannot set `RUSTC_BOOTSTRAP=1` [..]")
141141
.run();
142142
// RUSTC_BOOTSTRAP set to the name of the library should warn
143143
p.cargo("check")
144144
.env("RUSTC_BOOTSTRAP", "has_dashes")
145-
.with_stderr_contains("warning: Cannot set `RUSTC_BOOTSTRAP=1` [..]")
145+
.with_stderr_contains("warning: [email protected]: Cannot set `RUSTC_BOOTSTRAP=1` [..]")
146146
.run();
147147
// RUSTC_BOOTSTRAP set to some random value should error
148148
p.cargo("check")
@@ -169,7 +169,7 @@ fn rustc_bootstrap() {
169169
// NOTE: uses RUSTC_BOOTSTRAP so it will be propagated to rustc
170170
// (this matters when tests are being run with a beta or stable cargo)
171171
.env("RUSTC_BOOTSTRAP", "1")
172-
.with_stderr_contains("warning: Cannot set `RUSTC_BOOTSTRAP=1` [..]")
172+
.with_stderr_contains("warning: [email protected]: Cannot set `RUSTC_BOOTSTRAP=1` [..]")
173173
.run();
174174
// RUSTC_BOOTSTRAP conditionally set when there's no library should error (regardless of the value)
175175
p.cargo("check")

tests/testsuite/build_script_extra_link_arg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ fn cdylib_link_arg_transitive() {
204204
[COMPILING] bar v1.0.0 [..]
205205
[RUNNING] `rustc --crate-name build_script_build bar/build.rs [..]
206206
[RUNNING] `[..]build-script-build[..]
207-
warning: cargo:rustc-link-arg-cdylib was specified in the build script of bar v1.0.0 \
207+
warning: [email protected]: cargo:rustc-link-arg-cdylib was specified in the build script of bar v1.0.0 \
208208
([ROOT]/foo/bar), but that package does not contain a cdylib target
209209
210210
Allowing this was an unintended change in the 1.50 release, and may become an error in \

tests/testsuite/features2.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1807,7 +1807,7 @@ fn shared_dep_same_but_dependencies() {
18071807
[COMPILING] dep [..]
18081808
[COMPILING] bin2 [..]
18091809
[COMPILING] bin1 [..]
1810-
warning: feat: enabled
1810+
warning: [email protected]: feat: enabled
18111811
[FINISHED] [..]
18121812
",
18131813
)
@@ -1823,7 +1823,7 @@ warning: feat: enabled
18231823
[FRESH] subdep [..]
18241824
[FRESH] dep [..]
18251825
[FRESH] bin1 [..]
1826-
warning: feat: enabled
1826+
warning: [email protected]: feat: enabled
18271827
[FRESH] bin2 [..]
18281828
[FINISHED] [..]
18291829
",

tests/testsuite/warn_on_failure.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ fn warning_on_lib_failure() {
105105
.with_stderr_contains("[UPDATING] `[..]` index")
106106
.with_stderr_contains("[DOWNLOADED] bar v0.0.1 ([..])")
107107
.with_stderr_contains("[COMPILING] bar v0.0.1")
108-
.with_stderr_contains(&format!("[WARNING] {}", WARNING1))
109-
.with_stderr_contains(&format!("[WARNING] {}", WARNING2))
108+
.with_stderr_contains(&format!("[WARNING] [email protected]: {}", WARNING1))
109+
.with_stderr_contains(&format!("[WARNING] [email protected]: {}", WARNING2))
110110
.run();
111111
}

0 commit comments

Comments
 (0)