Implement #[diagnostic::on_unknown] for modules.#157926
Conversation
|
Some changes occurred in compiler/rustc_hir/src/attrs cc @jdonszelmann, @JonathanBrouwer Some changes occurred in compiler/rustc_attr_parsing |
|
rustbot has assigned @petrochenkov. Use Why was this reviewer chosen?The reviewer was selected based on:
|
#[diagnostic_on_unknown] for modules.#[diagnostic::on_unknown] for modules.
|
The implementation looks ok, but I don't like the general direction in which it goes. Could you move the |
|
Reminder, once the PR becomes ready for a review, use |
|
Let's benchmark this as well. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Implement `#[diagnostic::on_unknown]` for modules.
At least in cross-crate cases the |
I would just like to raise the concern that this is a rather general comment without any in depth explanation. That makes it hard for anyone to address your concerns there. Given that I would like to ask you to add at least a little explanation why you believe my presented use-case is not valid. As currently written it reads like the improvements and therefore the reduction in support work done the error messages to crates maintained by me are not worth the effort you/the compiler team need to have. I would like to polity disagree there as past improvements did significantly reduce the support load on my end and I don't believe passing a few more information trough the relevant code up to the error message construction is really a lot more work in the long run.
Anything in the |
It goes both ways, diagnostic attributes also let us remove error reporting code in the compiler. No need to have specialized code error reporting code just to give a custom error message if we can just use an attribute instead. They can remove a lot of special casing in general.
An example of something that I want to do is to put it on You can also imagine this being used as a tombstone mechanism: #[diagnostic::on_unknown(note = "`Foo` was renamed to `Bar` in the great bikeshed war")]
mod stuff { ... }
// elsewhere
use stuff::Foo;
+1. I looked into lazily loading them at first but I couldn't figure out how to get from a
@weiznich note that the comment was towards me and I'm aware-ish of the context, so it does not need in depth explanation. But the tl;dr is that name resolution and macro expansion, moreso than other things in the compiler, is rather "hacky":
As a result |
|
@mejrs Thanks for providing the context. That's helpful to know ❤️ (And yes I can understand what you mean by the code being hacky, it was rather hard to get the initial implementation in there) |
|
💥 Test timed out after |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Implement `#[diagnostic::on_unknown]` for modules.
This comment has been minimized.
This comment has been minimized.
Done. Fwiw,
I'll wait for the perf run to finish (if it finishes). |
|
Finished benchmarking commit (d954550): comparison URL. Overall result: ❌ regressions - no action neededBenchmarking means the PR may be perf-sensitive. Consider adding rollup=never if this change is not fit for rolling up. @rustbot label: -S-waiting-on-perf -perf-regression Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary 2.4%, secondary 3.7%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (secondary 2.0%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeThis perf run didn't have relevant results for this metric. Bootstrap: 523.739s -> 521.175s (-0.49%) |
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Implement `#[diagnostic::on_unknown]` for modules.
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (99947af): comparison URL. Overall result: no relevant changes - no action neededBenchmarking means the PR may be perf-sensitive. Consider adding rollup=never if this change is not fit for rolling up. @rustbot label: -S-waiting-on-perf -perf-regression Instruction countThis perf run didn't have relevant results for this metric. Max RSS (memory usage)Results (primary -3.4%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (secondary -2.8%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeResults (primary 0.0%, secondary 0.1%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 481.592s -> 480.903s (-0.14%) |
|
@rustbot ready |
|
@bors r+ |
|
@bors rollup |
…enkov
Implement `#[diagnostic::on_unknown]` for modules.
This lets you customize the error message if an item can't be found in a module. Primarily my motivation for this is that I was trying to dogfood `diagnostic::on_unknown` in my own crates and realized I was writing a lot of duplicate attributes and it'd be simpler if it just applied to things at a module level.
For example:
```rust
#[diagnostic::on_unknown(message = "oh no, `{Unresolved}` is not in module `{This}`")]
pub mod x {
pub struct Foo;
}
pub use x::Bar;
```
```
error[E0432]: oh no, `Bar` is not in module `x`
--> $DIR/on_module.rs:9:9
|
LL | pub use x::Bar;
| ^^^---
| |
| no `Bar` in `x`
|
= note: unresolved import `x::Bar`
```
Also, as shown, this implements `{Unresolved}` to reference whatever couldn't be found.
Inner attribute syntax (`#![diagnostic::on_unknown]`) is supported, however it (still) is an error to use inner tool attributes without `#![feature(custom_inner_attributes)]`.
cc @estebank @weiznich
…uwer Rollup of 4 pull requests Successful merges: - #157926 (Implement `#[diagnostic::on_unknown]` for modules.) - #158084 (`-Znext-solver` Emit error instead of ICE when combining {int, float} var with alias) - #158128 (std: use correct low surrogate range in Windows standard I/O code) - #158132 (std: correctly report file size on UWP)
…enkov
Implement `#[diagnostic::on_unknown]` for modules.
This lets you customize the error message if an item can't be found in a module. Primarily my motivation for this is that I was trying to dogfood `diagnostic::on_unknown` in my own crates and realized I was writing a lot of duplicate attributes and it'd be simpler if it just applied to things at a module level.
For example:
```rust
#[diagnostic::on_unknown(message = "oh no, `{Unresolved}` is not in module `{This}`")]
pub mod x {
pub struct Foo;
}
pub use x::Bar;
```
```
error[E0432]: oh no, `Bar` is not in module `x`
--> $DIR/on_module.rs:9:9
|
LL | pub use x::Bar;
| ^^^---
| |
| no `Bar` in `x`
|
= note: unresolved import `x::Bar`
```
Also, as shown, this implements `{Unresolved}` to reference whatever couldn't be found.
Inner attribute syntax (`#![diagnostic::on_unknown]`) is supported, however it (still) is an error to use inner tool attributes without `#![feature(custom_inner_attributes)]`.
cc @estebank @weiznich
…uwer Rollup of 8 pull requests Successful merges: - #158129 (ensure the new solver bootstraps on CI) - #158134 (Rename `lint-rust-version` to `hint-msrv`) - #157926 (Implement `#[diagnostic::on_unknown]` for modules.) - #158075 (Point to the unstable segment of an import path instead of to the whole path) - #158084 (`-Znext-solver` Emit error instead of ICE when combining {int, float} var with alias) - #158128 (std: use correct low surrogate range in Windows standard I/O code) - #158132 (std: correctly report file size on UWP) - #158138 (Remove redundant check for `#[loop_match]` and `#[const_continue]`)
View all comments
This lets you customize the error message if an item can't be found in a module. Primarily my motivation for this is that I was trying to dogfood
diagnostic::on_unknownin my own crates and realized I was writing a lot of duplicate attributes and it'd be simpler if it just applied to things at a module level.For example:
Also, as shown, this implements
{Unresolved}to reference whatever couldn't be found.Inner attribute syntax (
#![diagnostic::on_unknown]) is supported, however it (still) is an error to use inner tool attributes without#![feature(custom_inner_attributes)].cc @estebank @weiznich