Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upReplace macro backtraces with labeled local uses #35702
Conversation
rust-highfive
assigned
pnkfelix
Aug 15, 2016
This comment has been minimized.
This comment has been minimized.
|
r? @pnkfelix (rust_highfive has picked a reviewer for you, use r? to override) |
jonathandturner
changed the title
Add backtrace labels
Replace macro backtraces with labeled local uses
Aug 15, 2016
This comment has been minimized.
This comment has been minimized.
|
cc @nrc |
rust-highfive
assigned
nikomatsakis
and unassigned
pnkfelix
Aug 15, 2016
Mark-Simulacrum
reviewed
Aug 15, 2016
| span: &mut MultiSpan, | ||
| children: &mut Vec<SubDiagnostic>) { | ||
| let mut spans_updated = self.fix_multispan_in_std_macros(span); | ||
| for i in 0..children.len() { |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
This looks quite good; my only complaints are:
To make a cross-crate text, you can create a test with an
|
Mark-Simulacrum
reviewed
Aug 16, 2016
| replacements_occurred = true; | ||
| } | ||
| } | ||
| for i in 0..self.span_labels.len() { |
This comment has been minimized.
This comment has been minimized.
Mark-Simulacrum
Aug 16, 2016
Member
Both of these should be for span in &mut .. compatible, I think.
jonathandturner
referenced this pull request
Aug 16, 2016
Closed
Update spans that live in std macros to their use sites #35688
jonathandturner
force-pushed the
jonathandturner:add_backtrace_labels
branch
from
fb90d79
to
ce60c9e
Aug 17, 2016
This comment has been minimized.
This comment has been minimized.
|
@nikomatsakis - nits addressed, new ui test added, comment added. |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
@jonathandturner wonderful, r=me, but needs rebase =) |
Mark-Simulacrum
reviewed
Aug 17, 2016
| span: &mut MultiSpan, | ||
| children: &mut Vec<SubDiagnostic>) { | ||
| let mut spans_updated = self.fix_multispan_in_std_macros(span); | ||
| for child in &mut children.iter_mut() { |
This comment has been minimized.
This comment has been minimized.
Mark-Simulacrum
Aug 17, 2016
Member
Why &mut children.iter_mut()? Shouldn't just &mut children be enough?
This comment has been minimized.
This comment has been minimized.
jonathandturner
Aug 17, 2016
Author
Contributor
Probably a little overkill? &mut children doesn't compile:
error: the trait bound `std::vec::Vec<SubDiagnostic>: std::iter::Iterator` is not satisfied [--explain E0277]
--> src/librustc_errors/emitter.rs:468:9
|>
468 |> for child in &mut children {
|> ^
note: `std::vec::Vec<SubDiagnostic>` is not an iterator; maybe try calling `.iter()` or a similar method
note: required because of the requirements on the impl of `std::iter::Iterator` for `&mut std::vec::Vec<SubDiagnostic>`
But I probably could drop the &mut in front.
This comment has been minimized.
This comment has been minimized.
Mark-Simulacrum
Aug 17, 2016
•
Member
That's... odd, since it works in a simpler example: https://is.gd/Ep6Unm.
fn main() {
let mut v = vec![1, 2];
for el in &mut v {
*el += 10;
}
println!("{:?}", v);
}Edit: Actually, children is already &mut Vec<_>, so just for child in children should work, if I understand iterators correctly.
This comment has been minimized.
This comment has been minimized.
jonathandturner
Aug 17, 2016
Author
Contributor
Also doesn't work...
error: use of moved value: `*children` [--explain E0382]
--> src/librustc_errors/emitter.rs:472:13
|>
468 |> for child in children {
|> -------- value moved here
...
472 |> children.push(SubDiagnostic {
|> ^^^^^^^^ value used here after move
note: move occurs because `children` has type `&mut std::vec::Vec<SubDiagnostic>`, which does not implement the `Copy` trait
Sticking with the one that does :)
added some commits
Aug 17, 2016
jonathandturner
force-pushed the
jonathandturner:add_backtrace_labels
branch
from
ce60c9e
to
54d42cc
Aug 17, 2016
This comment has been minimized.
This comment has been minimized.
|
@bors r=nikomatsakis |
This comment has been minimized.
This comment has been minimized.
|
|
jonathandturner commentedAug 15, 2016
This PR (which builds on #35688) follows from the conversations on how best to handle the macro backtraces. The feeling there was that there were two different "groups" of users.
The first group, the macro users, rarely (and likely never) want to see the macro backtrace. This is often more confusing to users as it will be talking about code they didn't write.
The second group, the macro writers, are trying to debug a macro. They'll want to see something of the backtrace so that they can see where it's going wrong and what the steps were to get there.
For the first group, it seems clear that we don't want to show any macro backtrace. For the second group, we want to show enough to help the macro writer.
This PR uses a heuristic. It will only show any backtrace steps if they are in the same crate that is being compiled. This keeps errors in foreign crates from showing to users that didn't need them.
Additionally, in asking around I repeated heard that the middle steps of the backtrace are rarely, if ever, used in practice. This PR takes and applies this knowledge. Now, instead of a full backtrace, the user is given the error underline inside of a local macro as well as the use site as a secondary label. This effectively means seeing the root of the error and the top of the backtrace, eliding the middle steps.
Rather than being the "perfect solution", this PR opts to take an incremental step towards a better experience. Likely it would help to have additional macro debugging tools, as they could be much more verbose than we'd likely want to use in the error messages themselves.
Some examples follow.
Example 1
Before:
After:
Example 2
Before:
After: