mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 21:05:02 +00:00
Determine function unsafety semantically
This commit is contained in:
parent
12f803d1e3
commit
5d8b4c40eb
12 changed files with 107 additions and 98 deletions
|
@ -26,16 +26,16 @@ impl HirDisplay for Function {
|
|||
fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> {
|
||||
let data = f.db.function_data(self.id);
|
||||
write_visibility(self.module(f.db).id, self.visibility(f.db), f)?;
|
||||
if data.is_default() {
|
||||
if data.has_default_kw() {
|
||||
f.write_str("default ")?;
|
||||
}
|
||||
if data.is_const() {
|
||||
if data.has_const_kw() {
|
||||
f.write_str("const ")?;
|
||||
}
|
||||
if data.is_async() {
|
||||
if data.has_async_kw() {
|
||||
f.write_str("async ")?;
|
||||
}
|
||||
if data.is_unsafe() {
|
||||
if self.is_unsafe_to_call(f.db) {
|
||||
f.write_str("unsafe ")?;
|
||||
}
|
||||
if let Some(abi) = &data.abi {
|
||||
|
@ -96,7 +96,7 @@ impl HirDisplay for Function {
|
|||
// `FunctionData::ret_type` will be `::core::future::Future<Output = ...>` for async fns.
|
||||
// Use ugly pattern match to strip the Future trait.
|
||||
// Better way?
|
||||
let ret_type = if !data.is_async() {
|
||||
let ret_type = if !data.has_async_kw() {
|
||||
&data.ret_type
|
||||
} else {
|
||||
match &*data.ret_type {
|
||||
|
|
|
@ -1421,16 +1421,16 @@ impl Function {
|
|||
.collect()
|
||||
}
|
||||
|
||||
pub fn is_unsafe(self, db: &dyn HirDatabase) -> bool {
|
||||
db.function_data(self.id).is_unsafe()
|
||||
}
|
||||
|
||||
pub fn is_const(self, db: &dyn HirDatabase) -> bool {
|
||||
db.function_data(self.id).is_const()
|
||||
db.function_data(self.id).has_const_kw()
|
||||
}
|
||||
|
||||
pub fn is_async(self, db: &dyn HirDatabase) -> bool {
|
||||
db.function_data(self.id).is_async()
|
||||
db.function_data(self.id).has_async_kw()
|
||||
}
|
||||
|
||||
pub fn is_unsafe_to_call(self, db: &dyn HirDatabase) -> bool {
|
||||
hir_ty::is_fn_unsafe_to_call(db, self.id)
|
||||
}
|
||||
|
||||
/// Whether this function declaration has a definition.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue