Skip to content

Error codes new #42654

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

Merged
merged 1 commit into from
Jun 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions src/librustc_typeck/check/callee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use super::method::MethodCallee;
use hir::def::Def;
use hir::def_id::{DefId, LOCAL_CRATE};
use rustc::{infer, traits};
use rustc::ty::{self, TyCtxt, LvaluePreference, Ty};
use rustc::ty::{self, TyCtxt, TypeFoldable, LvaluePreference, Ty};
use rustc::ty::subst::Subst;
use rustc::ty::adjustment::{Adjustment, Adjust, AutoBorrow};
use syntax::abi;
Expand Down Expand Up @@ -209,17 +209,16 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
}
}
}
let mut err = if let Some(path) = unit_variant {
let mut err = self.type_error_struct(call_expr.span, |_| {
format!("`{}` is being called, but it is not a function", path)
}, callee_ty);
let mut err = type_error_struct!(self.tcx.sess, call_expr.span, callee_ty, E0618,
"expected function, found `{}`",
if let Some(ref path) = unit_variant {
path.to_string()
} else {
callee_ty.to_string()
});
if let Some(path) = unit_variant {
err.help(&format!("did you mean to write `{}`?", path));
err
} else {
self.type_error_struct(call_expr.span, |actual| {
format!("expected function, found `{}`", actual)
}, callee_ty)
};
}

if let hir::ExprCall(ref expr, _) = call_expr.node {
let def = if let hir::ExprPath(ref qpath) = expr.node {
Expand Down
28 changes: 28 additions & 0 deletions src/librustc_typeck/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4173,6 +4173,34 @@ as possible. For better explanations, see The Rust Book:
https://doc.rust-lang.org/book/
"##,

E0618: r##"
Attempted to call something which isn't a function nor a method.

Erroneous code examples:

```compile_fail,E0618
enum X {
Entry,
}

X::Entry(); // error: expected function, found `X::Entry`

// Or even simpler:
let x = 0i32;
x(); // error: expected function, found `i32`
```

Only functions and methods can be called using `()`. Example:

```
// We declare a function:
fn i_am_a_function() {}

// And we call it:
i_am_a_function();
```
"##,

}

register_diagnostics! {
Expand Down
20 changes: 20 additions & 0 deletions src/test/compile-fail/E0618.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

enum X {
Entry,
}

fn main() {
X::Entry(); //~ ERROR expected function, found `X::Entry` [E0618]
//~| HELP did you mean to write `X::Entry`?
let x = 0i32;
x(); //~ ERROR expected function, found `i32` [E0618]
}
4 changes: 2 additions & 2 deletions src/test/compile-fail/empty-struct-unit-expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ enum E {
fn main() {
let e2 = Empty2(); //~ ERROR expected function, found `Empty2`
let e4 = E::Empty4();
//~^ ERROR `E::Empty4` is being called, but it is not a function
//~^ ERROR expected function, found `E::Empty4` [E0618]
//~| HELP did you mean to write `E::Empty4`?
let xe2 = XEmpty2(); //~ ERROR expected function, found `empty_struct::XEmpty2`
let xe4 = XE::XEmpty4();
//~^ ERROR `XE::XEmpty4` is being called, but it is not a function
//~^ ERROR expected function, found `XE::XEmpty4` [E0618]
//~| HELP did you mean to write `XE::XEmpty4`?
}