Skip to content

Commit 451cc1b

Browse files
authored
Unrolled build for rust-lang#140632
Rollup merge of rust-lang#140632 - Skgland:test-for-issue-81317, r=oli-obk add a test for issue rust-lang#81317 closes rust-lang#81317
2 parents f5d3fe2 + fb87845 commit 451cc1b

File tree

2 files changed

+88
-0
lines changed

2 files changed

+88
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Regression test for #81317: type can no longer be infered as of 1.49
2+
//
3+
// The problem is that the xor operator and the index.into() call
4+
// each have two candidate impls that could apply
5+
// { S as BitXor<S>, S as BitXor<&'a S> } for xor and
6+
// { T::I as Into<u64>, T::I as Into<S> } for index.into()
7+
// previously inference was able to infer that the only valid combination was
8+
// S as BitXor<S> and T::I as Into<S>
9+
//
10+
// after rust-lang/rust#73905 this is no longer infered
11+
//
12+
// the error message could be better e.g.
13+
// when iv is unused or has an an explicitly specified type S
14+
// there is currently the following help message
15+
//
16+
// error[E0284]: type annotations needed
17+
// --> src/main.rs:13:24
18+
// |
19+
// 44 | let iv = S ^ index.into();
20+
// | - ^^^^
21+
// | |
22+
// | type must be known at this point
23+
// |
24+
// = note: cannot satisfy `<S as BitXor<_>>::Output == _`
25+
// help: try using a fully qualified path to specify the expected types
26+
// |
27+
// 44 - let iv = S ^ index.into();
28+
// 44 + let iv = S ^ <<T as P>::I as Into<T>>::into(index);
29+
//
30+
// this is better as it's actually sufficent to fix the problem,
31+
// while just specifying the type of iv as currently suggested is insufficent
32+
//
33+
//@ check-fail
34+
35+
use std::ops::BitXor;
36+
37+
pub struct S;
38+
39+
pub trait P {
40+
type I: Into<u64> + Into<S>;
41+
}
42+
43+
pub fn decrypt_portion<T: P>(index: T::I) {
44+
let iv = S ^ index.into();
45+
//~^ ERROR type annotations needed
46+
&iv.to_bytes_be();
47+
}
48+
49+
impl S {
50+
fn to_bytes_be(&self) -> &[u8] {
51+
&[]
52+
}
53+
}
54+
55+
impl BitXor for S {
56+
type Output = S;
57+
58+
fn bitxor(self, _rhs: Self) -> Self::Output {
59+
S
60+
}
61+
}
62+
63+
impl<'a> BitXor<&'a S> for S {
64+
type Output = S;
65+
66+
fn bitxor(self, _rhs: &'a S) -> Self::Output {
67+
S
68+
}
69+
}
70+
71+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0282]: type annotations needed
2+
--> $DIR/regression-issue-81317.rs:44:9
3+
|
4+
LL | let iv = S ^ index.into();
5+
| ^^
6+
LL |
7+
LL | &iv.to_bytes_be();
8+
| -- type must be known at this point
9+
|
10+
help: consider giving `iv` an explicit type
11+
|
12+
LL | let iv: /* Type */ = S ^ index.into();
13+
| ++++++++++++
14+
15+
error: aborting due to 1 previous error
16+
17+
For more information about this error, try `rustc --explain E0282`.

0 commit comments

Comments
 (0)