mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
Ignore extern items in incorrect-case check
This commit is contained in:
parent
1341a98f05
commit
d82292e1ce
4 changed files with 36 additions and 5 deletions
|
@ -28,6 +28,7 @@ pub struct FunctionData {
|
|||
pub has_body: bool,
|
||||
pub is_unsafe: bool,
|
||||
pub is_varargs: bool,
|
||||
pub is_extern: bool,
|
||||
pub visibility: RawVisibility,
|
||||
}
|
||||
|
||||
|
@ -46,6 +47,7 @@ impl FunctionData {
|
|||
has_body: func.has_body,
|
||||
is_unsafe: func.is_unsafe,
|
||||
is_varargs: func.is_varargs,
|
||||
is_extern: func.is_extern,
|
||||
visibility: item_tree[func.visibility].clone(),
|
||||
})
|
||||
}
|
||||
|
@ -191,6 +193,7 @@ pub struct StaticData {
|
|||
pub type_ref: TypeRef,
|
||||
pub visibility: RawVisibility,
|
||||
pub mutable: bool,
|
||||
pub is_extern: bool,
|
||||
}
|
||||
|
||||
impl StaticData {
|
||||
|
@ -204,6 +207,7 @@ impl StaticData {
|
|||
type_ref: statik.type_ref.clone(),
|
||||
visibility: item_tree[statik.visibility].clone(),
|
||||
mutable: statik.mutable,
|
||||
is_extern: statik.is_extern,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -507,6 +507,9 @@ pub struct Function {
|
|||
pub has_self_param: bool,
|
||||
pub has_body: bool,
|
||||
pub is_unsafe: bool,
|
||||
/// Whether the function is located in an `extern` block (*not* whether it is an
|
||||
/// `extern "abi" fn`).
|
||||
pub is_extern: bool,
|
||||
pub params: Box<[TypeRef]>,
|
||||
pub is_varargs: bool,
|
||||
pub ret_type: TypeRef,
|
||||
|
@ -565,6 +568,8 @@ pub struct Static {
|
|||
pub name: Name,
|
||||
pub visibility: RawVisibilityId,
|
||||
pub mutable: bool,
|
||||
/// Whether the static is in an `extern` block.
|
||||
pub is_extern: bool,
|
||||
pub type_ref: TypeRef,
|
||||
pub ast_id: FileAstId<ast::Static>,
|
||||
}
|
||||
|
|
|
@ -340,6 +340,7 @@ impl Ctx {
|
|||
has_self_param,
|
||||
has_body,
|
||||
is_unsafe: func.unsafe_token().is_some(),
|
||||
is_extern: false,
|
||||
params: params.into_boxed_slice(),
|
||||
is_varargs,
|
||||
ret_type,
|
||||
|
@ -378,7 +379,7 @@ impl Ctx {
|
|||
let visibility = self.lower_visibility(static_);
|
||||
let mutable = static_.mut_token().is_some();
|
||||
let ast_id = self.source_ast_id_map.ast_id(static_);
|
||||
let res = Static { name, visibility, mutable, type_ref, ast_id };
|
||||
let res = Static { name, visibility, mutable, type_ref, ast_id, is_extern: false };
|
||||
Some(id(self.data().statics.alloc(res)))
|
||||
}
|
||||
|
||||
|
@ -554,13 +555,15 @@ impl Ctx {
|
|||
let attrs = Attrs::new(&item, &self.hygiene);
|
||||
let id: ModItem = match item {
|
||||
ast::ExternItem::Fn(ast) => {
|
||||
let func = self.lower_function(&ast)?;
|
||||
self.data().functions[func.index].is_unsafe =
|
||||
is_intrinsic_fn_unsafe(&self.data().functions[func.index].name);
|
||||
func.into()
|
||||
let func_id = self.lower_function(&ast)?;
|
||||
let func = &mut self.data().functions[func_id.index];
|
||||
func.is_unsafe = is_intrinsic_fn_unsafe(&func.name);
|
||||
func.is_extern = true;
|
||||
func_id.into()
|
||||
}
|
||||
ast::ExternItem::Static(ast) => {
|
||||
let statik = self.lower_static(&ast)?;
|
||||
self.data().statics[statik.index].is_extern = true;
|
||||
statik.into()
|
||||
}
|
||||
ast::ExternItem::TypeAlias(ty) => {
|
||||
|
|
|
@ -87,6 +87,10 @@ impl<'a, 'b> DeclValidator<'a, 'b> {
|
|||
|
||||
fn validate_func(&mut self, db: &dyn HirDatabase, func: FunctionId) {
|
||||
let data = db.function_data(func);
|
||||
if data.is_extern {
|
||||
return;
|
||||
}
|
||||
|
||||
let body = db.body(func.into());
|
||||
|
||||
// Recursively validate inner scope items, such as static variables and constants.
|
||||
|
@ -648,6 +652,9 @@ impl<'a, 'b> DeclValidator<'a, 'b> {
|
|||
|
||||
fn validate_static(&mut self, db: &dyn HirDatabase, static_id: StaticId) {
|
||||
let data = db.static_data(static_id);
|
||||
if data.is_extern {
|
||||
return;
|
||||
}
|
||||
|
||||
if self.allowed(db, static_id.into(), allow::NON_UPPER_CASE_GLOBAL) {
|
||||
return;
|
||||
|
@ -920,4 +927,16 @@ fn main() {
|
|||
"#,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ignores_extern_items() {
|
||||
check_diagnostics(
|
||||
r#"
|
||||
extern {
|
||||
fn NonSnakeCaseName(SOME_VAR: u8) -> u8;
|
||||
pub static SomeStatic: u8 = 10;
|
||||
}
|
||||
"#,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue