-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Fix span of unsafe attribute diagnostic #133270
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2966,6 +2966,7 @@ impl NormalAttr { | |
path: Path::from_ident(ident), | ||
args: AttrArgs::Empty, | ||
tokens: None, | ||
span: DUMMY_SP, | ||
}, | ||
tokens: None, | ||
} | ||
|
@@ -2979,6 +2980,10 @@ pub struct AttrItem { | |
pub args: AttrArgs, | ||
// Tokens for the meta item, e.g. just the `foo` within `#[foo]` or `#![foo]`. | ||
pub tokens: Option<LazyAttrTokenStream>, | ||
/// The span of the contents of the attribute. | ||
/// | ||
/// This is the span starting from the path and ending at the end of the args. | ||
pub span: Span, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Increasing the size of |
||
} | ||
|
||
impl AttrItem { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -241,10 +241,6 @@ impl Attribute { | |
} | ||
|
||
impl AttrItem { | ||
pub fn span(&self) -> Span { | ||
self.args.span().map_or(self.path.span, |args_span| self.path.span.to(args_span)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you sure we can't save this by using one of the span ancestor functions like https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/span_encoding/struct.Span.html#method.find_ancestor_in_same_ctxt? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is another instance of the span combining problem really. The logic in The only certain thing here is that the manual span arithmetic ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe just remove the span arithmetic and not try to improve spans for macro scenarios? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see a way to get I think supporting proper suggestions in macros is pretty important, as this pattern comes up quite frequently. I realize this can only be tuned to support certain scenarios, and not be perfect in all situations. However, I think recording the span as implemented in this PR covers the vast majority of situations well. Are you still concerned with the regressions here? |
||
} | ||
|
||
pub fn meta_item_list(&self) -> Option<ThinVec<MetaItemInner>> { | ||
match &self.args { | ||
AttrArgs::Delimited(args) if args.delim == Delimiter::Parenthesis => { | ||
|
@@ -633,7 +629,7 @@ pub fn mk_attr( | |
args: AttrArgs, | ||
span: Span, | ||
) -> Attribute { | ||
mk_attr_from_item(g, AttrItem { unsafety, path, args, tokens: None }, None, style, span) | ||
mk_attr_from_item(g, AttrItem { unsafety, path, args, tokens: None, span }, None, style, span) | ||
} | ||
|
||
pub fn mk_attr_from_item( | ||
|
Uh oh!
There was an error while loading. Please reload this page.