mirror of
https://github.com/allankoechke/rust.git
synced 2026-11-30 11:05:36 +00:00
remove ast::MutTy
This commit is contained in:
@@ -651,8 +651,8 @@ impl Pat {
|
||||
PatKind::MacCall(mac) => TyKind::MacCall(mac.clone()),
|
||||
// `&mut? P` can be reinterpreted as `&mut? T` where `T` is `P` reparsed as a type.
|
||||
PatKind::Ref(pat, pinned, mutbl) => pat.to_ty().map(|ty| match pinned {
|
||||
Pinnedness::Not => TyKind::Ref(None, MutTy { ty, mutbl: *mutbl }),
|
||||
Pinnedness::Pinned => TyKind::PinnedRef(None, MutTy { ty, mutbl: *mutbl }),
|
||||
Pinnedness::Not => TyKind::Ref(None, ty, *mutbl),
|
||||
Pinnedness::Pinned => TyKind::PinnedRef(None, ty, *mutbl),
|
||||
})?,
|
||||
// A slice/array pattern `[P]` can be reparsed as `[T]`, an unsized array,
|
||||
// when `P` can be reparsed as a type `T`.
|
||||
@@ -1507,7 +1507,7 @@ impl Expr {
|
||||
ExprKind::Paren(expr) => expr.to_ty().map(TyKind::Paren)?,
|
||||
|
||||
ExprKind::AddrOf(BorrowKind::Ref, mutbl, expr) => {
|
||||
expr.to_ty().map(|ty| TyKind::Ref(None, MutTy { ty, mutbl: *mutbl }))?
|
||||
expr.to_ty().map(|ty| TyKind::Ref(None, ty, *mutbl))?
|
||||
}
|
||||
|
||||
ExprKind::Repeat(expr, expr_len) => {
|
||||
@@ -2336,14 +2336,6 @@ impl LitKind {
|
||||
}
|
||||
}
|
||||
|
||||
// N.B., If you change this, you'll probably want to change the corresponding
|
||||
// type structure in `middle/ty.rs` as well.
|
||||
#[derive(Clone, Encodable, Decodable, Debug, Walkable)]
|
||||
pub struct MutTy {
|
||||
pub ty: Box<Ty>,
|
||||
pub mutbl: Mutability,
|
||||
}
|
||||
|
||||
/// Represents a function's signature in a trait declaration,
|
||||
/// trait implementation, or free function.
|
||||
#[derive(Clone, Encodable, Decodable, Debug)]
|
||||
@@ -2470,8 +2462,7 @@ impl From<Box<Ty>> for Ty {
|
||||
impl Ty {
|
||||
pub fn peel_refs(&self) -> &Self {
|
||||
let mut final_ty = self;
|
||||
while let TyKind::Ref(_, MutTy { ty, .. }) | TyKind::Ptr(MutTy { ty, .. }) = &final_ty.kind
|
||||
{
|
||||
while let TyKind::Ref(_, ty, _) | TyKind::Ptr(ty, ..) = &final_ty.kind {
|
||||
final_ty = ty;
|
||||
}
|
||||
final_ty
|
||||
@@ -2528,13 +2519,13 @@ pub enum TyKind {
|
||||
/// A fixed length array (`[T; n]`).
|
||||
Array(Box<Ty>, AnonConst),
|
||||
/// A raw pointer (`*const T` or `*mut T`).
|
||||
Ptr(MutTy),
|
||||
Ptr(Box<Ty>, Mutability),
|
||||
/// A reference (`&'a T` or `&'a mut T`).
|
||||
Ref(#[visitable(extra = LifetimeCtxt::Ref)] Option<Lifetime>, MutTy),
|
||||
Ref(#[visitable(extra = LifetimeCtxt::Ref)] Option<Lifetime>, Box<Ty>, Mutability),
|
||||
/// A pinned reference (`&'a pin const T` or `&'a pin mut T`).
|
||||
///
|
||||
/// Desugars into `Pin<&'a T>` or `Pin<&'a mut T>`.
|
||||
PinnedRef(#[visitable(extra = LifetimeCtxt::Ref)] Option<Lifetime>, MutTy),
|
||||
PinnedRef(#[visitable(extra = LifetimeCtxt::Ref)] Option<Lifetime>, Box<Ty>, Mutability),
|
||||
/// A function pointer type (e.g., `fn(usize) -> bool`).
|
||||
FnPtr(Box<FnPtrTy>),
|
||||
/// An unsafe existential lifetime binder (e.g., `unsafe<'a> &'a ()`).
|
||||
@@ -2979,12 +2970,10 @@ impl Param {
|
||||
if ident.name == kw::SelfLower {
|
||||
return match self.ty.kind {
|
||||
TyKind::ImplicitSelf => Some(respan(self.pat.span, SelfKind::Value(mutbl))),
|
||||
TyKind::Ref(lt, MutTy { ref ty, mutbl }) if ty.kind.is_implicit_self() => {
|
||||
TyKind::Ref(lt, ref ty, mutbl) if ty.kind.is_implicit_self() => {
|
||||
Some(respan(self.pat.span, SelfKind::Region(lt, mutbl)))
|
||||
}
|
||||
TyKind::PinnedRef(lt, MutTy { ref ty, mutbl })
|
||||
if ty.kind.is_implicit_self() =>
|
||||
{
|
||||
TyKind::PinnedRef(lt, ref ty, mutbl) if ty.kind.is_implicit_self() => {
|
||||
Some(respan(self.pat.span, SelfKind::Pinned(lt, mutbl)))
|
||||
}
|
||||
_ => Some(respan(
|
||||
@@ -3016,17 +3005,13 @@ impl Param {
|
||||
SelfKind::Value(mutbl) => (mutbl, infer_ty),
|
||||
SelfKind::Region(lt, mutbl) => (
|
||||
Mutability::Not,
|
||||
Box::new(Ty {
|
||||
id: DUMMY_NODE_ID,
|
||||
kind: TyKind::Ref(lt, MutTy { ty: infer_ty, mutbl }),
|
||||
span,
|
||||
}),
|
||||
Box::new(Ty { id: DUMMY_NODE_ID, kind: TyKind::Ref(lt, infer_ty, mutbl), span }),
|
||||
),
|
||||
SelfKind::Pinned(lt, mutbl) => (
|
||||
Mutability::Not,
|
||||
Box::new(Ty {
|
||||
id: DUMMY_NODE_ID,
|
||||
kind: TyKind::PinnedRef(lt, MutTy { ty: infer_ty, mutbl }),
|
||||
kind: TyKind::PinnedRef(lt, infer_ty, mutbl),
|
||||
span,
|
||||
}),
|
||||
),
|
||||
|
||||
@@ -160,7 +160,7 @@ pub fn valid_ty_for_activity(ty: &Box<Ty>, activity: DiffActivity) -> bool {
|
||||
if matches!(activity, Active | ActiveOnly) {
|
||||
return true;
|
||||
}
|
||||
matches!(ty.kind, TyKind::Ptr(_) | TyKind::Ref(..))
|
||||
matches!(ty.kind, TyKind::Ptr(..) | TyKind::Ref(..))
|
||||
&& matches!(activity, Duplicated | DuplicatedOnly)
|
||||
}
|
||||
pub fn valid_input_activity(mode: DiffMode, activity: DiffActivity) -> bool {
|
||||
|
||||
@@ -262,10 +262,10 @@ fn type_trailing_braced_mac_call(mut ty: &ast::Ty) -> Option<&ast::MacCall> {
|
||||
break (mac.args.delim == Delimiter::Brace).then_some(mac);
|
||||
}
|
||||
|
||||
ast::TyKind::Ptr(mut_ty)
|
||||
| ast::TyKind::Ref(_, mut_ty)
|
||||
| ast::TyKind::PinnedRef(_, mut_ty) => {
|
||||
ty = &mut_ty.ty;
|
||||
ast::TyKind::Ptr(inner_ty, _)
|
||||
| ast::TyKind::Ref(_, inner_ty, _)
|
||||
| ast::TyKind::PinnedRef(_, inner_ty, _) => {
|
||||
ty = inner_ty;
|
||||
}
|
||||
|
||||
ast::TyKind::UnsafeBinder(binder) => {
|
||||
|
||||
@@ -542,7 +542,6 @@ macro_rules! common_visitor_and_walkers {
|
||||
MethodCall,
|
||||
ModKind,
|
||||
ModSpans,
|
||||
MutTy,
|
||||
NormalAttr,
|
||||
Parens,
|
||||
ParenthesizedArgs,
|
||||
|
||||
@@ -1527,14 +1527,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||
TyKind::Infer => hir::TyKind::Infer(()),
|
||||
TyKind::Err(guar) => hir::TyKind::Err(*guar),
|
||||
TyKind::Slice(ty) => hir::TyKind::Slice(self.lower_ty_alloc(ty, itctx)),
|
||||
TyKind::Ptr(mt) => hir::TyKind::Ptr(self.lower_mt(mt, itctx)),
|
||||
TyKind::Ref(region, mt) => {
|
||||
TyKind::Ptr(ty, mutbl) => hir::TyKind::Ptr(self.lower_mt(ty, *mutbl, itctx)),
|
||||
TyKind::Ref(region, ty, mutbl) => {
|
||||
let lifetime = self.lower_ty_direct_lifetime(t, *region);
|
||||
hir::TyKind::Ref(lifetime, self.lower_mt(mt, itctx))
|
||||
hir::TyKind::Ref(lifetime, self.lower_mt(ty, *mutbl, itctx))
|
||||
}
|
||||
TyKind::PinnedRef(region, mt) => {
|
||||
TyKind::PinnedRef(region, ty, mutbl) => {
|
||||
let lifetime = self.lower_ty_direct_lifetime(t, *region);
|
||||
let kind = hir::TyKind::Ref(lifetime, self.lower_mt(mt, itctx));
|
||||
let kind = hir::TyKind::Ref(lifetime, self.lower_mt(ty, *mutbl, itctx));
|
||||
let span = self.lower_span(t.span);
|
||||
let arg = hir::Ty { kind, span, hir_id: self.next_id() };
|
||||
let args = self.arena.alloc(hir::GenericArgs {
|
||||
@@ -1998,10 +1998,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||
// Given we are only considering `ImplicitSelf` types, we needn't consider
|
||||
// the case where we have a mutable pattern to a reference as that would
|
||||
// no longer be an `ImplicitSelf`.
|
||||
TyKind::Ref(_, mt) | TyKind::PinnedRef(_, mt)
|
||||
if mt.ty.kind.is_implicit_self() =>
|
||||
TyKind::Ref(_, ty, mutbl) | TyKind::PinnedRef(_, ty, mutbl)
|
||||
if ty.kind.is_implicit_self() =>
|
||||
{
|
||||
match mt.mutbl {
|
||||
match mutbl {
|
||||
hir::Mutability::Not => hir::ImplicitSelfKind::RefImm,
|
||||
hir::Mutability::Mut => hir::ImplicitSelfKind::RefMut,
|
||||
}
|
||||
@@ -2473,8 +2473,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||
.emit();
|
||||
}
|
||||
|
||||
fn lower_mt(&mut self, mt: &MutTy, itctx: ImplTraitContext) -> hir::MutTy<'hir> {
|
||||
hir::MutTy { ty: self.lower_ty_alloc(&mt.ty, itctx), mutbl: mt.mutbl }
|
||||
fn lower_mt(
|
||||
&mut self,
|
||||
ty: &Ty,
|
||||
mutbl: Mutability,
|
||||
itctx: ImplTraitContext,
|
||||
) -> hir::MutTy<'hir> {
|
||||
hir::MutTy { ty: self.lower_ty_alloc(ty, itctx), mutbl }
|
||||
}
|
||||
|
||||
#[instrument(level = "debug", skip(self), ret)]
|
||||
|
||||
@@ -1346,20 +1346,23 @@ impl<'a> State<'a> {
|
||||
self.print_type(ty);
|
||||
self.word("]");
|
||||
}
|
||||
ast::TyKind::Ptr(mt) => {
|
||||
ast::TyKind::Ptr(ty, mutbl) => {
|
||||
self.word("*");
|
||||
self.print_mt(mt, true);
|
||||
self.print_mutability(*mutbl, true);
|
||||
self.print_type(ty);
|
||||
}
|
||||
ast::TyKind::Ref(lifetime, mt) => {
|
||||
ast::TyKind::Ref(lifetime, ty, mutbl) => {
|
||||
self.word("&");
|
||||
self.print_opt_lifetime(lifetime);
|
||||
self.print_mt(mt, false);
|
||||
self.print_mutability(*mutbl, false);
|
||||
self.print_type(ty);
|
||||
}
|
||||
ast::TyKind::PinnedRef(lifetime, mt) => {
|
||||
ast::TyKind::PinnedRef(lifetime, ty, mutbl) => {
|
||||
self.word("&");
|
||||
self.print_opt_lifetime(lifetime);
|
||||
self.word("pin ");
|
||||
self.print_mt(mt, true);
|
||||
self.print_mutability(*mutbl, true);
|
||||
self.print_type(ty);
|
||||
}
|
||||
ast::TyKind::Never => {
|
||||
self.word("!");
|
||||
@@ -2229,11 +2232,6 @@ impl<'a> State<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
fn print_mt(&mut self, mt: &ast::MutTy, print_const: bool) {
|
||||
self.print_mutability(mt.mutbl, print_const);
|
||||
self.print_type(&mt.ty)
|
||||
}
|
||||
|
||||
fn print_param(&mut self, input: &ast::Param, is_closure: bool) {
|
||||
let ib = self.ibox(INDENT_UNIT);
|
||||
|
||||
|
||||
@@ -473,11 +473,11 @@ mod llvm_enzyme {
|
||||
fn assure_mut_ref(ty: &ast::Ty) -> ast::Ty {
|
||||
let mut ty = ty.clone();
|
||||
match ty.kind {
|
||||
TyKind::Ptr(ref mut mut_ty) => {
|
||||
mut_ty.mutbl = ast::Mutability::Mut;
|
||||
TyKind::Ptr(_, ref mut mutbl) => {
|
||||
*mutbl = ast::Mutability::Mut;
|
||||
}
|
||||
TyKind::Ref(_, ref mut mut_ty) => {
|
||||
mut_ty.mutbl = ast::Mutability::Mut;
|
||||
TyKind::Ref(_, _, ref mut mutbl) => {
|
||||
*mutbl = ast::Mutability::Mut;
|
||||
}
|
||||
_ => {
|
||||
panic!("unsupported type: {:?}", ty);
|
||||
@@ -510,10 +510,15 @@ mod llvm_enzyme {
|
||||
.map(|param| {
|
||||
let ty = match ¶m.ty.kind {
|
||||
TyKind::ImplicitSelf => self_ty(),
|
||||
TyKind::Ref(lt, mt) if matches!(mt.ty.kind, TyKind::ImplicitSelf) => ecx
|
||||
.ty(span, TyKind::Ref(*lt, ast::MutTy { ty: self_ty(), mutbl: mt.mutbl })),
|
||||
TyKind::Ptr(mt) if matches!(mt.ty.kind, TyKind::ImplicitSelf) => {
|
||||
ecx.ty(span, TyKind::Ptr(ast::MutTy { ty: self_ty(), mutbl: mt.mutbl }))
|
||||
TyKind::Ref(lt, inner_ty, mutbl)
|
||||
if matches!(inner_ty.kind, TyKind::ImplicitSelf) =>
|
||||
{
|
||||
ecx.ty(span, TyKind::Ref(*lt, self_ty(), *mutbl))
|
||||
}
|
||||
TyKind::Ptr(inner_ty, mutbl)
|
||||
if matches!(inner_ty.kind, TyKind::ImplicitSelf) =>
|
||||
{
|
||||
ecx.ty(span, TyKind::Ptr(self_ty(), *mutbl))
|
||||
}
|
||||
_ => param.ty.clone(),
|
||||
};
|
||||
|
||||
@@ -77,10 +77,6 @@ impl<'a> ExtCtxt<'a> {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn ty_mt(&self, ty: Box<ast::Ty>, mutbl: ast::Mutability) -> ast::MutTy {
|
||||
ast::MutTy { ty, mutbl }
|
||||
}
|
||||
|
||||
pub fn ty(&self, span: Span, kind: ast::TyKind) -> Box<ast::Ty> {
|
||||
Box::new(ast::Ty { id: ast::DUMMY_NODE_ID, span, kind })
|
||||
}
|
||||
@@ -127,11 +123,11 @@ impl<'a> ExtCtxt<'a> {
|
||||
lifetime: Option<ast::Lifetime>,
|
||||
mutbl: ast::Mutability,
|
||||
) -> Box<ast::Ty> {
|
||||
self.ty(span, ast::TyKind::Ref(lifetime, self.ty_mt(ty, mutbl)))
|
||||
self.ty(span, ast::TyKind::Ref(lifetime, ty, mutbl))
|
||||
}
|
||||
|
||||
pub fn ty_ptr(&self, span: Span, ty: Box<ast::Ty>, mutbl: ast::Mutability) -> Box<ast::Ty> {
|
||||
self.ty(span, ast::TyKind::Ptr(self.ty_mt(ty, mutbl)))
|
||||
self.ty(span, ast::TyKind::Ptr(ty, mutbl))
|
||||
}
|
||||
|
||||
pub fn ty_unit(&self, span: Span) -> Box<ast::Ty> {
|
||||
|
||||
@@ -1000,7 +1000,7 @@ impl EarlyLintPass for UnusedParens {
|
||||
|
||||
self.with_self_ty_parens = false;
|
||||
}
|
||||
ast::TyKind::Ref(_, mut_ty) | ast::TyKind::Ptr(mut_ty) => {
|
||||
ast::TyKind::Ref(_, inner_ty, _) | ast::TyKind::Ptr(inner_ty, _) => {
|
||||
// If this type itself appears in no-bounds position, we propagate its
|
||||
// potentially tighter constraint or risk a false posive (issue 143653).
|
||||
let own_constraint = self.in_no_bounds_pos.get(&ty.id);
|
||||
@@ -1009,7 +1009,7 @@ impl EarlyLintPass for UnusedParens {
|
||||
Some(NoBoundsException::OneBound) => NoBoundsException::OneBound,
|
||||
None => NoBoundsException::OneBound,
|
||||
};
|
||||
self.in_no_bounds_pos.insert(mut_ty.ty.id, constraint);
|
||||
self.in_no_bounds_pos.insert(inner_ty.id, constraint);
|
||||
}
|
||||
ast::TyKind::TraitObject(bounds, _) | ast::TyKind::ImplTrait(_, bounds) => {
|
||||
for i in 0..bounds.len() {
|
||||
|
||||
@@ -1562,8 +1562,8 @@ impl<'a> Parser<'a> {
|
||||
self.bump(); // `+`
|
||||
let _bounds = self.parse_generic_bounds()?;
|
||||
let sub = match &ty.kind {
|
||||
TyKind::Ref(_lifetime, mut_ty) => {
|
||||
let lo = mut_ty.ty.span.shrink_to_lo();
|
||||
TyKind::Ref(_lifetime, inner_ty, _) => {
|
||||
let lo = inner_ty.span.shrink_to_lo();
|
||||
let hi = self.prev_token.span.shrink_to_hi();
|
||||
BadTypePlusSub::AddParen { suggestion: AddParen { lo, hi } }
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@ use rustc_ast::token::{self, IdentKind, MetaVarKind, Token, TokenKind};
|
||||
use rustc_ast::util::case::Case;
|
||||
use rustc_ast::{
|
||||
self as ast, BoundAsyncness, BoundConstness, BoundPolarity, DUMMY_NODE_ID, FnPtrTy, FnRetTy,
|
||||
GenericBound, GenericBounds, GenericParam, Generics, Lifetime, MacCall, MutTy, Mutability,
|
||||
Path, Pinnedness, PolyTraitRef, PreciseCapturingArg, TraitBoundModifiers, TraitObjectSyntax,
|
||||
Ty, TyKind, UnsafeBinderTy,
|
||||
GenericBound, GenericBounds, GenericParam, Generics, Lifetime, MacCall, Mutability, Path,
|
||||
Pinnedness, PolyTraitRef, PreciseCapturingArg, TraitBoundModifiers, TraitObjectSyntax, Ty,
|
||||
TyKind, UnsafeBinderTy,
|
||||
};
|
||||
use rustc_errors::{Applicability, Diag, E0516, PResult};
|
||||
use rustc_span::{ErrorGuaranteed, Ident, Span, kw, sym};
|
||||
@@ -565,7 +565,7 @@ impl<'a> Parser<'a> {
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
err.emit();
|
||||
Ok(TyKind::Ref(Some(lt), MutTy { ty, mutbl }))
|
||||
Ok(TyKind::Ref(Some(lt), ty, mutbl))
|
||||
}
|
||||
Err(diag) => {
|
||||
diag.cancel();
|
||||
@@ -626,7 +626,7 @@ impl<'a> Parser<'a> {
|
||||
)
|
||||
.emit();
|
||||
|
||||
return Ok(TyKind::Ptr(MutTy { ty, mutbl }));
|
||||
return Ok(TyKind::Ptr(ty, mutbl));
|
||||
}
|
||||
// This is unreachable because we always get into if above and return from it
|
||||
unreachable!("this could never happen")
|
||||
@@ -643,7 +643,7 @@ impl<'a> Parser<'a> {
|
||||
Mutability::Not
|
||||
});
|
||||
let ty = self.parse_ty_no_plus()?;
|
||||
Ok(TyKind::Ptr(MutTy { ty, mutbl }))
|
||||
Ok(TyKind::Ptr(ty, mutbl))
|
||||
}
|
||||
|
||||
/// Parses an array (`[TYPE; EXPR]`) or slice (`[TYPE]`) type.
|
||||
@@ -761,8 +761,8 @@ impl<'a> Parser<'a> {
|
||||
}
|
||||
let ty = self.parse_ty_no_plus()?;
|
||||
Ok(match pinned {
|
||||
Pinnedness::Not => TyKind::Ref(opt_lifetime, MutTy { ty, mutbl }),
|
||||
Pinnedness::Pinned => TyKind::PinnedRef(opt_lifetime, MutTy { ty, mutbl }),
|
||||
Pinnedness::Not => TyKind::Ref(opt_lifetime, ty, mutbl),
|
||||
Pinnedness::Pinned => TyKind::PinnedRef(opt_lifetime, ty, mutbl),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -923,7 +923,7 @@ impl<'ast, 'ra, 'tcx> Visitor<'ast> for LateResolutionVisitor<'_, 'ast, 'ra, 'tc
|
||||
let prev = self.diag_metadata.current_trait_object;
|
||||
let prev_ty = self.diag_metadata.current_type_path;
|
||||
match &ty.kind {
|
||||
TyKind::Ref(None, _) | TyKind::PinnedRef(None, _) => {
|
||||
TyKind::Ref(None, ..) | TyKind::PinnedRef(None, ..) => {
|
||||
// Elided lifetime in reference: we resolve as if there was some lifetime `'_` with
|
||||
// NodeId `ty.id`.
|
||||
// This span will be used in case of elision failure.
|
||||
@@ -2116,8 +2116,8 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
|
||||
type Result = ControlFlow<Span>;
|
||||
|
||||
fn visit_ty(&mut self, ty: &'ast ast::Ty) -> Self::Result {
|
||||
if let ast::TyKind::Ref(None, mut_ty) = &ty.kind {
|
||||
return ControlFlow::Break(mut_ty.ty.span.shrink_to_lo());
|
||||
if let ast::TyKind::Ref(None, inner_ty, _) = &ty.kind {
|
||||
return ControlFlow::Break(inner_ty.span.shrink_to_lo());
|
||||
}
|
||||
visit::walk_ty(self, ty)
|
||||
}
|
||||
@@ -2656,7 +2656,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
|
||||
impl<'ra> Visitor<'ra> for FindReferenceVisitor<'_, '_, '_> {
|
||||
fn visit_ty(&mut self, ty: &'ra Ty) {
|
||||
trace!("FindReferenceVisitor considering ty={:?}", ty);
|
||||
if let TyKind::Ref(lt, _) | TyKind::PinnedRef(lt, _) = ty.kind {
|
||||
if let TyKind::Ref(lt, ..) | TyKind::PinnedRef(lt, ..) = ty.kind {
|
||||
// See if anything inside the &thing contains Self
|
||||
let mut visitor =
|
||||
SelfVisitor { r: self.r, impl_self: self.impl_self, self_found: false };
|
||||
|
||||
@@ -2924,7 +2924,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
|
||||
fn extract_node_id(t: &Ty) -> Option<NodeId> {
|
||||
match t.kind {
|
||||
TyKind::Path(None, _) => Some(t.id),
|
||||
TyKind::Ref(_, ref mut_ty) => extract_node_id(&mut_ty.ty),
|
||||
TyKind::Ref(_, ref inner_ty, _) => extract_node_id(inner_ty),
|
||||
// This doesn't handle the remaining `Ty` variants as they are not
|
||||
// that commonly the self_type, it might be interesting to provide
|
||||
// support for those in future.
|
||||
@@ -4472,8 +4472,8 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
|
||||
.seen
|
||||
.iter()
|
||||
.filter_map(|ty| match &ty.kind {
|
||||
TyKind::Ref(_, mut_ty) => {
|
||||
let span = ty.span.with_hi(mut_ty.ty.span.lo());
|
||||
TyKind::Ref(_, inner_ty, _) => {
|
||||
let span = ty.span.with_hi(inner_ty.span.lo());
|
||||
Some((span, "&'a ".to_string()))
|
||||
}
|
||||
_ => None,
|
||||
@@ -4513,7 +4513,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
|
||||
let mut ret_lt_finder =
|
||||
LifetimeFinder { lifetime: lt.span, found: None, seen: vec![] };
|
||||
ret_lt_finder.visit_ty(ret_ty);
|
||||
if let [Ty { span, kind: TyKind::Ref(_, mut_ty), .. }] =
|
||||
if let [Ty { span, kind: TyKind::Ref(_, inner_ty, _), .. }] =
|
||||
&ret_lt_finder.seen[..]
|
||||
{
|
||||
// We might have a situation like
|
||||
@@ -4521,7 +4521,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
|
||||
// but `lt.span` only points at `'_`, so to suggest `-> Option<()>`
|
||||
// we need to find a more accurate span to end up with
|
||||
// fn g<'a>(mut x: impl Iterator<Item = &'_ ()>) -> Option<()>
|
||||
sugg = vec![(span.with_hi(mut_ty.ty.span.lo()), String::new())];
|
||||
sugg = vec![(span.with_hi(inner_ty.span.lo()), String::new())];
|
||||
owned_sugg = true;
|
||||
}
|
||||
}
|
||||
@@ -4746,10 +4746,10 @@ struct LifetimeFinder<'ast> {
|
||||
|
||||
impl<'ast> Visitor<'ast> for LifetimeFinder<'ast> {
|
||||
fn visit_ty(&mut self, t: &'ast Ty) {
|
||||
if let TyKind::Ref(_, mut_ty) | TyKind::PinnedRef(_, mut_ty) = &t.kind {
|
||||
if let TyKind::Ref(_, ty, _) | TyKind::PinnedRef(_, ty, _) = &t.kind {
|
||||
self.seen.push(t);
|
||||
if t.span.lo() == self.lifetime.lo() {
|
||||
self.found = Some(&mut_ty.ty);
|
||||
self.found = Some(ty);
|
||||
}
|
||||
}
|
||||
walk_ty(self, t)
|
||||
@@ -4766,10 +4766,10 @@ impl<'ast> Visitor<'ast> for RefPrefixSpanFinder {
|
||||
if self.span.is_some() {
|
||||
return;
|
||||
}
|
||||
if let TyKind::Ref(_, mut_ty) | TyKind::PinnedRef(_, mut_ty) = &t.kind
|
||||
if let TyKind::Ref(_, inner_ty, _) | TyKind::PinnedRef(_, inner_ty, _) = &t.kind
|
||||
&& t.span.lo() == self.lifetime.lo()
|
||||
{
|
||||
self.span = Some(t.span.with_hi(mut_ty.ty.span.lo()));
|
||||
self.span = Some(t.span.with_hi(inner_ty.span.lo()));
|
||||
return;
|
||||
}
|
||||
walk_ty(self, t);
|
||||
|
||||
@@ -74,11 +74,11 @@ impl EarlyLintPass for NeedlessArbitrarySelfType {
|
||||
TyKind::Path(None, path) if let PatKind::Ident(BindingMode(ByRef::No, mutbl), _, _) = p.pat.kind => {
|
||||
(path, Mode::Value, mutbl)
|
||||
},
|
||||
TyKind::Ref(lifetime, mut_ty)
|
||||
if let TyKind::Path(None, path) = &mut_ty.ty.kind
|
||||
TyKind::Ref(lifetime, ty, mutbl)
|
||||
if let TyKind::Path(None, path) = &ty.kind
|
||||
&& let PatKind::Ident(BindingMode::NONE, _, _) = p.pat.kind =>
|
||||
{
|
||||
(path, Mode::Ref(*lifetime), mut_ty.mutbl)
|
||||
(path, Mode::Ref(*lifetime), *mutbl)
|
||||
},
|
||||
_ => return,
|
||||
};
|
||||
|
||||
@@ -59,15 +59,15 @@ impl RedundantStaticLifetimes {
|
||||
}
|
||||
},
|
||||
// This is what we are looking for !
|
||||
TyKind::Ref(ref optional_lifetime, ref borrow_type) => {
|
||||
TyKind::Ref(ref optional_lifetime, ref borrow_type, mutbl) => {
|
||||
// Match the 'static lifetime
|
||||
if let Some(lifetime) = *optional_lifetime {
|
||||
match borrow_type.ty.kind {
|
||||
match borrow_type.kind {
|
||||
TyKind::Path(..) | TyKind::Slice(..) | TyKind::Array(..) | TyKind::Tup(..)
|
||||
if lifetime.ident.name == kw::StaticLifetime =>
|
||||
{
|
||||
let snip = snippet(cx, borrow_type.ty.span, "<type>");
|
||||
let sugg = format!("&{}{snip}", borrow_type.mutbl.prefix_str());
|
||||
let snip = snippet(cx, borrow_type.span, "<type>");
|
||||
let sugg = format!("&{}{snip}", mutbl.prefix_str());
|
||||
span_lint_and_then(cx, REDUNDANT_STATIC_LIFETIMES, lifetime.ident.span, reason, |diag| {
|
||||
diag.span_suggestion(
|
||||
ty.span,
|
||||
@@ -80,7 +80,7 @@ impl RedundantStaticLifetimes {
|
||||
_ => {},
|
||||
}
|
||||
}
|
||||
Self::visit_type(&borrow_type.ty, cx, reason);
|
||||
Self::visit_type(borrow_type, cx, reason);
|
||||
},
|
||||
_ => {},
|
||||
}
|
||||
|
||||
@@ -867,12 +867,12 @@ fn eq_ty(l: &Ty, r: &Ty) -> bool {
|
||||
},
|
||||
(Slice(l), Slice(r)) => eq_ty(l, r),
|
||||
(Array(le, ls), Array(re, rs)) => eq_ty(le, re) && eq_expr(&ls.value, &rs.value),
|
||||
(Ptr(l), Ptr(r)) => l.mutbl == r.mutbl && eq_ty(&l.ty, &r.ty),
|
||||
(Ref(ll, l), Ref(rl, r)) => {
|
||||
both(ll.as_ref(), rl.as_ref(), |l, r| eq_id(l.ident, r.ident)) && l.mutbl == r.mutbl && eq_ty(&l.ty, &r.ty)
|
||||
(Ptr(l_ty, l_mutbl), Ptr(r_ty, r_mutbl)) => l_mutbl == r_mutbl && eq_ty(l_ty, r_ty),
|
||||
(Ref(ll, l_ty, l_mutbl), Ref(rl, r_ty, r_mutbl)) => {
|
||||
both(ll.as_ref(), rl.as_ref(), |l, r| eq_id(l.ident, r.ident)) && l_mutbl == r_mutbl && eq_ty(l_ty, r_ty)
|
||||
},
|
||||
(PinnedRef(ll, l), PinnedRef(rl, r)) => {
|
||||
both(ll.as_ref(), rl.as_ref(), |l, r| eq_id(l.ident, r.ident)) && l.mutbl == r.mutbl && eq_ty(&l.ty, &r.ty)
|
||||
(PinnedRef(ll, l_ty, l_mutbl), PinnedRef(rl, r_ty, r_mutbl)) => {
|
||||
both(ll.as_ref(), rl.as_ref(), |l, r| eq_id(l.ident, r.ident)) && l_mutbl == r_mutbl && eq_ty(l_ty, r_ty)
|
||||
},
|
||||
(FnPtr(l), FnPtr(r)) => {
|
||||
l.safety == r.safety
|
||||
|
||||
@@ -431,12 +431,12 @@ fn ty_search_pat(ty: &Ty<'_>) -> (Pat, Pat) {
|
||||
}
|
||||
|
||||
fn ast_ty_search_pat(ty: &ast::Ty) -> (Pat, Pat) {
|
||||
use ast::{Extern, FnRetTy, MutTy, Safety, TraitObjectSyntax, TyKind};
|
||||
use ast::{Extern, FnRetTy, Safety, TraitObjectSyntax, TyKind};
|
||||
|
||||
match &ty.kind {
|
||||
TyKind::Slice(..) | TyKind::Array(..) => (Pat::Str("["), Pat::Str("]")),
|
||||
TyKind::Ptr(MutTy { ty, .. }) => (Pat::Str("*"), ast_ty_search_pat(ty).1),
|
||||
TyKind::Ref(_, MutTy { ty, .. }) | TyKind::PinnedRef(_, MutTy { ty, .. }) => {
|
||||
TyKind::Ptr(ty, ..) => (Pat::Str("*"), ast_ty_search_pat(ty).1),
|
||||
TyKind::Ref(_, ty, ..) | TyKind::PinnedRef(_, ty, ..) => {
|
||||
(Pat::Str("&"), ast_ty_search_pat(ty).1)
|
||||
},
|
||||
TyKind::FnPtr(fn_ptr) => (
|
||||
|
||||
@@ -821,17 +821,17 @@ impl Rewrite for ast::Ty {
|
||||
}
|
||||
Ok(format!("{prefix}{res}"))
|
||||
}
|
||||
ast::TyKind::Ptr(ref mt) => {
|
||||
let prefix = match mt.mutbl {
|
||||
ast::TyKind::Ptr(ref ty, mutbl) => {
|
||||
let prefix = match mutbl {
|
||||
Mutability::Mut => "*mut ",
|
||||
Mutability::Not => "*const ",
|
||||
};
|
||||
|
||||
rewrite_unary_prefix(context, prefix, &*mt.ty, shape)
|
||||
rewrite_unary_prefix(context, prefix, &*ty, shape)
|
||||
}
|
||||
ast::TyKind::Ref(ref lifetime, ref mt)
|
||||
| ast::TyKind::PinnedRef(ref lifetime, ref mt) => {
|
||||
let mut_str = format_mutability(mt.mutbl);
|
||||
ast::TyKind::Ref(ref lifetime, ref ty, mutbl)
|
||||
| ast::TyKind::PinnedRef(ref lifetime, ref ty, mutbl) => {
|
||||
let mut_str = format_mutability(mutbl);
|
||||
let mut_len = mut_str.len();
|
||||
let mut result = String::with_capacity(128);
|
||||
result.push('&');
|
||||
@@ -866,12 +866,12 @@ impl Rewrite for ast::Ty {
|
||||
|
||||
if let ast::TyKind::PinnedRef(..) = self.kind {
|
||||
result.push_str("pin ");
|
||||
if ast::Mutability::Not == mt.mutbl {
|
||||
if ast::Mutability::Not == mutbl {
|
||||
result.push_str("const ");
|
||||
}
|
||||
}
|
||||
|
||||
if ast::Mutability::Mut == mt.mutbl {
|
||||
if ast::Mutability::Mut == mutbl {
|
||||
let mut_hi = context.snippet_provider.span_after(self.span(), "mut");
|
||||
let before_mut_span = mk_sp(cmnt_lo, mut_hi - BytePos::from_usize(3));
|
||||
if contains_comment(context.snippet(before_mut_span)) {
|
||||
@@ -889,12 +889,12 @@ impl Rewrite for ast::Ty {
|
||||
cmnt_lo = mut_hi;
|
||||
}
|
||||
|
||||
let before_ty_span = mk_sp(cmnt_lo, mt.ty.span.lo());
|
||||
let before_ty_span = mk_sp(cmnt_lo, ty.span.lo());
|
||||
if contains_comment(context.snippet(before_ty_span)) {
|
||||
result = combine_strs_with_missing_comments(
|
||||
context,
|
||||
result.trim_end(),
|
||||
&mt.ty.rewrite_result(context, shape)?,
|
||||
&ty.rewrite_result(context, shape)?,
|
||||
before_ty_span,
|
||||
shape,
|
||||
true,
|
||||
@@ -905,7 +905,7 @@ impl Rewrite for ast::Ty {
|
||||
.width
|
||||
.checked_sub(used_width)
|
||||
.max_width_error(shape.width, self.span())?;
|
||||
let ty_str = mt.ty.rewrite_result(
|
||||
let ty_str = ty.rewrite_result(
|
||||
context,
|
||||
Shape::legacy(budget, shape.indent + used_width),
|
||||
)?;
|
||||
@@ -1333,9 +1333,9 @@ pub(crate) fn can_be_overflowed_type(
|
||||
) -> bool {
|
||||
match ty.kind {
|
||||
ast::TyKind::Tup(..) => context.use_block_indent() && len == 1,
|
||||
ast::TyKind::Ref(_, ref mutty)
|
||||
| ast::TyKind::PinnedRef(_, ref mutty)
|
||||
| ast::TyKind::Ptr(ref mutty) => can_be_overflowed_type(context, &*mutty.ty, len),
|
||||
ast::TyKind::Ref(_, ref ty, _)
|
||||
| ast::TyKind::PinnedRef(_, ref ty, _)
|
||||
| ast::TyKind::Ptr(ref ty, _) => can_be_overflowed_type(context, &*ty, len),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user