Auto merge of #7684 - surechen:solve_derivable_impls, r=flip1995
fix for issue #7683
Fixes #7683.
For Repeat [x; y] (x is the type and y is the times to repeat) . When y > 32, the compiler will report an error:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=7148558162685e91056e0550797ea74c
Because 6cdd42f9f8/library/std/src/primitive_docs.rs (L538)
/// Arrays of sizes from 0 to 32 (inclusive) implement [`Default`] trait
/// if the element type allows it. As a stopgap, trait implementations are
/// statically generated up to size 32.
So here to detect this situation.
changelog: [`derivable_impls`]: No longer lints when arrays bigger than 32 elements are involved
This commit is contained in:
commit
ab99eec15f
3 changed files with 44 additions and 2 deletions
|
|
@ -684,7 +684,17 @@ pub fn is_default_equivalent(cx: &LateContext<'_>, e: &Expr<'_>) -> bool {
|
|||
_ => false,
|
||||
},
|
||||
ExprKind::Tup(items) | ExprKind::Array(items) => items.iter().all(|x| is_default_equivalent(cx, x)),
|
||||
ExprKind::Repeat(x, _) => is_default_equivalent(cx, x),
|
||||
ExprKind::Repeat(x, y) => if_chain! {
|
||||
if let ExprKind::Lit(ref const_lit) = cx.tcx.hir().body(y.body).value.kind;
|
||||
if let LitKind::Int(v, _) = const_lit.node;
|
||||
if v <= 32 && is_default_equivalent(cx, x);
|
||||
then {
|
||||
true
|
||||
}
|
||||
else {
|
||||
false
|
||||
}
|
||||
},
|
||||
ExprKind::Call(repl_func, _) => if_chain! {
|
||||
if let ExprKind::Path(ref repl_func_qpath) = repl_func.kind;
|
||||
if let Some(repl_def_id) = cx.qpath_res(repl_func_qpath, repl_func.hir_id).opt_def_id();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue