Skip to content

Commit 0ce131b

Browse files
committed
avoid type-check body of DefId
1 parent e928e94 commit 0ce131b

File tree

3 files changed

+61
-10
lines changed

3 files changed

+61
-10
lines changed

src/librustc_typeck/check/op.rs

+6
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
443443
) -> bool /* did we suggest to call a function because of missing parenthesis? */ {
444444
err.span_label(span, ty.to_string());
445445
if let FnDef(def_id, _) = ty.sty {
446+
if self.tcx.has_typeck_tables(def_id) == false {
447+
return false;
448+
}
446449
let source_map = self.tcx.sess.source_map();
447450
let hir_id = &self.tcx.hir().as_local_hir_id(def_id).unwrap();
448451
let fn_sig = {
@@ -455,6 +458,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
455458
};
456459

457460
let other_ty = if let FnDef(def_id, _) = other_ty.sty {
461+
if self.tcx.has_typeck_tables(def_id) == false {
462+
return false;
463+
}
458464
let hir_id = &self.tcx.hir().as_local_hir_id(def_id).unwrap();
459465
match self.tcx.typeck_tables_of(def_id).liberated_fn_sigs().get(*hir_id) {
460466
Some(f) => f.clone().output(),

src/test/ui/issues/issue-59488.rs

+11
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ fn bar(a: i64) -> i64 {
88
43
99
}
1010

11+
enum Foo {
12+
Bar(usize),
13+
}
14+
1115
fn main() {
1216
foo > 12;
1317
//~^ ERROR binary operation `>` cannot be applied to type `fn() -> i32 {foo}` [E0369]
@@ -23,4 +27,11 @@ fn main() {
2327
foo > bar;
2428
//~^ ERROR binary operation `>` cannot be applied to type `fn() -> i32 {foo}` [E0369]
2529
//~| ERROR mismatched types [E0308]
30+
31+
let i = Foo::Bar;
32+
assert_eq!(Foo::Bar, i);
33+
//~^ ERROR binary operation `==` cannot be applied to type `fn(usize) -> Foo {Foo::Bar}` [E0369]
34+
//~| ERROR `fn(usize) -> Foo {Foo::Bar}` doesn't implement `std::fmt::Debug` [E0277]
35+
//~| ERROR `fn(usize) -> Foo {Foo::Bar}` doesn't implement `std::fmt::Debug` [E0277]
2636
}
37+

src/test/ui/issues/issue-59488.stderr

+44-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0369]: binary operation `>` cannot be applied to type `fn() -> i32 {foo}`
2-
--> $DIR/issue-59488.rs:12:9
2+
--> $DIR/issue-59488.rs:16:9
33
|
44
LL | foo > 12;
55
| --- ^ -- {integer}
@@ -8,7 +8,7 @@ LL | foo > 12;
88
| help: you might have forgotten to call this function: `foo()`
99

1010
error[E0308]: mismatched types
11-
--> $DIR/issue-59488.rs:12:11
11+
--> $DIR/issue-59488.rs:16:11
1212
|
1313
LL | foo > 12;
1414
| ^^ expected fn item, found integer
@@ -17,7 +17,7 @@ LL | foo > 12;
1717
found type `i32`
1818

1919
error[E0369]: binary operation `>` cannot be applied to type `fn(i64) -> i64 {bar}`
20-
--> $DIR/issue-59488.rs:16:9
20+
--> $DIR/issue-59488.rs:20:9
2121
|
2222
LL | bar > 13;
2323
| --- ^ -- {integer}
@@ -26,7 +26,7 @@ LL | bar > 13;
2626
| help: you might have forgotten to call this function: `bar( /* arguments */ )`
2727

2828
error[E0308]: mismatched types
29-
--> $DIR/issue-59488.rs:16:11
29+
--> $DIR/issue-59488.rs:20:11
3030
|
3131
LL | bar > 13;
3232
| ^^ expected fn item, found integer
@@ -35,7 +35,7 @@ LL | bar > 13;
3535
found type `i64`
3636

3737
error[E0369]: binary operation `>` cannot be applied to type `fn() -> i32 {foo}`
38-
--> $DIR/issue-59488.rs:20:9
38+
--> $DIR/issue-59488.rs:24:9
3939
|
4040
LL | foo > foo;
4141
| --- ^ --- fn() -> i32 {foo}
@@ -51,7 +51,7 @@ LL | foo > foo();
5151
| ^^^^^
5252

5353
error[E0369]: binary operation `>` cannot be applied to type `fn() -> i32 {foo}`
54-
--> $DIR/issue-59488.rs:23:9
54+
--> $DIR/issue-59488.rs:27:9
5555
|
5656
LL | foo > bar;
5757
| --- ^ --- fn(i64) -> i64 {bar}
@@ -61,15 +61,49 @@ LL | foo > bar;
6161
= note: an implementation of `std::cmp::PartialOrd` might be missing for `fn() -> i32 {foo}`
6262

6363
error[E0308]: mismatched types
64-
--> $DIR/issue-59488.rs:23:11
64+
--> $DIR/issue-59488.rs:27:11
6565
|
6666
LL | foo > bar;
6767
| ^^^ expected fn item, found a different fn item
6868
|
6969
= note: expected type `fn() -> i32 {foo}`
7070
found type `fn(i64) -> i64 {bar}`
7171

72-
error: aborting due to 7 previous errors
72+
error[E0369]: binary operation `==` cannot be applied to type `fn(usize) -> Foo {Foo::Bar}`
73+
--> $DIR/issue-59488.rs:32:5
74+
|
75+
LL | assert_eq!(Foo::Bar, i);
76+
| ^^^^^^^^^^^^^^^^^^^^^^^^
77+
| |
78+
| fn(usize) -> Foo {Foo::Bar}
79+
| fn(usize) -> Foo {Foo::Bar}
80+
|
81+
= note: an implementation of `std::cmp::PartialEq` might be missing for `fn(usize) -> Foo {Foo::Bar}`
82+
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
83+
84+
error[E0277]: `fn(usize) -> Foo {Foo::Bar}` doesn't implement `std::fmt::Debug`
85+
--> $DIR/issue-59488.rs:32:5
86+
|
87+
LL | assert_eq!(Foo::Bar, i);
88+
| ^^^^^^^^^^^^^^^^^^^^^^^^ `fn(usize) -> Foo {Foo::Bar}` cannot be formatted using `{:?}` because it doesn't implement `std::fmt::Debug`
89+
|
90+
= help: the trait `std::fmt::Debug` is not implemented for `fn(usize) -> Foo {Foo::Bar}`
91+
= note: required because of the requirements on the impl of `std::fmt::Debug` for `&fn(usize) -> Foo {Foo::Bar}`
92+
= note: required by `std::fmt::Debug::fmt`
93+
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
94+
95+
error[E0277]: `fn(usize) -> Foo {Foo::Bar}` doesn't implement `std::fmt::Debug`
96+
--> $DIR/issue-59488.rs:32:5
97+
|
98+
LL | assert_eq!(Foo::Bar, i);
99+
| ^^^^^^^^^^^^^^^^^^^^^^^^ `fn(usize) -> Foo {Foo::Bar}` cannot be formatted using `{:?}` because it doesn't implement `std::fmt::Debug`
100+
|
101+
= help: the trait `std::fmt::Debug` is not implemented for `fn(usize) -> Foo {Foo::Bar}`
102+
= note: required because of the requirements on the impl of `std::fmt::Debug` for `&fn(usize) -> Foo {Foo::Bar}`
103+
= note: required by `std::fmt::Debug::fmt`
104+
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
105+
106+
error: aborting due to 10 previous errors
73107

74-
Some errors have detailed explanations: E0308, E0369.
75-
For more information about an error, try `rustc --explain E0308`.
108+
Some errors have detailed explanations: E0277, E0308, E0369.
109+
For more information about an error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)