Make RawPtr take Ty and Mutbl separately
This commit is contained in:
parent
ff0c31e6b9
commit
7be0dbe772
36 changed files with 111 additions and 112 deletions
|
@ -2477,7 +2477,7 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue {
|
|||
Adt(..) if ty.is_box() => Some("`Box` must be non-null".into()),
|
||||
FnPtr(..) => Some("function pointers must be non-null".into()),
|
||||
Never => Some("the `!` type has no valid value".into()),
|
||||
RawPtr(tm) if matches!(tm.ty.kind(), Dynamic(..)) =>
|
||||
RawPtr(ty, _) if matches!(ty.kind(), Dynamic(..)) =>
|
||||
// raw ptr to dyn Trait
|
||||
{
|
||||
Some("the vtable of a wide raw pointer must be non-null".into())
|
||||
|
|
|
@ -322,10 +322,10 @@ fn structurally_same_type_impl<'tcx>(
|
|||
(Slice(a_ty), Slice(b_ty)) => {
|
||||
structurally_same_type_impl(seen_types, tcx, param_env, *a_ty, *b_ty, ckind)
|
||||
}
|
||||
(RawPtr(a_tymut), RawPtr(b_tymut)) => {
|
||||
a_tymut.mutbl == b_tymut.mutbl
|
||||
(RawPtr(a_ty, a_mutbl), RawPtr(b_ty, b_mutbl)) => {
|
||||
a_mutbl == b_mutbl
|
||||
&& structurally_same_type_impl(
|
||||
seen_types, tcx, param_env, a_tymut.ty, b_tymut.ty, ckind,
|
||||
seen_types, tcx, param_env, *a_ty, *b_ty, ckind,
|
||||
)
|
||||
}
|
||||
(Ref(_a_region, a_ty, a_mut), Ref(_b_region, b_ty, b_mut)) => {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use rustc_ast::Mutability;
|
||||
use rustc_hir::{Expr, ExprKind, UnOp};
|
||||
use rustc_middle::ty::layout::LayoutOf as _;
|
||||
use rustc_middle::ty::{self, layout::TyAndLayout, TypeAndMut};
|
||||
use rustc_middle::ty::{self, layout::TyAndLayout};
|
||||
use rustc_span::sym;
|
||||
|
||||
use crate::{lints::InvalidReferenceCastingDiag, LateContext, LateLintPass, LintContext};
|
||||
|
@ -153,7 +153,7 @@ fn is_cast_from_ref_to_mut_ptr<'tcx>(
|
|||
let end_ty = cx.typeck_results().node_type(orig_expr.hir_id);
|
||||
|
||||
// Bail out early if the end type is **not** a mutable pointer.
|
||||
if !matches!(end_ty.kind(), ty::RawPtr(TypeAndMut { ty: _, mutbl: Mutability::Mut })) {
|
||||
if !matches!(end_ty.kind(), ty::RawPtr(_, Mutability::Mut)) {
|
||||
return None;
|
||||
}
|
||||
|
||||
|
|
|
@ -18,10 +18,10 @@ use rustc_errors::DiagMessage;
|
|||
use rustc_hir as hir;
|
||||
use rustc_hir::{is_range_literal, Expr, ExprKind, Node};
|
||||
use rustc_middle::ty::layout::{IntegerExt, LayoutOf, SizeSkeleton};
|
||||
use rustc_middle::ty::GenericArgsRef;
|
||||
use rustc_middle::ty::{
|
||||
self, AdtKind, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitableExt,
|
||||
};
|
||||
use rustc_middle::ty::{GenericArgsRef, TypeAndMut};
|
||||
use rustc_span::def_id::LocalDefId;
|
||||
use rustc_span::source_map;
|
||||
use rustc_span::symbol::sym;
|
||||
|
@ -1046,7 +1046,7 @@ fn get_nullable_type<'tcx>(
|
|||
}
|
||||
ty::Int(ty) => Ty::new_int(tcx, ty),
|
||||
ty::Uint(ty) => Ty::new_uint(tcx, ty),
|
||||
ty::RawPtr(ty_mut) => Ty::new_ptr(tcx, ty_mut.ty, ty_mut.mutbl),
|
||||
ty::RawPtr(ty, mutbl) => Ty::new_ptr(tcx, ty, mutbl),
|
||||
// As these types are always non-null, the nullable equivalent of
|
||||
// `Option<T>` of these types are their raw pointer counterparts.
|
||||
ty::Ref(_region, ty, mutbl) => Ty::new_ptr(tcx, ty, mutbl),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue