mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-27 07:00:55 +00:00
Update and fix clippy tests
This commit is contained in:
parent
b86620da37
commit
43ce0a94af
3 changed files with 24 additions and 5 deletions
|
@ -3,6 +3,7 @@ use clippy_utils::qualify_min_const_fn::is_min_const_fn;
|
|||
use clippy_utils::ty::has_drop;
|
||||
use clippy_utils::{fn_has_unsatisfiable_preds, is_entrypoint_fn, meets_msrv, msrvs, trait_ref_of_method};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def_id::CRATE_DEF_ID;
|
||||
use rustc_hir::intravisit::FnKind;
|
||||
use rustc_hir::{Body, Constness, FnDecl, GenericParamKind, HirId};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
|
@ -131,6 +132,18 @@ impl<'tcx> LateLintPass<'tcx> for MissingConstForFn {
|
|||
FnKind::Closure => return,
|
||||
}
|
||||
|
||||
// Const fns are not allowed as methods in a trait.
|
||||
{
|
||||
let parent = cx.tcx.hir().get_parent_item(hir_id);
|
||||
if parent != CRATE_DEF_ID {
|
||||
if let hir::Node::Item(item) = cx.tcx.hir().get_by_def_id(parent) {
|
||||
if let hir::ItemKind::Trait(..) = &item.kind {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let mir = cx.tcx.optimized_mir(def_id);
|
||||
|
||||
if let Err((span, err)) = is_min_const_fn(cx.tcx, mir, self.msrv.as_ref()) {
|
||||
|
|
|
@ -49,8 +49,6 @@ fn sub(x: u32) -> usize {
|
|||
unsafe { transmute(&x) }
|
||||
}
|
||||
|
||||
// NOTE: This is currently not yet allowed to be const
|
||||
// Once implemented, Clippy should be able to suggest this as const, too.
|
||||
fn generic_arr<T: Copy>(t: [T; 1]) -> T {
|
||||
t[0]
|
||||
}
|
||||
|
|
|
@ -58,7 +58,15 @@ LL | | }
|
|||
| |_^
|
||||
|
||||
error: this could be a `const fn`
|
||||
--> $DIR/could_be_const.rs:67:9
|
||||
--> $DIR/could_be_const.rs:52:1
|
||||
|
|
||||
LL | / fn generic_arr<T: Copy>(t: [T; 1]) -> T {
|
||||
LL | | t[0]
|
||||
LL | | }
|
||||
| |_^
|
||||
|
||||
error: this could be a `const fn`
|
||||
--> $DIR/could_be_const.rs:65:9
|
||||
|
|
||||
LL | / pub fn b(self, a: &A) -> B {
|
||||
LL | | B
|
||||
|
@ -66,12 +74,12 @@ LL | | }
|
|||
| |_________^
|
||||
|
||||
error: this could be a `const fn`
|
||||
--> $DIR/could_be_const.rs:77:5
|
||||
--> $DIR/could_be_const.rs:75:5
|
||||
|
|
||||
LL | / fn const_fn_stabilized_before_msrv(byte: u8) {
|
||||
LL | | byte.is_ascii_digit();
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
||||
error: aborting due to 9 previous errors
|
||||
error: aborting due to 10 previous errors
|
||||
|
||||
|
|
Loading…
Reference in a new issue