Skip to content
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

Lint unused labels and types with fn new() -> Self and no Default impl #730

Merged
merged 4 commits into from
Mar 9, 2016

Conversation

mcarton
Copy link
Member

@mcarton mcarton commented Mar 1, 2016

Fix #705. Fix #708.

@mcarton mcarton force-pushed the unused-labels branch 2 times, most recently from 5fabd44 to 8a2e65e Compare March 1, 2016 15:35
return;
}

if let FnKind::Method(name, _, _) = kind {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this might be a candidate for an if_let_chain!

fn check_expr(&mut self, _: &LateContext, expr: &hir::Expr) {
match expr.node {
hir::ExprBreak(Some(label)) | hir::ExprAgain(Some(label)) => {
self.used_labels.insert(label.node.name.as_str());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could just remove the appropriate label from declared_labels, then you just need to iterate over the hash-map at the end instead of indexing it from the values in the hashset

@mcarton mcarton force-pushed the unused-labels branch 2 times, most recently from 11524fe to ddb8cb7 Compare March 1, 2016 16:23
@oli-obk
Copy link
Contributor

oli-obk commented Mar 1, 2016

lgtm

/// Return whether a method returns `Self`.
pub fn returns_self(cx: &LateContext, ret: &FunctionRetTy, ty: ty::Ty) -> bool {
if let FunctionRetTy::Return(ref ret_ty) = *ret {
let ast_ty_to_ty_cache = cx.tcx.ast_ty_to_ty_cache.borrow();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should not use ast_ty_to_ty_cache. We should use node_ty or something else here (@eddyb can help).

I know it was broken before too, but let's fix it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I just tried ctxt::node_types which returns None and InferCtxt::node_ty{pe,} which panic 😅.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should get the return type from the function type and not look at the function's AST/HIR at all.

@eddyb
Copy link
Member

eddyb commented Mar 1, 2016

Also, it would be great if you could remove all mentions of TyBareFn because of rust-lang/rust#31710.

@mcarton mcarton force-pushed the unused-labels branch 6 times, most recently from 87f379d to 7068f0e Compare March 7, 2016 19:20
@mcarton
Copy link
Member Author

mcarton commented Mar 9, 2016

Can this be merged now?

Manishearth added a commit that referenced this pull request Mar 9, 2016
Lint unused labels and types with `fn new() -> Self` and no `Default` impl
@Manishearth Manishearth merged commit d9b5b2a into rust-lang:master Mar 9, 2016
@mcarton mcarton deleted the unused-labels branch March 9, 2016 10:38
phansch added a commit to phansch/rust-clippy that referenced this pull request Apr 25, 2020
This delegates our `same_tys` to [ty::TyS::same_type][same_type] to
remove some duplication.

Our `same_tys` was introduced 4 years ago in rust-lang#730.

Before, `same_tys` was building an inference context to be able to call
`can_eq` to compare the types. The `rustc-dev-guide` has some more details
about `can_eq` in [Type Inference -> Trying equality][try_eq].

Now, using the rustc function, we are essentially comparing the `DefId`s
of the given types, which also makes more sense, IMO.

I also confirmed that the FIXME is resolved via a bit of `dbg!`, however
no UI tests were affected.

[same_type]: https://github.com/rust-lang/rust/blob/659951c4a0d7450e43f61c61c0e87d0ceae17087/src/librustc_middle/ty/util.rs#L777
[try_eq]: https://rustc-dev-guide.rust-lang.org/type-inference.html#trying-equality
phansch added a commit to phansch/rust-clippy that referenced this pull request Apr 25, 2020
This delegates our `same_tys` to [ty::TyS::same_type][same_type] to
remove some duplication.

Our `same_tys` was introduced 4 years ago in rust-lang#730.

Before, `same_tys` was building an inference context to be able to call
`can_eq` to compare the types. The `rustc-dev-guide` has some more details
about `can_eq` in [Type Inference -> Trying equality][try_eq].

Now, using the rustc function, we are essentially comparing the `DefId`s
of the given types, which also makes more sense, IMO.

I also confirmed that the FIXME is resolved via a bit of `dbg!`, however
no UI tests were affected.

[same_type]: https://github.com/rust-lang/rust/blob/659951c4a0d7450e43f61c61c0e87d0ceae17087/src/librustc_middle/ty/util.rs#L777
[try_eq]: https://rustc-dev-guide.rust-lang.org/type-inference.html#trying-equality
phansch added a commit to phansch/rust-clippy that referenced this pull request Apr 26, 2020
This delegates our `same_tys` to [ty::TyS::same_type][same_type] to
remove some duplication.

Our `same_tys` was introduced 4 years ago in rust-lang#730.

Before, `same_tys` was building an inference context to be able to call
`can_eq` to compare the types. The `rustc-dev-guide` has some more details
about `can_eq` in [Type Inference -> Trying equality][try_eq].

Now, using the rustc function, we are essentially comparing the `DefId`s
of the given types, which also makes more sense, IMO.

I also confirmed that the FIXME is resolved via a bit of `dbg!`, however
no UI tests were affected.

[same_type]: https://github.com/rust-lang/rust/blob/659951c4a0d7450e43f61c61c0e87d0ceae17087/src/librustc_middle/ty/util.rs#L777
[try_eq]: https://rustc-dev-guide.rust-lang.org/type-inference.html#trying-equality
phansch added a commit to phansch/rust-clippy that referenced this pull request Apr 26, 2020
This replaces our `same_tys` with [ty::TyS::same_type][same_type] to
remove some duplication.

Our `same_tys` was introduced 4 years ago in rust-lang#730.

Before, `same_tys` was building an inference context to be able to call
`can_eq` to compare the types. The `rustc-dev-guide` has some more details
about `can_eq` in [Type Inference -> Trying equality][try_eq].

Now, using the rustc function, we are essentially comparing the `DefId`s
of the given types, which also makes more sense, IMO.

I also confirmed that the FIXME is resolved via a bit of `dbg!`, however
no UI tests were affected.

[same_type]: https://github.com/rust-lang/rust/blob/659951c4a0d7450e43f61c61c0e87d0ceae17087/src/librustc_middle/ty/util.rs#L777
[try_eq]: https://rustc-dev-guide.rust-lang.org/type-inference.html#trying-equality
bors added a commit that referenced this pull request Jun 6, 2020
Cleanup: Use rustc's `same_type` for our `same_tys`

This delegates our `same_tys` to [ty::TyS::same_type][same_type] to
remove some duplication.

Our `same_tys` was introduced 4 years ago in #730. Before, it was
building an inference context to be able to call
`can_eq` to compare the types. The `rustc-dev-guide` has some more details
about `can_eq` in [Type Inference -> Trying equality][try_eq].

Now, using the rustc function, we are essentially comparing the `DefId`s
of the given types, which also makes more sense, IMO.

I also confirmed that the FIXME is resolved via a bit of `dbg!`, however
no UI tests seem to have been affected.

[same_type]: https://github.com/rust-lang/rust/blob/659951c4a0d7450e43f61c61c0e87d0ceae17087/src/librustc_middle/ty/util.rs#L777
[try_eq]: https://rustc-dev-guide.rust-lang.org/type-inference.html#trying-equality

---

changelog: none
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants