-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix(shell): Make warn/note/error consistent with lints/toml errors #15917
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
@@ -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()), |
There was a problem hiding this comment.
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.
625330c
to
f1be881
Compare
7079ccf
to
2605d32
Compare
…#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?
There was a problem hiding this 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?
Might be good to give any feedback in parallel so I know its worth putting in time to fix things :) |
There was a problem hiding this 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}` |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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:
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
My long term vision is
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())?; |
There was a problem hiding this comment.
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
self.err().write_all("\n".as_bytes())?; | |
self.err().write_all(b"\n")?; |
There was a problem hiding this comment.
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.
[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>. |
There was a problem hiding this comment.
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.
### 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
☔ The latest upstream changes (possibly 3ceb2cb) made this pull request unmergeable. Please resolve the merge conflicts. |
This is from some review feedback left on rust-lang#15917 which was merged in rust-lang#15920.
What does this PR try to resolve?
This hardens
Shell::print_report
to work forShell::warn
,note
, anderror
and migrates them to it so we get a more consistent experience and prep for switching the callers over toShell::print_report
.In terms of end-user behavior changes,
error
is now bright red instead of rednote
is now green instead of cyan:
after the level is no longer boldedHow to test and review this PR?