diff options
| author | lcnr <rust@lcnr.de> | 2024-02-26 10:46:57 +0100 |
|---|---|---|
| committer | lcnr <rust@lcnr.de> | 2024-02-26 11:01:31 +0100 |
| commit | 1c264ca9cafaa06d529ce2d701559e9da982023c (patch) | |
| tree | cba8451cdd2c62cb8ecce4bbab0956a6999a787a | |
| parent | 2c7ede8f52fb2d861ab875ac44ddd88850315cc6 (diff) | |
| download | rust-1c264ca9cafaa06d529ce2d701559e9da982023c.tar.gz rust-1c264ca9cafaa06d529ce2d701559e9da982023c.zip | |
add regression tests
| -rw-r--r-- | tests/ui/traits/next-solver/assembly/candidates-equal-modulo-norm-1.rs | 26 | ||||
| -rw-r--r-- | tests/ui/traits/next-solver/assembly/candidates-equal-modulo-norm-2.rs | 26 |
2 files changed, 52 insertions, 0 deletions
diff --git a/tests/ui/traits/next-solver/assembly/candidates-equal-modulo-norm-1.rs b/tests/ui/traits/next-solver/assembly/candidates-equal-modulo-norm-1.rs new file mode 100644 index 00000000000..3ac1639cfba --- /dev/null +++ b/tests/ui/traits/next-solver/assembly/candidates-equal-modulo-norm-1.rs @@ -0,0 +1,26 @@ +//@ compile-flags: -Znext-solver +//@ check-pass + +// Regression test for trait-system-refactor-initiative#84. +// +// We try to infer `T::Rigid: Into<?0>` and have 2 candidates from where-clauses: +// +// - `Into<String>` +// - `Into<<T::Rigid as Elaborate>::Assoc>` +// +// This causes ambiguity unless we normalize the alias in the second candidate +// to detect that they actually result in the same constraints. +trait Trait { + type Rigid: Elaborate<Assoc = String> + Into<String> + Default; +} + +trait Elaborate: Into<Self::Assoc> { + type Assoc; +} + +fn test<T: Trait>() { + let rigid: T::Rigid = Default::default(); + drop(rigid.into()); +} + +fn main() {} diff --git a/tests/ui/traits/next-solver/assembly/candidates-equal-modulo-norm-2.rs b/tests/ui/traits/next-solver/assembly/candidates-equal-modulo-norm-2.rs new file mode 100644 index 00000000000..a1b736184f1 --- /dev/null +++ b/tests/ui/traits/next-solver/assembly/candidates-equal-modulo-norm-2.rs @@ -0,0 +1,26 @@ +//@ compile-flags: -Znext-solver +//@ check-pass + +// Regression test for trait-system-refactor-initiative#86. This previously +// failed with ambiguity due to multiple candidates with different +// normalization. + +trait Bar { + type Item; + type Assoc: AsRef<[Self::Item]>; +} + +struct Foo<T: Bar> { + t: <T as Bar>::Assoc, +} + +impl<T: Bar<Item = u32>> Foo<T> +where + <T as Bar>::Assoc: AsRef<[u32]>, +{ + fn hello(&self) { + println!("{}", self.t.as_ref().len()); + } +} + +fn main() {} |
