-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Port #[crate_name]
to the new attribute parsing infrastructure
#137729
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.
04bafec
to
3898182
Compare
This comment has been minimized.
This comment has been minimized.
3898182
to
81fc9d1
Compare
4e90cee
to
21838d5
Compare
21838d5
to
d1ee9c4
Compare
@fmease and I decided to delay this PR for a bit until more diagnostic infra for attrs lands (hopefully next week) to make the duplicate error a warning to be consistent with current master. |
r=fmease,bjorn3 once that PR lands and you can downgrade the error to a lint warning again. @bors delegate+ |
✌️ @jdonszelmann, you can now approve this pull request! If @fmease told you to " |
This comment was marked as resolved.
This comment was marked as resolved.
Hi @jdonszelmann and @fmease, #137687 has reached beta so it would be great if we could resolve that via a beta-backport of this PR. Do you think it's possible to resolve the review feedback and merge this PR in the next week or so? I can probably pitch in to help if necessary 🙂 |
Hi there. We wanted to delay this until attribute diagnostics. Something that should not be a lot of work but I have not worked as much on recently as I maybe should. I can't to this tomorrow, but likely next week. The pr has been reviewed but there was a bit of an issue around incremental, which I now know how to solve but just haven't yet. Is that a reasonable timeframe? I am pretty busy with organising rust week atm, but knowing the solution I guess the only important thing is that it gets quick reviews? Let me know how that sounds |
Just to clarify, will this PR then depend on the attribute diagnostics work? (Is that #138164?) Generally, for backports, we try to keep the backport as small as possible so if this PR can be made to work independently of that PR (possibly even with a degraded diagnostics experience), that would be highly preferred. |
No. We decided to delay this because it's relatively low prio and any nice and permanent solution for this depends on that. I'll make a temp fix that at least doesn't ice separately then, that sounds better for now. I don't mind doing it, I know the problem now and then I also know how to fix it permanently later. You'll hear from me |
Note that #137687 actually has two separate problems/subissues:
This PR only appears to address the first problem. The second problem would probably need to have a separate fix. |
ok this is weird, I've copied just the tests over to master to fix it in a temporary way, but can no longer reporoduce the issue. Something else must have solved it in the meantime. Let me see what. |
(I know I've said this in the other PR too, but just in case) Just a heads up: I split #137687 into two issues:
|
d1ee9c4
to
1f5c49f
Compare
@rustbot review |
a584056
to
86f64ca
Compare
This comment was marked as resolved.
This comment was marked as resolved.
86f64ca
to
56fd2c6
Compare
This comment was marked as resolved.
This comment was marked as resolved.
56fd2c6
to
6e298c6
Compare
This comment has been minimized.
This comment has been minimized.
@rustbot review |
☔ The latest upstream changes (presumably #145600) made this pull request unmergeable. Please resolve the merge conflicts. |
6e298c6
to
ae54d0a
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
ae54d0a
to
c04570f
Compare
This comment was marked as resolved.
This comment was marked as resolved.
c04570f
to
e8dac5d
Compare
These commits modify the If this was unintentional then you should revert the changes before this PR is merged. |
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. |
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.
Some small comments. r=me with nits addressed in one way or another
@@ -9,7 +9,7 @@ rustc_abi = { path = "../rustc_abi" } | |||
rustc_ast = { path = "../rustc_ast" } | |||
rustc_data_structures = { path = "../rustc_data_structures" } | |||
rustc_error_messages = { path = "../rustc_error_messages" } | |||
rustc_hir_id = { path = "../rustc_hir_id" } |
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.
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.
sigh, I actually considered making a similar change in the past but found it too destructive of a thing to do and found other solutions. Was very surprised when I saw someone else ended up doing this anyway 🙃
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'll move that some day in another PR
let Some(name) = n.value_as_str() else { | ||
cx.expected_string_literal(n.value_span, Some(n.value_as_lit())); | ||
return None; | ||
}; |
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.
Does this regress #[crate_name = concat!("x")] fn f() {}
? I guess it won't because concat!
is already expanded by then?
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 discussed, AttributeLintDecoratorOrEmitter
, decorate_or_emit
, etc. would be more accurate.
Or going vague, AttributeLintHandler
, fn handle
, DeferredAttributeLintHandler
, type Handler: …;
.
But if you feel it's too churny to go rename them again, it's okay to leave it.
@@ -1244,8 +1246,7 @@ 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 = | |||
validate_and_find_value_str_builtin_attr(sym::crate_name, sess, krate_attrs); |
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.
(once we port #[recursion_limit]
, we can get rid of validate_and_find_value_str_builtin_attr
)
} | ||
} | ||
|
||
struct DiagEmitter<'a, 'b>(&'a mut Diag<'b, ()>); |
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.
struct DiagEmitter<'a, 'b>(&'a mut Diag<'b, ()>); | |
struct DiagDecorator<'a, 'b>(&'a mut Diag<'b, ()>); |
@@ -1417,15 +1418,24 @@ pub struct TyCtxt<'tcx> { | |||
gcx: &'tcx GlobalCtxt<'tcx>, | |||
} | |||
|
|||
impl<'tcx> LintEmitter for TyCtxt<'tcx> { | |||
fn emit_node_span_lint( | |||
pub struct Decorator<'tcx>(TyCtxt<'tcx>, &'static Lint, HirId, MultiSpan); |
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.
pub struct Decorator<'tcx>(TyCtxt<'tcx>, &'static Lint, HirId, MultiSpan); | |
pub struct Emitter<'tcx>(TyCtxt<'tcx>, &'static Lint, HirId, MultiSpan); |
match style { | ||
Some(ast::AttrStyle::Outer) => self.tcx.emit_node_span_lint( | ||
match attr { | ||
// FIXME(jdonszelmann) after https://github.com/rust-lang/rust/pull/145085 merges, move to attribute parsing |
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.
(#145085 has been merged)
| | ||
LL | #[crate_name = "0900"] | ||
| ^^^^^^^^^^^^^^^^^^^^^^ | ||
| ^^^^^^ |
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.
Wait, the highlight should span the entire attribute; the problem isn't with the string literal (contrary to diagnostics like crate name must not be empty
or `--crate-name` and `#[crate_name]` are required to match
)
@@ -1244,8 +1246,7 @@ 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 = | |||
validate_and_find_value_str_builtin_attr(sym::crate_name, sess, krate_attrs); | |||
let attr_crate_name = parse_crate_name(sess, krate_attrs, ShouldEmit::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.
Could you please make this raise a FatalError on parse error to address https://github.com/rust-lang/rust/pull/137729/files#r2267446182 or add a FIXME(fmease): Exit fatally on parse error.
so I can do so as a follow-up?
#[crate_name]
to a new-style attribute parser#[crate_name]
to a new-style attribute parser
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.
(random file)
Did this PR actually add a regression test for #137687? Did I miss it
#[crate_name]
to a new-style attribute parser#[crate_name]
to the new attribute parsing infrastructure
r? @fmease
Closes #137687