Rename Rptr to Ref in AST and HIR
The name makes a lot more sense, and `ty::TyKind` calls it `Ref` already as well.
This commit is contained in:
parent
a1fc71196a
commit
9067e4417e
57 changed files with 93 additions and 97 deletions
|
|
@ -1612,7 +1612,7 @@ pub(crate) fn clean_ty<'tcx>(ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> T
|
|||
match ty.kind {
|
||||
TyKind::Never => Primitive(PrimitiveType::Never),
|
||||
TyKind::Ptr(ref m) => RawPointer(m.mutbl, Box::new(clean_ty(m.ty, cx))),
|
||||
TyKind::Rptr(ref l, ref m) => {
|
||||
TyKind::Ref(ref l, ref m) => {
|
||||
let lifetime = if l.is_anonymous() { None } else { Some(clean_lifetime(*l, cx)) };
|
||||
BorrowedRef { lifetime, mutability: m.mutbl, type_: Box::new(clean_ty(m.ty, cx)) }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ pub async fn const_generics<const N: usize>(_: impl Trait<N>) {}
|
|||
// @has - '//pre[@class="rust fn"]' 'pub async fn elided(foo: &str) -> &str'
|
||||
pub async fn elided(foo: &str) -> &str {}
|
||||
// This should really be shown as written, but for implementation reasons it's difficult.
|
||||
// See `impl Clean for TyKind::Rptr`.
|
||||
// See `impl Clean for TyKind::Ref`.
|
||||
// @has async_fn/fn.user_elided.html
|
||||
// @has - '//pre[@class="rust fn"]' 'pub async fn user_elided(foo: &str) -> &str'
|
||||
pub async fn user_elided(foo: &'_ str) -> &str {}
|
||||
|
|
|
|||
|
|
@ -801,7 +801,7 @@ fn test_ty() {
|
|||
assert_eq!(stringify_ty!(*const T), "*const T");
|
||||
assert_eq!(stringify_ty!(*mut T), "*mut T");
|
||||
|
||||
// TyKind::Rptr
|
||||
// TyKind::Ref
|
||||
assert_eq!(stringify_ty!(&T), "&T");
|
||||
assert_eq!(stringify_ty!(&mut T), "&mut T");
|
||||
assert_eq!(stringify_ty!(&'a T), "&'a T");
|
||||
|
|
|
|||
|
|
@ -41,8 +41,8 @@ ast-stats-1 - Wild 88 ( 1.2%) 1
|
|||
ast-stats-1 - Ident 440 ( 5.9%) 5
|
||||
ast-stats-1 PathSegment 720 ( 9.7%) 30 24
|
||||
ast-stats-1 Ty 896 (12.1%) 14 64
|
||||
ast-stats-1 - Rptr 64 ( 0.9%) 1
|
||||
ast-stats-1 - Ptr 64 ( 0.9%) 1
|
||||
ast-stats-1 - Ref 64 ( 0.9%) 1
|
||||
ast-stats-1 - ImplicitSelf 128 ( 1.7%) 2
|
||||
ast-stats-1 - Path 640 ( 8.6%) 10
|
||||
ast-stats-1 Item 1_656 (22.3%) 9 184
|
||||
|
|
@ -100,8 +100,8 @@ ast-stats-2 - Lit 144 ( 1.8%) 2
|
|||
ast-stats-2 - Block 216 ( 2.7%) 3
|
||||
ast-stats-2 PathSegment 792 ( 9.8%) 33 24
|
||||
ast-stats-2 Ty 896 (11.0%) 14 64
|
||||
ast-stats-2 - Rptr 64 ( 0.8%) 1
|
||||
ast-stats-2 - Ptr 64 ( 0.8%) 1
|
||||
ast-stats-2 - Ref 64 ( 0.8%) 1
|
||||
ast-stats-2 - ImplicitSelf 128 ( 1.6%) 2
|
||||
ast-stats-2 - Path 640 ( 7.9%) 10
|
||||
ast-stats-2 Item 2_024 (25.0%) 11 184
|
||||
|
|
@ -154,7 +154,7 @@ hir-stats GenericParam 400 ( 4.4%) 5 80
|
|||
hir-stats Generics 560 ( 6.2%) 10 56
|
||||
hir-stats Ty 720 ( 8.0%) 15 48
|
||||
hir-stats - Ptr 48 ( 0.5%) 1
|
||||
hir-stats - Rptr 48 ( 0.5%) 1
|
||||
hir-stats - Ref 48 ( 0.5%) 1
|
||||
hir-stats - Path 624 ( 6.9%) 13
|
||||
hir-stats Expr 768 ( 8.5%) 12 64
|
||||
hir-stats - Path 64 ( 0.7%) 1
|
||||
|
|
|
|||
|
|
@ -969,14 +969,14 @@ fn binding_ty_auto_deref_stability<'tcx>(
|
|||
precedence: i8,
|
||||
binder_args: &'tcx List<BoundVariableKind>,
|
||||
) -> Position {
|
||||
let TyKind::Rptr(_, ty) = &ty.kind else {
|
||||
let TyKind::Ref(_, ty) = &ty.kind else {
|
||||
return Position::Other(precedence);
|
||||
};
|
||||
let mut ty = ty;
|
||||
|
||||
loop {
|
||||
break match ty.ty.kind {
|
||||
TyKind::Rptr(_, ref ref_ty) => {
|
||||
TyKind::Ref(_, ref ref_ty) => {
|
||||
ty = ref_ty;
|
||||
continue;
|
||||
},
|
||||
|
|
|
|||
|
|
@ -152,7 +152,7 @@ fn captures_all_lifetimes(inputs: &[Ty<'_>], output_lifetimes: &[LifetimeName])
|
|||
let input_lifetimes: Vec<LifetimeName> = inputs
|
||||
.iter()
|
||||
.filter_map(|ty| {
|
||||
if let TyKind::Rptr(lt, _) = ty.kind {
|
||||
if let TyKind::Ref(lt, _) = ty.kind {
|
||||
Some(lt.res)
|
||||
} else {
|
||||
None
|
||||
|
|
|
|||
|
|
@ -3986,7 +3986,7 @@ impl OutType {
|
|||
(Self::Unit, &hir::FnRetTy::Return(ty)) if is_unit(ty) => true,
|
||||
(Self::Bool, &hir::FnRetTy::Return(ty)) if is_bool(ty) => true,
|
||||
(Self::Any, &hir::FnRetTy::Return(ty)) if !is_unit(ty) => true,
|
||||
(Self::Ref, &hir::FnRetTy::Return(ty)) => matches!(ty.kind, hir::TyKind::Rptr(_, _)),
|
||||
(Self::Ref, &hir::FnRetTy::Return(ty)) => matches!(ty.kind, hir::TyKind::Ref(_, _)),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for MutVisitor<'a, 'tcx> {
|
|||
return;
|
||||
}
|
||||
|
||||
if let hir::TyKind::Rptr(
|
||||
if let hir::TyKind::Ref(
|
||||
_,
|
||||
hir::MutTy {
|
||||
ty: pty,
|
||||
|
|
@ -94,7 +94,7 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for MutVisitor<'a, 'tcx> {
|
|||
},
|
||||
) = ty.kind
|
||||
{
|
||||
if let hir::TyKind::Rptr(
|
||||
if let hir::TyKind::Ref(
|
||||
_,
|
||||
hir::MutTy {
|
||||
mutbl: hir::Mutability::Mut,
|
||||
|
|
|
|||
|
|
@ -124,7 +124,7 @@ impl EarlyLintPass for NeedlessArbitrarySelfType {
|
|||
check_param_inner(cx, path, p.span.to(p.ty.span), &Mode::Value, mutbl);
|
||||
}
|
||||
},
|
||||
TyKind::Rptr(lifetime, mut_ty) => {
|
||||
TyKind::Ref(lifetime, mut_ty) => {
|
||||
if_chain! {
|
||||
if let TyKind::Path(None, path) = &mut_ty.ty.kind;
|
||||
if let PatKind::Ident(BindingAnnotation::NONE, _, _) = p.pat.kind;
|
||||
|
|
|
|||
|
|
@ -184,7 +184,7 @@ impl<'tcx> PassByRefOrValue {
|
|||
if is_copy(cx, ty)
|
||||
&& let Some(size) = cx.layout_of(ty).ok().map(|l| l.size.bytes())
|
||||
&& size <= self.ref_min_size
|
||||
&& let hir::TyKind::Rptr(_, MutTy { ty: decl_ty, .. }) = input.kind
|
||||
&& let hir::TyKind::Ref(_, MutTy { ty: decl_ty, .. }) = input.kind
|
||||
{
|
||||
if let Some(typeck) = cx.maybe_typeck_results() {
|
||||
// Don't lint if an unsafe pointer is created.
|
||||
|
|
|
|||
|
|
@ -421,7 +421,7 @@ fn check_fn_args<'cx, 'tcx: 'cx>(
|
|||
if let ty::Ref(_, ty, mutability) = *ty.kind();
|
||||
if let ty::Adt(adt, substs) = *ty.kind();
|
||||
|
||||
if let TyKind::Rptr(lt, ref ty) = hir_ty.kind;
|
||||
if let TyKind::Ref(lt, ref ty) = hir_ty.kind;
|
||||
if let TyKind::Path(QPath::Resolved(None, path)) = ty.ty.kind;
|
||||
|
||||
// Check that the name as typed matches the actual name of the type.
|
||||
|
|
@ -503,14 +503,14 @@ fn check_fn_args<'cx, 'tcx: 'cx>(
|
|||
|
||||
fn check_mut_from_ref<'tcx>(cx: &LateContext<'tcx>, sig: &FnSig<'_>, body: Option<&'tcx Body<'_>>) {
|
||||
if let FnRetTy::Return(ty) = sig.decl.output
|
||||
&& let Some((out, Mutability::Mut, _)) = get_rptr_lm(ty)
|
||||
&& let Some((out, Mutability::Mut, _)) = get_ref_lm(ty)
|
||||
{
|
||||
let out_region = cx.tcx.named_region(out.hir_id);
|
||||
let args: Option<Vec<_>> = sig
|
||||
.decl
|
||||
.inputs
|
||||
.iter()
|
||||
.filter_map(get_rptr_lm)
|
||||
.filter_map(get_ref_lm)
|
||||
.filter(|&(lt, _, _)| cx.tcx.named_region(lt.hir_id) == out_region)
|
||||
.map(|(_, mutability, span)| (mutability == Mutability::Not).then_some(span))
|
||||
.collect();
|
||||
|
|
@ -704,8 +704,8 @@ fn matches_preds<'tcx>(
|
|||
})
|
||||
}
|
||||
|
||||
fn get_rptr_lm<'tcx>(ty: &'tcx hir::Ty<'tcx>) -> Option<(&'tcx Lifetime, Mutability, Span)> {
|
||||
if let TyKind::Rptr(lt, ref m) = ty.kind {
|
||||
fn get_ref_lm<'tcx>(ty: &'tcx hir::Ty<'tcx>) -> Option<(&'tcx Lifetime, Mutability, Span)> {
|
||||
if let TyKind::Ref(lt, ref m) = ty.kind {
|
||||
Some((lt, m.mutbl, ty.span))
|
||||
} else {
|
||||
None
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ impl RedundantStaticLifetimes {
|
|||
}
|
||||
},
|
||||
// This is what we are looking for !
|
||||
TyKind::Rptr(ref optional_lifetime, ref borrow_type) => {
|
||||
TyKind::Ref(ref optional_lifetime, ref borrow_type) => {
|
||||
// Match the 'static lifetime
|
||||
if let Some(lifetime) = *optional_lifetime {
|
||||
match borrow_type.ty.kind {
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ declare_lint_pass!(RefOptionRef => [REF_OPTION_REF]);
|
|||
impl<'tcx> LateLintPass<'tcx> for RefOptionRef {
|
||||
fn check_ty(&mut self, cx: &LateContext<'tcx>, ty: &'tcx Ty<'tcx>) {
|
||||
if_chain! {
|
||||
if let TyKind::Rptr(_, ref mut_ty) = ty.kind;
|
||||
if let TyKind::Ref(_, ref mut_ty) = ty.kind;
|
||||
if mut_ty.mutbl == Mutability::Not;
|
||||
if let TyKind::Path(ref qpath) = &mut_ty.ty.kind;
|
||||
let last = last_path_segment(qpath);
|
||||
|
|
@ -52,7 +52,7 @@ impl<'tcx> LateLintPass<'tcx> for RefOptionRef {
|
|||
GenericArg::Type(inner_ty) => Some(inner_ty),
|
||||
_ => None,
|
||||
});
|
||||
if let TyKind::Rptr(_, ref inner_mut_ty) = inner_ty.kind;
|
||||
if let TyKind::Ref(_, ref inner_mut_ty) = inner_ty.kind;
|
||||
if inner_mut_ty.mutbl == Mutability::Not;
|
||||
|
||||
then {
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ pub(super) fn check<'tcx>(
|
|||
/// Gets the type `Bar` in `…::transmute<Foo, &Bar>`.
|
||||
fn get_explicit_type<'tcx>(path: &'tcx Path<'tcx>) -> Option<&'tcx hir::Ty<'tcx>> {
|
||||
if let GenericArg::Type(ty) = path.segments.last()?.args?.args.get(1)?
|
||||
&& let TyKind::Rptr(_, ty) = &ty.kind
|
||||
&& let TyKind::Ref(_, ty) = &ty.kind
|
||||
{
|
||||
Some(ty.ty)
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -539,7 +539,7 @@ impl Types {
|
|||
QPath::LangItem(..) => {},
|
||||
}
|
||||
},
|
||||
TyKind::Rptr(lt, ref mut_ty) => {
|
||||
TyKind::Ref(lt, ref mut_ty) => {
|
||||
context.is_nested_call = true;
|
||||
if !borrowed_box::check(cx, hir_ty, lt, mut_ty) {
|
||||
self.check_ty(cx, mut_ty.ty, context);
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ impl<'tcx> Visitor<'tcx> for TypeComplexityVisitor {
|
|||
fn visit_ty(&mut self, ty: &'tcx hir::Ty<'_>) {
|
||||
let (add_score, sub_nest) = match ty.kind {
|
||||
// _, &x and *x have only small overhead; don't mess with nesting level
|
||||
TyKind::Infer | TyKind::Ptr(..) | TyKind::Rptr(..) => (1, 0),
|
||||
TyKind::Infer | TyKind::Ptr(..) | TyKind::Ref(..) => (1, 0),
|
||||
|
||||
// the "normal" components of a type: named types, arrays/tuples
|
||||
TyKind::Path(..) | TyKind::Slice(..) | TyKind::Tup(..) | TyKind::Array(..) => (10 * self.nest, 1),
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ pub(super) fn match_borrows_parameter(_cx: &LateContext<'_>, qpath: &QPath<'_>)
|
|||
GenericArg::Type(ty) => Some(ty),
|
||||
_ => None,
|
||||
});
|
||||
if let TyKind::Rptr(..) = ty.kind;
|
||||
if let TyKind::Ref(..) = ty.kind;
|
||||
then {
|
||||
return Some(ty.span);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -257,7 +257,7 @@ impl<'tcx> LateLintPass<'tcx> for LintWithoutLintPass {
|
|||
}
|
||||
|
||||
pub(super) fn is_lint_ref_type(cx: &LateContext<'_>, ty: &hir::Ty<'_>) -> bool {
|
||||
if let TyKind::Rptr(
|
||||
if let TyKind::Ref(
|
||||
_,
|
||||
MutTy {
|
||||
ty: inner,
|
||||
|
|
|
|||
|
|
@ -625,7 +625,7 @@ pub 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),
|
||||
(Rptr(ll, l), Rptr(rl, r)) => {
|
||||
(Ref(ll, l), Ref(rl, r)) => {
|
||||
both(ll, rl, |l, r| eq_id(l.ident, r.ident)) && l.mutbl == r.mutbl && eq_ty(&l.ty, &r.ty)
|
||||
},
|
||||
(BareFn(l), BareFn(r)) => {
|
||||
|
|
|
|||
|
|
@ -430,7 +430,7 @@ impl HirEqInterExpr<'_, '_, '_> {
|
|||
(&TyKind::Slice(l_vec), &TyKind::Slice(r_vec)) => self.eq_ty(l_vec, r_vec),
|
||||
(&TyKind::Array(lt, ll), &TyKind::Array(rt, rl)) => self.eq_ty(lt, rt) && self.eq_array_length(ll, rl),
|
||||
(TyKind::Ptr(l_mut), TyKind::Ptr(r_mut)) => l_mut.mutbl == r_mut.mutbl && self.eq_ty(l_mut.ty, r_mut.ty),
|
||||
(TyKind::Rptr(_, l_rmut), TyKind::Rptr(_, r_rmut)) => {
|
||||
(TyKind::Ref(_, l_rmut), TyKind::Ref(_, r_rmut)) => {
|
||||
l_rmut.mutbl == r_rmut.mutbl && self.eq_ty(l_rmut.ty, r_rmut.ty)
|
||||
},
|
||||
(TyKind::Path(l), TyKind::Path(r)) => self.eq_qpath(l, r),
|
||||
|
|
@ -950,7 +950,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
|
|||
self.hash_ty(mut_ty.ty);
|
||||
mut_ty.mutbl.hash(&mut self.s);
|
||||
},
|
||||
TyKind::Rptr(lifetime, ref mut_ty) => {
|
||||
TyKind::Ref(lifetime, ref mut_ty) => {
|
||||
self.hash_lifetime(lifetime);
|
||||
self.hash_ty(mut_ty.ty);
|
||||
mut_ty.mutbl.hash(&mut self.s);
|
||||
|
|
|
|||
|
|
@ -2264,7 +2264,7 @@ pub fn peel_hir_ty_refs<'a>(mut ty: &'a hir::Ty<'a>) -> (&'a hir::Ty<'a>, usize)
|
|||
let mut count = 0;
|
||||
loop {
|
||||
match &ty.kind {
|
||||
TyKind::Rptr(_, ref_ty) => {
|
||||
TyKind::Ref(_, ref_ty) => {
|
||||
ty = ref_ty.ty;
|
||||
count += 1;
|
||||
},
|
||||
|
|
|
|||
|
|
@ -813,9 +813,9 @@ pub fn deref_closure_args(cx: &LateContext<'_>, closure: &hir::Expr<'_>) -> Opti
|
|||
let closure_body = cx.tcx.hir().body(body);
|
||||
// is closure arg a type annotated double reference (i.e.: `|x: &&i32| ...`)
|
||||
// a type annotation is present if param `kind` is different from `TyKind::Infer`
|
||||
let closure_arg_is_type_annotated_double_ref = if let TyKind::Rptr(_, MutTy { ty, .. }) = fn_decl.inputs[0].kind
|
||||
let closure_arg_is_type_annotated_double_ref = if let TyKind::Ref(_, MutTy { ty, .. }) = fn_decl.inputs[0].kind
|
||||
{
|
||||
matches!(ty.kind, TyKind::Rptr(_, MutTy { .. }))
|
||||
matches!(ty.kind, TyKind::Ref(_, MutTy { .. }))
|
||||
} else {
|
||||
false
|
||||
};
|
||||
|
|
|
|||
|
|
@ -496,7 +496,7 @@ pub fn type_is_unsafe_function<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bo
|
|||
/// Returns the base type for HIR references and pointers.
|
||||
pub fn walk_ptrs_hir_ty<'tcx>(ty: &'tcx hir::Ty<'tcx>) -> &'tcx hir::Ty<'tcx> {
|
||||
match ty.kind {
|
||||
TyKind::Ptr(ref mut_ty) | TyKind::Rptr(_, ref mut_ty) => walk_ptrs_hir_ty(mut_ty.ty),
|
||||
TyKind::Ptr(ref mut_ty) | TyKind::Ref(_, ref mut_ty) => walk_ptrs_hir_ty(mut_ty.ty),
|
||||
_ => ty,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -688,7 +688,7 @@ impl Rewrite for ast::Ty {
|
|||
|
||||
rewrite_unary_prefix(context, prefix, &*mt.ty, shape)
|
||||
}
|
||||
ast::TyKind::Rptr(ref lifetime, ref mt) => {
|
||||
ast::TyKind::Ref(ref lifetime, ref mt) => {
|
||||
let mut_str = format_mutability(mt.mutbl);
|
||||
let mut_len = mut_str.len();
|
||||
let mut result = String::with_capacity(128);
|
||||
|
|
@ -1059,7 +1059,7 @@ pub(crate) fn can_be_overflowed_type(
|
|||
) -> bool {
|
||||
match ty.kind {
|
||||
ast::TyKind::Tup(..) => context.use_block_indent() && len == 1,
|
||||
ast::TyKind::Rptr(_, ref mutty) | ast::TyKind::Ptr(ref mutty) => {
|
||||
ast::TyKind::Ref(_, ref mutty) | ast::TyKind::Ptr(ref mutty) => {
|
||||
can_be_overflowed_type(context, &*mutty.ty, len)
|
||||
}
|
||||
_ => false,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue