Skip to content

Commit a6c8098

Browse files
Merge #6798
6798: Ignore extern items in incorrect-case check r=jonas-schievink a=jonas-schievink Fixes #6736 bors r+ Co-authored-by: Jonas Schievink <[email protected]>
2 parents bd78578 + 05d4a5a commit a6c8098

File tree

5 files changed

+43
-446
lines changed

5 files changed

+43
-446
lines changed

crates/hir_def/src/data.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ pub struct FunctionData {
2828
pub has_body: bool,
2929
pub is_unsafe: bool,
3030
pub is_varargs: bool,
31+
pub is_extern: bool,
3132
pub visibility: RawVisibility,
3233
}
3334

@@ -46,6 +47,7 @@ impl FunctionData {
4647
has_body: func.has_body,
4748
is_unsafe: func.is_unsafe,
4849
is_varargs: func.is_varargs,
50+
is_extern: func.is_extern,
4951
visibility: item_tree[func.visibility].clone(),
5052
})
5153
}
@@ -191,6 +193,7 @@ pub struct StaticData {
191193
pub type_ref: TypeRef,
192194
pub visibility: RawVisibility,
193195
pub mutable: bool,
196+
pub is_extern: bool,
194197
}
195198

196199
impl StaticData {
@@ -204,6 +207,7 @@ impl StaticData {
204207
type_ref: statik.type_ref.clone(),
205208
visibility: item_tree[statik.visibility].clone(),
206209
mutable: statik.mutable,
210+
is_extern: statik.is_extern,
207211
})
208212
}
209213
}

crates/hir_def/src/item_tree.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
//! A simplified AST that only contains items.
22
33
mod lower;
4-
#[cfg(test)]
5-
mod tests;
64

75
use std::{
86
any::type_name,
@@ -507,6 +505,9 @@ pub struct Function {
507505
pub has_self_param: bool,
508506
pub has_body: bool,
509507
pub is_unsafe: bool,
508+
/// Whether the function is located in an `extern` block (*not* whether it is an
509+
/// `extern "abi" fn`).
510+
pub is_extern: bool,
510511
pub params: Box<[TypeRef]>,
511512
pub is_varargs: bool,
512513
pub ret_type: TypeRef,
@@ -565,6 +566,8 @@ pub struct Static {
565566
pub name: Name,
566567
pub visibility: RawVisibilityId,
567568
pub mutable: bool,
569+
/// Whether the static is in an `extern` block.
570+
pub is_extern: bool,
568571
pub type_ref: TypeRef,
569572
pub ast_id: FileAstId<ast::Static>,
570573
}

crates/hir_def/src/item_tree/lower.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ impl Ctx {
340340
has_self_param,
341341
has_body,
342342
is_unsafe: func.unsafe_token().is_some(),
343+
is_extern: false,
343344
params: params.into_boxed_slice(),
344345
is_varargs,
345346
ret_type,
@@ -378,7 +379,7 @@ impl Ctx {
378379
let visibility = self.lower_visibility(static_);
379380
let mutable = static_.mut_token().is_some();
380381
let ast_id = self.source_ast_id_map.ast_id(static_);
381-
let res = Static { name, visibility, mutable, type_ref, ast_id };
382+
let res = Static { name, visibility, mutable, type_ref, ast_id, is_extern: false };
382383
Some(id(self.data().statics.alloc(res)))
383384
}
384385

@@ -554,13 +555,15 @@ impl Ctx {
554555
let attrs = Attrs::new(&item, &self.hygiene);
555556
let id: ModItem = match item {
556557
ast::ExternItem::Fn(ast) => {
557-
let func = self.lower_function(&ast)?;
558-
self.data().functions[func.index].is_unsafe =
559-
is_intrinsic_fn_unsafe(&self.data().functions[func.index].name);
560-
func.into()
558+
let func_id = self.lower_function(&ast)?;
559+
let func = &mut self.data().functions[func_id.index];
560+
func.is_unsafe = is_intrinsic_fn_unsafe(&func.name);
561+
func.is_extern = true;
562+
func_id.into()
561563
}
562564
ast::ExternItem::Static(ast) => {
563565
let statik = self.lower_static(&ast)?;
566+
self.data().statics[statik.index].is_extern = true;
564567
statik.into()
565568
}
566569
ast::ExternItem::TypeAlias(ty) => {

0 commit comments

Comments
 (0)