From fc1cb48d3b7e2fbf02bf9f98040b2af908cf30dc Mon Sep 17 00:00:00 2001 From: Chayim Refael Friedman Date: Sat, 27 Dec 2025 20:06:24 +0200 Subject: [PATCH] Fix tests that relied on the default variance to be invariant And now it changed to bivariant. --- .../crates/hir-ty/src/tests/traits.rs | 24 +++++++++---------- .../ide-completion/src/completions/dot.rs | 3 ++- .../crates/ide/src/inlay_hints/bind_pat.rs | 12 +++++----- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/tests/traits.rs b/src/tools/rust-analyzer/crates/hir-ty/src/tests/traits.rs index a54c0a799dfc..38591f486e97 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/tests/traits.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/tests/traits.rs @@ -851,7 +851,7 @@ fn obligation_from_impl_clause() { trait Trait {} impl Trait<&str> for S {} -struct O; +struct O(T); impl> O { fn foo(&self) -> U { loop {} } } @@ -1492,7 +1492,7 @@ fn dyn_trait_in_impl() { trait Trait { fn foo(&self) -> (T, U); } -struct S {} +struct S(T, U); impl S { fn bar(&self) -> &dyn Trait { loop {} } } @@ -1506,16 +1506,16 @@ fn test(s: S) { }"#, expect![[r#" 32..36 'self': &'? Self - 102..106 'self': &'? S - 128..139 '{ loop {} }': &'? (dyn Trait + 'static) - 130..137 'loop {}': ! - 135..137 '{}': () - 175..179 'self': &'? Self - 251..252 's': S - 267..289 '{ ...z(); }': () - 273..274 's': S - 273..280 's.bar()': &'? (dyn Trait + 'static) - 273..286 's.bar().baz()': (u32, i32) + 106..110 'self': &'? S + 132..143 '{ loop {} }': &'? (dyn Trait + 'static) + 134..141 'loop {}': ! + 139..141 '{}': () + 179..183 'self': &'? Self + 255..256 's': S + 271..293 '{ ...z(); }': () + 277..278 's': S + 277..284 's.bar()': &'? (dyn Trait + 'static) + 277..290 's.bar().baz()': (u32, i32) "#]], ); } diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/completions/dot.rs b/src/tools/rust-analyzer/crates/ide-completion/src/completions/dot.rs index 18cfa53f8e96..18c1992afa24 100644 --- a/src/tools/rust-analyzer/crates/ide-completion/src/completions/dot.rs +++ b/src/tools/rust-analyzer/crates/ide-completion/src/completions/dot.rs @@ -652,7 +652,7 @@ fn foo(u: U) { u.$0 } fn test_method_completion_only_fitting_impls() { check_no_kw( r#" -struct A {} +struct A(T); impl A { fn the_method(&self) {} } @@ -662,6 +662,7 @@ fn the_other_method(&self) {} fn foo(a: A) { a.$0 } "#, expect![[r#" + fd 0 u32 me the_method() fn(&self) "#]], ) diff --git a/src/tools/rust-analyzer/crates/ide/src/inlay_hints/bind_pat.rs b/src/tools/rust-analyzer/crates/ide/src/inlay_hints/bind_pat.rs index de207c7821da..547004687c73 100644 --- a/src/tools/rust-analyzer/crates/ide/src/inlay_hints/bind_pat.rs +++ b/src/tools/rust-analyzer/crates/ide/src/inlay_hints/bind_pat.rs @@ -339,14 +339,14 @@ pub fn quux() -> T::Bar { fn lt_hints() { check_types( r#" -struct S<'lt>; +struct S<'lt>(*mut &'lt ()); fn f<'a>() { - let x = S::<'static>; + let x = S::<'static>(loop {}); //^ S<'static> - let y = S::<'_>; + let y = S::<'_>(loop {}); //^ S<'_> - let z = S::<'a>; + let z = S::<'a>(loop {}); //^ S<'a> } @@ -632,10 +632,10 @@ fn main() { fn multi_dyn_trait_bounds() { check_types( r#" -pub struct Vec {} +pub struct Vec(*mut T); impl Vec { - pub fn new() -> Self { Vec {} } + pub fn new() -> Self { Vec(0 as *mut T) } } pub struct Box {}