-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Remove name_or_empty
#139615
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
Remove name_or_empty
#139615
Conversation
Some changes occurred in compiler/rustc_codegen_ssa/src/codegen_attrs.rs Some changes occurred in compiler/rustc_passes/src/check_attr.rs Some changes occurred in src/tools/clippy cc @rust-lang/clippy Some changes occurred in compiler/rustc_attr_parsing Some changes occurred in compiler/rustc_codegen_ssa |
Best reviewed one commit at a time. |
Nice Nicholas! Yea I can give this a review :) |
@@ -561,12 +561,15 @@ impl<'tcx> CheckAttrVisitor<'tcx> { | |||
allowed_target: Target, | |||
) { | |||
if target != allowed_target { | |||
let path = attr.path(); | |||
let path: Vec<_> = path.iter().map(|s| s.as_str()).collect(); | |||
let attr_name = path.join("::"); |
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.
if this happens a lot throughout the compiler it's a bit ugly to keep iterating and joining these. In HIR I think I had a solution for this, with hir::AttributePath which implements Display. I'll add this to my own TODO list, to make this nicer at the same time when AttributeExt is removed :)
@@ -347,7 +347,7 @@ impl<'a> AstValidator<'a> { | |||
sym::forbid, | |||
sym::warn, | |||
]; | |||
!arr.contains(&attr.name_or_empty()) && rustc_attr_parsing::is_builtin_attr(*attr) | |||
!attr.has_any_name(&arr) && rustc_attr_parsing::is_builtin_attr(*attr) |
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 like has_any_name
, good change :)
@@ -2346,8 +2346,9 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { | |||
let hir_id = self.fcx.tcx.local_def_id_to_hir_id(local_def_id); | |||
let attrs = self.fcx.tcx.hir_attrs(hir_id); | |||
for attr in attrs { | |||
if sym::doc == attr.name_or_empty() { | |||
} else if sym::rustc_confusables == attr.name_or_empty() { | |||
if attr.has_name(sym::doc) { |
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.
all these if chains are terribly when you're changing things, who knows whether things are exhaustive or not. They should be matches. But that's by no means your fault, it just reminds me again how bad this is...
Thanks for the review comments. I don't think any of them require action, are there more to come? |
there are more to come, paused my review halfway through but just wanted to comment what there was already. sorry for the confusion |
@@ -144,9 +144,10 @@ impl RustcMirAttrs { | |||
attr: &ast::MetaItemInner, | |||
mapper: impl FnOnce(Symbol) -> Result<T, ()>, | |||
) -> Result<(), ()> { | |||
// Unwrapping the name is safe because this is only called when `has_name` has succeeded. |
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 could be nicer to just pass the name in that case, to make sure this can never go wrong
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.
Ok, I added a new commit doing this.
#[primary_span] | ||
pub span: Span, | ||
pub name: Symbol, |
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 a little unfortunate that the symbol is removed from the error here now. In another case earlier I thought it didn't matter so much but having the name there can be nice during testing, i.e. the main error string will list the attribute that's an error. If there are multiple errors on one line, it's afaik hard to deduce which one was the error based just on the span.
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.
though it does not seem to affect any test right now, which is nice I guess. What do you think?
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 are a few cases like this. E.g. for this code:
#[macro_export(not_local_inner_macros)]
The old error was:
error: `not_local_inner_macros` isn't a valid `#[macro_export]`
and the new error is:
invalid `#[macro_export]` argument
which doesn't mention the invalid argument, because that argument might be a non-identifer, e.g. a string literal.
It could be made to mention it, it's requires an extra case, which is a little more code and complexity, and didn't seem worth it for these quite obscure error messages.
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.
hmm, no I do agree the error is still perfectly clear for users and the value might be small
67d536a
to
20d7373
Compare
alright! very nice this, r=me then :) |
Thanks! @bors r=jdonszelmann |
…onszelmann Remove `name_or_empty` Another step towards rust-lang#137978. r? `@jdonszelmann`
☔ The latest upstream changes (presumably #139912) made this pull request unmergeable. Please resolve the merge conflicts. |
This adds two new warnings, both of which print the attribute incorrectly as `#[]`. The next commit will fix this.
The current code assumes that the attribute is just an identifier, and so misprints paths.
This shows places where the use of `name_or_empty` causes problems, i.e. we print empty identifiers in error messages: ``` error: unrecognized field name `` error: `` isn't a valid `#[macro_export]` argument `#[no_sanitize()]` should be applied to a function ``` (The last one is about an attribute `#[no_sanitize("address")]`.) The next commit will fix these.
I'm removing empty identifiers everywhere, because in practice they always mean "no identifier" rather than "empty identifier". (An empty identifier is impossible.) It's better to use `Option` to mean "no identifier" because you then can't forget about the "no identifier" possibility. Some specifics: - When testing an attribute for a single name, the commit uses the `has_name` method. - When testing an attribute for multiple names, the commit uses the new `has_any_name` method. - When using `match` on an attribute, the match arms now have `Some` on them. In the tests, we now avoid printing empty identifiers by not printing the identifier in the `error:` line at all, instead letting the carets point out the problem.
20d7373
to
846c10f
Compare
I rebased. @bors r=jdonszelmann |
…iaskrgr Rollup of 8 pull requests Successful merges: - rust-lang#139084 (hygiene: Rename semi-transparent to semi-opaque) - rust-lang#139236 (Use a session counter to make anon dep nodes unique) - rust-lang#139650 (Fix `register_group_alias` for tools) - rust-lang#139770 (Rename `LifetimeName` as `LifetimeKind`.) - rust-lang#139846 (Remove `kw::Empty` uses in rustdoc) - rust-lang#139891 (Include optional dso_local marker for functions in `enum-match.rs`) - rust-lang#139908 (parser: Remove old diagnostic notes for type ascription syntax) - rust-lang#139917 (fix for multiple `#[repr(align(N))]` on functions) Failed merges: - rust-lang#139615 (Remove `name_or_empty`) r? `@ghost` `@rustbot` modify labels: rollup
…onszelmann Remove `name_or_empty` Another step towards rust-lang#137978. r? `@jdonszelmann`
…iaskrgr Rollup of 9 pull requests Successful merges: - rust-lang#138528 (deref patterns: implement implicit deref patterns) - rust-lang#138934 (support config extensions) - rust-lang#139114 (Implement `pin!()` using `super let`) - rust-lang#139393 (rustdoc-json: Output target feature information) - rust-lang#139553 (sync::mpsc: prevent double free on `Drop`) - rust-lang#139615 (Remove `name_or_empty`) - rust-lang#139853 (Disable combining LLD with external llvm-config) - rust-lang#139913 (rustdoc/clean: Fix lowering of fn params (fixes correctness & HIR vs. middle parity regressions)) - rust-lang#139942 (Ignore aix for tests/ui/erros/pic-linker.rs) r? `@ghost` `@rustbot` modify labels: rollup
…onszelmann Remove `name_or_empty` Another step towards rust-lang#137978. r? `@jdonszelmann`
…iaskrgr Rollup of 8 pull requests Successful merges: - rust-lang#138528 (deref patterns: implement implicit deref patterns) - rust-lang#138934 (support config extensions) - rust-lang#139393 (rustdoc-json: Output target feature information) - rust-lang#139553 (sync::mpsc: prevent double free on `Drop`) - rust-lang#139615 (Remove `name_or_empty`) - rust-lang#139853 (Disable combining LLD with external llvm-config) - rust-lang#139913 (rustdoc/clean: Fix lowering of fn params (fixes correctness & HIR vs. middle parity regressions)) - rust-lang#139942 (Ignore aix for tests/ui/erros/pic-linker.rs) r? `@ghost` `@rustbot` modify labels: rollup
…iaskrgr Rollup of 8 pull requests Successful merges: - rust-lang#138528 (deref patterns: implement implicit deref patterns) - rust-lang#138934 (support config extensions) - rust-lang#139393 (rustdoc-json: Output target feature information) - rust-lang#139553 (sync::mpsc: prevent double free on `Drop`) - rust-lang#139615 (Remove `name_or_empty`) - rust-lang#139853 (Disable combining LLD with external llvm-config) - rust-lang#139913 (rustdoc/clean: Fix lowering of fn params (fixes correctness & HIR vs. middle parity regressions)) - rust-lang#139942 (Ignore aix for tests/ui/erros/pic-linker.rs) r? `@ghost` `@rustbot` modify labels: rollup
…iaskrgr Rollup of 7 pull requests Successful merges: - rust-lang#138528 (deref patterns: implement implicit deref patterns) - rust-lang#139393 (rustdoc-json: Output target feature information) - rust-lang#139553 (sync::mpsc: prevent double free on `Drop`) - rust-lang#139615 (Remove `name_or_empty`) - rust-lang#139853 (Disable combining LLD with external llvm-config) - rust-lang#139913 (rustdoc/clean: Fix lowering of fn params (fixes correctness & HIR vs. middle parity regressions)) - rust-lang#139942 (Ignore aix for tests/ui/erros/pic-linker.rs) r? `@ghost` `@rustbot` modify labels: rollup
…iaskrgr Rollup of 7 pull requests Successful merges: - rust-lang#138528 (deref patterns: implement implicit deref patterns) - rust-lang#139393 (rustdoc-json: Output target feature information) - rust-lang#139553 (sync::mpsc: prevent double free on `Drop`) - rust-lang#139615 (Remove `name_or_empty`) - rust-lang#139853 (Disable combining LLD with external llvm-config) - rust-lang#139913 (rustdoc/clean: Fix lowering of fn params (fixes correctness & HIR vs. middle parity regressions)) - rust-lang#139942 (Ignore aix for tests/ui/erros/pic-linker.rs) r? `@ghost` `@rustbot` modify labels: rollup
…iaskrgr Rollup of 7 pull requests Successful merges: - rust-lang#138528 (deref patterns: implement implicit deref patterns) - rust-lang#139393 (rustdoc-json: Output target feature information) - rust-lang#139553 (sync::mpsc: prevent double free on `Drop`) - rust-lang#139615 (Remove `name_or_empty`) - rust-lang#139853 (Disable combining LLD with external llvm-config) - rust-lang#139913 (rustdoc/clean: Fix lowering of fn params (fixes correctness & HIR vs. middle parity regressions)) - rust-lang#139942 (Ignore aix for tests/ui/erros/pic-linker.rs) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#139615 - nnethercote:rm-name_or_empty, r=jdonszelmann Remove `name_or_empty` Another step towards rust-lang#137978. r? ``@jdonszelmann``
…iaskrgr Rollup of 7 pull requests Successful merges: - rust-lang#138528 (deref patterns: implement implicit deref patterns) - rust-lang#139393 (rustdoc-json: Output target feature information) - rust-lang#139553 (sync::mpsc: prevent double free on `Drop`) - rust-lang#139615 (Remove `name_or_empty`) - rust-lang#139853 (Disable combining LLD with external llvm-config) - rust-lang#139913 (rustdoc/clean: Fix lowering of fn params (fixes correctness & HIR vs. middle parity regressions)) - rust-lang#139942 (Ignore aix for tests/ui/erros/pic-linker.rs) r? `@ghost` `@rustbot` modify labels: rollup
Another step towards #137978.
r? @jdonszelmann