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

Update Clippy #100419

Merged
merged 94 commits into from
Aug 12, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
94 commits
Select commit Hold shift + click to select a range
4c43aa7
Fix suggestion for `async` in redundant_closure_call
AaronC81 Jun 25, 2022
c990e29
Don't suggest using auto deref for block expressions
Jarcho Jul 5, 2022
9ce0f82
Include the borrow in the suggestion for `explicit_auto_deref`
Jarcho Jul 6, 2022
84e03b6
Don't lint `explicit_auto_deref` on `dyn Trait` return
Jarcho Jul 10, 2022
d602ab1
Don't lint `exlipicit_auto_deref` when other adjustments are needed
Jarcho Jul 17, 2022
6ee03e2
unwrap_used: Stop recommending using `expect` when the `expect_used` …
sgued Jul 21, 2022
3e52031
unwrap_used: Fix help, "an `None`" -> "`None`"
sgued Jul 22, 2022
af8ae10
Generate correct suggestion with named arguments used positionally
PrestonFrom Jul 16, 2022
08e7ec4
Read and use deprecated configuration (as well as emitting a warning)
flip1995 Jul 27, 2022
38e8013
Enable test empty_loop_no_std on windows
alex-semenyuk Jul 28, 2022
67c405c
Merge commit '3c7e7dbc1583a0b06df5bd7623dd354a4debd23d' into clippyup
flip1995 Jul 28, 2022
307b800
unwrap_used: Fix doc to not recommend expect when expect_used is not …
sgued Jul 28, 2022
1fd9f2d
Fix tests
sgued Jul 28, 2022
ea25ef1
Harden duplicates checking and add tests
bossmc Jul 28, 2022
53a09d4
Auto merge of #9252 - Metaswitch:use-deprecated-config, r=Jarcho
bors Jul 29, 2022
61c6d16
Auto merge of #99660 - PrestonFrom:issue_99265, r=compiler-errors
bors Jul 29, 2022
1a6f02b
Remove `TreeAndSpacing`.
nnethercote Jul 28, 2022
2f48257
Rename "blacklisted name" to "disallowed name" throughout
bossmc Jun 8, 2022
66b4674
Change lint name to plural
bossmc Jun 8, 2022
56c9cc4
Add deprecation test for old configuration entry
bossmc Jun 9, 2022
a0ed687
Auto merge of #8974 - Metaswitch:remove-blacklist-terminology, r=Mani…
bors Jul 29, 2022
ca0996e
Change maybe_body_owned_by to take local def id
kckeiks Jul 16, 2022
29a0f69
Rename local_did to def_id
kckeiks Jul 19, 2022
ce5fa10
Change enclosing_body_owner to return LocalDefId
kckeiks Jul 19, 2022
6c1110e
Avoid ICE when fetching LocalDefId
kckeiks Jul 20, 2022
23b4fe6
Apply suggestions from code review
sgued Jul 30, 2022
ab7e555
Auto merge of #99887 - nnethercote:rm-TreeAndSpacing, r=petrochenkov
bors Jul 30, 2022
3641b0c
Auto merge of #99948 - Dylan-DPC:rollup-ed5136t, r=Dylan-DPC
bors Jul 30, 2022
6290772
Use LocalDefId for closures more
camsteffen Jul 12, 2022
72649cf
Rollup merge of #99186 - camsteffen:closure-localdefid, r=cjgillot
Dylan-DPC Jul 31, 2022
cd13574
Always include a position span in rustc_parse_format::Argument
Alexendoo Jul 31, 2022
09f9ace
Shrink `Token`.
nnethercote Jul 27, 2022
a591e72
Auto merge of #9223 - sgued:unwrap-expect-used, r=giraffate
bors Aug 1, 2022
e00ceb9
move [`assertions_on_result_states`] to restriction
tabokie Aug 1, 2022
72e7064
Make it easier to find the developer guide
schubart Jul 31, 2022
7c427f0
Auto merge of #9270 - schubart:link_to_developer_guide, r=xFrednet
bors Aug 1, 2022
48ad9d8
do not apply [`assertions_on_result_states`] to unwrap unit type
tabokie Aug 1, 2022
a5a6c95
Auto merge of #9273 - tabokie:assert_ok_fp, r=flip1995
bors Aug 1, 2022
80a5687
Auto merge of #99884 - nnethercote:lexer-improvements, r=matklad
bors Aug 1, 2022
d17a30a
Store associated item defaultness in impl_defaultness.
cjgillot Mar 12, 2022
119247a
Remove DefId from AssocItemContainer.
cjgillot Mar 12, 2022
0696624
Add `elapsed_instant` lint
guerinoni Jul 30, 2022
367d09f
Auto merge of #9254 - alex-semenyuk:enable_empty_loop_no_std_on_windo…
bors Aug 2, 2022
2fcaac7
move [`assertions_on_result_states`] to restriction
tabokie Aug 1, 2022
9ab6146
simplify unit type check
tabokie Aug 2, 2022
ac7a91e
use slice match more often
tabokie Aug 2, 2022
4914833
Auto merge of #9279 - tabokie:weight-loss, r=flip1995
bors Aug 2, 2022
00e59cd
Auto merge of #9264 - guerinoni:instant-elapsed, r=Alexendoo
bors Aug 2, 2022
05e7d54
Auto merge of #9053 - AaronC81:fix-9052, r=flip1995
bors Aug 2, 2022
4546f5d
Rollup merge of #99987 - Alexendoo:parse-format-position-span, r=fee1…
matthiaskrgr Aug 2, 2022
7aaeee7
Rollup merge of #100053 - flip1995:clippy_backport, r=xFrednet
matthiaskrgr Aug 2, 2022
145ebb1
add paren before '?' when suggesting deref
macovedj Aug 2, 2022
503c03c
clean up
macovedj Aug 2, 2022
b50ba06
fix typo in tests/ui/redundant_allocation.rs
lengyijun Aug 3, 2022
5dc90a1
Auto merge of #9282 - macovedj:clone-on-copy-try-precedence, r=flip1995
bors Aug 3, 2022
f232402
Warn about dead tuple struct fields
FabianWolff Jul 25, 2022
7177746
Auto merge of #9284 - lengyijun:typo, r=dswij
bors Aug 3, 2022
ccbc965
Add `traits::fully_solve_obligation` that acts like `traits::fully_no…
compiler-errors Aug 2, 2022
7062a01
Fix some typos
alex-semenyuk Aug 4, 2022
0e1d658
Fix cast_abs_to_unsigned generates non-compiling code when original c…
alex-semenyuk Jul 30, 2022
2dc7d2f
Auto merge of #9266 - alex-semenyuk:cast_abs_to_unsigned_paren_fix, r…
bors Aug 4, 2022
f63b324
Fix some typos
alex-semenyuk Aug 4, 2022
57731f1
Auto merge of #9292 - alex-semenyuk:typos_fixed, r=Alexendoo
bors Aug 5, 2022
1e1193f
Enable test for def_id_nocore for windows
alex-semenyuk Aug 5, 2022
5721ca9
Auto merge of #9294 - alex-semenyuk:enable_def_id_nocore_on_windows, …
bors Aug 5, 2022
f719599
Auto merge of #99743 - compiler-errors:fulfillment-context-cleanups, …
bors Aug 6, 2022
aa0b0af
Move `significant_drop_in_scrutinee` into `nursey`
Jarcho Aug 8, 2022
2ae8b30
Don't lint `unit_arg` when expanded from a proc-macro
Jarcho Apr 13, 2022
37e838f
Use new util function in `suspicious_else_formatting`
Jarcho Apr 13, 2022
4ae582e
Don't lint `missing_docs_in_private_items` on proc-macro output
Jarcho Apr 13, 2022
670efd5
Don't lint `default_trait_access` in proc-macro expansions
Jarcho Apr 13, 2022
8dda974
Add note to the docs on `is_from_proc_macro`
Jarcho Apr 24, 2022
745b194
Small cleanup for `check_proc_macro.rs`
Jarcho Aug 8, 2022
99abd4a
Fix ICE when reading literals with weird proc-macro spans
Jarcho Aug 8, 2022
97a0cf2
Auto merge of #9302 - Jarcho:sig_drop_nursery, r=flip1995
bors Aug 8, 2022
10853f7
Auto merge of #8694 - Jarcho:check_proc_macro, r=xFrednet
bors Aug 8, 2022
0ee7025
Auto merge of #9303 - Jarcho:ice_9297, r=Alexendoo
bors Aug 8, 2022
5285928
Fix ICE when checking the HIR ty of closure args.
Jarcho Aug 8, 2022
ecb51fe
Lint `explicit_auto_deref` in implicit return positions for closures
Jarcho Aug 8, 2022
4912c0e
Auto merge of #9126 - Jarcho:auto_deref_sugg, r=Manishearth
bors Aug 8, 2022
f6cab94
Rename `logic_bug` to `overly_complex_bool_expr`
guerinoni Aug 8, 2022
8f39061
Auto merge of #9306 - guerinoni:rename-logic-bug, r=llogiq,xFrednet
bors Aug 8, 2022
657b0da
Add partialeq_to_none lint
lukaslueg Aug 3, 2022
3af9072
Auto merge of #9288 - lukaslueg:partialeqnone, r=Jarcho
bors Aug 9, 2022
8d4f2ac
Use `check_proc_macro` for `missing_const_for_fn`
daxpedda Aug 9, 2022
6f5d648
Address review
daxpedda Aug 9, 2022
fd60581
Address review take 2
daxpedda Aug 9, 2022
f7e2cb4
Auto merge of #9308 - daxpedda:missing-const-for-fn, r=Jarcho
bors Aug 9, 2022
879855b
Merge remote-tracking branch 'upstream/master' into rustup
flip1995 Aug 11, 2022
eda0b00
Bump nightly version -> 2022-08-11
flip1995 Aug 11, 2022
280b527
Bump Clippy version -> 0.1.65
flip1995 Aug 11, 2022
2b2190c
Auto merge of #9323 - flip1995:rustup, r=flip1995
bors Aug 11, 2022
ad76883
Merge commit '2b2190cb5667cdd276a24ef8b9f3692209c54a89' into clippyup
flip1995 Aug 11, 2022
ea90d4b
Update Cargo.lock
flip1995 Aug 11, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Lint explicit_auto_deref in implicit return positions for closures
  • Loading branch information
Jarcho committed Aug 8, 2022
commit ecb51fe6a55f975f2d3bfd65d3568c263c248460
45 changes: 30 additions & 15 deletions clippy_lints/src/dereference.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_hir_and_then};
use clippy_utils::source::{snippet_with_applicability, snippet_with_context};
use clippy_utils::sugg::has_enclosing_paren;
use clippy_utils::ty::{expr_sig, peel_mid_ty_refs, variant_of_res};
use clippy_utils::ty::{expr_sig, peel_mid_ty_refs, ty_sig, variant_of_res};
use clippy_utils::{get_parent_expr, is_lint_allowed, path_to_local, walk_to_expr_usage};
use rustc_ast::util::parser::{PREC_POSTFIX, PREC_PREFIX};
use rustc_data_structures::fx::FxIndexMap;
Expand Down Expand Up @@ -704,24 +704,13 @@ fn walk_parents<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> (Position, &
let owner_id = cx.tcx.hir().body_owner(cx.enclosing_body.unwrap());
Some(
if let Node::Expr(
closure @ Expr {
kind: ExprKind::Closure(&Closure { fn_decl, .. }),
closure_expr @ Expr {
kind: ExprKind::Closure(closure),
..
},
) = cx.tcx.hir().get(owner_id)
{
match fn_decl.output {
FnRetTy::Return(ty) => {
if let Some(sig) = expr_sig(cx, closure)
&& let Some(output) = sig.output()
{
binding_ty_auto_deref_stability(cx, ty, precedence, output.bound_vars())
} else {
Position::Other(precedence)
}
},
FnRetTy::DefaultReturn(_) => Position::Other(precedence),
}
closure_result_position(cx, closure, cx.typeck_results().expr_ty(closure_expr), precedence)
} else {
let output = cx
.tcx
Expand All @@ -730,6 +719,12 @@ fn walk_parents<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> (Position, &
},
)
},
ExprKind::Closure(closure) => Some(closure_result_position(
cx,
closure,
cx.typeck_results().expr_ty(parent),
precedence,
)),
ExprKind::Call(func, _) if func.hir_id == child_id => {
(child_id == e.hir_id).then_some(Position::Callee)
},
Expand Down Expand Up @@ -825,6 +820,26 @@ fn walk_parents<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> (Position, &
(position, adjustments)
}

fn closure_result_position<'tcx>(
cx: &LateContext<'tcx>,
closure: &'tcx Closure<'_>,
ty: Ty<'tcx>,
precedence: i8,
) -> Position {
match closure.fn_decl.output {
FnRetTy::Return(hir_ty) => {
if let Some(sig) = ty_sig(cx, ty)
&& let Some(output) = sig.output()
{
binding_ty_auto_deref_stability(cx, hir_ty, precedence, output.bound_vars())
} else {
Position::Other(precedence)
}
},
FnRetTy::DefaultReturn(_) => Position::Other(precedence),
}
}

// Checks the stability of auto-deref when assigned to a binding with the given explicit type.
//
// e.g.
Expand Down
3 changes: 2 additions & 1 deletion clippy_utils/src/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,8 @@ pub fn expr_sig<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>) -> Option<ExprFnS
}
}

fn ty_sig<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option<ExprFnSig<'tcx>> {
/// If the type is function like, get the signature for it.
pub fn ty_sig<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option<ExprFnSig<'tcx>> {
if ty.is_box() {
return ty_sig(cx, ty.boxed_ty());
}
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/explicit_auto_deref.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -257,13 +257,13 @@ fn main() {
let x = S7([0]);
let _: &[u32] = &*x;

let c1 = |x: &Vec<&u32>| {};
let c1 = |_: &Vec<&u32>| {};
let x = &&vec![&1u32];
c1(x);
let _ = for<'a, 'b> |x: &'a &'a Vec<&'b u32>, b: bool| -> &'a Vec<&'b u32> {
if b {
return x;
}
*x
x
};
}
2 changes: 1 addition & 1 deletion tests/ui/explicit_auto_deref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ fn main() {
let x = S7([0]);
let _: &[u32] = &*x;

let c1 = |x: &Vec<&u32>| {};
let c1 = |_: &Vec<&u32>| {};
let x = &&vec![&1u32];
c1(*x);
let _ = for<'a, 'b> |x: &'a &'a Vec<&'b u32>, b: bool| -> &'a Vec<&'b u32> {
Expand Down
8 changes: 7 additions & 1 deletion tests/ui/explicit_auto_deref.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -228,5 +228,11 @@ error: deref which would be done by auto-deref
LL | return *x;
| ^^ help: try this: `x`

error: aborting due to 38 previous errors
error: deref which would be done by auto-deref
--> $DIR/explicit_auto_deref.rs:267:9
|
LL | *x
| ^^ help: try this: `x`

error: aborting due to 39 previous errors