Skip to content

Commit 6aeeb4e

Browse files
bors[bot]Veykril
andauthored
Merge #10603
10603: fix: Don't resolve attributes to non attribute macros r=Veykril a=Veykril Also changes `const`s to `static`s for `Limit`s as we have interior mutability in those(though only used with a certain feature flag enabled). Co-authored-by: Lukas Wirth <[email protected]>
2 parents 6877240 + ea2a2c5 commit 6aeeb4e

File tree

7 files changed

+38
-8
lines changed

7 files changed

+38
-8
lines changed

crates/hir_def/src/body.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ pub struct Expander {
5454
}
5555

5656
#[cfg(test)]
57-
const EXPANSION_RECURSION_LIMIT: Limit = Limit::new(32);
57+
static EXPANSION_RECURSION_LIMIT: Limit = Limit::new(32);
5858

5959
#[cfg(not(test))]
60-
const EXPANSION_RECURSION_LIMIT: Limit = Limit::new(128);
60+
static EXPANSION_RECURSION_LIMIT: Limit = Limit::new(128);
6161

6262
impl CfgExpander {
6363
pub(crate) fn new(

crates/hir_def/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,7 @@ fn attr_macro_as_call_id(
779779
resolver: impl Fn(path::ModPath) -> Option<MacroDefId>,
780780
) -> Result<MacroCallId, UnresolvedMacro> {
781781
let def: MacroDefId = resolver(item_attr.path.clone())
782+
.filter(MacroDefId::is_attribute)
782783
.ok_or_else(|| UnresolvedMacro { path: item_attr.path.clone() })?;
783784
let last_segment = item_attr
784785
.path

crates/hir_def/src/macro_expansion_tests/mbe.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1446,3 +1446,25 @@ fn f() {
14461446
"#]],
14471447
)
14481448
}
1449+
1450+
#[test]
1451+
fn mbe_are_not_attributes() {
1452+
check(
1453+
r#"
1454+
macro_rules! error {
1455+
() => {struct Bar}
1456+
}
1457+
1458+
#[error]
1459+
struct Foo;
1460+
"#,
1461+
expect![[r##"
1462+
macro_rules! error {
1463+
() => {struct Bar}
1464+
}
1465+
1466+
#[error]
1467+
struct Foo;
1468+
"##]],
1469+
)
1470+
}

crates/hir_def/src/nameres/collector.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ use crate::{
5050
UnresolvedMacro,
5151
};
5252

53-
const GLOB_RECURSION_LIMIT: Limit = Limit::new(100);
54-
const EXPANSION_DEPTH_LIMIT: Limit = Limit::new(128);
55-
const FIXED_POINT_LIMIT: Limit = Limit::new(8192);
53+
static GLOB_RECURSION_LIMIT: Limit = Limit::new(100);
54+
static EXPANSION_DEPTH_LIMIT: Limit = Limit::new(128);
55+
static FIXED_POINT_LIMIT: Limit = Limit::new(8192);
5656

5757
pub(super) fn collect_defs(
5858
db: &dyn DefDatabase,
@@ -1705,7 +1705,7 @@ impl ModCollector<'_, '_> {
17051705
/// Returns `Err` when some attributes could not be resolved to builtins and have been
17061706
/// registered as unresolved.
17071707
///
1708-
/// If `ignore_up_to` is `Some`, attributes precending and including that attribute will be
1708+
/// If `ignore_up_to` is `Some`, attributes preceding and including that attribute will be
17091709
/// assumed to be resolved already.
17101710
fn resolve_attributes(&mut self, attrs: &Attrs, mod_item: ModItem) -> Result<(), ()> {
17111711
let mut ignore_up_to =

crates/hir_expand/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,13 @@ impl MacroDefId {
306306
pub fn is_proc_macro(&self) -> bool {
307307
matches!(self.kind, MacroDefKind::ProcMacro(..))
308308
}
309+
310+
pub fn is_attribute(&self) -> bool {
311+
matches!(
312+
self.kind,
313+
MacroDefKind::BuiltInAttr(..) | MacroDefKind::ProcMacro(_, ProcMacroKind::Attr, _)
314+
)
315+
}
309316
}
310317

311318
// FIXME: attribute indices do not account for `cfg_attr`, which means that we'll strip the whole

crates/hir_ty/src/autoderef.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crate::{
1818
ProjectionTyExt, Solution, Substitution, Ty, TyBuilder, TyKind,
1919
};
2020

21-
const AUTODEREF_RECURSION_LIMIT: Limit = Limit::new(10);
21+
static AUTODEREF_RECURSION_LIMIT: Limit = Limit::new(10);
2222

2323
pub(crate) enum AutoderefKind {
2424
Builtin,

crates/ide_db/src/items_locator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crate::{
1818
};
1919

2020
/// A value to use, when uncertain which limit to pick.
21-
pub const DEFAULT_QUERY_SEARCH_LIMIT: Limit = Limit::new(40);
21+
pub static DEFAULT_QUERY_SEARCH_LIMIT: Limit = Limit::new(40);
2222

2323
/// Three possible ways to search for the name in associated and/or other items.
2424
#[derive(Debug, Clone, Copy)]

0 commit comments

Comments
 (0)