Auto merge of #12916 - Veykril:nits, r=Veykril

minor: Properly cfg the `max` field of Limit
This commit is contained in:
bors 2022-07-31 17:42:10 +00:00
commit af646621de
2 changed files with 19 additions and 9 deletions

View File

@ -1055,7 +1055,7 @@ impl DefCollector<'_> {
};
let mut res = ReachedFixedPoint::Yes;
macros.retain(|directive| {
let resolver2 = |path| {
let resolver = |path| {
let resolved_res = self.def_map.resolve_path_fp_with_macro(
self.db,
ResolveMode::Other,
@ -1068,7 +1068,7 @@ impl DefCollector<'_> {
.take_macros()
.map(|it| (it, macro_id_to_def_id(self.db, it)))
};
let resolver = |path| resolver2(path).map(|(_, it)| it);
let resolver_def_id = |path| resolver(path).map(|(_, it)| it);
match &directive.kind {
MacroDirectiveKind::FnLike { ast_id, expand_to } => {
@ -1077,7 +1077,7 @@ impl DefCollector<'_> {
ast_id,
*expand_to,
self.def_map.krate,
&resolver,
&resolver_def_id,
&mut |_err| (),
);
if let Ok(Ok(call_id)) = call_id {
@ -1093,7 +1093,7 @@ impl DefCollector<'_> {
*derive_attr,
*derive_pos as u32,
self.def_map.krate,
&resolver2,
&resolver,
);
if let Ok((macro_id, def_id, call_id)) = id {
@ -1158,7 +1158,7 @@ impl DefCollector<'_> {
}
}
let def = match resolver(path.clone()) {
let def = match resolver_def_id(path.clone()) {
Some(def) if def.is_attribute() => def,
_ => return true,
};
@ -1292,7 +1292,8 @@ impl DefCollector<'_> {
true
});
// Attribute resolution can add unresolved macro invocations, so concatenate the lists.
self.unresolved_macros.extend(macros);
macros.extend(mem::take(&mut self.unresolved_macros));
self.unresolved_macros = macros;
for (module_id, depth, container, macro_call_id) in resolved {
self.collect_macro_expansion(module_id, macro_call_id, depth, container);

View File

@ -2,12 +2,13 @@
#![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)]
#[cfg(feature = "tracking")]
use std::sync::atomic::AtomicUsize;
/// Represents a struct used to enforce a numerical limit.
pub struct Limit {
upper_bound: usize,
#[allow(unused)]
#[cfg(feature = "tracking")]
max: AtomicUsize,
}
@ -15,14 +16,22 @@ impl Limit {
/// Creates a new limit.
#[inline]
pub const fn new(upper_bound: usize) -> Self {
Self { upper_bound, max: AtomicUsize::new(0) }
Self {
upper_bound,
#[cfg(feature = "tracking")]
max: AtomicUsize::new(0),
}
}
/// Creates a new limit.
#[inline]
#[cfg(feature = "tracking")]
pub const fn new_tracking(upper_bound: usize) -> Self {
Self { upper_bound, max: AtomicUsize::new(1) }
Self {
upper_bound,
#[cfg(feature = "tracking")]
max: AtomicUsize::new(1),
}
}
/// Gets the underlying numeric limit.