Skip to content

Commit 1889d48

Browse files
Add support for the #[debugger_visualizer] attribute to target modules.
1 parent e4220fb commit 1889d48

File tree

1 file changed

+33
-16
lines changed

1 file changed

+33
-16
lines changed

text/0000-debugger-visualizer.md

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -294,28 +294,44 @@ above and reference it via the `#![debugger_visualizer]` attribute as follows:
294294
# Reference-level explanation
295295
[reference-level-explanation]: #reference-level-explanation
296296

297-
In rustc, a new built-in crate-level attribute `#![debugger_visualizer]` will be
298-
added which instructs the compiler to take the debugger visualizer specified by the
299-
attribute and add it to the current binary being built. The file path specified must
300-
be relative to the location of the attribute and is resolved in a manner that is
301-
identical to how paths are resolved in the `include_str!` macro.
302-
303-
Since the `#![debugger_visualizer]` is a crate-level attribute, any usage of this
304-
attribute in a different context (i.e. targeting types, modules, etc) will cause a
305-
compiler error.
306-
307-
For example, the `#![debugger_visualizer]` attribute may be used in the following:
297+
In rustc, a new built-in attribute `#[debugger_visualizer]` will be added which
298+
instructs the compiler to take the specified file path for a debugger visualizer
299+
and add it to the current binary being built. The file path specified must be
300+
relative to the location of the attribute and is resolved in a manner that is
301+
identical to how paths are resolved in the `include_str!` macro. This attribute
302+
will directly target modules which means the syntax `#![debugger_visualizer]` is
303+
also valid when placed at the module level. This would allow for this attribute to
304+
be used as a crate-level attribute as well which is different than a typical module item
305+
when placed at the top-level crate file, `lib.rs` or `main.rs`.
306+
307+
For example, the following uses of the attribute are valid:
308308

309309
Where `main.rs` contains:
310310

311311
```rust
312312
#![debugger_visualizer(natvis_file = "../main.natvis")]
313+
314+
#[debugger_visualizer(natvis_file = "../foo.natvis")]
315+
mod foo;
316+
```
317+
318+
and `bar.rs` contains:
319+
320+
```rust
321+
#![debugger_visualizer(natvis_file = "../bar.natvis")]
313322
```
314323

315-
The attribute must be placed at the top of `main.rs` where other crate-level
316-
attributes are placed.
324+
In the first case, the attribute is applied to the crate as a crate-level attribute
325+
using the inner attribute syntax on the top-level crate source file. It is also
326+
added to the module foo using the outer attribute syntax. In the second case,
327+
the attribute is applied to the module bar using the inner attribute syntax which
328+
also is valid since it is still targeting a module.
329+
330+
The only valid targets for this attribute are modules or as a crate-level attribute.
331+
Using this attribute on any other target, for instance a type or a function, will
332+
cause rustc to raise a compiler error that will need to be resolved.
317333

318-
The `#![debugger_visualizer]` attribute will reserve multiple keys to be able to
334+
The `#[debugger_visualizer]` attribute will reserve multiple keys to be able to
319335
specify which type of visualizer is being applied. The following keys will be
320336
reserved as part of this RFC:
321337

@@ -600,8 +616,9 @@ struct FancyRect {
600616
}
601617
```
602618

603-
Currently the `#![debugger_visualizer]` attribute is only allowed to be used as a
604-
crate-level attribute. This can be updated to allow targeting types as well if the
619+
Currently the `#[debugger_visualizer]` attribute is only allowed to target modules
620+
which includes being used as crate-level attribute when targeting the top-level
621+
`*.rs` source file. This can be updated to allow targeting types as well if the
605622
same attribute was to be re-used to support this.
606623

607624
## Inline Natvis XML fragments via a macro

0 commit comments

Comments
 (0)