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

DiagnosticBuilder::span_label (sometimes?) does nothing #71857

Closed
RalfJung opened this issue May 3, 2020 · 2 comments · Fixed by #79088
Closed

DiagnosticBuilder::span_label (sometimes?) does nothing #71857

RalfJung opened this issue May 3, 2020 · 2 comments · Fixed by #79088
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@RalfJung
Copy link
Member

RalfJung commented May 3, 2020

Recently, I was constructing a diagnostic with code like this:

            let mut diag = self.struct_warn("skipping const checks");
            for &(span, feature_gate) in unleashed_features.iter() {
                if let Some(feature_gate) = feature_gate {
                    diag.span_label(span, format!("skipping check for `{}` feature", feature_gate));
                } else {
                    diag.span_label(span, "skipping check that does not even have a feature gate");
                }
            }
            diag.emit();

I expected this to print a warning with a bunch of labels pointing to the given spans attached to it. But instead, the labels are just entirely ignored.

I am now using span_help instead, but that's a gross hack as this is not a "help" information. (This warning is for permanently unstable nightly-only testing flags, so it's not a big deal.) Unfortunately the span_label doc comment is also not very helpful, talking about the internal representation of the diagnostic builder ("multispan" etc) and about what happens when I do not call this method (?!?) but not about why adding a label might just have no effect at all.

Cc @rust-lang/wg-diagnostics which hopefully has people that actually understand this API, unlike me. :)

@jonas-schievink jonas-schievink added A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 3, 2020
@estebank
Copy link
Contributor

estebank commented May 3, 2020

Did span_help show a subdiagnostic in the output or just the help? If the span isn't displayable (points at code that rustc can't find or it's a DUMMY_SP) then span_label does nothing because it assumes that the label without the context isn't understandable, while note and help assume that the text might be enough.

@RalfJung
Copy link
Member Author

RalfJung commented May 4, 2020

If the span isn't displayable (points at code that rustc can't find or it's a DUMMY_SP) then span_label does nothing because it assumes that the label without the context isn't understandable, while note and help assume that the text might be enough.

That kind of "detail" would be really good to have stated in the doc comments of the involved functions. :D

Final output looks like this:

warning: skipping const checks
   |
help: skipping check that does not even have a feature gate
  --> $DIR/const_refers_to_static2.rs:14:18
   |
LL |     unsafe { &*(&FOO as *const _ as *const usize) }
   |                  ^^^
help: skipping check for `const_raw_ptr_deref` feature
  --> $DIR/const_refers_to_static2.rs:14:14
   |
LL |     unsafe { &*(&FOO as *const _ as *const usize) }
   |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: skipping check that does not even have a feature gate
  --> $DIR/const_refers_to_static2.rs:22:6
   |
LL |     &FOO
   |      ^^^

Indeed the "root warning" has no span we could attach it to.

Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Nov 17, 2020
clarify `span_label` documentation

Fixes rust-lang#71857.

r? `@estebank`

cc `@RalfJung`
@bors bors closed this as completed in c459ab3 Nov 17, 2020
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-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants