Skip to content

Commit

Permalink
avoid type-check body of DefId
Browse files Browse the repository at this point in the history
  • Loading branch information
rchaser53 committed Apr 19, 2019
1 parent e928e94 commit 0ce131b
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 10 deletions.
6 changes: 6 additions & 0 deletions src/librustc_typeck/check/op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
) -> bool /* did we suggest to call a function because of missing parenthesis? */ {
err.span_label(span, ty.to_string());
if let FnDef(def_id, _) = ty.sty {
if self.tcx.has_typeck_tables(def_id) == false {
return false;
}
let source_map = self.tcx.sess.source_map();
let hir_id = &self.tcx.hir().as_local_hir_id(def_id).unwrap();
let fn_sig = {
Expand All @@ -455,6 +458,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
};

let other_ty = if let FnDef(def_id, _) = other_ty.sty {
if self.tcx.has_typeck_tables(def_id) == false {
return false;
}
let hir_id = &self.tcx.hir().as_local_hir_id(def_id).unwrap();
match self.tcx.typeck_tables_of(def_id).liberated_fn_sigs().get(*hir_id) {
Some(f) => f.clone().output(),
Expand Down
11 changes: 11 additions & 0 deletions src/test/ui/issues/issue-59488.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ fn bar(a: i64) -> i64 {
43
}

enum Foo {
Bar(usize),
}

fn main() {
foo > 12;
//~^ ERROR binary operation `>` cannot be applied to type `fn() -> i32 {foo}` [E0369]
Expand All @@ -23,4 +27,11 @@ fn main() {
foo > bar;
//~^ ERROR binary operation `>` cannot be applied to type `fn() -> i32 {foo}` [E0369]
//~| ERROR mismatched types [E0308]

let i = Foo::Bar;
assert_eq!(Foo::Bar, i);
//~^ ERROR binary operation `==` cannot be applied to type `fn(usize) -> Foo {Foo::Bar}` [E0369]
//~| ERROR `fn(usize) -> Foo {Foo::Bar}` doesn't implement `std::fmt::Debug` [E0277]
//~| ERROR `fn(usize) -> Foo {Foo::Bar}` doesn't implement `std::fmt::Debug` [E0277]
}

54 changes: 44 additions & 10 deletions src/test/ui/issues/issue-59488.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0369]: binary operation `>` cannot be applied to type `fn() -> i32 {foo}`
--> $DIR/issue-59488.rs:12:9
--> $DIR/issue-59488.rs:16:9
|
LL | foo > 12;
| --- ^ -- {integer}
Expand All @@ -8,7 +8,7 @@ LL | foo > 12;
| help: you might have forgotten to call this function: `foo()`

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

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

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

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

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

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

error: aborting due to 7 previous errors
error[E0369]: binary operation `==` cannot be applied to type `fn(usize) -> Foo {Foo::Bar}`
--> $DIR/issue-59488.rs:32:5
|
LL | assert_eq!(Foo::Bar, i);
| ^^^^^^^^^^^^^^^^^^^^^^^^
| |
| fn(usize) -> Foo {Foo::Bar}
| fn(usize) -> Foo {Foo::Bar}
|
= note: an implementation of `std::cmp::PartialEq` might be missing for `fn(usize) -> Foo {Foo::Bar}`
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

error[E0277]: `fn(usize) -> Foo {Foo::Bar}` doesn't implement `std::fmt::Debug`
--> $DIR/issue-59488.rs:32:5
|
LL | assert_eq!(Foo::Bar, i);
| ^^^^^^^^^^^^^^^^^^^^^^^^ `fn(usize) -> Foo {Foo::Bar}` cannot be formatted using `{:?}` because it doesn't implement `std::fmt::Debug`
|
= help: the trait `std::fmt::Debug` is not implemented for `fn(usize) -> Foo {Foo::Bar}`
= note: required because of the requirements on the impl of `std::fmt::Debug` for `&fn(usize) -> Foo {Foo::Bar}`
= note: required by `std::fmt::Debug::fmt`
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

error[E0277]: `fn(usize) -> Foo {Foo::Bar}` doesn't implement `std::fmt::Debug`
--> $DIR/issue-59488.rs:32:5
|
LL | assert_eq!(Foo::Bar, i);
| ^^^^^^^^^^^^^^^^^^^^^^^^ `fn(usize) -> Foo {Foo::Bar}` cannot be formatted using `{:?}` because it doesn't implement `std::fmt::Debug`
|
= help: the trait `std::fmt::Debug` is not implemented for `fn(usize) -> Foo {Foo::Bar}`
= note: required because of the requirements on the impl of `std::fmt::Debug` for `&fn(usize) -> Foo {Foo::Bar}`
= note: required by `std::fmt::Debug::fmt`
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

error: aborting due to 10 previous errors

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

0 comments on commit 0ce131b

Please sign in to comment.