Skip to content

Commit d729e76

Browse files
authored
Rollup merge of #80170 - ldm0:fixice, r=lcnr
Fix ICE when lookup method in trait for type that have bound vars Closes #77910
2 parents 251d435 + 00bb293 commit d729e76

File tree

6 files changed

+66
-3
lines changed

6 files changed

+66
-3
lines changed

compiler/rustc_typeck/src/check/_match.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
3131
_ => (false, false, false),
3232
};
3333

34-
// Type check the descriminant and get its type.
34+
// Type check the discriminant and get its type.
3535
let scrutinee_ty = if force_scrutinee_bool {
3636
// Here we want to ensure:
3737
//

compiler/rustc_typeck/src/check/op.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -503,8 +503,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
503503
if !self.tcx.has_typeck_results(def_id) {
504504
return false;
505505
}
506-
// We're emitting a suggestion, so we can just ignore regions
507-
let fn_sig = self.tcx.fn_sig(def_id).skip_binder();
506+
// FIXME: Instead of exiting early when encountering bound vars in
507+
// the function signature, consider keeping the binder here and
508+
// propagating it downwards.
509+
let fn_sig = if let Some(fn_sig) = self.tcx.fn_sig(def_id).no_bound_vars() {
510+
fn_sig
511+
} else {
512+
return false;
513+
};
508514

509515
let other_ty = if let FnDef(def_id, _) = *other_ty.kind() {
510516
if !self.tcx.has_typeck_results(def_id) {

src/test/ui/binop/issue-77910-1.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
fn foo(s: &i32) -> &i32 {
2+
let xs;
3+
xs
4+
}
5+
fn main() {
6+
let y;
7+
// we shouldn't ice with the bound var here.
8+
assert_eq!(foo, y);
9+
//~^ ERROR binary operation `==` cannot be applied to type
10+
//~| ERROR `for<'r> fn(&'r i32) -> &'r i32 {foo}` doesn't implement `Debug`
11+
}
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
error[E0369]: binary operation `==` cannot be applied to type `for<'r> fn(&'r i32) -> &'r i32 {foo}`
2+
--> $DIR/issue-77910-1.rs:8:5
3+
|
4+
LL | assert_eq!(foo, y);
5+
| ^^^^^^^^^^^^^^^^^^^
6+
| |
7+
| for<'r> fn(&'r i32) -> &'r i32 {foo}
8+
| _
9+
|
10+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
11+
12+
error[E0277]: `for<'r> fn(&'r i32) -> &'r i32 {foo}` doesn't implement `Debug`
13+
--> $DIR/issue-77910-1.rs:8:5
14+
|
15+
LL | assert_eq!(foo, y);
16+
| ^^^^^^^^^^^^^^^^^^^ `for<'r> fn(&'r i32) -> &'r i32 {foo}` cannot be formatted using `{:?}` because it doesn't implement `Debug`
17+
|
18+
= help: the trait `Debug` is not implemented for `for<'r> fn(&'r i32) -> &'r i32 {foo}`
19+
= note: required because of the requirements on the impl of `Debug` for `&for<'r> fn(&'r i32) -> &'r i32 {foo}`
20+
= note: required by `std::fmt::Debug::fmt`
21+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
22+
23+
error: aborting due to 2 previous errors
24+
25+
Some errors have detailed explanations: E0277, E0369.
26+
For more information about an error, try `rustc --explain E0277`.

src/test/ui/binop/issue-77910-2.rs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
fn foo(s: &i32) -> &i32 {
2+
let xs;
3+
xs
4+
}
5+
fn main() {
6+
let y;
7+
if foo == y {}
8+
//~^ ERROR binary operation `==` cannot be applied to type
9+
}
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0369]: binary operation `==` cannot be applied to type `for<'r> fn(&'r i32) -> &'r i32 {foo}`
2+
--> $DIR/issue-77910-2.rs:7:12
3+
|
4+
LL | if foo == y {}
5+
| --- ^^ - _
6+
| |
7+
| for<'r> fn(&'r i32) -> &'r i32 {foo}
8+
9+
error: aborting due to previous error
10+
11+
For more information about this error, try `rustc --explain E0369`.

0 commit comments

Comments
 (0)