self.definitions.def_index_to_hir_id(def_id.to_def_id().index)
}
- fn def_kind(&self, hir_id: HirId) -> Option<DefKind> {
+ pub fn def_kind(&self, hir_id: HirId) -> Option<DefKind> {
let node = if let Some(node) = self.find(hir_id) {
node
} else {
ty::FnDef(..) | ty::FnPtr(_) => {}
_ => return false,
}
+ let hir = self.tcx.hir();
let sig = found.fn_sig(self.tcx);
let sig = self
let (mut sugg_call, applicability) = if sig.inputs().is_empty() {
(String::new(), Applicability::MachineApplicable)
} else {
- ("...".to_owned(), Applicability::HasPlaceholders)
+ ("...".to_string(), Applicability::HasPlaceholders)
};
let mut msg = "call this function";
if let ty::FnDef(def_id, ..) = found.sty {
- match self.tcx.hir().get_if_local(def_id) {
+ match hir.get_if_local(def_id) {
Some(Node::Item(hir::Item {
node: ItemKind::Fn(.., body_id),
..
})) => {
- let body = self.tcx.hir().body(*body_id);
+ let body = hir.body(*body_id);
sugg_call = body.arguments.iter()
- .map(|arg| hir::print::to_string(
- hir::print::NO_ANN,
- |s| s.print_pat(&arg.pat),
- )).collect::<Vec<_>>().join(", ");
+ .map(|arg| match &arg.pat.node {
+ hir::PatKind::Binding(_, _, ident, None) => ident.to_string(),
+ _ => "_".to_string(),
+ }).collect::<Vec<_>>().join(", ");
}
- Some(Node::Ctor(hir::VariantData::Tuple(field, _))) => {
- sugg_call = field.iter().map(|_| "_").collect::<Vec<_>>().join(", ");
- msg = "instatiate this tuple struct";
+ Some(Node::Ctor(hir::VariantData::Tuple(fields, _))) => {
+ sugg_call = fields.iter().map(|_| "_").collect::<Vec<_>>().join(", ");
+ match hir.as_local_hir_id(def_id).and_then(|hir_id| hir.def_kind(hir_id)) {
+ Some(hir::def::DefKind::Ctor(hir::def::CtorOf::Variant, _)) => {
+ msg = "instatiate this tuple variant";
+ }
+ Some(hir::def::DefKind::Ctor(hir::def::CtorOf::Struct, _)) => {
+ msg = "instatiate this tuple struct";
+ }
+ _ => {}
+ }
}
_ => {}
}
| ^^^^^
| |
| expected enum `m::n::Z`, found fn item
- | help: use parentheses to instatiate this tuple struct: `Z::Fn(_)`
+ | help: use parentheses to instatiate this tuple variant: `Z::Fn(_)`
|
= note: expected type `m::n::Z`
found type `fn(u8) -> m::n::Z {m::n::Z::Fn}`
| ^^^^^^^^
| |
| expected enum `m::E`, found fn item
- | help: use parentheses to instatiate this tuple struct: `m::E::Fn(_)`
+ | help: use parentheses to instatiate this tuple variant: `m::E::Fn(_)`
|
= note: expected type `m::E`
found type `fn(u8) -> m::E {m::E::Fn}`
| ^^^^^
| |
| expected enum `m::E`, found fn item
- | help: use parentheses to instatiate this tuple struct: `E::Fn(_)`
+ | help: use parentheses to instatiate this tuple variant: `E::Fn(_)`
|
= note: expected type `m::E`
found type `fn(u8) -> m::E {m::E::Fn}`
fn bar() -> usize { 42 }
struct S(usize, usize);
+enum E {
+ A(usize),
+ B { a: usize },
+}
struct V();
trait T {
let _: V = V; //~ ERROR mismatched types
let _: usize = T::baz; //~ ERROR mismatched types
let _: usize = T::bat; //~ ERROR mismatched types
+ let _: E = E::A; //~ ERROR mismatched types
+ let _: E = E::B; //~ ERROR expected value, found struct variant `E::B`
}
+error[E0423]: expected value, found struct variant `E::B`
+ --> $DIR/fn-or-tuple-struct-without-args.rs:25:16
+ |
+LL | let _: E = E::B;
+ | ^^^-
+ | | |
+ | | help: a tuple variant with a similar name exists: `A`
+ | did you mean `E::B { /* fields */ }`?
+
error[E0308]: mismatched types
- --> $DIR/fn-or-tuple-struct-without-args.rs:14:20
+ --> $DIR/fn-or-tuple-struct-without-args.rs:18:20
|
LL | fn foo(a: usize, b: usize) -> usize { a }
| ----------------------------------- fn(usize, usize) -> usize {foo} defined here
found type `fn(usize, usize) -> usize {foo}`
error[E0308]: mismatched types
- --> $DIR/fn-or-tuple-struct-without-args.rs:15:16
+ --> $DIR/fn-or-tuple-struct-without-args.rs:19:16
|
LL | struct S(usize, usize);
| ----------------------- fn(usize, usize) -> S {S} defined here
found type `fn(usize, usize) -> S {S}`
error[E0308]: mismatched types
- --> $DIR/fn-or-tuple-struct-without-args.rs:16:20
+ --> $DIR/fn-or-tuple-struct-without-args.rs:20:20
|
LL | fn bar() -> usize { 42 }
| ----------------- fn() -> usize {bar} defined here
found type `fn() -> usize {bar}`
error[E0308]: mismatched types
- --> $DIR/fn-or-tuple-struct-without-args.rs:17:16
+ --> $DIR/fn-or-tuple-struct-without-args.rs:21:16
|
LL | struct V();
| ----------- fn() -> V {V} defined here
found type `fn() -> V {V}`
error[E0308]: mismatched types
- --> $DIR/fn-or-tuple-struct-without-args.rs:18:20
+ --> $DIR/fn-or-tuple-struct-without-args.rs:22:20
|
LL | fn baz(x: usize, y: usize) -> usize { x }
| ----------------------------------- fn(usize, usize) -> usize {<_ as T>::baz} defined here
found type `fn(usize, usize) -> usize {<_ as T>::baz}`
error[E0308]: mismatched types
- --> $DIR/fn-or-tuple-struct-without-args.rs:19:20
+ --> $DIR/fn-or-tuple-struct-without-args.rs:23:20
|
LL | fn bat() -> usize { 42 }
| ----------------- fn() -> usize {<_ as T>::bat} defined here
= note: expected type `usize`
found type `fn() -> usize {<_ as T>::bat}`
-error: aborting due to 6 previous errors
+error[E0308]: mismatched types
+ --> $DIR/fn-or-tuple-struct-without-args.rs:24:16
+ |
+LL | A(usize),
+ | -------- fn(usize) -> E {E::A} defined here
+...
+LL | let _: E = E::A;
+ | ^^^^
+ | |
+ | expected enum `E`, found fn item
+ | help: use parentheses to instatiate this tuple variant: `E::A(_)`
+ |
+ = note: expected type `E`
+ found type `fn(usize) -> E {E::A}`
+
+error: aborting due to 8 previous errors
-For more information about this error, try `rustc --explain E0308`.
+Some errors have detailed explanations: E0308, E0423.
+For more information about an error, try `rustc --explain E0308`.