-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Conversation
5fabd44
to
8a2e65e
Compare
return; | ||
} | ||
|
||
if let FnKind::Method(name, _, _) = kind { |
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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
11524fe
to
ddb8cb7
Compare
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(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 😅.
There was a problem hiding this comment.
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.
Also, it would be great if you could remove all mentions of |
87f379d
to
7068f0e
Compare
Can this be merged now? |
Lint unused labels and types with `fn new() -> Self` and no `Default` impl
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
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
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
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
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
Fix #705. Fix #708.