From 4ba683ee529ed87cc52d4983492dbf89b495ca0f Mon Sep 17 00:00:00 2001 From: Skgland Date: Sat, 3 May 2025 22:36:17 +0200 Subject: [PATCH 1/3] 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 0000000000000..50deb013d4b1e --- /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 0000000000000..d018a2c485452 --- /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`. From 7fc84ac964b45955cc9beb7ec269d3d06a3591ab Mon Sep 17 00:00:00 2001 From: Skgland Date: Mon, 5 May 2025 20:40:44 +0200 Subject: [PATCH 2/3] expand comment --- .../type-inference/regression-issue-81317.rs | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/ui/type-inference/regression-issue-81317.rs b/tests/ui/type-inference/regression-issue-81317.rs index 50deb013d4b1e..39c91948426b0 100644 --- a/tests/ui/type-inference/regression-issue-81317.rs +++ b/tests/ui/type-inference/regression-issue-81317.rs @@ -1,4 +1,33 @@ // Regression test for #81317: type can no longer be infered as of 1.49 +// +// The problem is that the xor operator and the index.into() each have two candidate impls that could apply +// { S as BitXor, S as BitXor<&'a S> } for xor and +// { T::I as Into, T::I as Into } for index.into() +// previously inference was able to infer that the only valid combination was +// S as BitXor and T::I as Into +// +// after rust-lang/rust#73905 this is no longer infered +// +// the error message could be better e.g. when iv is unused or has an an explicitly specified type S +// there is currently the following help message +// +// error[E0284]: type annotations needed +// --> src/main.rs:13:24 +// | +// 42 | let iv = S ^ index.into(); +// | - ^^^^ +// | | +// | type must be known at this point +// | +// = note: cannot satisfy `>::Output == _` +// help: try using a fully qualified path to specify the expected types +// | +// 42 - let iv = S ^ index.into(); +// 42 + let iv = S ^ <::I as Into>::into(index); +// +// this is better as it's actually sufficent to fix the problem, +// while just specifying the type of iv as currently suggested is insufficent +// //@ check-fail use std::ops::BitXor; From fb8784585eece42a22c782bb01c1c2f188f70505 Mon Sep 17 00:00:00 2001 From: Skgland Date: Mon, 5 May 2025 21:09:31 +0200 Subject: [PATCH 3/3] fix tidy and bless test --- tests/ui/type-inference/regression-issue-81317.rs | 12 +++++++----- .../ui/type-inference/regression-issue-81317.stderr | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/ui/type-inference/regression-issue-81317.rs b/tests/ui/type-inference/regression-issue-81317.rs index 39c91948426b0..0b1266e6a0fd2 100644 --- a/tests/ui/type-inference/regression-issue-81317.rs +++ b/tests/ui/type-inference/regression-issue-81317.rs @@ -1,6 +1,7 @@ // Regression test for #81317: type can no longer be infered as of 1.49 // -// The problem is that the xor operator and the index.into() each have two candidate impls that could apply +// The problem is that the xor operator and the index.into() call +// each have two candidate impls that could apply // { S as BitXor, S as BitXor<&'a S> } for xor and // { T::I as Into, T::I as Into } for index.into() // previously inference was able to infer that the only valid combination was @@ -8,13 +9,14 @@ // // after rust-lang/rust#73905 this is no longer infered // -// the error message could be better e.g. when iv is unused or has an an explicitly specified type S +// the error message could be better e.g. +// when iv is unused or has an an explicitly specified type S // there is currently the following help message // // error[E0284]: type annotations needed // --> src/main.rs:13:24 // | -// 42 | let iv = S ^ index.into(); +// 44 | let iv = S ^ index.into(); // | - ^^^^ // | | // | type must be known at this point @@ -22,8 +24,8 @@ // = note: cannot satisfy `>::Output == _` // help: try using a fully qualified path to specify the expected types // | -// 42 - let iv = S ^ index.into(); -// 42 + let iv = S ^ <::I as Into>::into(index); +// 44 - let iv = S ^ index.into(); +// 44 + let iv = S ^ <::I as Into>::into(index); // // this is better as it's actually sufficent to fix the problem, // while just specifying the type of iv as currently suggested is insufficent diff --git a/tests/ui/type-inference/regression-issue-81317.stderr b/tests/ui/type-inference/regression-issue-81317.stderr index d018a2c485452..fcd3fca06e18b 100644 --- a/tests/ui/type-inference/regression-issue-81317.stderr +++ b/tests/ui/type-inference/regression-issue-81317.stderr @@ -1,5 +1,5 @@ error[E0282]: type annotations needed - --> $DIR/regression-issue-81317.rs:13:9 + --> $DIR/regression-issue-81317.rs:44:9 | LL | let iv = S ^ index.into(); | ^^