-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Port #[rustc_layout_scalar_valid_range_start/end]
to the new attrib…
#142921
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
Open
JonathanBrouwer
wants to merge
1
commit into
rust-lang:master
Choose a base branch
from
JonathanBrouwer:rustc_attributes_parser
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+144
−69
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
use rustc_ast::LitKind; | ||
use rustc_attr_data_structures::AttributeKind; | ||
use rustc_feature::{AttributeTemplate, template}; | ||
use rustc_span::{Symbol, sym}; | ||
|
||
use crate::attributes::{AttributeOrder, OnDuplicate, SingleAttributeParser}; | ||
use crate::context::{AcceptContext, Stage}; | ||
use crate::parser::ArgParser; | ||
|
||
pub(crate) struct RustcLayoutScalarValidRangeStart; | ||
|
||
impl<S: Stage> SingleAttributeParser<S> for RustcLayoutScalarValidRangeStart { | ||
const PATH: &'static [Symbol] = &[sym::rustc_layout_scalar_valid_range_start]; | ||
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepFirst; | ||
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error; | ||
const TEMPLATE: AttributeTemplate = template!(List: "start"); | ||
|
||
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> { | ||
parse_rustc_layout_scalar_valid_range(cx, args) | ||
.map(|n| AttributeKind::RustcLayoutScalarValidRangeStart(n, cx.attr_span)) | ||
} | ||
} | ||
|
||
pub(crate) struct RustcLayoutScalarValidRangeEnd; | ||
|
||
impl<S: Stage> SingleAttributeParser<S> for RustcLayoutScalarValidRangeEnd { | ||
const PATH: &'static [Symbol] = &[sym::rustc_layout_scalar_valid_range_end]; | ||
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepFirst; | ||
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error; | ||
const TEMPLATE: AttributeTemplate = template!(List: "end"); | ||
|
||
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> { | ||
parse_rustc_layout_scalar_valid_range(cx, args) | ||
.map(|n| AttributeKind::RustcLayoutScalarValidRangeEnd(n, cx.attr_span)) | ||
} | ||
} | ||
|
||
fn parse_rustc_layout_scalar_valid_range<S: Stage>( | ||
cx: &mut AcceptContext<'_, '_, S>, | ||
args: &ArgParser<'_>, | ||
) -> Option<Box<u128>> { | ||
let Some(list) = args.list() else { | ||
cx.expected_list(cx.attr_span); | ||
return None; | ||
}; | ||
let Some(single) = list.single() else { | ||
cx.expected_single_argument(list.span); | ||
return None; | ||
}; | ||
let Some(lit) = single.lit() else { | ||
cx.expected_integer_literal(single.span()); | ||
return None; | ||
}; | ||
let LitKind::Int(num, _ty) = lit.kind else { | ||
cx.expected_integer_literal(single.span()); | ||
return None; | ||
}; | ||
Some(Box::new(num.0)) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really like this change, but not sure how to fix it. I think my new lint is the one which should not be triggered, but I just get an attribute with an empty list with no way to detect that it is empty because something previously errored. @jdonszelmann advice?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not 100% sure about this but this might be what dcx.has_stashed_diagnostic(span, StashKey) could be useful for
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a hack I printed the entire stashed_diagnostics when
parse_rustc_layout_scalar_valid_range
is called and it is empty, so this does not seem to be the solutionThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea because when the initial diagnostic is emitted, nothing is stashed with that stash key
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
take a look at the stash key enum
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pretty printed the entire
stashed_diagnostics
map from dcx, it is empty. So what stash key I used shouldn't matterThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think
stashed_diagnostics
can be used for this. It is meant to delay emitting an error, to add more information, which is not what I want to do here.As an experiment, I tried not emitting the attribute when a parsing error happened, but this has bad results for other tests. Given those results, I think keeping this error here is not that big of a deal, but feel free to disagree and propose a solution