Skip to content

Commit 78adb20

Browse files
authored
Rollup merge of rust-lang#139751 - frank-king:feature/pin-project, r=Nadrieril,traviscross
Implement pin-project in pattern matching for `&pin mut|const T` This PR implements part of rust-lang#130494. It supports pin-project in pattern matching for `&pin mut|const T`. ~Pin-projection by field access (i.e. `&pin mut|const place.field`) is not fully supported yet since pinned-borrow is not ready (rust-lang#135731).~ CC ``````@traviscross``````
2 parents 33232af + 8992878 commit 78adb20

File tree

11 files changed

+23
-14
lines changed

11 files changed

+23
-14
lines changed

clippy_lints/src/index_refutable_slice.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ fn find_slice_values(cx: &LateContext<'_>, pat: &hir::Pat<'_>) -> FxIndexMap<Hir
9494
// We'll just ignore mut and ref mut for simplicity sake right now
9595
if let hir::PatKind::Binding(hir::BindingMode(by_ref, hir::Mutability::Not), value_hir_id, ident, sub_pat) =
9696
pat.kind
97-
&& by_ref != hir::ByRef::Yes(hir::Mutability::Mut)
97+
&& !matches!(by_ref, hir::ByRef::Yes(_, hir::Mutability::Mut))
9898
{
9999
// This block catches bindings with sub patterns. It would be hard to build a correct suggestion
100100
// for them and it's likely that the user knows what they are doing in such a case.

clippy_lints/src/matches/match_as_ref.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ fn is_ref_some_arm(cx: &LateContext<'_>, arm: &Arm<'_>) -> Option<Mutability> {
6363
.qpath_res(qpath, arm.pat.hir_id)
6464
.ctor_parent(cx)
6565
.is_lang_item(cx, LangItem::OptionSome)
66-
&& let PatKind::Binding(BindingMode(ByRef::Yes(mutabl), _), .., ident, _) = first_pat.kind
66+
&& let PatKind::Binding(BindingMode(ByRef::Yes(_, mutabl), _), .., ident, _) = first_pat.kind
6767
&& let ExprKind::Call(e, [arg]) = peel_blocks(arm.body).kind
6868
&& e.res(cx).ctor_parent(cx).is_lang_item(cx, LangItem::OptionSome)
6969
&& let ExprKind::Path(QPath::Resolved(_, path2)) = arg.kind

clippy_lints/src/matches/needless_match.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ fn pat_same_as_expr(pat: &Pat<'_>, expr: &Expr<'_>) -> bool {
172172
},
173173
)),
174174
) => {
175-
return !matches!(annot, BindingMode(ByRef::Yes(_), _)) && pat_ident.name == first_seg.ident.name;
175+
return !matches!(annot, BindingMode(ByRef::Yes(..), _)) && pat_ident.name == first_seg.ident.name;
176176
},
177177
// Example: `Custom::TypeA => Custom::TypeB`, or `None => None`
178178
(

clippy_lints/src/matches/redundant_guards.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ fn get_pat_binding<'tcx>(
176176
if let PatKind::Binding(bind_annot, hir_id, ident, _) = pat.kind
177177
&& hir_id == local
178178
{
179-
if matches!(bind_annot.0, rustc_ast::ByRef::Yes(_)) {
179+
if matches!(bind_annot.0, rustc_ast::ByRef::Yes(..)) {
180180
let _ = byref_ident.insert(ident);
181181
}
182182
// the second call of `replace()` returns a `Some(span)`, meaning a multi-binding pattern

clippy_lints/src/methods/clone_on_copy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, receiver: &Expr<'_>)
5757
_ => false,
5858
},
5959
// local binding capturing a reference
60-
Node::LetStmt(l) if matches!(l.pat.kind, PatKind::Binding(BindingMode(ByRef::Yes(_), _), ..)) => {
60+
Node::LetStmt(l) if matches!(l.pat.kind, PatKind::Binding(BindingMode(ByRef::Yes(..), _), ..)) => {
6161
return;
6262
},
6363
_ => false,

clippy_lints/src/question_mark.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ fn check_let_some_else_return_none(cx: &LateContext<'_>, stmt: &Stmt<'_>) {
150150
let init_expr_str = Sugg::hir_with_applicability(cx, init_expr, "..", &mut applicability).maybe_paren();
151151
// Take care when binding is `ref`
152152
let sugg = if let PatKind::Binding(
153-
BindingMode(ByRef::Yes(ref_mutability), binding_mutability),
153+
BindingMode(ByRef::Yes(_,ref_mutability), binding_mutability),
154154
_hir_id,
155155
ident,
156156
subpattern,
@@ -169,7 +169,7 @@ fn check_let_some_else_return_none(cx: &LateContext<'_>, stmt: &Stmt<'_>) {
169169
// Handle subpattern (@ subpattern)
170170
let maybe_subpattern = match subpattern {
171171
Some(Pat {
172-
kind: PatKind::Binding(BindingMode(ByRef::Yes(_), _), _, subident, None),
172+
kind: PatKind::Binding(BindingMode(ByRef::Yes(..), _), _, subident, None),
173173
..
174174
}) => {
175175
// avoid `&ref`
@@ -504,8 +504,8 @@ fn check_if_let_some_or_err_and_early_return<'tcx>(cx: &LateContext<'tcx>, expr:
504504
let receiver_str = snippet_with_applicability(cx, let_expr.span, "..", &mut applicability);
505505
let requires_semi = matches!(cx.tcx.parent_hir_node(expr.hir_id), Node::Stmt(_));
506506
let method_call_str = match by_ref {
507-
ByRef::Yes(Mutability::Mut) => ".as_mut()",
508-
ByRef::Yes(Mutability::Not) => ".as_ref()",
507+
ByRef::Yes(_, Mutability::Mut) => ".as_mut()",
508+
ByRef::Yes(_, Mutability::Not) => ".as_ref()",
509509
ByRef::No => "",
510510
};
511511
let sugg = format!(

clippy_lints/src/toplevel_ref_arg.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ impl<'tcx> LateLintPass<'tcx> for ToplevelRefArg {
6161
) {
6262
if !matches!(k, FnKind::Closure) {
6363
for arg in iter_input_pats(decl, body) {
64-
if let PatKind::Binding(BindingMode(ByRef::Yes(_), _), ..) = arg.pat.kind
64+
if let PatKind::Binding(BindingMode(ByRef::Yes(..), _), ..) = arg.pat.kind
6565
&& is_lint_allowed(cx, REF_PATTERNS, arg.pat.hir_id)
6666
&& !arg.span.in_external_macro(cx.tcx.sess.source_map())
6767
{
@@ -80,7 +80,7 @@ impl<'tcx> LateLintPass<'tcx> for ToplevelRefArg {
8080

8181
fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'_>) {
8282
if let StmtKind::Let(local) = stmt.kind
83-
&& let PatKind::Binding(BindingMode(ByRef::Yes(mutabl), _), .., name, None) = local.pat.kind
83+
&& let PatKind::Binding(BindingMode(ByRef::Yes(_, mutabl), _), .., name, None) = local.pat.kind
8484
&& let Some(init) = local.init
8585
// Do not emit if clippy::ref_patterns is not allowed to avoid having two lints for the same issue.
8686
&& is_lint_allowed(cx, REF_PATTERNS, local.pat.hir_id)

clippy_lints/src/utils/author.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,10 +743,14 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
743743
let ann = match ann {
744744
BindingMode::NONE => "NONE",
745745
BindingMode::REF => "REF",
746+
BindingMode::REF_PIN => "REF_PIN",
746747
BindingMode::MUT => "MUT",
747748
BindingMode::REF_MUT => "REF_MUT",
749+
BindingMode::REF_PIN_MUT => "REF_PIN_MUT",
748750
BindingMode::MUT_REF => "MUT_REF",
751+
BindingMode::MUT_REF_PIN => "MUT_REF_PIN",
749752
BindingMode::MUT_REF_MUT => "MUT_REF_MUT",
753+
BindingMode::MUT_REF_PIN_MUT => "MUT_REF_PIN_MUT",
750754
};
751755
kind!("Binding(BindingMode::{ann}, _, {name}, {sub})");
752756
self.ident(name);

clippy_utils/src/eager_or_lazy.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,12 @@ fn expr_eagerness<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> EagernessS
211211

212212
// Custom `Deref` impl might have side effects
213213
ExprKind::Unary(UnOp::Deref, e)
214-
if self.cx.typeck_results().expr_ty(e).builtin_deref(true).is_none() =>
214+
if self
215+
.cx
216+
.typeck_results()
217+
.expr_ty(e)
218+
.builtin_deref(true)
219+
.is_none() =>
215220
{
216221
self.eagerness |= NoChange;
217222
},

clippy_utils/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ pub fn capture_local_usage(cx: &LateContext<'_>, e: &Expr<'_>) -> CaptureKind {
782782
ByRef::No if !is_copy(cx, cx.typeck_results().node_type(id)) => {
783783
capture = CaptureKind::Value;
784784
},
785-
ByRef::Yes(Mutability::Mut) if capture != CaptureKind::Value => {
785+
ByRef::Yes(_, Mutability::Mut) if capture != CaptureKind::Value => {
786786
capture = CaptureKind::Ref(Mutability::Mut);
787787
},
788788
_ => (),
@@ -1830,7 +1830,7 @@ pub fn is_expr_identity_of_pat(cx: &LateContext<'_>, pat: &Pat<'_>, expr: &Expr<
18301830
.typeck_results()
18311831
.pat_binding_modes()
18321832
.get(pat.hir_id)
1833-
.is_some_and(|mode| matches!(mode.0, ByRef::Yes(_)))
1833+
.is_some_and(|mode| matches!(mode.0, ByRef::Yes(..)))
18341834
{
18351835
// If the parameter is `(x, y)` of type `&(T, T)`, or `[x, y]` of type `&[T; 2]`, then
18361836
// due to match ergonomics, the inner patterns become references. Don't consider this

0 commit comments

Comments
 (0)