From 4ba683ee529ed87cc52d4983492dbf89b495ca0f Mon Sep 17 00:00:00 2001 From: Skgland Date: Sat, 3 May 2025 22:36:17 +0200 Subject: [PATCH] add a test for issue rust-lang/rust#81317 --- .../type-inference/regression-issue-81317.rs | 40 +++++++++++++++++++ .../regression-issue-81317.stderr | 17 ++++++++ 2 files changed, 57 insertions(+) create mode 100644 tests/ui/type-inference/regression-issue-81317.rs create mode 100644 tests/ui/type-inference/regression-issue-81317.stderr diff --git a/tests/ui/type-inference/regression-issue-81317.rs b/tests/ui/type-inference/regression-issue-81317.rs new file mode 100644 index 000000000000..50deb013d4b1 --- /dev/null +++ b/tests/ui/type-inference/regression-issue-81317.rs @@ -0,0 +1,40 @@ +// Regression test for #81317: type can no longer be infered as of 1.49 +//@ check-fail + +use std::ops::BitXor; + +pub struct S; + +pub trait P { + type I: Into + Into; +} + +pub fn decrypt_portion(index: T::I) { + let iv = S ^ index.into(); + //~^ ERROR type annotations needed + &iv.to_bytes_be(); +} + +impl S { + fn to_bytes_be(&self) -> &[u8] { + &[] + } +} + +impl BitXor for S { + type Output = S; + + fn bitxor(self, _rhs: Self) -> Self::Output { + S + } +} + +impl<'a> BitXor<&'a S> for S { + type Output = S; + + fn bitxor(self, _rhs: &'a S) -> Self::Output { + S + } +} + +fn main() {} diff --git a/tests/ui/type-inference/regression-issue-81317.stderr b/tests/ui/type-inference/regression-issue-81317.stderr new file mode 100644 index 000000000000..d018a2c48545 --- /dev/null +++ b/tests/ui/type-inference/regression-issue-81317.stderr @@ -0,0 +1,17 @@ +error[E0282]: type annotations needed + --> $DIR/regression-issue-81317.rs:13:9 + | +LL | let iv = S ^ index.into(); + | ^^ +LL | +LL | &iv.to_bytes_be(); + | -- type must be known at this point + | +help: consider giving `iv` an explicit type + | +LL | let iv: /* Type */ = S ^ index.into(); + | ++++++++++++ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0282`.