-
-
Notifications
You must be signed in to change notification settings - Fork 14.5k
Open
Labels
A-inferenceArea: Type inferenceArea: Type inferenceC-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.This issue may need triage. Remove it if it has been sufficiently triaged.
Description
Providing the unary operator (! or -) for a type T with the Output of different type results in inability to apply
this operator to the block returning this T (the compiler expects the value of type <T as UnaryOp>::Output be the return type of the block instead).
I tried this code:
struct Foo;
// the same problem persists for core::ops::Not
impl core::ops::Neg for Foo {
type Output = u8;
fn neg(self) -> Self::Output {
42
}
}
fn main() {
let x: u8 = core::ops::Neg::neg({
println!("Entered block in explicit function call");
Foo
});
println!("{x}");
let x: u8 = -{
println!("Entered block in sugared operator call");
Foo
};
}The first usage with operator in its explicit function form has no problem, while the second one fails with the error[E0308]: mismatched types.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-inferenceArea: Type inferenceArea: Type inferenceC-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.This issue may need triage. Remove it if it has been sufficiently triaged.