-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Emit alias-eq when equating numeric var and projection #108828
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -148,10 +148,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | |
rhs_ty, | ||
op, | ||
); | ||
self.demand_suptype(expr.span, builtin_return_ty, return_ty); | ||
self.demand_eqtype(expr.span, builtin_return_ty, return_ty); | ||
builtin_return_ty | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But returning |
||
} else { | ||
return_ty | ||
} | ||
|
||
return_ty | ||
} | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -411,15 +411,28 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Canonicalizer<'cx, 'tcx> { | |
} | ||
} | ||
|
||
ty::Infer(ty::IntVar(_)) => self.canonicalize_ty_var( | ||
CanonicalVarInfo { kind: CanonicalVarKind::Ty(CanonicalTyVarKind::Int) }, | ||
t, | ||
), | ||
|
||
ty::Infer(ty::FloatVar(_)) => self.canonicalize_ty_var( | ||
CanonicalVarInfo { kind: CanonicalVarKind::Ty(CanonicalTyVarKind::Float) }, | ||
t, | ||
), | ||
ty::Infer(ty::IntVar(vid)) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We also needed to fix the canonicalizer bug for int and float vars as well... |
||
let nt = self.infcx.opportunistic_resolve_int_var(vid); | ||
if nt != t { | ||
return self.fold_ty(nt); | ||
} else { | ||
self.canonicalize_ty_var( | ||
CanonicalVarInfo { kind: CanonicalVarKind::Ty(CanonicalTyVarKind::Int) }, | ||
t, | ||
) | ||
} | ||
} | ||
ty::Infer(ty::FloatVar(vid)) => { | ||
let nt = self.infcx.opportunistic_resolve_float_var(vid); | ||
if nt != t { | ||
return self.fold_ty(nt); | ||
} else { | ||
self.canonicalize_ty_var( | ||
CanonicalVarInfo { kind: CanonicalVarKind::Ty(CanonicalTyVarKind::Float) }, | ||
t, | ||
) | ||
} | ||
} | ||
|
||
ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => { | ||
bug!("encountered a fresh type during canonicalization") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,19 @@ | ||
fn first() { | ||
second == 1 //~ ERROR binary operation | ||
//~^ ERROR mismatched types | ||
//~| ERROR mismatched types | ||
} | ||
|
||
fn second() { | ||
first == 1 //~ ERROR binary operation | ||
//~^ ERROR mismatched types | ||
//~| ERROR mismatched types | ||
} | ||
|
||
fn bar() { | ||
bar == 1 //~ ERROR binary operation | ||
//~^ ERROR mismatched types | ||
//~| ERROR mismatched types | ||
} | ||
|
||
fn main() {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,41 +15,65 @@ LL | second == 1 | |
= note: expected fn item `fn() {second}` | ||
found type `{integer}` | ||
|
||
error[E0308]: mismatched types | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Due to the changes to typeck, we end up emitting this additional error. I can work around it pretty easily by checking if the output type of the binop references errors before returning |
||
--> $DIR/issue-66667-function-cmp-cycle.rs:2:5 | ||
| | ||
LL | fn first() { | ||
| - help: try adding a return type: `-> bool` | ||
LL | second == 1 | ||
| ^^^^^^^^^^^ expected `()`, found `bool` | ||
|
||
error[E0369]: binary operation `==` cannot be applied to type `fn() {first}` | ||
--> $DIR/issue-66667-function-cmp-cycle.rs:7:11 | ||
--> $DIR/issue-66667-function-cmp-cycle.rs:8:11 | ||
| | ||
LL | first == 1 | ||
| ----- ^^ - {integer} | ||
| | | ||
| fn() {first} | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/issue-66667-function-cmp-cycle.rs:7:14 | ||
--> $DIR/issue-66667-function-cmp-cycle.rs:8:14 | ||
| | ||
LL | first == 1 | ||
| ^ expected fn item, found integer | ||
| | ||
= note: expected fn item `fn() {first}` | ||
found type `{integer}` | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/issue-66667-function-cmp-cycle.rs:8:5 | ||
| | ||
LL | fn second() { | ||
| - help: try adding a return type: `-> bool` | ||
LL | first == 1 | ||
| ^^^^^^^^^^ expected `()`, found `bool` | ||
|
||
error[E0369]: binary operation `==` cannot be applied to type `fn() {bar}` | ||
--> $DIR/issue-66667-function-cmp-cycle.rs:12:9 | ||
--> $DIR/issue-66667-function-cmp-cycle.rs:14:9 | ||
| | ||
LL | bar == 1 | ||
| --- ^^ - {integer} | ||
| | | ||
| fn() {bar} | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/issue-66667-function-cmp-cycle.rs:12:12 | ||
--> $DIR/issue-66667-function-cmp-cycle.rs:14:12 | ||
| | ||
LL | bar == 1 | ||
| ^ expected fn item, found integer | ||
| | ||
= note: expected fn item `fn() {bar}` | ||
found type `{integer}` | ||
|
||
error: aborting due to 6 previous errors | ||
error[E0308]: mismatched types | ||
--> $DIR/issue-66667-function-cmp-cycle.rs:14:5 | ||
| | ||
LL | fn bar() { | ||
| - help: try adding a return type: `-> bool` | ||
LL | bar == 1 | ||
| ^^^^^^^^ expected `()`, found `bool` | ||
|
||
error: aborting due to 9 previous errors | ||
|
||
Some errors have detailed explanations: E0308, E0369. | ||
For more information about an error, try `rustc --explain E0308`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// check-pass | ||
|
||
trait Mirror { | ||
type Assoc; | ||
} | ||
|
||
impl<T> Mirror for T { | ||
type Assoc = T; | ||
} | ||
|
||
trait Test {} | ||
impl Test for i64 {} | ||
impl Test for u64 {} | ||
|
||
fn mirror_me<T: Mirror>(t: T, s: <T as Mirror>::Assoc) where <T as Mirror>::Assoc: Test {} | ||
|
||
fn main() { | ||
let mut x = 0; | ||
mirror_me(x, 1); | ||
x = 1i64; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// check-pass | ||
compiler-errors marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// compile-flags: -Ztrait-solver=next | ||
|
||
// HIR typeck ends up equating `<_#0i as Add>::Output == _#0i`. | ||
// Want to make sure that we emit an alias-eq goal for this, | ||
// instead of treating it as a type error and bailing. | ||
|
||
fn test() { | ||
// fallback | ||
let x = 1 + 2; | ||
} | ||
|
||
fn test2() -> u32 { | ||
// expectation from return ty | ||
1 + 2 | ||
} | ||
|
||
fn main() {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
// compile-flags: -Ztrait-solver=next | ||
// known-bug: unknown | ||
// check-pass | ||
|
||
fn main() { | ||
(0u8 + 0u8) as char; | ||
|
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This
demand_suptype
doesn't matter because the only types we're gonna encounter here are scalars.