fix: classify safe as a contextual kw

This commit is contained in:
roife 2024-10-21 02:56:21 +08:00
parent 1b90ae4892
commit 8183f6b473
5 changed files with 11 additions and 11 deletions

View File

@ -273,7 +273,7 @@ pub fn is_fn_unsafe_to_call(db: &dyn HirDatabase, func: FunctionId) -> bool {
!data.attrs.by_key(&sym::rustc_safe_intrinsic).exists() !data.attrs.by_key(&sym::rustc_safe_intrinsic).exists()
} else { } else {
// Extern items without `safe` modifier are always unsafe // Extern items without `safe` modifier are always unsafe
!db.function_data(func).is_safe() !data.is_safe()
} }
} }
_ => false, _ => false,

View File

@ -554,7 +554,7 @@ fn rustc_deprecated_safe_2024() {
r#" r#"
//- /ed2021.rs crate:ed2021 edition:2021 //- /ed2021.rs crate:ed2021 edition:2021
#[rustc_deprecated_safe_2024] #[rustc_deprecated_safe_2024]
unsafe fn safe_fn() -> u8 { unsafe fn safe() -> u8 {
0 0
} }
//- /ed2024.rs crate:ed2024 edition:2024 //- /ed2024.rs crate:ed2024 edition:2024
@ -564,7 +564,7 @@ unsafe fn not_safe() -> u8 {
} }
//- /main.rs crate:main deps:ed2021,ed2024 //- /main.rs crate:main deps:ed2021,ed2024
fn main() { fn main() {
ed2021::safe_fn(); ed2021::safe();
ed2024::not_safe(); ed2024::not_safe();
//^^^^^^^^^^^^^^^^^^💡 error: this operation is unsafe and requires an unsafe function or block //^^^^^^^^^^^^^^^^^^💡 error: this operation is unsafe and requires an unsafe function or block
} }

View File

@ -135,8 +135,8 @@ pub(super) fn opt_item(p: &mut Parser<'_>, m: Marker) -> Result<(), Marker> {
has_mods = true; has_mods = true;
} }
if p.at(T![safe]) { if p.at_contextual_kw(T![safe]) {
p.eat(T![safe]); p.eat_contextual_kw(T![safe]);
has_mods = true; has_mods = true;
} }

File diff suppressed because one or more lines are too long

View File

@ -111,7 +111,7 @@ fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) {
// keywords that are keywords only in specific parse contexts // keywords that are keywords only in specific parse contexts
#[doc(alias = "WEAK_KEYWORDS")] #[doc(alias = "WEAK_KEYWORDS")]
const CONTEXTUAL_KEYWORDS: &[&str] = const CONTEXTUAL_KEYWORDS: &[&str] =
&["macro_rules", "union", "default", "raw", "dyn", "auto", "yeet"]; &["macro_rules", "union", "default", "raw", "dyn", "auto", "yeet", "safe"];
// keywords we use for special macro expansions // keywords we use for special macro expansions
const CONTEXTUAL_BUILTIN_KEYWORDS: &[&str] = &[ const CONTEXTUAL_BUILTIN_KEYWORDS: &[&str] = &[
"asm", "asm",