File tree Expand file tree Collapse file tree 2 files changed +18
-2
lines changed
src/tools/rust-analyzer/crates
ide-diagnostics/src/handlers Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -754,7 +754,7 @@ impl Module {
754754 GenericDef :: Impl ( impl_def) . diagnostics ( db, acc) ;
755755
756756 let loc = impl_def. id . lookup ( db) ;
757- let source_map = db. impl_signature_with_source_map ( impl_def. id ) . 1 ;
757+ let ( impl_signature , source_map) = db. impl_signature_with_source_map ( impl_def. id ) ;
758758 expr_store_diagnostics ( db, acc, & source_map) ;
759759
760760 let file_id = loc. id . file_id ;
@@ -783,10 +783,17 @@ impl Module {
783783 }
784784
785785 let trait_ = impl_def. trait_ ( db) ;
786- let trait_is_unsafe = trait_. is_some_and ( |t| t. is_unsafe ( db) ) ;
786+ let mut trait_is_unsafe = trait_. is_some_and ( |t| t. is_unsafe ( db) ) ;
787787 let impl_is_negative = impl_def. is_negative ( db) ;
788788 let impl_is_unsafe = impl_def. is_unsafe ( db) ;
789789
790+ let trait_is_unresolved = trait_. is_none ( ) && impl_signature. target_trait . is_some ( ) ;
791+ if trait_is_unresolved {
792+ // Ignore trait safety errors when the trait is unresolved, as otherwise we'll treat it as safe,
793+ // which may not be correct.
794+ trait_is_unsafe = impl_is_unsafe;
795+ }
796+
790797 let drop_maybe_dangle = ( || {
791798 // FIXME: This can be simplified a lot by exposing hir-ty's utils.rs::Generics helper
792799 let trait_ = trait_?;
Original file line number Diff line number Diff line change @@ -127,4 +127,13 @@ struct S;
127127"# ,
128128 ) ;
129129 }
130+
131+ #[ test]
132+ fn unsafe_unresolved_trait ( ) {
133+ check_diagnostics (
134+ r#"
135+ unsafe impl TestTrait for u32 {}
136+ "# ,
137+ ) ;
138+ }
130139}
You can’t perform that action at this time.
0 commit comments