From 85b7d646cd9b2deb6e65b3bd4aa045a71a6415b4 Mon Sep 17 00:00:00 2001 From: Shoyu Vanilla Date: Mon, 27 Oct 2025 02:18:52 +0900 Subject: [PATCH] Add regression tests for some fixed `A-ty` issues --- .../hir-ty/src/tests/regression/new_solver.rs | 52 +++++++++++++++ .../src/handlers/mismatched_arg_count.rs | 23 +++++++ .../crates/ide/src/goto_definition.rs | 64 +++++++++++++++++++ 3 files changed, 139 insertions(+) diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/tests/regression/new_solver.rs b/src/tools/rust-analyzer/crates/hir-ty/src/tests/regression/new_solver.rs index 5983ec764790..f8b73cd50551 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/tests/regression/new_solver.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/tests/regression/new_solver.rs @@ -472,3 +472,55 @@ where "#, ); } + +#[test] +fn regression_16282() { + check_infer( + r#" +//- minicore: coerce_unsized, dispatch_from_dyn +trait MapLookup { + type MapValue; +} + +impl MapLookup for K { + type MapValue = K; +} + +trait Map: MapLookup<::Key> { + type Key; +} + +impl Map for K { + type Key = K; +} + + +fn main() { + let _ = &() + as &dyn Map; +} +"#, + expect![[r#" + 210..272 '{ ...32>; }': () + 220..221 '_': &'? (dyn Map + '?) + 224..227 '&()': &'? () + 224..269 '&() ...e=u32>': &'? (dyn Map + 'static) + 225..227 '()': () + "#]], + ); +} + +#[test] +fn regression_18692() { + check_no_mismatches( + r#" +//- minicore: coerce_unsized, dispatch_from_dyn, send +trait Trait: Send {} + +fn f(_: *const (dyn Trait + Send)) {} +fn g(it: *const (dyn Trait)) { + f(it); +} +"#, + ); +} diff --git a/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/mismatched_arg_count.rs b/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/mismatched_arg_count.rs index 25c1e633ba3b..4ed71f0d3fb8 100644 --- a/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/mismatched_arg_count.rs +++ b/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/mismatched_arg_count.rs @@ -485,6 +485,29 @@ fn foo((): (), (): ()) { foo(1); // ^ error: expected 2 arguments, found 1 } +"#, + ); + } + + #[test] + fn regression_17233() { + check_diagnostics( + r#" +pub trait A { + type X: B; +} +pub trait B: A { + fn confused_name(self, _: i32); +} + +pub struct Foo; +impl Foo { + pub fn confused_name(&self) {} +} + +pub fn repro() { + Foo.confused_name(); +} "#, ); } diff --git a/src/tools/rust-analyzer/crates/ide/src/goto_definition.rs b/src/tools/rust-analyzer/crates/ide/src/goto_definition.rs index e335989ab2b0..0ee9795af580 100644 --- a/src/tools/rust-analyzer/crates/ide/src/goto_definition.rs +++ b/src/tools/rust-analyzer/crates/ide/src/goto_definition.rs @@ -4015,4 +4015,68 @@ fn bar() { "##, ); } + + #[test] + fn regression_20038() { + check( + r#" +//- minicore: clone, fn +struct Map(Fut, F); + +struct InspectFn(F); + +trait FnOnce1 { + type Output; +} + +trait Future1 { + type Output; +} + +trait FusedFuture1: Future1 { + fn is_terminated(&self) -> bool; + //^^^^^^^^^^^^^ +} + +impl FnOnce1 for T +where + T: FnOnce(A) -> R, +{ + type Output = R; +} + +impl FnOnce1 for InspectFn +where + F: for<'a> FnOnce1<&'a A, Output = ()>, +{ + type Output = A; +} + +impl Future1 for Map +where + Fut: Future1, + F: FnOnce1, +{ + type Output = T; +} + +impl FusedFuture1 for Map +where + Fut: Future1, + F: FnOnce1, +{ + fn is_terminated(&self) -> bool { + false + } +} + +fn overflows(inner: &Map>) +where + Map>: FusedFuture1 +{ + let _x = inner.is_terminated$0(); +} +"#, + ) + } }