Skip to content

Commit c384cd6

Browse files
authored
Merge pull request #1923 from ehuss/collapse_debuginfo
Update `collapse_debuginfo` to use the attribute template
2 parents f83e52a + 843d11b commit c384cd6

File tree

1 file changed

+41
-19
lines changed

1 file changed

+41
-19
lines changed

src/attributes/debugger.md

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -151,36 +151,58 @@ When the crate's debug executable is passed into GDB[^rust-gdb], `print bob` wil
151151
[Natvis documentation]: https://docs.microsoft.com/en-us/visualstudio/debugger/create-custom-views-of-native-objects
152152
[pretty printing documentation]: https://sourceware.org/gdb/onlinedocs/gdb/Pretty-Printing.html
153153

154+
<!-- template:attributes -->
154155
r[attributes.debugger.collapse_debuginfo]
155156
## The `collapse_debuginfo` attribute
156157

157158
r[attributes.debugger.collapse_debuginfo.intro]
158-
The *`collapse_debuginfo` [attribute]* controls whether code locations from a macro definition are collapsed into a single location associated with the macro's call site,
159-
when generating debuginfo for code calling this macro.
159+
The *`collapse_debuginfo` [attribute]* controls whether code locations from a macro definition are collapsed into a single location associated with the macro's call site when generating debuginfo for code calling this macro.
160+
161+
> [!EXAMPLE]
162+
> ```rust
163+
> #[collapse_debuginfo(yes)]
164+
> macro_rules! example {
165+
> () => {
166+
> println!("hello!");
167+
> };
168+
> }
169+
> ```
170+
>
171+
> When using a debugger, invoking the `example` macro may appear as though it is calling a function. That is, when you step to the invocation site, it may show the macro invocation rather than the expanded code.
172+
173+
<!-- TODO: I think it would be nice to extend this to explain a little more about why this is useful, and the kinds of scenarios where you would want one vs the other. See https://github.com/rust-lang/rfcs/pull/2117 for some guidance. -->
160174
161175
r[attributes.debugger.collapse_debuginfo.syntax]
162-
The attribute uses the [MetaListIdents] syntax to specify its inputs, and can only be applied to macro definitions.
176+
The syntax for the `collapse_debuginfo` attribute is:
177+
178+
```grammar,attributes
179+
@root CollapseDebuginfoAttribute -> `collapse_debuginfo` `(` CollapseDebuginfoOption `)`
180+
181+
CollapseDebuginfoOption ->
182+
`yes`
183+
| `no`
184+
| `external`
185+
```
186+
187+
r[attributes.debugger.collapse_debuginfo.allowed-positions]
188+
The `collapse_debuginfo` attribute may only be applied to a [`macro_rules` definition].
189+
190+
r[attributes.debugger.collapse_debuginfo.duplicates]
191+
The `collapse_debuginfo` attribute may used only once on a macro.
163192

164193
r[attributes.debugger.collapse_debuginfo.options]
165-
Accepted options:
166-
- `#[collapse_debuginfo(yes)]` --- code locations in debuginfo are collapsed.
167-
- `#[collapse_debuginfo(no)]` --- code locations in debuginfo are not collapsed.
168-
- `#[collapse_debuginfo(external)]` --- code locations in debuginfo are collapsed only if the macro comes from a different crate.
194+
The `collapse_debuginfo` attribute accepts these options:
195+
196+
- `#[collapse_debuginfo(yes)]` --- Code locations in debuginfo are collapsed.
197+
- `#[collapse_debuginfo(no)]` --- Code locations in debuginfo are not collapsed.
198+
- `#[collapse_debuginfo(external)]` --- Code locations in debuginfo are collapsed only if the macro comes from a different crate.
169199

170200
r[attributes.debugger.collapse_debuginfo.default]
171-
The `external` behavior is the default for macros that don't have this attribute, unless they are built-in macros.
172-
For built-in macros the default is `yes`.
201+
The `external` behavior is the default for macros that don't have this attribute unless they are built-in macros. For built-in macros the default is `yes`.
173202

174203
> [!NOTE]
175-
> `rustc` has a `-C collapse-macro-debuginfo` CLI option to override both the default collapsing behavior and `#[collapse_debuginfo]` attributes.
176-
177-
```rust
178-
#[collapse_debuginfo(yes)]
179-
macro_rules! example {
180-
() => {
181-
println!("hello!");
182-
};
183-
}
184-
```
204+
> `rustc` has a [`-C collapse-macro-debuginfo`] CLI option to override both the default behavior and the values of any `#[collapse_debuginfo]` attributes.
185205
206+
[`-C collapse-macro-debuginfo`]: ../../rustc/codegen-options/index.html#collapse-macro-debuginfo
207+
[`macro_rules` definition]: ../macros-by-example.md
186208
[attribute]: ../attributes.md

0 commit comments

Comments
 (0)