mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-27 01:04:03 +00:00
Update clippy for associated item changes
This commit is contained in:
parent
3b7d496f72
commit
9e5f23e2a6
@ -4,24 +4,6 @@ error[E0437]: type `bar` is not a member of trait `Foo`
|
||||
LL | type bar = u64;
|
||||
| ^^^^^^^^^^^^^^^ not a member of trait `Foo`
|
||||
|
||||
error[E0323]: item `bar` is an associated const, which doesn't match its trait `Foo`
|
||||
--> $DIR/impl-wrong-item-for-trait.rs:12:5
|
||||
|
|
||||
LL | fn bar(&self);
|
||||
| -------------- item in trait
|
||||
...
|
||||
LL | const bar: u64 = 1;
|
||||
| ^^^^^^^^^^^^^^^^^^^ does not match trait
|
||||
|
||||
error[E0046]: not all trait items implemented, missing: `bar`
|
||||
--> $DIR/impl-wrong-item-for-trait.rs:10:1
|
||||
|
|
||||
LL | fn bar(&self);
|
||||
| -------------- `bar` from trait
|
||||
...
|
||||
LL | impl Foo for FooConstForMethod {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `bar` in implementation
|
||||
|
||||
error[E0324]: item `MY_CONST` is an associated method, which doesn't match its trait `Foo`
|
||||
--> $DIR/impl-wrong-item-for-trait.rs:22:5
|
||||
|
|
||||
@ -31,14 +13,14 @@ LL | const MY_CONST: u32;
|
||||
LL | fn MY_CONST() {}
|
||||
| ^^^^^^^^^^^^^^^^ does not match trait
|
||||
|
||||
error[E0046]: not all trait items implemented, missing: `MY_CONST`
|
||||
--> $DIR/impl-wrong-item-for-trait.rs:19:1
|
||||
error[E0323]: item `bar` is an associated const, which doesn't match its trait `Foo`
|
||||
--> $DIR/impl-wrong-item-for-trait.rs:12:5
|
||||
|
|
||||
LL | const MY_CONST: u32;
|
||||
| -------------------- `MY_CONST` from trait
|
||||
LL | fn bar(&self);
|
||||
| -------------- item in trait
|
||||
...
|
||||
LL | impl Foo for FooMethodForConst {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `MY_CONST` in implementation
|
||||
LL | const bar: u64 = 1;
|
||||
| ^^^^^^^^^^^^^^^^^^^ does not match trait
|
||||
|
||||
error[E0325]: item `bar` is an associated type, which doesn't match its trait `Foo`
|
||||
--> $DIR/impl-wrong-item-for-trait.rs:30:5
|
||||
@ -49,6 +31,24 @@ LL | fn bar(&self);
|
||||
LL | type bar = u64;
|
||||
| ^^^^^^^^^^^^^^^ does not match trait
|
||||
|
||||
error[E0046]: not all trait items implemented, missing: `bar`
|
||||
--> $DIR/impl-wrong-item-for-trait.rs:10:1
|
||||
|
|
||||
LL | fn bar(&self);
|
||||
| -------------- `bar` from trait
|
||||
...
|
||||
LL | impl Foo for FooConstForMethod {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `bar` in implementation
|
||||
|
||||
error[E0046]: not all trait items implemented, missing: `MY_CONST`
|
||||
--> $DIR/impl-wrong-item-for-trait.rs:19:1
|
||||
|
|
||||
LL | const MY_CONST: u32;
|
||||
| -------------------- `MY_CONST` from trait
|
||||
...
|
||||
LL | impl Foo for FooMethodForConst {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `MY_CONST` in implementation
|
||||
|
||||
error[E0046]: not all trait items implemented, missing: `bar`
|
||||
--> $DIR/impl-wrong-item-for-trait.rs:28:1
|
||||
|
|
||||
|
@ -214,14 +214,14 @@ fn check_trait_items(cx: &LateContext<'_>, visited_trait: &Item<'_>, trait_items
|
||||
{
|
||||
let mut current_and_super_traits = DefIdSet::default();
|
||||
fill_trait_set(visited_trait.def_id.to_def_id(), &mut current_and_super_traits, cx);
|
||||
let is_empty = sym!(is_empty);
|
||||
|
||||
let is_empty_method_found = current_and_super_traits
|
||||
.iter()
|
||||
.flat_map(|&i| cx.tcx.associated_items(i).in_definition_order())
|
||||
.flat_map(|&i| cx.tcx.associated_items(i).filter_by_name_unhygienic(is_empty))
|
||||
.any(|i| {
|
||||
i.kind == ty::AssocKind::Fn
|
||||
&& i.fn_has_self_parameter
|
||||
&& i.ident.name == sym!(is_empty)
|
||||
&& cx.tcx.fn_sig(i.def_id).inputs().skip_binder().len() == 1
|
||||
});
|
||||
|
||||
@ -458,7 +458,7 @@ fn is_empty_array(expr: &Expr<'_>) -> bool {
|
||||
fn has_is_empty(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
|
||||
/// Gets an `AssocItem` and return true if it matches `is_empty(self)`.
|
||||
fn is_is_empty(cx: &LateContext<'_>, item: &ty::AssocItem) -> bool {
|
||||
if item.kind == ty::AssocKind::Fn && item.ident.name.as_str() == "is_empty" {
|
||||
if item.kind == ty::AssocKind::Fn {
|
||||
let sig = cx.tcx.fn_sig(item.def_id);
|
||||
let ty = sig.skip_binder();
|
||||
ty.inputs().len() == 1
|
||||
@ -469,10 +469,11 @@ fn has_is_empty(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
|
||||
|
||||
/// Checks the inherent impl's items for an `is_empty(self)` method.
|
||||
fn has_is_empty_impl(cx: &LateContext<'_>, id: DefId) -> bool {
|
||||
let is_empty = sym!(is_empty);
|
||||
cx.tcx.inherent_impls(id).iter().any(|imp| {
|
||||
cx.tcx
|
||||
.associated_items(*imp)
|
||||
.in_definition_order()
|
||||
.filter_by_name_unhygienic(is_empty)
|
||||
.any(|item| is_is_empty(cx, item))
|
||||
})
|
||||
}
|
||||
@ -480,9 +481,10 @@ fn has_is_empty(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
|
||||
let ty = &cx.typeck_results().expr_ty(expr).peel_refs();
|
||||
match ty.kind() {
|
||||
ty::Dynamic(tt, ..) => tt.principal().map_or(false, |principal| {
|
||||
let is_empty = sym!(is_empty);
|
||||
cx.tcx
|
||||
.associated_items(principal.def_id())
|
||||
.in_definition_order()
|
||||
.filter_by_name_unhygienic(is_empty)
|
||||
.any(|item| is_is_empty(cx, item))
|
||||
}),
|
||||
ty::Projection(ref proj) => has_is_empty_impl(cx, proj.item_def_id),
|
||||
|
@ -12,11 +12,10 @@ use rustc_hir::def_id::DefId;
|
||||
use rustc_hir::{
|
||||
BodyId, Expr, ExprKind, HirId, Impl, ImplItem, ImplItemKind, Item, ItemKind, Node, TraitItem, TraitItemKind, UnOp,
|
||||
};
|
||||
use rustc_infer::traits::specialization_graph;
|
||||
use rustc_lint::{LateContext, LateLintPass, Lint};
|
||||
use rustc_middle::mir::interpret::{ConstValue, ErrorHandled};
|
||||
use rustc_middle::ty::adjustment::Adjust;
|
||||
use rustc_middle::ty::{self, AssocKind, Const, Ty};
|
||||
use rustc_middle::ty::{self, Const, Ty};
|
||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||
use rustc_span::{InnerSpan, Span, DUMMY_SP};
|
||||
use rustc_typeck::hir_ty_to_ty;
|
||||
@ -293,8 +292,10 @@ impl<'tcx> LateLintPass<'tcx> for NonCopyConst {
|
||||
// Lint a trait impl item only when the definition is a generic type,
|
||||
// assuming an assoc const is not meant to be an interior mutable type.
|
||||
if let Some(of_trait_def_id) = of_trait_ref.trait_def_id();
|
||||
if let Some(of_assoc_item) = specialization_graph::Node::Trait(of_trait_def_id)
|
||||
.item(cx.tcx, impl_item.ident, AssocKind::Const, of_trait_def_id);
|
||||
if let Some(of_assoc_item) = cx
|
||||
.tcx
|
||||
.associated_item(impl_item.def_id)
|
||||
.trait_item_def_id;
|
||||
if cx
|
||||
.tcx
|
||||
.layout_of(cx.tcx.param_env(of_trait_def_id).and(
|
||||
@ -303,7 +304,7 @@ impl<'tcx> LateLintPass<'tcx> for NonCopyConst {
|
||||
// and, in that case, the definition is *not* generic.
|
||||
cx.tcx.normalize_erasing_regions(
|
||||
cx.tcx.param_env(of_trait_def_id),
|
||||
cx.tcx.type_of(of_assoc_item.def_id),
|
||||
cx.tcx.type_of(of_assoc_item),
|
||||
),
|
||||
))
|
||||
.is_err();
|
||||
|
@ -13,7 +13,6 @@ use rustc_hir::{
|
||||
};
|
||||
use rustc_lint::{LateContext, LateLintPass, LintContext};
|
||||
use rustc_middle::hir::map::Map;
|
||||
use rustc_middle::ty::AssocKind;
|
||||
use rustc_semver::RustcVersion;
|
||||
use rustc_session::{declare_tool_lint, impl_lint_pass};
|
||||
use rustc_span::Span;
|
||||
@ -143,10 +142,10 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf {
|
||||
// trait, not in the impl of the trait.
|
||||
let trait_method = cx
|
||||
.tcx
|
||||
.associated_items(impl_trait_ref.def_id)
|
||||
.find_by_name_and_kind(cx.tcx, impl_item.ident, AssocKind::Fn, impl_trait_ref.def_id)
|
||||
.associated_item(impl_item.def_id)
|
||||
.trait_item_def_id
|
||||
.expect("impl method matches a trait method");
|
||||
let trait_method_sig = cx.tcx.fn_sig(trait_method.def_id);
|
||||
let trait_method_sig = cx.tcx.fn_sig(trait_method);
|
||||
let trait_method_sig = cx.tcx.erase_late_bound_regions(trait_method_sig);
|
||||
|
||||
// `impl_inputs_outputs` is an iterator over the types (`hir::Ty`) declared in the
|
||||
|
Loading…
Reference in New Issue
Block a user