-
Notifications
You must be signed in to change notification settings - Fork 13.4k
add a test for issue rust-lang/rust#81317 #140632
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.