Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
3a6a29b
Use associated_type_bounds where applicable - closes #61738
iluuu1994 Jul 31, 2019
322a7d6
Add test for issue 36804
jackh726 Aug 8, 2019
3d231ac
Add missing #![feature(associated_type_bounds)]
iluuu1994 Aug 8, 2019
77bfd7f
Don't use associated type bounds in docs until it is stable
iluuu1994 Aug 9, 2019
c076392
Tweak mismatched types error on break expressions
estebank Aug 6, 2019
799b13a
Do not suggest using ! with break
estebank Aug 7, 2019
4fbbf99
Be more accurate when mentioning type of found match arms
estebank Aug 7, 2019
01a6139
Change wording for function without return value
estebank Aug 7, 2019
94fe8a3
Suggest calling function on type error when finding bare fn
estebank Aug 7, 2019
195d837
When suggesting fn call use an appropriate number of placeholder argu…
estebank Aug 8, 2019
b7f7756
Recover parser from `foo(_, _)`
estebank Aug 8, 2019
0d53f69
review comments
estebank Aug 8, 2019
efa62d6
Tweak wording of fn without explicit return
estebank Aug 8, 2019
52da091
Differentiate between tuple structs and tuple variants
estebank Aug 8, 2019
5a54945
Extend suggestion support for traits and foreign items
estebank Aug 8, 2019
33d1082
review comment: review wording or missing return error
estebank Aug 8, 2019
bc1a4f5
review comments: typo and rewording
estebank Aug 8, 2019
45a5bc7
fix tests
estebank Aug 9, 2019
7c96d90
More explicit diagnostic when using a `vec![]` in a pattern
estebank Aug 9, 2019
75c5ad2
review comments: use structured suggestion
estebank Aug 9, 2019
4dd96d2
check against more collisions for TypeId of fn pointer
RalfJung Aug 9, 2019
b9865d9
Mention that tuple structs are private if their fields are
estebank Aug 9, 2019
cbcc7dd
Give built-in macros stable addresses in the standard library
petrochenkov Jul 27, 2019
0ef7c28
resolve: Populate external modules in more automatic and lazy way
petrochenkov Jul 29, 2019
3ee614b
resolve: Populate external traits lazily as well
petrochenkov Jul 30, 2019
2cb9207
resolve: Move some code around
petrochenkov Jul 30, 2019
a38cbcf
Rollup merge of #63056 - petrochenkov:macstd2, r=alexcrichton
Centril Aug 10, 2019
a14318d
Rollup merge of #63149 - petrochenkov:lazypop2, r=eddyb
Centril Aug 10, 2019
5379a7d
Rollup merge of #63337 - estebank:break-ee0308, r=Centril
Centril Aug 10, 2019
a29196d
Rollup merge of #63350 - iluuu1994:use-associated-type-bounds, r=Centril
Centril Aug 10, 2019
45d089a
Rollup merge of #63394 - jackh726:issue-36804, r=jonas-schievink
Centril Aug 10, 2019
9ece794
Rollup merge of #63399 - estebank:vec-in-pat, r=Centril
Centril Aug 10, 2019
664b34d
Rollup merge of #63419 - RalfJung:typeid, r=alexcrichton
Centril Aug 10, 2019
2dfa3a9
Rollup merge of #63423 - estebank:priv-tuple, r=zackmdavis
Centril Aug 10, 2019
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
Prev Previous commit
Next Next commit
Differentiate between tuple structs and tuple variants
  • Loading branch information
estebank committed Aug 9, 2019
commit 52da091ee687f3d065713626a10b4cc961f04f75
2 changes: 1 addition & 1 deletion src/librustc/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ impl<'hir> Map<'hir> {
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 {
Expand Down
29 changes: 19 additions & 10 deletions src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3839,6 +3839,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
ty::FnDef(..) | ty::FnPtr(_) => {}
_ => return false,
}
let hir = self.tcx.hir();

let sig = found.fn_sig(self.tcx);
let sig = self
Expand All @@ -3849,25 +3850,33 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
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";
}
_ => {}
}
}
_ => {}
}
Expand Down
6 changes: 3 additions & 3 deletions src/test/ui/resolve/privacy-enum-ctor.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ LL | let _: Z = Z::Fn;
| ^^^^^
| |
| 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}`
Expand Down Expand Up @@ -232,7 +232,7 @@ LL | let _: E = m::E::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}`
Expand Down Expand Up @@ -262,7 +262,7 @@ LL | let _: E = 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}`
Expand Down
6 changes: 6 additions & 0 deletions src/test/ui/suggestions/fn-or-tuple-struct-without-args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ fn foo(a: usize, b: usize) -> usize { a }
fn bar() -> usize { 42 }

struct S(usize, usize);
enum E {
A(usize),
B { a: usize },
}
struct V();

trait T {
Expand All @@ -17,4 +21,6 @@ fn main() {
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`
}
41 changes: 33 additions & 8 deletions src/test/ui/suggestions/fn-or-tuple-struct-without-args.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
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
Expand All @@ -14,7 +23,7 @@ LL | let _: usize = foo;
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
Expand All @@ -29,7 +38,7 @@ LL | let _: S = S;
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
Expand All @@ -44,7 +53,7 @@ LL | let _: usize = bar;
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
Expand All @@ -59,7 +68,7 @@ LL | let _: V = V;
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
Expand All @@ -74,7 +83,7 @@ LL | let _: usize = T::baz;
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
Expand All @@ -88,6 +97,22 @@ LL | let _: usize = T::bat;
= 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`.