-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Port limit attributes to the new attribute parsing infrastructure #145819
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
base: master
Are you sure you want to change the base?
Conversation
|
This comment has been minimized.
This comment has been minimized.
@jdonszelmann #145792 is mostly ready so you can probably rebase now :3 |
This comment was marked as resolved.
This comment was marked as resolved.
835549e
to
995056a
Compare
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt Some changes occurred to the CTFE / Miri interpreter cc @rust-lang/miri These commits modify the If this was unintentional then you should revert the changes before this PR is merged. Some changes occurred to the CTFE machinery |
This comment has been minimized.
This comment has been minimized.
995056a
to
11da338
Compare
does conflict with #145937 but it's an easy rebase so we'll just see what merges first |
@@ -6,15 +6,5 @@ LL | #![recursion_limit = "-100"] | |||
| | | |||
| not a valid integer | |||
|
|||
error: `limit` must be a non-negative integer | |||
--> $DIR/invalid_digit.rs:3:1 | |||
| |
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.
this doubled up error cannot be prevented. If we do, we'd get a similar situation as with crate_name where we either forget some cases, or delay as bug giving an ice when this literal happens to be a macro that before expansion is invalid but expanded is valid. e.g. concat!("100")
which before expansion is an expression we should reject but after expansion is a perfectly valid integer literal
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.
It's not doubled up? Your PR removes duplication looking at the diff. Am I missing something?
11da338
to
06599a5
Compare
I presume this fixes some of these reported ICEs: #145922? You don't need to add regression tests, not worth it I think. |
☔ The latest upstream changes (presumably #145958) made this pull request unmergeable. Please resolve the merge conflicts. |
I think the ices are already mostly fixed because we don't delay bugs anymore for this specific case. So I think it's fixed without this pr but we'll want this anyway |
06599a5
to
1de3926
Compare
This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
@rustbot ready |
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.
r=me after nits
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError; | ||
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "N"); | ||
|
||
// FIXME: recursion limit is allowed on all targets and ignored, |
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.
// FIXME: recursion limit is allowed on all targets and ignored, | |
// FIXME: move size limit is allowed on all targets and ignored, |
impl<S: Stage> SingleAttributeParser<S> for MoveSizeLimitParser { | ||
const PATH: &[Symbol] = &[sym::move_size_limit]; | ||
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost; | ||
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError; |
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.
Not sure if you want to do that in this PR but #![move_size_limit]
is still unstable under feature large_assignments
(RUST-83518), so theoretically we could just bump this to OnDuplicate::Error
.
|
||
// FIXME: recursion limit is allowed on all targets and ignored, | ||
// even though it should only be valid on crates of course | ||
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(ALL_TARGETS); |
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.
Similarly, this could be bumped to AllowedTargets::AllowList(&[Target::Crate])
(is that how it's done?) because it's still unstable.
impl<S: Stage> SingleAttributeParser<S> for PatternComplexityLimitParser { | ||
const PATH: &[Symbol] = &[sym::pattern_complexity_limit]; | ||
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost; | ||
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError; |
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.
Since #![pattern_complexity_limit]
is gated behind the internal feature rustc_attrs
(for some reason, lol), this could be upgraded to OnDuplicate::Error
.
|
||
// FIXME: recursion limit is allowed on all targets and ignored, | ||
// even though it should only be valid on crates of course | ||
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(ALL_TARGETS); |
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.
… and this one to AllowList(&[Level::Crate])
(if that's the correct policy) for the same reason.
@@ -677,7 +680,7 @@ pub enum ShouldEmit { | |||
/// | |||
/// Only relevant when early parsing, in late parsing equivalent to `ErrorsAndLints`. | |||
/// Late parsing is never fatal, and instead tries to emit as many diagnostics as possible. | |||
EarlyFatal, | |||
EarlyFatal { also_emit_lints: bool }, | |||
/// The operation will emit errors and lints. | |||
/// This is usually what you need. | |||
ErrorsAndLints, |
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.
(preexisting) docs of variant Nothing
mention nonexistent variant Emit
.
@@ -1245,7 +1246,8 @@ pub fn get_crate_name(sess: &Session, krate_attrs: &[ast::Attribute]) -> Symbol | |||
// in all code paths that require the crate name very early on, namely before | |||
// macro expansion. | |||
|
|||
let attr_crate_name = parse_crate_name(sess, krate_attrs, ShouldEmit::EarlyFatal); | |||
let attr_crate_name = | |||
parse_crate_name(sess, krate_attrs, ShouldEmit::EarlyFatal { also_emit_lints: true }); |
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.
Ah, cool! You've (added &) set also_emit_lints
to true
for warning on e.g., duplicate #![crate_names]
, is that correct?
I've experimented a bit and noticed that printf '#![crate_name = "x"]#![crate_name="x"]' | rustc +master-2025-08-29 - --print=crate-name
doesn't emit any warning on master. Does your change incidentally fix that? (It does emit during normal execution)
DUMMY_SP, | ||
rustc_ast::node_id::CRATE_NODE_ID, | ||
None, | ||
ShouldEmit::EarlyFatal { also_emit_lints: false }, |
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.
Why false
? Since it's non-obvious to me, could you add a small comment please, thanks!
LL | #[recursion_limit="0200"] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
note: This attribute does not have an `!`, which means it is applied to this module |
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.
(preexisting) The This should be lower-case, https://rustc-dev-guide.rust-lang.org/diagnostics.html#diagnostic-output-style-guide, can be fixed in a different PR.
@@ -6,15 +6,5 @@ LL | #![recursion_limit = "-100"] | |||
| | | |||
| not a valid integer | |||
|
|||
error: `limit` must be a non-negative integer | |||
--> $DIR/invalid_digit.rs:3:1 | |||
| |
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.
It's not doubled up? Your PR removes duplication looking at the diff. Am I missing something?
Doesn't pass tests, to be rebased on #145792 which will solve that
r? @fmease