File tree 1 file changed +25
-3
lines changed
src/tools/rust-analyzer/crates/ide-completion/src
1 file changed +25
-3
lines changed Original file line number Diff line number Diff line change @@ -628,11 +628,9 @@ fn compute_ref_match(
628
628
let expected_type = ctx. expected_type . as_ref ( ) ?;
629
629
let expected_without_ref = expected_type. remove_ref ( ) ;
630
630
let completion_without_ref = completion_ty. remove_ref ( ) ;
631
-
632
- if completion_ty == expected_type {
631
+ if expected_type. could_unify_with ( ctx. db , completion_ty) {
633
632
return None ;
634
633
}
635
-
636
634
if let Some ( expected_without_ref) = & expected_without_ref {
637
635
if completion_ty. autoderef ( ctx. db ) . any ( |ty| ty == * expected_without_ref) {
638
636
cov_mark:: hit!( suggest_ref) ;
@@ -2007,6 +2005,30 @@ fn f() {
2007
2005
) ;
2008
2006
}
2009
2007
2008
+ #[ test]
2009
+ fn test_avoid_redundant_suggestion ( ) {
2010
+ check_relevance (
2011
+ r#"
2012
+ struct aa([u8]);
2013
+
2014
+ impl aa {
2015
+ fn from_bytes(bytes: &[u8]) -> &Self {
2016
+ unsafe { &*(bytes as *const [u8] as *const aa) }
2017
+ }
2018
+ }
2019
+
2020
+ fn bb()-> &'static aa {
2021
+ let bytes = b"hello";
2022
+ aa::$0
2023
+ }
2024
+ "# ,
2025
+ expect ! [ [ r#"
2026
+ ex bb() [type]
2027
+ fn from_bytes(…) fn(&[u8]) -> &aa [type_could_unify]
2028
+ "# ] ] ,
2029
+ ) ;
2030
+ }
2031
+
2010
2032
#[ test]
2011
2033
fn suggest_ref_mut ( ) {
2012
2034
cov_mark:: check!( suggest_ref) ;
You can’t perform that action at this time.
0 commit comments