mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 05:15:04 +00:00
Don't highlight unsafe traits as unsafe in safe impls
This commit is contained in:
parent
64fb7be247
commit
33cdc21832
12 changed files with 44 additions and 56 deletions
|
@ -89,8 +89,6 @@ fn str() {
|
|||
str();
|
||||
}
|
||||
|
||||
static mut STATIC_MUT: i32 = 0;
|
||||
|
||||
fn foo<'a, T>() -> T {
|
||||
foo::<'a, i32>()
|
||||
}
|
||||
|
@ -158,10 +156,6 @@ fn main() {
|
|||
let x = 92;
|
||||
vec.push(Foo { x, y: 1 });
|
||||
}
|
||||
unsafe {
|
||||
vec.set_len(0);
|
||||
STATIC_MUT = 1;
|
||||
}
|
||||
|
||||
for e in vec {
|
||||
// Do nothing
|
||||
|
@ -229,9 +223,6 @@ async fn async_main() {
|
|||
futures::join!(f1, f2);
|
||||
}
|
||||
|
||||
unsafe trait Dangerous {}
|
||||
impl Dangerous for () {}
|
||||
|
||||
fn use_foo_items() {
|
||||
let bob = foo::Person {
|
||||
name: "Bob",
|
||||
|
@ -514,6 +505,8 @@ fn main() {
|
|||
fn test_unsafe_highlighting() {
|
||||
check_highlighting(
|
||||
r#"
|
||||
static mut MUT_GLOBAL: Struct = Struct { field: 0 };
|
||||
static GLOBAL: Struct = Struct { field: 0 };
|
||||
unsafe fn unsafe_fn() {}
|
||||
|
||||
union Union {
|
||||
|
@ -521,18 +514,11 @@ union Union {
|
|||
b: f32,
|
||||
}
|
||||
|
||||
struct HasUnsafeFn;
|
||||
|
||||
impl HasUnsafeFn {
|
||||
struct Struct { field: i32 }
|
||||
impl Struct {
|
||||
unsafe fn unsafe_method(&self) {}
|
||||
}
|
||||
|
||||
struct TypeForStaticMut {
|
||||
a: u8
|
||||
}
|
||||
|
||||
static mut global_mut: TypeForStaticMut = TypeForStaticMut { a: 0 };
|
||||
|
||||
#[repr(packed)]
|
||||
struct Packed {
|
||||
a: u16,
|
||||
|
@ -540,8 +526,9 @@ struct Packed {
|
|||
|
||||
unsafe trait UnsafeTrait {}
|
||||
unsafe impl UnsafeTrait for Packed {}
|
||||
impl !UnsafeTrait for () {}
|
||||
|
||||
fn require_unsafe_trait<T: UnsafeTrait>(_: T) {}
|
||||
fn unsafe_trait_bound<T: UnsafeTrait>(_: T) {}
|
||||
|
||||
trait DoTheAutoref {
|
||||
fn calls_autoref(&self);
|
||||
|
@ -562,13 +549,14 @@ fn main() {
|
|||
Union { b: 0 } => (),
|
||||
Union { a } => (),
|
||||
}
|
||||
HasUnsafeFn.unsafe_method();
|
||||
Struct { field: 0 }.unsafe_method();
|
||||
|
||||
// unsafe deref
|
||||
let y = *x;
|
||||
*x;
|
||||
|
||||
// unsafe access to a static mut
|
||||
let a = global_mut.a;
|
||||
MUT_GLOBAL.field;
|
||||
GLOBAL.field;
|
||||
|
||||
// unsafe ref of packed fields
|
||||
let packed = Packed { a: 0 };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue