Skip to content

Commit c0746b9

Browse files
committed
Add sugar for &pin (const|mut) types
1 parent a18800f commit c0746b9

File tree

18 files changed

+159
-47
lines changed

18 files changed

+159
-47
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
use std::borrow::Cow;
2222
use std::{cmp, fmt, mem};
2323

24-
pub use rustc_ast_ir::{Movability, Mutability};
24+
pub use rustc_ast_ir::{Movability, Mutability, Pinnedness};
2525
use rustc_data_structures::packed::Pu128;
2626
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
2727
use rustc_data_structures::stack::ensure_sufficient_stack;
@@ -580,9 +580,9 @@ impl Pat {
580580
PatKind::Path(qself, path) => TyKind::Path(qself.clone(), path.clone()),
581581
PatKind::MacCall(mac) => TyKind::MacCall(mac.clone()),
582582
// `&mut? P` can be reinterpreted as `&mut? T` where `T` is `P` reparsed as a type.
583-
PatKind::Ref(pat, mutbl) => {
584-
pat.to_ty().map(|ty| TyKind::Ref(None, MutTy { ty, mutbl: *mutbl }))?
585-
}
583+
PatKind::Ref(pat, mutbl) => pat
584+
.to_ty()
585+
.map(|ty| TyKind::Ref(None, Pinnedness::Not, MutTy { ty, mutbl: *mutbl }))?,
586586
// A slice/array pattern `[P]` can be reparsed as `[T]`, an unsized array,
587587
// when `P` can be reparsed as a type `T`.
588588
PatKind::Slice(pats) if let [pat] = pats.as_slice() => {
@@ -1246,9 +1246,9 @@ impl Expr {
12461246

12471247
ExprKind::Paren(expr) => expr.to_ty().map(TyKind::Paren)?,
12481248

1249-
ExprKind::AddrOf(BorrowKind::Ref, mutbl, expr) => {
1250-
expr.to_ty().map(|ty| TyKind::Ref(None, MutTy { ty, mutbl: *mutbl }))?
1251-
}
1249+
ExprKind::AddrOf(BorrowKind::Ref, mutbl, expr) => expr
1250+
.to_ty()
1251+
.map(|ty| TyKind::Ref(None, Pinnedness::Not, MutTy { ty, mutbl: *mutbl }))?,
12521252

12531253
ExprKind::Repeat(expr, expr_len) => {
12541254
expr.to_ty().map(|ty| TyKind::Array(ty, expr_len.clone()))?
@@ -2127,7 +2127,8 @@ impl Clone for Ty {
21272127
impl Ty {
21282128
pub fn peel_refs(&self) -> &Self {
21292129
let mut final_ty = self;
2130-
while let TyKind::Ref(_, MutTy { ty, .. }) | TyKind::Ptr(MutTy { ty, .. }) = &final_ty.kind
2130+
while let TyKind::Ref(_, _, MutTy { ty, .. }) | TyKind::Ptr(MutTy { ty, .. }) =
2131+
&final_ty.kind
21312132
{
21322133
final_ty = ty;
21332134
}
@@ -2158,7 +2159,7 @@ pub enum TyKind {
21582159
/// A raw pointer (`*const T` or `*mut T`).
21592160
Ptr(MutTy),
21602161
/// A reference (`&'a T` or `&'a mut T`).
2161-
Ref(Option<Lifetime>, MutTy),
2162+
Ref(Option<Lifetime>, Pinnedness, MutTy),
21622163
/// A bare function (e.g., `fn(usize) -> bool`).
21632164
BareFn(P<BareFnTy>),
21642165
/// The never type (`!`).
@@ -2481,7 +2482,7 @@ impl Param {
24812482
if ident.name == kw::SelfLower {
24822483
return match self.ty.kind {
24832484
TyKind::ImplicitSelf => Some(respan(self.pat.span, SelfKind::Value(mutbl))),
2484-
TyKind::Ref(lt, MutTy { ref ty, mutbl }) if ty.kind.is_implicit_self() => {
2485+
TyKind::Ref(lt, _, MutTy { ref ty, mutbl }) if ty.kind.is_implicit_self() => {
24852486
Some(respan(self.pat.span, SelfKind::Region(lt, mutbl)))
24862487
}
24872488
_ => Some(respan(
@@ -2519,7 +2520,7 @@ impl Param {
25192520
Mutability::Not,
25202521
P(Ty {
25212522
id: DUMMY_NODE_ID,
2522-
kind: TyKind::Ref(lt, MutTy { ty: infer_ty, mutbl }),
2523+
kind: TyKind::Ref(lt, Pinnedness::Not, MutTy { ty: infer_ty, mutbl }),
25232524
span,
25242525
tokens: None,
25252526
}),

compiler/rustc_ast/src/mut_visit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ pub fn walk_ty<T: MutVisitor>(vis: &mut T, ty: &mut P<Ty>) {
485485
}
486486
TyKind::Slice(ty) => vis.visit_ty(ty),
487487
TyKind::Ptr(mt) => vis.visit_mt(mt),
488-
TyKind::Ref(lt, mt) => {
488+
TyKind::Ref(lt, _, mt) => {
489489
visit_opt(lt, |lt| vis.visit_lifetime(lt));
490490
vis.visit_mt(mt);
491491
}

compiler/rustc_ast/src/util/classify.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ fn type_trailing_braced_mac_call(mut ty: &ast::Ty) -> Option<&ast::MacCall> {
247247
break (mac.args.delim == Delimiter::Brace).then_some(mac);
248248
}
249249

250-
ast::TyKind::Ptr(mut_ty) | ast::TyKind::Ref(_, mut_ty) => {
250+
ast::TyKind::Ptr(mut_ty) | ast::TyKind::Ref(_, _, mut_ty) => {
251251
ty = &mut_ty.ty;
252252
}
253253

compiler/rustc_ast/src/visit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ pub fn walk_ty<'a, V: Visitor<'a>>(visitor: &mut V, typ: &'a Ty) -> V::Result {
499499
match kind {
500500
TyKind::Slice(ty) | TyKind::Paren(ty) => try_visit!(visitor.visit_ty(ty)),
501501
TyKind::Ptr(MutTy { ty, mutbl: _ }) => try_visit!(visitor.visit_ty(ty)),
502-
TyKind::Ref(opt_lifetime, MutTy { ty, mutbl: _ }) => {
502+
TyKind::Ref(opt_lifetime, _, MutTy { ty, mutbl: _ }) => {
503503
visit_opt!(visitor, visit_lifetime, opt_lifetime, LifetimeCtxt::Ref);
504504
try_visit!(visitor.visit_ty(ty));
505505
}

compiler/rustc_ast_ir/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,10 @@ impl Mutability {
7979
matches!(self, Self::Not)
8080
}
8181
}
82+
83+
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Copy)]
84+
#[cfg_attr(feature = "nightly", derive(Encodable, Decodable, HashStable_NoContext))]
85+
pub enum Pinnedness {
86+
Not,
87+
Pinned,
88+
}

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
638638
self.lower_span(span),
639639
Some(self.allow_gen_future.clone()),
640640
);
641-
let resume_ty = self.make_lang_item_qpath(hir::LangItem::ResumeTy, unstable_span);
641+
let resume_ty =
642+
self.make_lang_item_qpath(hir::LangItem::ResumeTy, unstable_span, None);
642643
let input_ty = hir::Ty {
643644
hir_id: self.next_id(),
644645
kind: hir::TyKind::Path(resume_ty),
@@ -2063,7 +2064,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
20632064
lang_item: hir::LangItem,
20642065
name: Symbol,
20652066
) -> hir::Expr<'hir> {
2066-
let qpath = self.make_lang_item_qpath(lang_item, self.lower_span(span));
2067+
let qpath = self.make_lang_item_qpath(lang_item, self.lower_span(span), None);
20672068
let path = hir::ExprKind::Path(hir::QPath::TypeRelative(
20682069
self.arena.alloc(self.ty(span, hir::TyKind::Path(qpath))),
20692070
self.arena.alloc(hir::PathSegment::new(

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ use rustc_errors::{DiagArgFromDisplay, DiagCtxtHandle, StashKey};
5555
use rustc_hir::def::{DefKind, LifetimeRes, Namespace, PartialRes, PerNS, Res};
5656
use rustc_hir::def_id::{LocalDefId, LocalDefIdMap, CRATE_DEF_ID, LOCAL_CRATE};
5757
use rustc_hir::{
58-
self as hir, ConstArg, GenericArg, HirId, ItemLocalMap, MissingLifetimeKind, ParamName,
59-
TraitCandidate,
58+
self as hir, ConstArg, GenericArg, HirId, ItemLocalMap, LangItem, MissingLifetimeKind,
59+
ParamName, TraitCandidate,
6060
};
6161
use rustc_index::{Idx, IndexSlice, IndexVec};
6262
use rustc_macros::extension;
@@ -756,8 +756,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
756756
res
757757
}
758758

759-
fn make_lang_item_qpath(&mut self, lang_item: hir::LangItem, span: Span) -> hir::QPath<'hir> {
760-
hir::QPath::Resolved(None, self.make_lang_item_path(lang_item, span, None))
759+
fn make_lang_item_qpath(
760+
&mut self,
761+
lang_item: hir::LangItem,
762+
span: Span,
763+
args: Option<&'hir hir::GenericArgs<'hir>>,
764+
) -> hir::QPath<'hir> {
765+
hir::QPath::Resolved(None, self.make_lang_item_path(lang_item, span, args))
761766
}
762767

763768
fn make_lang_item_path(
@@ -1284,7 +1289,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
12841289
}
12851290
TyKind::Slice(ty) => hir::TyKind::Slice(self.lower_ty(ty, itctx)),
12861291
TyKind::Ptr(mt) => hir::TyKind::Ptr(self.lower_mt(mt, itctx)),
1287-
TyKind::Ref(region, mt) => {
1292+
TyKind::Ref(region, pinned, mt) => {
12881293
let region = region.unwrap_or_else(|| {
12891294
let id = if let Some(LifetimeRes::ElidedAnchor { start, end }) =
12901295
self.resolver.get_lifetime_res(t.id)
@@ -1298,7 +1303,22 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
12981303
Lifetime { ident: Ident::new(kw::UnderscoreLifetime, span), id }
12991304
});
13001305
let lifetime = self.lower_lifetime(&region);
1301-
hir::TyKind::Ref(lifetime, self.lower_mt(mt, itctx))
1306+
let kind = hir::TyKind::Ref(lifetime, self.lower_mt(mt, itctx));
1307+
match pinned {
1308+
Pinnedness::Not => kind,
1309+
Pinnedness::Pinned => {
1310+
let span = self.lower_span(t.span);
1311+
let arg = hir::Ty { kind, span, hir_id: self.next_id() };
1312+
let args = self.arena.alloc(hir::GenericArgs {
1313+
args: self.arena.alloc([hir::GenericArg::Type(self.arena.alloc(arg))]),
1314+
constraints: &[],
1315+
parenthesized: hir::GenericArgsParentheses::No,
1316+
span_ext: span,
1317+
});
1318+
let path = self.make_lang_item_qpath(LangItem::Pin, span, Some(args));
1319+
hir::TyKind::Path(path)
1320+
}
1321+
}
13021322
}
13031323
TyKind::BareFn(f) => {
13041324
let generic_params = self.lower_lifetime_binder(t.id, &f.generic_params);
@@ -1882,7 +1902,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
18821902
// Given we are only considering `ImplicitSelf` types, we needn't consider
18831903
// the case where we have a mutable pattern to a reference as that would
18841904
// no longer be an `ImplicitSelf`.
1885-
TyKind::Ref(_, mt) if mt.ty.kind.is_implicit_self() => match mt.mutbl {
1905+
TyKind::Ref(_, _, mt) if mt.ty.kind.is_implicit_self() => match mt.mutbl {
18861906
hir::Mutability::Not => hir::ImplicitSelfKind::RefImm,
18871907
hir::Mutability::Mut => hir::ImplicitSelfKind::RefMut,
18881908
},

compiler/rustc_ast_lowering/src/lifetime_collector.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ impl<'ast> Visitor<'ast> for LifetimeCollectVisitor<'ast> {
9595
visit::walk_ty(self, t);
9696
self.current_binders.pop();
9797
}
98-
TyKind::Ref(None, _) => {
98+
TyKind::Ref(None, _, _) => {
9999
self.record_elided_anchor(t.id, t.span);
100100
visit::walk_ty(self, t);
101101
}

compiler/rustc_ast_pretty/src/pprust/state.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use rustc_ast::util::comments::{Comment, CommentStyle};
2020
use rustc_ast::{
2121
self as ast, attr, AttrArgs, AttrArgsEq, BindingMode, BlockCheckMode, ByRef, DelimArgs,
2222
GenericArg, GenericBound, InlineAsmOperand, InlineAsmOptions, InlineAsmRegOrRegClass,
23-
InlineAsmTemplatePiece, PatKind, RangeEnd, RangeSyntax, Safety, SelfKind, Term,
23+
InlineAsmTemplatePiece, PatKind, Pinnedness, RangeEnd, RangeSyntax, Safety, SelfKind, Term,
2424
};
2525
use rustc_span::edition::Edition;
2626
use rustc_span::source_map::{SourceMap, Spanned};
@@ -1158,10 +1158,13 @@ impl<'a> State<'a> {
11581158
self.word("*");
11591159
self.print_mt(mt, true);
11601160
}
1161-
ast::TyKind::Ref(lifetime, mt) => {
1161+
ast::TyKind::Ref(lifetime, pinned, mt) => {
11621162
self.word("&");
11631163
self.print_opt_lifetime(lifetime);
1164-
self.print_mt(mt, false);
1164+
if pinned == &Pinnedness::Pinned {
1165+
self.word("pin ");
1166+
}
1167+
self.print_mt(mt, pinned == &Pinnedness::Pinned);
11651168
}
11661169
ast::TyKind::Never => {
11671170
self.word("!");

compiler/rustc_expand/src/build.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use rustc_ast::ptr::P;
22
use rustc_ast::util::literal;
33
use rustc_ast::{
4-
self as ast, attr, token, AttrVec, BlockCheckMode, Expr, LocalKind, MatchKind, PatKind, UnOp,
4+
self as ast, attr, token, AttrVec, BlockCheckMode, Expr, LocalKind, MatchKind, PatKind,
5+
Pinnedness, UnOp,
56
};
67
use rustc_span::source_map::Spanned;
78
use rustc_span::symbol::{kw, sym, Ident, Symbol};
@@ -114,7 +115,7 @@ impl<'a> ExtCtxt<'a> {
114115
lifetime: Option<ast::Lifetime>,
115116
mutbl: ast::Mutability,
116117
) -> P<ast::Ty> {
117-
self.ty(span, ast::TyKind::Ref(lifetime, self.ty_mt(ty, mutbl)))
118+
self.ty(span, ast::TyKind::Ref(lifetime, Pinnedness::Not, self.ty_mt(ty, mutbl)))
118119
}
119120

120121
pub fn ty_ptr(&self, span: Span, ty: P<ast::Ty>, mutbl: ast::Mutability) -> P<ast::Ty> {

compiler/rustc_hir/src/hir.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
use std::fmt;
22

3-
use rustc_ast as ast;
43
use rustc_ast::util::parser::ExprPrecedence;
54
use rustc_ast::{
6-
Attribute, FloatTy, InlineAsmOptions, InlineAsmTemplatePiece, IntTy, Label, LitKind,
7-
TraitObjectSyntax, UintTy,
5+
self as ast, Attribute, FloatTy, InlineAsmOptions, InlineAsmTemplatePiece, IntTy, Label,
6+
LitKind, TraitObjectSyntax, UintTy,
87
};
98
pub use rustc_ast::{
109
BinOp, BinOpKind, BindingMode, BorrowKind, ByRef, CaptureBy, ImplPolarity, IsAuto, Movability,

compiler/rustc_parse/src/parser/diagnostics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1689,7 +1689,7 @@ impl<'a> Parser<'a> {
16891689
let sum_span = ty.span.to(self.prev_token.span);
16901690

16911691
let sub = match &ty.kind {
1692-
TyKind::Ref(_lifetime, mut_ty) => {
1692+
TyKind::Ref(_lifetime, _pinned, mut_ty) => {
16931693
let lo = mut_ty.ty.span.shrink_to_lo();
16941694
let hi = self.prev_token.span.shrink_to_hi();
16951695
BadTypePlusSub::AddParen { suggestion: AddParen { lo, hi } }

compiler/rustc_parse/src/parser/ty.rs

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ use rustc_ast::token::{self, BinOpToken, Delimiter, IdentIsRaw, Token, TokenKind
33
use rustc_ast::util::case::Case;
44
use rustc_ast::{
55
self as ast, BareFnTy, BoundAsyncness, BoundConstness, BoundPolarity, FnRetTy, GenericBound,
6-
GenericBounds, GenericParam, Generics, Lifetime, MacCall, MutTy, Mutability, PolyTraitRef,
7-
PreciseCapturingArg, TraitBoundModifiers, TraitObjectSyntax, Ty, TyKind, DUMMY_NODE_ID,
6+
GenericBounds, GenericParam, Generics, Lifetime, MacCall, MutTy, Mutability, Pinnedness,
7+
PolyTraitRef, PreciseCapturingArg, TraitBoundModifiers, TraitObjectSyntax, Ty, TyKind,
8+
DUMMY_NODE_ID,
89
};
910
use rustc_errors::{Applicability, PResult};
1011
use rustc_span::symbol::{kw, sym, Ident};
@@ -529,7 +530,7 @@ impl<'a> Parser<'a> {
529530
fn parse_borrowed_pointee(&mut self) -> PResult<'a, TyKind> {
530531
let and_span = self.prev_token.span;
531532
let mut opt_lifetime = self.check_lifetime().then(|| self.expect_lifetime());
532-
let mut mutbl = self.parse_mutability();
533+
let (pinned, mut mutbl) = self.parse_pin_and_mut();
533534
if self.token.is_lifetime() && mutbl == Mutability::Mut && opt_lifetime.is_none() {
534535
// A lifetime is invalid here: it would be part of a bare trait bound, which requires
535536
// it to be followed by a plus, but we disallow plus in the pointee type.
@@ -565,7 +566,38 @@ impl<'a> Parser<'a> {
565566
self.bump_with((dyn_tok, dyn_tok_sp));
566567
}
567568
let ty = self.parse_ty_no_plus()?;
568-
Ok(TyKind::Ref(opt_lifetime, MutTy { ty, mutbl }))
569+
Ok(TyKind::Ref(opt_lifetime, pinned, MutTy { ty, mutbl }))
570+
}
571+
572+
/// Parses `pin` and `mut` annotations on references.
573+
///
574+
/// It must be either `pin const` or `pin mut`.
575+
pub(crate) fn parse_pin_and_mut(&mut self) -> (Pinnedness, Mutability) {
576+
let pinned = if self.eat(&TokenKind::Ident(sym::pin, IdentIsRaw::No)) {
577+
Pinnedness::Pinned
578+
} else {
579+
Pinnedness::Not
580+
};
581+
582+
if pinned == Pinnedness::Pinned {
583+
self.psess.gated_spans.gate(sym::pin_ergonomics, self.prev_token.span);
584+
}
585+
586+
match pinned {
587+
Pinnedness::Pinned => {
588+
if self.eat_keyword(kw::Const) {
589+
(pinned, Mutability::Not)
590+
} else if self.eat_keyword(kw::Mut) {
591+
(pinned, Mutability::Mut)
592+
} else {
593+
// FIXME: Emit an error here
594+
595+
// self.dcx().emit_err();
596+
(pinned, Mutability::Not)
597+
}
598+
}
599+
Pinnedness::Not => (pinned, self.parse_mutability()),
600+
}
569601
}
570602

571603
// Parses the `typeof(EXPR)`.

compiler/rustc_resolve/src/late.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ impl<'ra: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'_, 'ast, 'r
753753
let prev = self.diag_metadata.current_trait_object;
754754
let prev_ty = self.diag_metadata.current_type_path;
755755
match &ty.kind {
756-
TyKind::Ref(None, _) => {
756+
TyKind::Ref(None, _, _) => {
757757
// Elided lifetime in reference: we resolve as if there was some lifetime `'_` with
758758
// NodeId `ty.id`.
759759
// This span will be used in case of elision failure.
@@ -2275,7 +2275,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
22752275
impl<'ra> Visitor<'ra> for FindReferenceVisitor<'_, '_, '_> {
22762276
fn visit_ty(&mut self, ty: &'ra Ty) {
22772277
trace!("FindReferenceVisitor considering ty={:?}", ty);
2278-
if let TyKind::Ref(lt, _) = ty.kind {
2278+
if let TyKind::Ref(lt, _, _) = ty.kind {
22792279
// See if anything inside the &thing contains Self
22802280
let mut visitor =
22812281
SelfVisitor { r: self.r, impl_self: self.impl_self, self_found: false };

compiler/rustc_resolve/src/late/diagnostics.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2002,7 +2002,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
20022002
fn extract_node_id(t: &Ty) -> Option<NodeId> {
20032003
match t.kind {
20042004
TyKind::Path(None, _) => Some(t.id),
2005-
TyKind::Ref(_, ref mut_ty) => extract_node_id(&mut_ty.ty),
2005+
TyKind::Ref(_, _, ref mut_ty) => extract_node_id(&mut_ty.ty),
20062006
// This doesn't handle the remaining `Ty` variants as they are not
20072007
// that commonly the self_type, it might be interesting to provide
20082008
// support for those in future.
@@ -3227,7 +3227,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
32273227
.seen
32283228
.iter()
32293229
.filter_map(|ty| match &ty.kind {
3230-
TyKind::Ref(_, mut_ty) => {
3230+
TyKind::Ref(_, _, mut_ty) => {
32313231
let span = ty.span.with_hi(mut_ty.ty.span.lo());
32323232
Some((span, "&'a ".to_string()))
32333233
}
@@ -3262,7 +3262,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
32623262
LifetimeFinder { lifetime: lt.span, found: None, seen: vec![] };
32633263
lt_finder.visit_ty(&ty);
32643264

3265-
if let [Ty { span, kind: TyKind::Ref(_, mut_ty), .. }] =
3265+
if let [Ty { span, kind: TyKind::Ref(_, _, mut_ty), .. }] =
32663266
&lt_finder.seen[..]
32673267
{
32683268
// We might have a situation like
@@ -3467,7 +3467,7 @@ struct LifetimeFinder<'ast> {
34673467

34683468
impl<'ast> Visitor<'ast> for LifetimeFinder<'ast> {
34693469
fn visit_ty(&mut self, t: &'ast Ty) {
3470-
if let TyKind::Ref(_, mut_ty) = &t.kind {
3470+
if let TyKind::Ref(_, _, mut_ty) = &t.kind {
34713471
self.seen.push(t);
34723472
if t.span.lo() == self.lifetime.lo() {
34733473
self.found = Some(&mut_ty.ty);

src/tools/clippy/clippy_utils/src/ast_utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -722,8 +722,8 @@ pub fn eq_ty(l: &Ty, r: &Ty) -> bool {
722722
(Slice(l), Slice(r)) => eq_ty(l, r),
723723
(Array(le, ls), Array(re, rs)) => eq_ty(le, re) && eq_expr(&ls.value, &rs.value),
724724
(Ptr(l), Ptr(r)) => l.mutbl == r.mutbl && eq_ty(&l.ty, &r.ty),
725-
(Ref(ll, l), Ref(rl, r)) => {
726-
both(ll, rl, |l, r| eq_id(l.ident, r.ident)) && l.mutbl == r.mutbl && eq_ty(&l.ty, &r.ty)
725+
(Ref(ll, lp, l), Ref(rl, rp, r)) => {
726+
both(ll, rl, |l, r| eq_id(l.ident, r.ident)) && l.mutbl == r.mutbl && eq_ty(&l.ty, &r.ty) && lp == rp
727727
},
728728
(BareFn(l), BareFn(r)) => {
729729
l.safety == r.safety

0 commit comments

Comments
 (0)