Skip to content
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

Improve error message when writer is forgotten in write and writeln macro #109149

Merged
merged 1 commit into from
Mar 29, 2023

Conversation

mj10021
Copy link
Contributor

@mj10021 mj10021 commented Mar 14, 2023

Modified write! macro error message when writer is forgotten as in issue #108713

Fixes #108713

r? @WaffleLapkin

@rustbot
Copy link
Collaborator

rustbot commented Mar 14, 2023

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @WaffleLapkin (or someone else) soon.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 14, 2023
Copy link
Member

@compiler-errors compiler-errors left a comment

Choose a reason for hiding this comment

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

Thanks for the PR. Can you give this PR a more "functional" title -- something like, "improve error message when user forgets to pass a writer to write!(..)", or something that describes what this pr does, rather than just what issue this addresses?

Then in the body of the PR, you can put fixes #108713, and that'll link the issue appopriately.

Comment on lines 331 to 367
"no {} named `{}` found for {} `{}` in the current scope",
item_kind,
item_name,
rcvr_ty.prefix_string(self.tcx),
ty_str_reported,
);
err = struct_span_err!(
tcx.sess,
args.unwrap().0.span,
E0599,
"cannot write into '{}'",
ty_str_reported,
);
err.span_note(
arg_span,
"must implement 'io::Write', 'fmt::Write', or have a write_fmt method",
);
if writer_note.is_some() {
err.span_help(arg_span.shrink_to_lo(), writer_note.unwrap());
}
} else {
err = struct_span_err!(
tcx.sess,
span,
E0599,
"no {} named `{}` found for {} `{}` in the current scope",
item_kind,
item_name,
rcvr_ty.prefix_string(self.tcx),
ty_str_reported,
);
}
Copy link
Member

Choose a reason for hiding this comment

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

Maybe this would be a good opportunity to migrate this into a diagnostic struct...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry not sure I'm understanding correctly, are you suggesting moving the missing writer portion into a diagnostic struct or moving the entire report_no_match_method_error into a diagnostic struct?

Copy link
Member

Choose a reason for hiding this comment

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

Probably both, into different diagnostic structs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Gotcha, thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If the other changes I made look fine I can get started working on this

@mj10021 mj10021 changed the title Issue 108713 fix Improve error message when writer is forgotten in write! macro Mar 14, 2023
@WaffleLapkin WaffleLapkin added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 15, 2023
@mj10021 mj10021 changed the title Improve error message when writer is forgotten in write! macro Improve error message when writer is forgotten in write and writeln macro Mar 19, 2023
@rust-log-analyzer

This comment has been minimized.

@rustbot rustbot added A-meta Area: Issues & PRs about the rust-lang/rust repository itself A-testsuite Area: The testsuite used to check the correctness of rustc T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-infra Relevant to the infrastructure team, which will review and decide on the PR/issue. T-release Relevant to the release subteam, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Mar 19, 2023
@rustbot
Copy link
Collaborator

rustbot commented Mar 19, 2023

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

Some changes occurred in compiler/rustc_codegen_cranelift

cc @bjorn3

Some changes occurred in src/tools/cargo

cc @ehuss

These commits modify compiler targets.
(See the Target Tier Policy.)

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

Some changes occurred in engine.rs, potentially modifying the public API of ObligationCtxt.

cc @lcnr, @compiler-errors

Some changes occurred to the CTFE / Miri engine

cc @rust-lang/miri

Some changes occurred to the core trait solver

cc @rust-lang/initiative-trait-system-refactor

The Miri subtree was changed

cc @rust-lang/miri

Some changes occurred in diagnostic error codes

cc @GuillaumeGomez

This PR changes MIR

cc @oli-obk, @RalfJung, @JakobDegen, @davidtwco, @celinval, @vakaras

This PR changes src/bootstrap/defaults/config.codegen.toml. If appropriate, please also update config.compiler.toml so the defaults are in sync.

These commits modify the Cargo.lock file. Random changes to Cargo.lock can be introduced when switching branches and rebasing PRs.
This was probably unintentional and should be reverted before this PR is merged.

If this was intentional then you can ignore this comment.

@mj10021
Copy link
Contributor Author

mj10021 commented Mar 19, 2023

I'm sorry I did something wrong when I was trying to ff master

@rust-log-analyzer

This comment has been minimized.

@Noratrieb
Copy link
Member

Hi, you accidentally added a merge commit pulling in tons of other commits. Just use git rebase master after updating your local master branch and then force push the result, that should hopefully fix it.
You can check https://rustc-dev-guide.rust-lang.org/git.html for more info. No worries, it's fine^^

@mj10021 mj10021 force-pushed the issue-108713-fix branch 2 times, most recently from 648960b to 46ed86e Compare March 19, 2023 18:19
@rust-log-analyzer

This comment has been minimized.

@mj10021
Copy link
Contributor Author

mj10021 commented Mar 19, 2023

@rustbot label -A-testsuite, -A-meta, -T-bootstrap, -T-release, -T-infra, -WG-trait-system-refactor

@rustbot rustbot removed A-testsuite Area: The testsuite used to check the correctness of rustc A-meta Area: Issues & PRs about the rust-lang/rust repository itself T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-release Relevant to the release subteam, which will review and decide on the PR/issue. T-infra Relevant to the infrastructure team, which will review and decide on the PR/issue. labels Mar 19, 2023
@rust-log-analyzer

This comment has been minimized.

Copy link
Member

@WaffleLapkin WaffleLapkin left a comment

Choose a reason for hiding this comment

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

couple of nit picks

struct_span_err!(self.tcx.sess, args.0.span, E0599, "cannot write into `{}`", ty_str);
err.span_note(
args.0.span,
"must implement 'io::Write', 'fmt::Write', or have a write_fmt method",
Copy link
Member

Choose a reason for hiding this comment

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

Again, diagnostics usually use backticks

Suggested change
"must implement 'io::Write', 'fmt::Write', or have a write_fmt method",
"must implement `io::Write`, `fmt::Write`, or have a `write_fmt` method",

@mj10021
Copy link
Contributor Author

mj10021 commented Mar 21, 2023

I am getting the following error when I run ./x.py test on my machine:

thread 'rustc' panicked at 'index out of bounds: the len is 51321 but the index is 51321', /rust/compiler/rustc_serialize/src/opaque.rs:594:21
stack backtrace:
   0:     0x7f69faa6df29 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::he5f97e1149b4b98d
   1:     0x7f69faae2dae - core::fmt::write::h4054f33d714f2e48
   2:     0x7f69faa4c955 - std::io::Write::write_fmt::h7033bd5c1b9da704
   3:     0x7f69faa6dce5 - std::sys_common::backtrace::print::ha1e8dfaf994e1661
   4:     0x7f69faa3ef8f - std::panicking::default_hook::{{closure}}::h6d8b1db20a2c55b5
   5:     0x7f69faa3ec55 - std::panicking::default_hook::h26618ab0f07fb3ee
   6:     0x7f69fb3303a5 - rustc_driver_impl[591904b1837e992b]::DEFAULT_HOOK::{closure#0}::{closure#0}
   7:     0x7f69faa3fd0d - std::panicking::rust_panic_with_hook::h51be139a6193b4d1
   8:     0x7f69faa6e259 - std::panicking::begin_panic_handler::{{closure}}::hd5264bde5e5b2f91
   9:     0x7f69faa6e036 - std::sys_common::backtrace::__rust_end_short_backtrace::h51c8ac09f2a0d06d
  10:     0x7f69faa3f862 - rust_begin_unwind
  11:     0x7f69faa14bf3 - core::panicking::panic_fmt::hae108289130a6835
  12:     0x7f69faa14d62 - core::panicking::panic_bounds_check::h7120c0eff84ec7f3
  13:     0x7f69fd11da5a - <rustc_metadata[79791ad705d4ab19]::rmeta::CrateRoot as rustc_serialize[28d70643afa36a2c]::serialize::Decodable<rustc_metadata[79791ad705d4ab19]::rmeta::decoder::DecodeContext>>::decode
  14:     0x7f69fd058132 - <rustc_metadata[79791ad705d4ab19]::locator::CrateLocator>::extract_one
  15:     0x7f69fd05709a - <rustc_metadata[79791ad705d4ab19]::locator::CrateLocator>::extract_lib
  16:     0x7f69fd055c57 - <rustc_metadata[79791ad705d4ab19]::locator::CrateLocator>::find_library_crate
  17:     0x7f69fd053e60 - <rustc_metadata[79791ad705d4ab19]::locator::CrateLocator>::maybe_load_library_crate
  18:     0x7f69fd0f565d - <rustc_metadata[79791ad705d4ab19]::creader::CrateLoader>::load
  19:     0x7f69fd0f19b3 - <rustc_metadata[79791ad705d4ab19]::creader::CrateLoader>::maybe_resolve_crate
  20:     0x7f69fd0f3a99 - <rustc_metadata[79791ad705d4ab19]::creader::CrateLoader>::maybe_resolve_crate
  21:     0x7f69fd0f81ad - <rustc_metadata[79791ad705d4ab19]::creader::CrateLoader>::maybe_process_path_extern
  22:     0x7f69fbf9303a - <rustc_resolve[39f173fbac3dd876]::Resolver>::extern_prelude_get
  23:     0x7f69fbf967a4 - <rustc_resolve[39f173fbac3dd876]::Resolver>::early_resolve_ident_in_lexical_scope
  24:     0x7f69fbf752bb - <rustc_resolve[39f173fbac3dd876]::Resolver>::resolve_path_with_ribs
  25:     0x7f69fbf80ef0 - <rustc_resolve[39f173fbac3dd876]::Resolver as rustc_expand[2c6503e5439025d1]::base::ResolverExpand>::resolve_imports
  26:     0x7f69fd2b37a5 - <rustc_expand[2c6503e5439025d1]::expand::MacroExpander>::fully_expand_fragment
  27:     0x7f69fd2b2ea0 - <rustc_expand[2c6503e5439025d1]::expand::MacroExpander>::expand_crate
  28:     0x7f69fb3bf2d1 - <rustc_session[4219d3d64f21f04b]::session::Session>::time::<rustc_ast[4aef29eb81a9ce2]::ast::Crate, rustc_interface[b270ec05995dc8d3]::passes::configure_and_expand::{closure#1}>
  29:     0x7f69fb397451 - rustc_interface[b270ec05995dc8d3]::passes::resolver_for_lowering
  30:     0x7f69fcc12f8c - rustc_query_system[827217707b92434c]::query::plumbing::try_execute_query::<rustc_query_impl[bb470f4c8b345078]::queries::resolver_for_lowering, rustc_query_impl[bb470f4c8b345078]::plumbing::QueryCtxt>
  31:     0x7f69fc93c9e5 - <rustc_query_impl[bb470f4c8b345078]::Queries as rustc_middle[ee4938beb2c48787]::ty::query::QueryEngine>::resolver_for_lowering
  32:     0x7f69fb338e5c - <rustc_middle[ee4938beb2c48787]::ty::context::GlobalCtxt>::enter::<rustc_driver_impl[591904b1837e992b]::run_compiler::{closure#1}::{closure#2}::{closure#2}, &rustc_data_structures[bd3456f1c2888d2b]::steal::Steal<(rustc_middle[ee4938beb2c48787]::ty::ResolverAstLowering, alloc[dc8a9bb7d5e1b453]::rc::Rc<rustc_ast[4aef29eb81a9ce2]::ast::Crate>)>>
  33:     0x7f69fb304a92 - rustc_span[5b47611f73d93c88]::with_source_map::<core[6ea3fe8105c2c65d]::result::Result<(), rustc_span[5b47611f73d93c88]::ErrorGuaranteed>, rustc_interface[b270ec05995dc8d3]::interface::run_compiler<core[6ea3fe8105c2c65d]::result::Result<(), rustc_span[5b47611f73d93c88]::ErrorGuaranteed>, rustc_driver_impl[591904b1837e992b]::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
  34:     0x7f69fb2d60f9 - std[91a00bd35404f355]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[b270ec05995dc8d3]::util::run_in_thread_pool_with_globals<rustc_interface[b270ec05995dc8d3]::interface::run_compiler<core[6ea3fe8105c2c65d]::result::Result<(), rustc_span[5b47611f73d93c88]::ErrorGuaranteed>, rustc_driver_impl[591904b1837e992b]::run_compiler::{closure#1}>::{closure#0}, core[6ea3fe8105c2c65d]::result::Result<(), rustc_span[5b47611f73d93c88]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[6ea3fe8105c2c65d]::result::Result<(), rustc_span[5b47611f73d93c88]::ErrorGuaranteed>>
  35:     0x7f69fb34f69d - <<std[91a00bd35404f355]::thread::Builder>::spawn_unchecked_<rustc_interface[b270ec05995dc8d3]::util::run_in_thread_pool_with_globals<rustc_interface[b270ec05995dc8d3]::interface::run_compiler<core[6ea3fe8105c2c65d]::result::Result<(), rustc_span[5b47611f73d93c88]::ErrorGuaranteed>, rustc_driver_impl[591904b1837e992b]::run_compiler::{closure#1}>::{closure#0}, core[6ea3fe8105c2c65d]::result::Result<(), rustc_span[5b47611f73d93c88]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[6ea3fe8105c2c65d]::result::Result<(), rustc_span[5b47611f73d93c88]::ErrorGuaranteed>>::{closure#1} as core[6ea3fe8105c2c65d]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  36:     0x7f69faa78de3 - std::sys::unix::thread::Thread::new::thread_start::hc2566c2f0887626b
  37:     0x7f69f3a88609 - start_thread
                               at /build/glibc-SzIz7B/glibc-2.31/nptl/pthread_create.c:477:8
  38:     0x7f69fa8b8133 - clone
                               at /build/glibc-SzIz7B/glibc-2.31/misc/../sysdeps/unix/sysv/linux/x86_64/clone.S:95
  39:                0x0 - <unknown>

error: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.70.0-dev running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type lib -C opt-level=3 -C embed-bitcode=no -C debuginfo=0 -Z unstable-options -C symbol-mangling-version=v0 -Z unstable-options -Z macro-backtrace -C link-args=-Wl,-z,origin -C link-args=-Wl,-rpath,$ORIGIN/../lib -C split-debuginfo=off -Z binary-dep-depinfo -Z tls-model=initial-exec

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [resolver_for_lowering] getting the resolver for lowering
end of query stack
error: could not compile `tracing-subscriber`
warning: build failed, waiting for other jobs to finish...
Build completed unsuccessfully in 0:20:33

I see that it's coming from write_fmt, is this likely because of my changes or should I report the bug?

@WaffleLapkin
Copy link
Member

@mj10021 I don't think this is caused by your changes. first, try using x clean (this is likely an incremental bug).

struct_span_err!(self.tcx.sess, args.0.span, E0599, "cannot write into `{}`", ty_str);
err.span_note(
args.0.span,
"must implement `io::Write`, `fmt::Write`, or have a write_fmt method",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"must implement `io::Write`, `fmt::Write`, or have a write_fmt method",
"must implement `io::Write`, `fmt::Write`, or have a `write_fmt` method",

write_fmt should be ticked too.

@mj10021
Copy link
Contributor Author

mj10021 commented Mar 22, 2023

@mj10021 I don't think this is caused by your changes. first, try using x clean (this is likely an incremental bug).

Yes, thank you, x clean fixed it

@compiler-errors
Copy link
Member

Can you rebase and squash this into one commit? This commit stack is getting pretty long for a pretty self-contained change.

@mj10021
Copy link
Contributor Author

mj10021 commented Mar 22, 2023

Can you rebase and squash this into one commit? This commit stack is getting pretty long for a pretty self-contained change.

Yes, absolutely

@mj10021 mj10021 force-pushed the issue-108713-fix branch 2 times, most recently from 879cce3 to ccb982a Compare March 28, 2023 00:11
@rust-log-analyzer

This comment has been minimized.

added ui test
blessed stderrs
fixed typo
reblessed
Copy link
Member

@compiler-errors compiler-errors left a comment

Choose a reason for hiding this comment

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

i'm happy with this for now, though perhaps @WaffleLapkin has more comments so i'll leave it to waffle to approve (or re-assign to me) -- any follow-ups can be done in further prs

struct_span_err!(self.tcx.sess, args.0.span, E0599, "cannot write into `{}`", ty_str);
err.span_note(
args.0.span,
"must implement `io::Write`, `fmt::Write`, or have a `write_fmt` method",
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this message include a subject? E.g.: "a writer must..."? I'm worried that otherwise it might not be clear what the message is talking about.

Copy link
Member

@WaffleLapkin WaffleLapkin left a comment

Choose a reason for hiding this comment

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

This looks good to me too. Improvements (like message tweaking that @mejrs suggested) can indeed be done in follow-ups. Thanks!

@WaffleLapkin
Copy link
Member

@bors r=compiler-errors,WaffleLapkin

@bors
Copy link
Collaborator

bors commented Mar 28, 2023

📌 Commit ff88787 has been approved by compiler-errors,WaffleLapkin

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 28, 2023
@WaffleLapkin
Copy link
Member

@bors rollup

bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 29, 2023
…iaskrgr

Rollup of 6 pull requests

Successful merges:

 - rust-lang#109149 (Improve error message when writer is forgotten in write and writeln macro)
 - rust-lang#109367 (Streamline fast rejection)
 - rust-lang#109548 (AnnotationColumn struct to fix hard tab column numbers in errors)
 - rust-lang#109694 (do not panic on failure to acquire jobserver token)
 - rust-lang#109705 (new solver: check for intercrate mode when accessing the cache)
 - rust-lang#109708 (Specialization involving RPITITs is broken so ignore the diagnostic differences)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 23813d8 into rust-lang:master Mar 29, 2023
@rustbot rustbot added this to the 1.70.0 milestone Mar 29, 2023
@mj10021 mj10021 deleted the issue-108713-fix branch November 1, 2024 22:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Diagnostic for forgetting a writer in write! is bad
8 participants