diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2025-05-06 14:50:46 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-05-06 14:50:46 +0200 |
| commit | 3501842edbce26248b423a9652bb9b5879cd3d91 (patch) | |
| tree | ecb041ec07a7740a0a5191ae9739637a880dd302 | |
| parent | a92ba60d0f88975461c1d98659c70ecf4de1bb82 (diff) | |
| parent | fb8784585eece42a22c782bb01c1c2f188f70505 (diff) | |
| download | rust-3501842edbce26248b423a9652bb9b5879cd3d91.tar.gz rust-3501842edbce26248b423a9652bb9b5879cd3d91.zip | |
Rollup merge of #140632 - Skgland:test-for-issue-81317, r=oli-obk
add a test for issue rust-lang/rust#81317 closes rust-lang/rust#81317
| -rw-r--r-- | tests/ui/type-inference/regression-issue-81317.rs | 71 | ||||
| -rw-r--r-- | tests/ui/type-inference/regression-issue-81317.stderr | 17 |
2 files changed, 88 insertions, 0 deletions
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 00000000000..0b1266e6a0f --- /dev/null +++ b/tests/ui/type-inference/regression-issue-81317.rs @@ -0,0 +1,71 @@ +// 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() call +// each have two candidate impls that could apply +// { S as BitXor<S>, S as BitXor<&'a S> } for xor and +// { T::I as Into<u64>, T::I as Into<S> } for index.into() +// previously inference was able to infer that the only valid combination was +// S as BitXor<S> and T::I as Into<S> +// +// 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 +// | +// 44 | let iv = S ^ index.into(); +// | - ^^^^ +// | | +// | type must be known at this point +// | +// = note: cannot satisfy `<S as BitXor<_>>::Output == _` +// help: try using a fully qualified path to specify the expected types +// | +// 44 - let iv = S ^ index.into(); +// 44 + let iv = S ^ <<T as P>::I as Into<T>>::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; + +pub struct S; + +pub trait P { + type I: Into<u64> + Into<S>; +} + +pub fn decrypt_portion<T: P>(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 00000000000..fcd3fca06e1 --- /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:44: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`. |
