|
| 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() {} |
0 commit comments