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

annotate-snippet emitter: Add UI test where annotated_files count is > 1 #64205

Closed
phansch opened this issue Sep 6, 2019 · 14 comments · Fixed by #114018
Closed

annotate-snippet emitter: Add UI test where annotated_files count is > 1 #64205

phansch opened this issue Sep 6, 2019 · 14 comments · Fixed by #114018
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. E-help-wanted Call for participation: Help is requested to fix this issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@phansch
Copy link
Member

phansch commented Sep 6, 2019

Part of #59346

It would be nice to have a UI test for the annotate-snippet emitter, that includes annotations that span multiple files. The goal of this issue is to find and add such a test.

Instructions

A simple way to look for this, would be to add this code:

if annotated_files.len() > 1 {
    let filename = primary_lo.file.name.to_string();
    eprintln!("annotated_files > 1 in {}", filename);
}

to the top of fn slices_for_files and then check the failing UI tests.

If there are failing UI tests, it means that those UI tests include a diagnostic that probably spans multiple files.

The next step, is to copy that file (and possible auxiliary files) over into src/test/ui/annotate-snippet/ and add // compile-flags: --error-format human-annotate-rs to the top of the UI test.

Once that's done, be sure to run the added test and open a PR including the blessed stderr files.

@phansch
Copy link
Member Author

phansch commented Sep 6, 2019

Under the assumption, that we do have an existing UI test with annotations from multiple files, I'm happy to help out anyone who wants to take on this issue. Otherwise we'll have to write a test case ourselves.

@rustbot modify labels to +A-diagnostics, +E-mentor, +E-help-wanted

@rustbot rustbot added A-diagnostics Area: Messages for errors, warnings, and lints E-help-wanted Call for participation: Help is requested to fix this issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. labels Sep 6, 2019
Centril added a commit to Centril/rust that referenced this issue Sep 6, 2019
annotate-snippet emitter: Update an issue number

The tracking issue has been replaced by one with mentoring instructions (rust-lang#64205).
Centril added a commit to Centril/rust that referenced this issue Sep 6, 2019
annotate-snippet emitter: Update an issue number

The tracking issue has been replaced by one with mentoring instructions (rust-lang#64205).
@bIgBV
Copy link

bIgBV commented Sep 7, 2019

Hey @phansch I'd like to pick this issue up.

@phansch
Copy link
Member Author

phansch commented Sep 8, 2019

@bIgBV sure, it's all yours! Let me know if you have any questions. The rustc-guide should help you to get started working on the compiler.

@bIgBV
Copy link

bIgBV commented Sep 9, 2019

@phansch I made the change suggested in the issue and ran all the ui tests (over 9000!). None of them failed, meaning a new test needs to be written for this specific usecase, correct?

@phansch
Copy link
Member Author

phansch commented Sep 9, 2019

Thanks! Unfortunately I just realized I made a mistake in the instructions :/
If it's included in annotate_snippet_emitter_writer.rs it will only get executed for UI tests that use the new work-in-progress emitter, which only has one UI test currently

Instead, you'll want to include the snippet below this line in emitter.rs:

let mut annotated_files = FileWithAnnotatedLines::collect_annotations(msp, &self.sm);

If you could give that a try too, that would be great!

@bIgBV
Copy link

bIgBV commented Sep 9, 2019

Will do!

EDIT: @phansch re-ran it with the new changes, still no failures. I'm guessing that we need to add a new test.

@bIgBV
Copy link

bIgBV commented Sep 13, 2019

@phansch looks like edits on github don't generate notifications, apologies. But I retried the tests with the second change you suggested. Still no failing tests.

@phansch
Copy link
Member Author

phansch commented Sep 15, 2019

@bIgBV Sorry, been out sick the past couple of days. Thanks for testing again!

It's weird that you don't get failing tests 🤔 Could you try to apply this specific patch?

diff --git a/src/librustc_errors/emitter.rs b/src/librustc_errors/emitter.rs
index 0ce69eecc6..8a3fbb6e09 100644
--- a/src/librustc_errors/emitter.rs
+++ b/src/librustc_errors/emitter.rs
@@ -1185,6 +1185,10 @@ impl EmitterWriter {
             emit_to_destination(&buffer.render(), level, &mut self.dst, self.short_message)?;
             return Ok(());
         };
+        if annotated_files.len() > 1 {
+            let filename = primary_lo.file.name.to_string();
+            panic!("annotated_files > 1 in {}", filename);
+        }
         if let Ok(pos) =
             annotated_files.binary_search_by(|x| x.file.name.cmp(&primary_lo.file.name)) {
             annotated_files.swap(0, pos);

When you run ./x.py test src/test/ui with the patch you should see at least 5 failing UI tests (At least I do, but I didn't have time to take a closer look, yet)

@bIgBV
Copy link

bIgBV commented Sep 18, 2019

Okay, something is weird, after pulling in the latest master and making the exact changes in the patch you provided, there are over 8000 failing tests. I want to check if there is something obviously wrong going on, but I might not get back until tomorrow, as each test run takes close to an hour on my laptop.

@bIgBV
Copy link

bIgBV commented Sep 27, 2019

@phansch sorry for the late reply, I got a little caught up but finally got around to making the changes and doing a fresh build and test. there are 18 failing tests on the latest stable rustc build.

failures:
    [ui] ui/async-await/issues/issue-62009-1.rs
    [ui] ui/closures/closure-move-sync.rs
    [ui] ui/cross/cross-file-errors/main.rs
    [ui] ui/derives/derives-span-Hash-enum-struct-variant.rs
    [ui] ui/derives/derives-span-Hash-enum.rs
    [ui] ui/derives/derives-span-Hash-struct.rs
    [ui] ui/derives/derives-span-Hash-tuple-struct.rs
    [ui] ui/editions/edition-keywords-2018-2015-parsing.rs
    [ui] ui/editions/edition-keywords-2018-2018-parsing.rs
    [ui] ui/impl-trait/impl-generic-mismatch.rs
    [ui] ui/interior-mutability/interior-mutability.rs
    [ui] ui/issues/issue-21160.rs
    [ui] ui/macro_backtrace/main.rs
    [ui] ui/no-send-res-ports.rs
    [ui] ui/proc-macro/multispan.rs
    [ui] ui/proc-macro/three-equals.rs
    [ui] ui/rfc-1937-termination-trait/termination-trait-test-wrong-type.rs
    [ui] ui/traits/trait-suggest-where-clause.rs

test result: FAILED. 8993 passed; 18 failed; 35 ignored; 0 measured; 0 filtered out

I'm guessing I need to move on to the next step as you detailed in the issue right? Could you give me some context into what an annotated snippet is and why it matters that it spans multiple files?

@phansch
Copy link
Member Author

phansch commented Oct 13, 2019

sorry for the late reply

Same here 😅

I'm guessing I need to move on to the next step as you detailed in the issue right?

Yup, at least one of those tests should fail with our panic message. I think
src/test/ui/proc-macro/multispan.rs would be a good candidate to copy.
Apart from the instructions, I think you'll also have to make sure to update the
path to the auxiliary file in the test header or copy the auxiliary file, too.
(The aux header allows to specify a second (or more) local crate to be compiled
so that it can be used in the test)

What is an annotated snippet?

In general, a snippet is a piece of code that can span multiple lines and
potentially files. An annotation points at a portion of the
snippet and contains annotations for parts of the snippet.

Aside: Note that rustc has a Line type instead of a Snippet type. The new
diagnostics library has a Snippet type instead of a line type.
That's why we have to convert from one to the other for #59346.

We care about the fact that a snippet can span more than one file, because the
new diagnostics emitting library might output those cases differently. This
issue is essentially about finding out how that output looks.

Let me know if you have more questions or need help (You can also ask on Zulip in #t-compiler/wg-diagnostics)

@hdhoang
Copy link
Contributor

hdhoang commented Nov 14, 2019

ping from triage @bIgBV, any updates on this? Thanks for your work!

@bIgBV
Copy link

bIgBV commented Nov 14, 2019

@hdhoang sorry about the delay, I got a bit busy with work recently, but I'm going to pick this up again.

@crlf0710 crlf0710 added C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 11, 2020
@Enselic
Copy link
Member

Enselic commented Jul 24, 2023

PR with fix: #114018

@bors bors closed this as completed in 427f3d3 Jul 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. E-help-wanted Call for participation: Help is requested to fix this issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
6 participants