Repository navigation
Add a new rustc_show_spans internal attribute - #164165
FranciscoTGouveia wants to merge 1 commit into
Conversation
|
Some changes occurred in compiler/rustc_attr_parsing cc @jdonszelmann, @JonathanBrouwer Some changes occurred in compiler/rustc_passes/src/check_attr.rs cc @jdonszelmann, @JonathanBrouwer Some changes occurred in compiler/rustc_attr_ir |
| // Internal attributes, Testing: | ||
| // ========================================================================== | ||
|
|
||
| sym::rustc_show_spans, |
There was a problem hiding this comment.
I was undecided about whether to consider this new attribute as Testing or Misc.
Since it seems to be temporary for the migration to the new span combining scheme, I went with the former.
| impl<'a> Visitor<'a> for ShowSpans<'a> { | ||
| fn visit_item(&mut self, item: &'a ast::Item) { | ||
| let saved = (self.expr, self.ty, self.path); | ||
| (self.expr, self.ty, self.path) = (false, false, false); |
There was a problem hiding this comment.
Before visiting a new item, I saved the current state of ShowSpans and reset it to support nested items.
Is this necessary, or is it redundant?
There was a problem hiding this comment.
That depends on whether this should print the path. I'd, perhaps naively, expect it to do print it, in which case resetting is wrong.
#[rustc_show_spans(path)]
fn bar() {
fn foo() {
let _ = a::b::c;
}
}(this is also something that should have a test)
| if let ItemKind::Fn(_) = &item.kind | ||
| && item.attrs.iter().any(|attr| attr.has_name(sym::rustc_show_spans)) | ||
| && let Some(Attribute::Parsed(AttributeKind::RustcShowSpans(kinds))) = | ||
| AttributeParser::parse_limited(self.sess, &item.attrs, &|attr| { |
There was a problem hiding this comment.
You can use parse_limited_sym in this case.
Also, no need for the item.attrs.iter().any(|attr| attr.has_name(sym::rustc_show_spans)) check, attribute parsing will check this.
There was a problem hiding this comment.
Oh, I did not know about parse_limited_sym; thanks!
The idea with item.attrs.iter().any(|attr| attr.has_name(sym::rustc_show_spans)) was to have a cheaper check to exit early. However, I am now realizing this is not a hot path, so the benefit is nil.
| impl<'a> Visitor<'a> for ShowSpans<'a> { | ||
| fn visit_item(&mut self, item: &'a ast::Item) { | ||
| let saved = (self.expr, self.ty, self.path); | ||
| (self.expr, self.ty, self.path) = (false, false, false); |
There was a problem hiding this comment.
That depends on whether this should print the path. I'd, perhaps naively, expect it to do print it, in which case resetting is wrong.
#[rustc_show_spans(path)]
fn bar() {
fn foo() {
let _ = a::b::c;
}
}(this is also something that should have a test)
|
Reminder, once the PR becomes ready for a review, use |
This new attribute is a first step for solving issue 126763. Now, we can easily test out where spans end up, particularly useful for ensuring that spans end up in the best suitable macro context.
e792a6e to
fdefc16
Compare
This new internal attribute is a first step for solving #126763.
Given the code:
We can now report the spans and thus show the bug of the span not falling inside the macro context:
r? @petrochenkov