Skip to content

Conversation

epage
Copy link
Contributor

@epage epage commented Sep 3, 2025

What does this PR try to resolve?

This hardens Shell::print_report to work for Shell::warn, note, and error and migrates them to it so we get a more consistent experience and prep for switching the callers over to Shell::print_report.

In terms of end-user behavior changes,

  • messages now have trailing lines indented.
  • error is now bright red instead of red
  • note is now green instead of cyan
  • the : after the level is no longer bolded

How to test and review this PR?

@rustbot
Copy link
Collaborator

rustbot commented Sep 3, 2025

r? @ehuss

rustbot has assigned @ehuss.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added A-console-output Area: Terminal output, colors, progress bar, etc. A-manifest Area: Cargo.toml issues S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 3, 2025
@@ -222,12 +222,18 @@ impl Shell {

/// Prints an amber 'warning' message.
pub fn warn<T: fmt::Display>(&mut self, message: T) -> CargoResult<()> {
self.print(&"warning", Some(&message), &WARN, false)
let report = &[annotate_snippets::Group::with_title(
annotate_snippets::Level::WARNING.secondary_title(message.to_string()),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used secondary_title (custom styling) as a short term hack because the callers may be passing in styled text to workaround the fact that we don't have annotate snippets. As we migrate things, we'll be able to use primary_title (no custom styling) as we should.

@epage epage force-pushed the annotate branch 4 times, most recently from 625330c to f1be881 Compare September 3, 2025 21:54
@epage epage force-pushed the annotate branch 2 times, most recently from 7079ccf to 2605d32 Compare September 4, 2025 01:17
github-merge-queue bot pushed a commit that referenced this pull request Sep 4, 2025
…#15920)

### What does this PR try to resolve?

This is preparation for changes like #15917 where we start to use
`annotate_snippets::Report` for handling more of the rendering of our
user messages to be more consistent with rustc and more feature rich in
what we are able to render.

### How to test and review this PR?
Copy link
Member

@weihanglo weihanglo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to rebase and fix the CI failure?

@epage
Copy link
Contributor Author

epage commented Sep 4, 2025

Do you want to rebase and fix the CI failure?

Might be good to give any feedback in parallel so I know its worth putting in time to fix things :)

Copy link
Member

@weihanglo weihanglo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally no objection to this change, though I'd like to understand the plan and where we are heading towards.

[HELP] available template variables are `{workspace-root}`, `{cargo-cache-home}`, `{workspace-path-hash}`
[HELP] available template variables are `{workspace-root}`, `{cargo-cache-home}`, `{workspace-path-hash}`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems a bit off. I would expect Help: start without leading spaces.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we'd need to update the call site to call print_report directly so that it can add a help message to this Report's Group.

@@ -21,7 +21,7 @@ fn non_nightly_fails() {
p.cargo("build -Zchecksum-freshness")
.with_stderr_data(str![[r#"
[ERROR] the `-Z` flag is only accepted on the nightly channel of Cargo, but this is the `stable` channel
See https://doc.rust-lang.org/book/appendix-07-nightly-rust.html for more information about Rust release channels.
See https://doc.rust-lang.org/book/appendix-07-nightly-rust.html for more information about Rust release channels.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This See stuff should start from its own line, or have a note:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, now that we have the full capabilities of annotate-snippets, we'll have to re-evaluate our warn/notes to decide if and how we should re-format them. The question is which would be blocking for this PR vs things we do over time. My hope is one like this could be non-blocking.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like we will need to rework on most of our messages. Not all the help and note should be under the same group.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't find a concrete example, but conceptually adding indentations to trailing lines would add efforts for people to remove those indentations when copy-pasting.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's merge #15928 first

@epage
Copy link
Contributor Author

epage commented Sep 4, 2025

Generally no objection to this change, though I'd like to understand the plan and where we are heading towards.

My long term vision is

  • Multiple errors report by cargo that matches rustc
  • as many warnings as possible converted to lints
  • as many errors, warnings, notes, and lints as possible show code snippets
  • All of this match rustc in style

This gets our existing output to be more like rustc and paves a way for using more features.

)
let rendered = Renderer::styled().term_width(term_width).render(report);
self.err().write_all(rendered.as_bytes())?;
self.err().write_all("\n".as_bytes())?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor nit, take it if you will

Suggested change
self.err().write_all("\n".as_bytes())?;
self.err().write_all(b"\n")?;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Posted #15937 to take care of this since this was actually from a PR that has already been merged.

Comment on lines 579 to +591
[WARNING] output filename collision.
The lib target `foo_macro` in package `foo-macro v1.0.0` has the same output filename as the lib target `foo_macro` in package `foo-macro v1.0.0 ([ROOT]/foo/foo-macro)`.
Colliding filename is: [ROOT]/foo/target/doc/foo_macro/index.html
The targets should have unique names.
This is a known bug where multiple crates with the same name use
the same path; see <https://github.com/rust-lang/cargo/issues/6313>.
[CHECKING] foo-macro v1.0.0
[DOCUMENTING] foo-macro v1.0.0
[CHECKING] abc v1.0.0 ([ROOT]/foo/abc)
[DOCUMENTING] foo-macro v1.0.0 ([ROOT]/foo/foo-macro)
[DOCUMENTING] abc v1.0.0 ([ROOT]/foo/abc)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[GENERATED] [ROOT]/foo/target/doc/abc/index.html and 1 other file
The lib target `foo_macro` in package `foo-macro v1.0.0` has the same output filename as the lib target `foo_macro` in package `foo-macro v1.0.0 ([ROOT]/foo/foo-macro)`.
Colliding filename is: [ROOT]/foo/target/doc/foo_macro/index.html
The targets should have unique names.
This is a known bug where multiple crates with the same name use
the same path; see <https://github.com/rust-lang/cargo/issues/6313>.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of these warnings seem to have some ordering issues where the message is split? Like the other messages are showing up in the middle of the warning.

github-merge-queue bot pushed a commit that referenced this pull request Sep 8, 2025
### What does this PR try to resolve?

Fixes #12740

This is also prep for #15917, #15922

Changes:
- `note` changes from Cyan to Bright Green
- `cargo info` had to be changed because the header and context colors
became the same
- Switch to Bright colors which is usually redundant with Bold but that
is theme dependent
- `warning` only changes to Bright on Windows which is to work around a
shell issue on some Windows versions
  - except for `PLACEHOLDER` to tell it apart from `LITERAL`
- the `:` in `note:` is no longer bolded to match rustc

### How to test and review this PR?

### Notes

While annotate-snippets does not have a style for every one of our
styles, I updated our manual styles to be similar to annotate snippets.

For annotate snippets color definitions, see
https://github.com/rust-lang/annotate-snippets-rs/blob/d38b08b81d7d574369ecfd30124195a970b37fd3/src/renderer/mod.rs#L41-L78
@rustbot
Copy link
Collaborator

rustbot commented Sep 8, 2025

☔ The latest upstream changes (possibly 3ceb2cb) made this pull request unmergeable. Please resolve the merge conflicts.

epage added a commit to epage/cargo that referenced this pull request Sep 8, 2025
This is from some review feedback left on rust-lang#15917 which was merged
in rust-lang#15920.
github-merge-queue bot pushed a commit that referenced this pull request Sep 8, 2025
### What does this PR try to resolve?

This is from some review feedback left on #15917 which was merged in
#15920.

### How to test and review this PR?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-console-output Area: Terminal output, colors, progress bar, etc. A-manifest Area: Cargo.toml issues S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants