Skip to content

Rollup of 5 pull requests #63412

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

Closed
wants to merge 32 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
ad832a1
add basic lint testing for misuse of mem::zeroed and mem::uninitialized
RalfJung Aug 6, 2019
16c0902
warn for more cases
RalfJung Aug 7, 2019
a902f7a
fix a comment
RalfJung Aug 7, 2019
d03b64a
add tuple_fields convenience method and use it in a few places
RalfJung Aug 7, 2019
1873844
note a FIXME
RalfJung Aug 7, 2019
b258ed5
proper doc comment for 'recovered' field of variant
RalfJung Aug 7, 2019
157b76a
allow the lint if a few UB-demonstrating doc tests
RalfJung Aug 7, 2019
6c7d84d
note down some more future plans
RalfJung Aug 7, 2019
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
e1bd8cb
rustc_target: add musl targets for MIPS64 arches
xen0n Jul 28, 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
4637396
Rollup merge of #63165 - xen0n:mips64-musl-targets, r=alexcrichton
Centril Aug 9, 2019
3b99865
Rollup merge of #63337 - estebank:break-ee0308, r=Centril
Centril Aug 9, 2019
a133e53
Rollup merge of #63346 - RalfJung:zeroed-lint, r=eddyb
Centril Aug 9, 2019
4cd0e7d
Rollup merge of #63350 - iluuu1994:use-associated-type-bounds, r=Centril
Centril Aug 9, 2019
56d3742
Rollup merge of #63394 - jackh726:issue-36804, r=jonas-schievink
Centril Aug 9, 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
Extend suggestion support for traits and foreign items
  • Loading branch information
estebank committed Aug 9, 2019
commit 5a54945b6f637eadd4848874db39b49d2764839f
25 changes: 24 additions & 1 deletion src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3858,11 +3858,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
Some(Node::Item(hir::Item {
node: ItemKind::Fn(.., body_id),
..
})) |
Some(Node::ImplItem(hir::ImplItem {
node: hir::ImplItemKind::Method(_, body_id),
..
})) |
Some(Node::TraitItem(hir::TraitItem {
node: hir::TraitItemKind::Method(.., hir::TraitMethod::Provided(body_id)),
..
})) => {
let body = hir.body(*body_id);
sugg_call = body.arguments.iter()
.map(|arg| match &arg.pat.node {
hir::PatKind::Binding(_, _, ident, None) => ident.to_string(),
hir::PatKind::Binding(_, _, ident, None)
if ident.name != kw::SelfLower => ident.to_string(),
_ => "_".to_string(),
}).collect::<Vec<_>>().join(", ");
}
Expand All @@ -3878,6 +3887,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
_ => {}
}
}
Some(Node::ForeignItem(hir::ForeignItem {
node: hir::ForeignItemKind::Fn(_, idents, _),
..
})) |
Some(Node::TraitItem(hir::TraitItem {
node: hir::TraitItemKind::Method(.., hir::TraitMethod::Required(idents)),
..
})) => sugg_call = idents.iter()
.map(|ident| if ident.name != kw::SelfLower {
ident.to_string()
} else {
"_".to_string()
}).collect::<Vec<_>>()
.join(", "),
_ => {}
}
};
Expand Down
21 changes: 20 additions & 1 deletion src/test/ui/suggestions/fn-or-tuple-struct-without-args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,18 @@ struct V();

trait T {
fn baz(x: usize, y: usize) -> usize { x }
fn bat() -> usize { 42 }
fn bat(x: usize) -> usize { 42 }
fn bax(x: usize) -> usize { 42 }
fn bach(x: usize) -> usize;
fn ban(&self) -> usize { 42 }
fn bal(&self) -> usize;
}

struct X;

impl T for X {
fn bach(x: usize) -> usize { 42 }
fn bal(&self) -> usize { 42 }
}

fn main() {
Expand All @@ -23,4 +34,12 @@ fn main() {
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`
let _: usize = X::baz; //~ ERROR mismatched types
let _: usize = X::bat; //~ ERROR mismatched types
let _: usize = X::bax; //~ ERROR mismatched types
let _: usize = X::bach; //~ ERROR mismatched types
let _: usize = X::ban; //~ ERROR mismatched types
let _: usize = X::bal; //~ ERROR mismatched types
let _: usize = X.ban; //~ ERROR attempted to take value of method
let _: usize = X.bal; //~ ERROR attempted to take value of method
}
132 changes: 117 additions & 15 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,5 @@
error[E0423]: expected value, found struct variant `E::B`
--> $DIR/fn-or-tuple-struct-without-args.rs:25:16
--> $DIR/fn-or-tuple-struct-without-args.rs:36:16
|
LL | let _: E = E::B;
| ^^^-
Expand All @@ -8,7 +8,7 @@ LL | let _: E = E::B;
| did you mean `E::B { /* fields */ }`?

error[E0308]: mismatched types
--> $DIR/fn-or-tuple-struct-without-args.rs:18:20
--> $DIR/fn-or-tuple-struct-without-args.rs:29:20
|
LL | fn foo(a: usize, b: usize) -> usize { a }
| ----------------------------------- fn(usize, usize) -> usize {foo} defined here
Expand All @@ -23,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:19:16
--> $DIR/fn-or-tuple-struct-without-args.rs:30:16
|
LL | struct S(usize, usize);
| ----------------------- fn(usize, usize) -> S {S} defined here
Expand All @@ -38,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:20:20
--> $DIR/fn-or-tuple-struct-without-args.rs:31:20
|
LL | fn bar() -> usize { 42 }
| ----------------- fn() -> usize {bar} defined here
Expand All @@ -53,7 +53,7 @@ LL | let _: usize = bar;
found type `fn() -> usize {bar}`

error[E0308]: mismatched types
--> $DIR/fn-or-tuple-struct-without-args.rs:21:16
--> $DIR/fn-or-tuple-struct-without-args.rs:32:16
|
LL | struct V();
| ----------- fn() -> V {V} defined here
Expand All @@ -68,7 +68,7 @@ LL | let _: V = V;
found type `fn() -> V {V}`

error[E0308]: mismatched types
--> $DIR/fn-or-tuple-struct-without-args.rs:22:20
--> $DIR/fn-or-tuple-struct-without-args.rs:33:20
|
LL | fn baz(x: usize, y: usize) -> usize { x }
| ----------------------------------- fn(usize, usize) -> usize {<_ as T>::baz} defined here
Expand All @@ -77,28 +77,28 @@ LL | let _: usize = T::baz;
| ^^^^^^
| |
| expected usize, found fn item
| help: use parentheses to call this function: `T::baz(...)`
| help: use parentheses to call this function: `T::baz(x, y)`
|
= note: expected type `usize`
found type `fn(usize, usize) -> usize {<_ as T>::baz}`

error[E0308]: mismatched types
--> $DIR/fn-or-tuple-struct-without-args.rs:23:20
--> $DIR/fn-or-tuple-struct-without-args.rs:34:20
|
LL | fn bat() -> usize { 42 }
| ----------------- fn() -> usize {<_ as T>::bat} defined here
LL | fn bat(x: usize) -> usize { 42 }
| ------------------------- fn(usize) -> usize {<_ as T>::bat} defined here
...
LL | let _: usize = T::bat;
| ^^^^^^
| |
| expected usize, found fn item
| help: use parentheses to call this function: `T::bat()`
| help: use parentheses to call this function: `T::bat(x)`
|
= note: expected type `usize`
found type `fn() -> usize {<_ as T>::bat}`
found type `fn(usize) -> usize {<_ as T>::bat}`

error[E0308]: mismatched types
--> $DIR/fn-or-tuple-struct-without-args.rs:24:16
--> $DIR/fn-or-tuple-struct-without-args.rs:35:16
|
LL | A(usize),
| -------- fn(usize) -> E {E::A} defined here
Expand All @@ -112,7 +112,109 @@ LL | let _: E = E::A;
= note: expected type `E`
found type `fn(usize) -> E {E::A}`

error: aborting due to 8 previous errors
error[E0308]: mismatched types
--> $DIR/fn-or-tuple-struct-without-args.rs:37:20
|
LL | fn baz(x: usize, y: usize) -> usize { x }
| ----------------------------------- fn(usize, usize) -> usize {<X as T>::baz} defined here
...
LL | let _: usize = X::baz;
| ^^^^^^
| |
| expected usize, found fn item
| help: use parentheses to call this function: `X::baz(x, y)`
|
= note: expected type `usize`
found type `fn(usize, usize) -> usize {<X as T>::baz}`

error[E0308]: mismatched types
--> $DIR/fn-or-tuple-struct-without-args.rs:38:20
|
LL | fn bat(x: usize) -> usize { 42 }
| ------------------------- fn(usize) -> usize {<X as T>::bat} defined here
...
LL | let _: usize = X::bat;
| ^^^^^^
| |
| expected usize, found fn item
| help: use parentheses to call this function: `X::bat(x)`
|
= note: expected type `usize`
found type `fn(usize) -> usize {<X as T>::bat}`

error[E0308]: mismatched types
--> $DIR/fn-or-tuple-struct-without-args.rs:39:20
|
LL | fn bax(x: usize) -> usize { 42 }
| ------------------------- fn(usize) -> usize {<X as T>::bax} defined here
...
LL | let _: usize = X::bax;
| ^^^^^^
| |
| expected usize, found fn item
| help: use parentheses to call this function: `X::bax(x)`
|
= note: expected type `usize`
found type `fn(usize) -> usize {<X as T>::bax}`

error[E0308]: mismatched types
--> $DIR/fn-or-tuple-struct-without-args.rs:40:20
|
LL | fn bach(x: usize) -> usize;
| --------------------------- fn(usize) -> usize {<X as T>::bach} defined here
...
LL | let _: usize = X::bach;
| ^^^^^^^
| |
| expected usize, found fn item
| help: use parentheses to call this function: `X::bach(x)`
|
= note: expected type `usize`
found type `fn(usize) -> usize {<X as T>::bach}`

error[E0308]: mismatched types
--> $DIR/fn-or-tuple-struct-without-args.rs:41:20
|
LL | fn ban(&self) -> usize { 42 }
| ---------------------- for<'r> fn(&'r X) -> usize {<X as T>::ban} defined here
...
LL | let _: usize = X::ban;
| ^^^^^^
| |
| expected usize, found fn item
| help: use parentheses to call this function: `X::ban(_)`
|
= note: expected type `usize`
found type `for<'r> fn(&'r X) -> usize {<X as T>::ban}`

error[E0308]: mismatched types
--> $DIR/fn-or-tuple-struct-without-args.rs:42:20
|
LL | fn bal(&self) -> usize;
| ----------------------- for<'r> fn(&'r X) -> usize {<X as T>::bal} defined here
...
LL | let _: usize = X::bal;
| ^^^^^^
| |
| expected usize, found fn item
| help: use parentheses to call this function: `X::bal(_)`
|
= note: expected type `usize`
found type `for<'r> fn(&'r X) -> usize {<X as T>::bal}`

error[E0615]: attempted to take value of method `ban` on type `X`
--> $DIR/fn-or-tuple-struct-without-args.rs:43:22
|
LL | let _: usize = X.ban;
| ^^^ help: use parentheses to call the method: `ban()`

error[E0615]: attempted to take value of method `bal` on type `X`
--> $DIR/fn-or-tuple-struct-without-args.rs:44:22
|
LL | let _: usize = X.bal;
| ^^^ help: use parentheses to call the method: `bal()`

error: aborting due to 16 previous errors

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