From 0623bb4d71725d6b07e8cef5665094581f951fc0 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sat, 20 Mar 2021 15:26:42 +0100 Subject: Test for a Salsa bug --- crates/hir_ty/src/tests/traits.rs | 51 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'crates/hir_ty/src/tests') diff --git a/crates/hir_ty/src/tests/traits.rs b/crates/hir_ty/src/tests/traits.rs index 8f2bdffc0..1bb6dff95 100644 --- a/crates/hir_ty/src/tests/traits.rs +++ b/crates/hir_ty/src/tests/traits.rs @@ -2271,6 +2271,57 @@ fn test() where T: Trait, U: Trait { ); } +#[test] +fn unselected_projection_in_trait_env_cycle_3() { + // this is a cycle, although it would be possible to handle if we didn't go + // into bindings when looking for traits + check_types( + r#" +//- /main.rs +trait Trait { + type Item; + type OtherItem; +} + +fn test() where T: Trait { + let x: T::Item = no_matter; +} //^ {unknown} +"#, + ); +} + +#[test] +fn unselected_projection_in_trait_env_no_cycle() { + // this is not a cycle + check_types( + r#" +//- /main.rs +trait Index { + type Output; +} + +type Key = ::Key; + +pub trait UnificationStoreBase: Index> { + type Key; + + fn len(&self) -> usize; +} + +pub trait UnificationStoreMut: UnificationStoreBase { + fn push(&mut self, value: Self::Key); +} + +fn test(t: T) where T: UnificationStoreMut { + let x; + t.push(x); + let y: Key; + (x, y); +} //^ (UnificationStoreBase::Key, UnificationStoreBase::Key) +"#, + ); +} + #[test] fn inline_assoc_type_bounds_1() { check_types( -- cgit v1.2.3 From d8f8b495ad5c9e3676ddf7af53b23bb5b7f2fde0 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sat, 20 Mar 2021 20:07:36 +0100 Subject: Ignore type bindings in generic_predicates_for_param This allows us to handle more cases without a query cycle, which includes certain cases that rustc accepted. That in turn means we avoid triggering salsa-rs/salsa#257 on valid code (it will still happen if the user writes an actual cycle). We actually accept more definitions than rustc now; that's because rustc only ignores bindings when looking up super traits, whereas we now also ignore them when looking for predicates to disambiguate associated type shorthand. We could introduce a separate query for super traits if necessary, but for now I think this should be fine. --- crates/hir_ty/src/tests/traits.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'crates/hir_ty/src/tests') diff --git a/crates/hir_ty/src/tests/traits.rs b/crates/hir_ty/src/tests/traits.rs index 1bb6dff95..37cd04c6f 100644 --- a/crates/hir_ty/src/tests/traits.rs +++ b/crates/hir_ty/src/tests/traits.rs @@ -2273,8 +2273,7 @@ fn test() where T: Trait, U: Trait { #[test] fn unselected_projection_in_trait_env_cycle_3() { - // this is a cycle, although it would be possible to handle if we didn't go - // into bindings when looking for traits + // this is a cycle for rustc; we currently accept it check_types( r#" //- /main.rs @@ -2285,7 +2284,7 @@ trait Trait { fn test() where T: Trait { let x: T::Item = no_matter; -} //^ {unknown} +} //^ Trait::Item "#, ); } -- cgit v1.2.3