Skip to content

Commit c128221

Browse files
committed
Auto merge of rust-lang#138747 - matthiaskrgr:rollup-68x44rw, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - rust-lang#138435 (Add support for postfix yield expressions) - rust-lang#138685 (Use `Option<Ident>` for lowered param names.) - rust-lang#138700 (Suggest `-Whelp` when pass `--print lints` to rustc) - rust-lang#138727 (Do not rely on `type_var_origin` in `OrphanCheckErr::NonLocalInputType`) - rust-lang#138729 (Clean up `FnCtxt::resolve_coroutine_interiors`) - rust-lang#138731 (coverage: Add LLVM plumbing for expansion regions) - rust-lang#138732 (Use `def_path_str` for def id arg in `UnsupportedOpInfo`) - rust-lang#138735 (Remove `llvm` and `llvms` triagebot ping aliases for `icebreakers-llvm` ping group) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 6fb13c6 + d9aec19 commit c128221

File tree

3 files changed

+32
-28
lines changed

3 files changed

+32
-28
lines changed

clippy_lints/src/functions/renamed_function_params.rs

+24-21
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_hir::hir_id::OwnerId;
55
use rustc_hir::{Impl, ImplItem, ImplItemKind, ImplItemRef, ItemKind, Node, TraitRef};
66
use rustc_lint::LateContext;
77
use rustc_span::Span;
8-
use rustc_span::symbol::{Ident, Symbol, kw};
8+
use rustc_span::symbol::{Ident, kw};
99

1010
use super::RENAMED_FUNCTION_PARAMS;
1111

@@ -51,22 +51,33 @@ struct RenamedFnArgs(Vec<(Span, String)>);
5151
impl RenamedFnArgs {
5252
/// Comparing between an iterator of default names and one with current names,
5353
/// then collect the ones that got renamed.
54-
fn new<I, T>(default_names: &mut I, current_names: &mut T) -> Self
54+
fn new<I1, I2>(default_idents: &mut I1, current_idents: &mut I2) -> Self
5555
where
56-
I: Iterator<Item = Ident>,
57-
T: Iterator<Item = Ident>,
56+
I1: Iterator<Item = Option<Ident>>,
57+
I2: Iterator<Item = Option<Ident>>,
5858
{
5959
let mut renamed: Vec<(Span, String)> = vec![];
6060

61-
debug_assert!(default_names.size_hint() == current_names.size_hint());
62-
while let (Some(def_name), Some(cur_name)) = (default_names.next(), current_names.next()) {
63-
let current_name = cur_name.name;
64-
let default_name = def_name.name;
65-
if is_unused_or_empty_symbol(current_name) || is_unused_or_empty_symbol(default_name) {
66-
continue;
67-
}
68-
if current_name != default_name {
69-
renamed.push((cur_name.span, default_name.to_string()));
61+
debug_assert!(default_idents.size_hint() == current_idents.size_hint());
62+
while let (Some(default_ident), Some(current_ident)) =
63+
(default_idents.next(), current_idents.next())
64+
{
65+
let has_name_to_check = |ident: Option<Ident>| {
66+
if let Some(ident) = ident
67+
&& ident.name != kw::Underscore
68+
&& !ident.name.as_str().starts_with('_')
69+
{
70+
Some(ident)
71+
} else {
72+
None
73+
}
74+
};
75+
76+
if let Some(default_ident) = has_name_to_check(default_ident)
77+
&& let Some(current_ident) = has_name_to_check(current_ident)
78+
&& default_ident.name != current_ident.name
79+
{
80+
renamed.push((current_ident.span, default_ident.to_string()));
7081
}
7182
}
7283

@@ -83,14 +94,6 @@ impl RenamedFnArgs {
8394
}
8495
}
8596

86-
fn is_unused_or_empty_symbol(symbol: Symbol) -> bool {
87-
// FIXME: `body_param_names` currently returning empty symbols for `wild` as well,
88-
// so we need to check if the symbol is empty first.
89-
// Therefore the check of whether it's equal to [`kw::Underscore`] has no use for now,
90-
// but it would be nice to keep it here just to be future-proof.
91-
symbol.is_empty() || symbol == kw::Underscore || symbol.as_str().starts_with('_')
92-
}
93-
9497
/// Get the [`trait_item_def_id`](ImplItemRef::trait_item_def_id) of a relevant impl item.
9598
fn trait_item_def_id_of_impl(items: &[ImplItemRef], target: OwnerId) -> Option<DefId> {
9699
items.iter().find_map(|item| {

clippy_lints/src/lifetimes.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ fn check_fn_inner<'tcx>(
189189
cx: &LateContext<'tcx>,
190190
sig: &'tcx FnSig<'_>,
191191
body: Option<BodyId>,
192-
trait_sig: Option<&[Ident]>,
192+
trait_sig: Option<&[Option<Ident>]>,
193193
generics: &'tcx Generics<'_>,
194194
span: Span,
195195
report_extra_lifetimes: bool,
@@ -264,7 +264,7 @@ fn could_use_elision<'tcx>(
264264
cx: &LateContext<'tcx>,
265265
func: &'tcx FnDecl<'_>,
266266
body: Option<BodyId>,
267-
trait_sig: Option<&[Ident]>,
267+
trait_sig: Option<&[Option<Ident>]>,
268268
named_generics: &'tcx [GenericParam<'_>],
269269
msrv: Msrv,
270270
) -> Option<(Vec<LocalDefId>, Vec<Lifetime>)> {
@@ -310,7 +310,7 @@ fn could_use_elision<'tcx>(
310310
let body = cx.tcx.hir_body(body_id);
311311

312312
let first_ident = body.params.first().and_then(|param| param.pat.simple_ident());
313-
if non_elidable_self_type(cx, func, first_ident, msrv) {
313+
if non_elidable_self_type(cx, func, Some(first_ident), msrv) {
314314
return None;
315315
}
316316

@@ -384,8 +384,8 @@ fn allowed_lts_from(named_generics: &[GenericParam<'_>]) -> FxIndexSet<LocalDefI
384384
}
385385

386386
// elision doesn't work for explicit self types before Rust 1.81, see rust-lang/rust#69064
387-
fn non_elidable_self_type<'tcx>(cx: &LateContext<'tcx>, func: &FnDecl<'tcx>, ident: Option<Ident>, msrv: Msrv) -> bool {
388-
if let Some(ident) = ident
387+
fn non_elidable_self_type<'tcx>(cx: &LateContext<'tcx>, func: &FnDecl<'tcx>, ident: Option<Option<Ident>>, msrv: Msrv) -> bool {
388+
if let Some(Some(ident)) = ident
389389
&& ident.name == kw::SelfLower
390390
&& !func.implicit_self.has_implicit_self()
391391
&& let Some(self_ty) = func.inputs.first()

clippy_utils/src/ast_utils/mod.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,8 @@ pub fn eq_expr(l: &Expr, r: &Expr) -> bool {
201201
(Loop(lt, ll, _), Loop(rt, rl, _)) => eq_label(ll.as_ref(), rl.as_ref()) && eq_block(lt, rt),
202202
(Block(lb, ll), Block(rb, rl)) => eq_label(ll.as_ref(), rl.as_ref()) && eq_block(lb, rb),
203203
(TryBlock(l), TryBlock(r)) => eq_block(l, r),
204-
(Yield(l), Yield(r)) | (Ret(l), Ret(r)) => eq_expr_opt(l.as_ref(), r.as_ref()),
204+
(Yield(l), Yield(r)) => eq_expr_opt(l.expr(), r.expr()) && l.same_kind(r),
205+
(Ret(l), Ret(r)) => eq_expr_opt(l.as_ref(), r.as_ref()),
205206
(Break(ll, le), Break(rl, re)) => eq_label(ll.as_ref(), rl.as_ref()) && eq_expr_opt(le.as_ref(), re.as_ref()),
206207
(Continue(ll), Continue(rl)) => eq_label(ll.as_ref(), rl.as_ref()),
207208
(Assign(l1, l2, _), Assign(r1, r2, _)) | (Index(l1, l2, _), Index(r1, r2, _)) => {
@@ -688,7 +689,7 @@ pub fn eq_generics(l: &Generics, r: &Generics) -> bool {
688689

689690
pub fn eq_where_predicate(l: &WherePredicate, r: &WherePredicate) -> bool {
690691
use WherePredicateKind::*;
691-
over(&l.attrs, &r.attrs, eq_attr)
692+
over(&l.attrs, &r.attrs, eq_attr)
692693
&& match (&l.kind, &r.kind) {
693694
(BoundPredicate(l), BoundPredicate(r)) => {
694695
over(&l.bound_generic_params, &r.bound_generic_params, |l, r| {

0 commit comments

Comments
 (0)