}
}
- let mut err = type_error_struct!(
- self.tcx.sess,
- call_expr.span,
- callee_ty,
- E0618,
- "expected function, found {}",
- match unit_variant {
- Some(ref path) => format!("enum variant `{}`", path),
- None => format!("`{}`", callee_ty),
- });
-
- err.span_label(call_expr.span, "not a function");
+ if let hir::ExprKind::Call(ref callee, _) = call_expr.node {
+ let mut err = type_error_struct!(
+ self.tcx.sess,
+ callee.span,
+ callee_ty,
+ E0618,
+ "expected function, found {}",
+ match unit_variant {
+ Some(ref path) => format!("enum variant `{}`", path),
+ None => format!("`{}`", callee_ty),
+ });
- if let Some(ref path) = unit_variant {
- err.span_suggestion_with_applicability(
- call_expr.span,
- &format!("`{}` is a unit variant, you need to write it \
- without the parenthesis", path),
- path.to_string(),
- Applicability::MachineApplicable
- );
- }
+ if let Some(ref path) = unit_variant {
+ err.span_suggestion_with_applicability(
+ call_expr.span,
+ &format!("`{}` is a unit variant, you need to write it \
+ without the parenthesis", path),
+ path.to_string(),
+ Applicability::MachineApplicable
+ );
+ }
- if let hir::ExprKind::Call(ref expr, _) = call_expr.node {
- let def = if let hir::ExprKind::Path(ref qpath) = expr.node {
- self.tables.borrow().qpath_def(qpath, expr.hir_id)
- } else {
- Def::Err
+ let mut inner_callee_path = None;
+ let def = match callee.node {
+ hir::ExprKind::Path(ref qpath) => {
+ self.tables.borrow().qpath_def(qpath, callee.hir_id)
+ },
+ hir::ExprKind::Call(ref inner_callee, _) => {
+ // If the call spans more than one line and the callee kind is
+ // itself another `ExprCall`, that's a clue that we might just be
+ // missing a semicolon (Issue #51055)
+ let call_is_multiline = self.tcx.sess.source_map()
+ .is_multiline(call_expr.span);
+ if call_is_multiline {
+ let span = self.tcx.sess.source_map().next_point(callee.span);
+ err.span_suggestion_with_applicability(
+ span,
+ "try adding a semicolon",
+ ";".to_owned(),
+ Applicability::MaybeIncorrect
+ );
+ }
+ if let hir::ExprKind::Path(ref inner_qpath) = inner_callee.node {
+ inner_callee_path = Some(inner_qpath);
+ self.tables.borrow().qpath_def(inner_qpath, inner_callee.hir_id)
+ } else {
+ Def::Err
+ }
+ },
+ _ => {
+ Def::Err
+ }
};
+
+ err.span_label(call_expr.span, "call expression requires function");
+
let def_span = match def {
Def::Err => None,
Def::Local(id) | Def::Upvar(id, ..) => {
_ => self.tcx.hir.span_if_local(def.def_id())
};
if let Some(span) = def_span {
- let name = match unit_variant {
- Some(path) => path,
- None => callee_ty.to_string(),
+ let label = match (unit_variant, inner_callee_path) {
+ (Some(path), _) => format!("`{}` defined here", path),
+ (_, Some(hir::QPath::Resolved(_, path))) => format!(
+ "`{}` defined here returns `{}`", path, callee_ty.to_string()
+ ),
+ _ => format!("`{}` defined here", callee_ty.to_string()),
};
- err.span_label(span, format!("`{}` defined here", name));
+ err.span_label(span, label);
}
+ err.emit();
+ } else {
+ bug!("call_expr.node should be an ExprKind::Call, got {:?}", call_expr.node);
}
- err.emit();
-
// This is the "default" function signature, used in case of error.
// In that case, we check each argument against "error" in order to
// set up all the node type bindings.
error[E0618]: expected function, found `()`
--> $DIR/issue-20862.rs:17:13
|
-LL | let x = foo(5)(2);
- | ^^^^^^^^^ not a function
+LL | / fn foo(x: i32) {
+LL | | |y| x + y
+LL | | //~^ ERROR: mismatched types
+LL | | }
+ | |_- `foo` defined here returns `()`
+...
+LL | let x = foo(5)(2);
+ | ^^^^^^---
+ | |
+ | call expression requires function
error: aborting due to 2 previous errors
| -------------- `Empty2` defined here
...
LL | let e2 = Empty2(); //~ ERROR expected function, found `Empty2`
- | ^^^^^^^^ not a function
+ | ^^^^^^--
+ | |
+ | call expression requires function
error[E0618]: expected function, found enum variant `E::Empty4`
--> $DIR/empty-struct-unit-expr.rs:26:14
| ------ `E::Empty4` defined here
...
LL | let e4 = E::Empty4();
- | ^^^^^^^^^^^ not a function
+ | ^^^^^^^^^--
+ | |
+ | call expression requires function
help: `E::Empty4` is a unit variant, you need to write it without the parenthesis
|
LL | let e4 = E::Empty4;
--> $DIR/empty-struct-unit-expr.rs:28:15
|
LL | let xe2 = XEmpty2(); //~ ERROR expected function, found `empty_struct::XEmpty2`
- | ^^^^^^^^^ not a function
+ | ^^^^^^^--
+ | |
+ | call expression requires function
error[E0618]: expected function, found enum variant `XE::XEmpty4`
--> $DIR/empty-struct-unit-expr.rs:29:15
|
LL | let xe4 = XE::XEmpty4();
- | ^^^^^^^^^^^^^ not a function
+ | ^^^^^^^^^^^--
+ | |
+ | call expression requires function
help: `XE::XEmpty4` is a unit variant, you need to write it without the parenthesis
|
LL | let xe4 = XE::XEmpty4;
| ----- `X::Entry` defined here
...
LL | X::Entry();
- | ^^^^^^^^^^ not a function
+ | ^^^^^^^^--
+ | |
+ | call expression requires function
help: `X::Entry` is a unit variant, you need to write it without the parenthesis
|
LL | X::Entry;
LL | let x = 0i32;
| - `i32` defined here
LL | x();
- | ^^^ not a function
+ | ^--
+ | |
+ | call expression requires function
error: aborting due to 2 previous errors
LL | fn func(i: i32) {
| - `i32` defined here
LL | i(); //~ERROR expected function, found `i32`
- | ^^^ not a function
+ | ^--
+ | |
+ | call expression requires function
error[E0618]: expected function, found `i32`
--> $DIR/issue-10969.rs:16:5
LL | let i = 0i32;
| - `i32` defined here
LL | i(); //~ERROR expected function, found `i32`
- | ^^^ not a function
+ | ^--
+ | |
+ | call expression requires function
error: aborting due to 2 previous errors
--> $DIR/issue-18532.rs:16:5
|
LL | (return)((),()); //~ ERROR expected function, found `!`
- | ^^^^^^^^^^^^^^^ not a function
+ | ^^^^^^^^-------
+ | |
+ | call expression requires function
error: aborting due to previous error
| --------- `G` defined here
...
LL | let g = G(); //~ ERROR: expected function, found `G`
- | ^^^ not a function
+ | ^--
+ | |
+ | call expression requires function
error: aborting due to previous error
LL | fn foo<U>(t: U) {
| - `U` defined here
LL | let y = t();
- | ^^^ not a function
+ | ^--
+ | |
+ | call expression requires function
error[E0618]: expected function, found `Bar`
--> $DIR/issue-21701.rs:19:13
| ----------- `Bar` defined here
...
LL | let f = Bar();
- | ^^^^^ not a function
+ | ^^^--
+ | |
+ | call expression requires function
error: aborting due to 2 previous errors
LL | let foo = "bar";
| --- `&str` defined here
LL | let x = foo("baz");
- | ^^^^^^^^^^ not a function
+ | ^^^-------
+ | |
+ | call expression requires function
error: aborting due to previous error
macro_rules! macro_panic {
($not_a_function:expr, $some_argument:ident) => {
$not_a_function($some_argument)
- //~^ ERROR expected function, found `{integer}`
}
}
let mut value_a = 0;
let mut value_b = 0;
macro_panic!(value_a, value_b);
- //~^ in this expansion of macro_panic!
+ //~^ ERROR expected function, found `{integer}`
}
error[E0618]: expected function, found `{integer}`
- --> $DIR/issue-26237.rs:13:9
+ --> $DIR/issue-26237.rs:20:18
|
LL | $not_a_function($some_argument)
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not a function
+ | ------------------------------- call expression requires function
...
LL | let mut value_a = 0;
| ----------- `{integer}` defined here
LL | let mut value_b = 0;
LL | macro_panic!(value_a, value_b);
- | ------------------------------- in this macro invocation
+ | ^^^^^^^
error: aborting due to previous error
--> $DIR/issue-45965.rs:12:30
|
LL | let a = |r: f64| if r != 0.0(r != 0.0) { 1.0 } else { 0.0 };
- | ^^^^^^^^^^^^^ not a function
+ | ^^^----------
+ | |
+ | call expression requires function
error: aborting due to previous error
LL | struct Foo;
| ----------- `main::Foo` defined here
LL | (1 .. 2).find(|_| Foo(0) == 0); //~ ERROR expected function, found `main::Foo`
- | ^^^^^^ not a function
+ | ^^^---
+ | |
+ | call expression requires function
error: aborting due to previous error
--> $DIR/issue-5100.rs:58:14
|
LL | let v = [('a', 'b') //~ ERROR expected function, found `(char, char)`
- | ______________^
+ | ______________-^^^^^^^^^
LL | | ('c', 'd'),
- | |_______________________^ not a function
+ | |_______________________- call expression requires function
error[E0308]: mismatched types
--> $DIR/issue-5100.rs:65:19
| - `{integer}` defined here
LL | let x = y.; //~ ERROR unexpected token
LL | let x = y.(); //~ ERROR unexpected token
- | ^^^^ not a function
+ | ^---
+ | |
+ | call expression requires function
error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields
--> $DIR/parse-error-correct.rs:21:15
| ---- `Z::Unit` defined here
...
LL | let _ = Z::Unit();
- | ^^^^^^^^^ not a function
+ | ^^^^^^^--
+ | |
+ | call expression requires function
help: `Z::Unit` is a unit variant, you need to write it without the parenthesis
|
LL | let _ = Z::Unit;
| ---- `m::E::Unit` defined here
...
LL | let _: E = m::E::Unit();
- | ^^^^^^^^^^^^ not a function
+ | ^^^^^^^^^^--
+ | |
+ | call expression requires function
help: `m::E::Unit` is a unit variant, you need to write it without the parenthesis
|
LL | let _: E = m::E::Unit;
| ---- `E::Unit` defined here
...
LL | let _: E = E::Unit();
- | ^^^^^^^^^ not a function
+ | ^^^^^^^--
+ | |
+ | call expression requires function
help: `E::Unit` is a unit variant, you need to write it without the parenthesis
|
LL | let _: E = E::Unit;
--- /dev/null
+fn vindictive() -> bool { true }
+
+fn perfidy() -> (i32, i32) {
+ vindictive() //~ ERROR expected function, found `bool`
+ (1, 2)
+}
+
+fn main() {}
--- /dev/null
+error[E0618]: expected function, found `bool`
+ --> $DIR/issue-51055-missing-semicolon-between-call-and-tuple.rs:4:5
+ |
+LL | fn vindictive() -> bool { true }
+ | -------------------------------- `vindictive` defined here returns `bool`
+...
+LL | vindictive() //~ ERROR expected function, found `bool`
+ | -^^^^^^^^^^^- help: try adding a semicolon: `;`
+ | _____|
+ | |
+LL | | (1, 2)
+ | |__________- call expression requires function
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0618`.