Anonymous constants should not be included in the Structure View
#7 221 ouverte le 13 mai 2021
Métriques du dépôt
- Stars
- (4 526 étoiles)
- Métriques de merge PR
- (Métriques PR en attente)
Description
Environment
- IntelliJ Rust plugin version: 0.3.146.3826-211
- Rust toolchain version: 1.54.0-nightly (bacf770f2 2021-05-05) x86_64-unknown-linux-gnu
- IDE name and version: CLion 2021.1 (CL-211.6693.114)
- Operating system: Linux 5.4.0-72-generic
- Macro expansion engine: new
- Name resolution engine: new
Problem description
Currently anonymous constants (i.e. of the form const _: T = value;) are included in the structure view. This is meaningless: such constants cannot be used in any way and exist solely for compile-time assertions. The static_assertions crate uses them extensively, and a module with many assertions will be polluted by many meaningless constant definitions.
Steps to reproduce
Add static_assertions crate to the dependencies. In any module write
static_assertions::const_assert_eq!(0, 1 - 1);
The structure view gets a new entry of the form null: [{}; {}]. These nameless entries should not be added.
The reason the nameless constant is added is that the above macro expands to the following code:
#[allow(unknown_lints, eq_op)]
const _: [(); 0 - !{
const ASSERT: bool = (0 == (1 - 1));
ASSERT
} as usize] = [];
which statically checks the equality of terms in the macro.
Similar anonymous constants are added for most other macros in static_assertions, such as assert_eq_size, assert_impl_one or assert_obj_safe.