1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
//! Variable declaration information.
#[cfg(feature = "no_std")]
use std::prelude::v1::*;
/// Information on a variable declaration.
#[derive(Debug, Clone, Hash)]
pub struct VarDefInfo<'a> {
/// Name of the variable to be declared.
///
/// # Deprecated API
///
/// [`VarDefInfo`] fields will be private in the next major version. Use `name()` instead.
#[deprecated(
since = "1.16.0",
note = "`VarDefInfo` fields will be private in the next major version. Use `name()` instead."
)]
pub name: &'a str,
/// `true` if the statement is `const`, otherwise it is `let`.
///
/// # Deprecated API
///
/// [`VarDefInfo`] fields will be private in the next major version. Use `is_const()` instead.
#[deprecated(
since = "1.16.0",
note = "`VarDefInfo` fields will be private in the next major version. Use `is_const()` instead."
)]
pub is_const: bool,
/// The current nesting level, with zero being the global level.
///
/// # Deprecated API
///
/// [`VarDefInfo`] fields will be private in the next major version. Use `nesting_level()` instead.
#[deprecated(
since = "1.16.0",
note = "`VarDefInfo` fields will be private in the next major version. Use `nesting_level()` instead."
)]
pub nesting_level: usize,
/// Will the variable _shadow_ an existing variable?
///
/// # Deprecated API
///
/// [`VarDefInfo`] fields will be private in the next major version. Use `will_shadow_other_variables()` instead.
#[deprecated(
since = "1.16.0",
note = "`VarDefInfo` fields will be private in the next major version. Use `will_shadow_other_variables()` instead."
)]
pub will_shadow: bool,
}
#[allow(deprecated)]
impl<'a> VarDefInfo<'a> {
/// Create a new [`VarDefInfo`].
#[inline(always)]
#[must_use]
pub(crate) const fn new(
name: &'a str,
is_const: bool,
nesting_level: usize,
will_shadow: bool,
) -> Self {
Self {
name,
is_const,
nesting_level,
will_shadow,
}
}
/// Name of the variable to be declared.
#[inline(always)]
#[must_use]
pub const fn name(&self) -> &str {
self.name
}
/// `true` if the statement is `const`, otherwise it is `let`.
#[inline(always)]
#[must_use]
pub const fn is_const(&self) -> bool {
self.is_const
}
/// The current nesting level, with zero being the global level.
#[inline(always)]
#[must_use]
pub const fn nesting_level(&self) -> usize {
self.nesting_level
}
/// `true` if the variable is declared at global level (i.e. nesting level zero).
#[inline(always)]
#[must_use]
pub const fn is_global_level(&self) -> bool {
self.nesting_level == 0
}
/// Will the variable _shadow_ an existing variable?
#[inline(always)]
#[must_use]
pub const fn will_shadow_other_variables(&self) -> bool {
self.will_shadow
}
}