Rollup merge of #150086 - Bryntet:parse_never_return_null_pointer, r=JonathanBrouwer
Port `#[rustc_never_returns_null_ptr]` to attribute parser Ports `#[rustc_never_returns_null_ptr]` to be parsed using the attribute parser r? `@JonathanBrouwer`
This commit is contained in:
commit
84d441f558
6 changed files with 28 additions and 8 deletions
|
|
@ -13,6 +13,21 @@ impl<S: Stage> NoArgsAttributeParser<S> for RustcMainParser {
|
||||||
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcMain;
|
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcMain;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) struct RustcNeverReturnsNullPointerParser;
|
||||||
|
|
||||||
|
impl<S: Stage> NoArgsAttributeParser<S> for RustcNeverReturnsNullPointerParser {
|
||||||
|
const PATH: &[Symbol] = &[sym::rustc_never_returns_null_ptr];
|
||||||
|
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
|
||||||
|
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
|
||||||
|
Allow(Target::Fn),
|
||||||
|
Allow(Target::Method(MethodKind::Inherent)),
|
||||||
|
Allow(Target::Method(MethodKind::Trait { body: false })),
|
||||||
|
Allow(Target::Method(MethodKind::Trait { body: true })),
|
||||||
|
Allow(Target::Method(MethodKind::TraitImpl)),
|
||||||
|
]);
|
||||||
|
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcNeverReturnsNullPointer;
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) struct RustcLayoutScalarValidRangeStartParser;
|
pub(crate) struct RustcLayoutScalarValidRangeStartParser;
|
||||||
|
|
||||||
impl<S: Stage> SingleAttributeParser<S> for RustcLayoutScalarValidRangeStartParser {
|
impl<S: Stage> SingleAttributeParser<S> for RustcLayoutScalarValidRangeStartParser {
|
||||||
|
|
|
||||||
|
|
@ -61,8 +61,9 @@ use crate::attributes::prototype::CustomMirParser;
|
||||||
use crate::attributes::repr::{AlignParser, AlignStaticParser, ReprParser};
|
use crate::attributes::repr::{AlignParser, AlignStaticParser, ReprParser};
|
||||||
use crate::attributes::rustc_internal::{
|
use crate::attributes::rustc_internal::{
|
||||||
RustcLayoutScalarValidRangeEndParser, RustcLayoutScalarValidRangeStartParser,
|
RustcLayoutScalarValidRangeEndParser, RustcLayoutScalarValidRangeStartParser,
|
||||||
RustcLegacyConstGenericsParser, RustcMainParser, RustcObjectLifetimeDefaultParser,
|
RustcLegacyConstGenericsParser, RustcMainParser, RustcNeverReturnsNullPointerParser,
|
||||||
RustcScalableVectorParser, RustcSimdMonomorphizeLaneLimitParser,
|
RustcObjectLifetimeDefaultParser, RustcScalableVectorParser,
|
||||||
|
RustcSimdMonomorphizeLaneLimitParser,
|
||||||
};
|
};
|
||||||
use crate::attributes::semantics::MayDangleParser;
|
use crate::attributes::semantics::MayDangleParser;
|
||||||
use crate::attributes::stability::{
|
use crate::attributes::stability::{
|
||||||
|
|
@ -255,6 +256,7 @@ attribute_parsers!(
|
||||||
Single<WithoutArgs<PubTransparentParser>>,
|
Single<WithoutArgs<PubTransparentParser>>,
|
||||||
Single<WithoutArgs<RustcCoherenceIsCoreParser>>,
|
Single<WithoutArgs<RustcCoherenceIsCoreParser>>,
|
||||||
Single<WithoutArgs<RustcMainParser>>,
|
Single<WithoutArgs<RustcMainParser>>,
|
||||||
|
Single<WithoutArgs<RustcNeverReturnsNullPointerParser>>,
|
||||||
Single<WithoutArgs<RustcPassIndirectlyInNonRusticAbisParser>>,
|
Single<WithoutArgs<RustcPassIndirectlyInNonRusticAbisParser>>,
|
||||||
Single<WithoutArgs<RustcShouldNotBeCalledOnConstItems>>,
|
Single<WithoutArgs<RustcShouldNotBeCalledOnConstItems>>,
|
||||||
Single<WithoutArgs<SpecializationTraitParser>>,
|
Single<WithoutArgs<SpecializationTraitParser>>,
|
||||||
|
|
|
||||||
|
|
@ -878,6 +878,9 @@ pub enum AttributeKind {
|
||||||
/// Represents `#[rustc_main]`.
|
/// Represents `#[rustc_main]`.
|
||||||
RustcMain,
|
RustcMain,
|
||||||
|
|
||||||
|
/// Represents `#[rustc_never_returns_null_ptr]`
|
||||||
|
RustcNeverReturnsNullPointer,
|
||||||
|
|
||||||
/// Represents `#[rustc_object_lifetime_default]`.
|
/// Represents `#[rustc_object_lifetime_default]`.
|
||||||
RustcObjectLifetimeDefault,
|
RustcObjectLifetimeDefault,
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -95,6 +95,7 @@ impl AttributeKind {
|
||||||
RustcLayoutScalarValidRangeStart(..) => Yes,
|
RustcLayoutScalarValidRangeStart(..) => Yes,
|
||||||
RustcLegacyConstGenerics { .. } => Yes,
|
RustcLegacyConstGenerics { .. } => Yes,
|
||||||
RustcMain => No,
|
RustcMain => No,
|
||||||
|
RustcNeverReturnsNullPointer => Yes,
|
||||||
RustcObjectLifetimeDefault => No,
|
RustcObjectLifetimeDefault => No,
|
||||||
RustcPassIndirectlyInNonRusticAbis(..) => No,
|
RustcPassIndirectlyInNonRusticAbis(..) => No,
|
||||||
RustcScalableVector { .. } => Yes,
|
RustcScalableVector { .. } => Yes,
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
use rustc_ast::LitKind;
|
use rustc_ast::LitKind;
|
||||||
use rustc_hir::{BinOpKind, Expr, ExprKind, TyKind};
|
use rustc_hir::attrs::AttributeKind;
|
||||||
|
use rustc_hir::{BinOpKind, Expr, ExprKind, TyKind, find_attr};
|
||||||
use rustc_middle::ty::RawPtr;
|
use rustc_middle::ty::RawPtr;
|
||||||
use rustc_session::{declare_lint, declare_lint_pass};
|
use rustc_session::{declare_lint, declare_lint_pass};
|
||||||
use rustc_span::{Span, sym};
|
use rustc_span::{Span, sym};
|
||||||
|
|
@ -72,14 +73,14 @@ fn useless_check<'a, 'tcx: 'a>(
|
||||||
e = e.peel_blocks();
|
e = e.peel_blocks();
|
||||||
if let ExprKind::MethodCall(_, _expr, [], _) = e.kind
|
if let ExprKind::MethodCall(_, _expr, [], _) = e.kind
|
||||||
&& let Some(def_id) = cx.typeck_results().type_dependent_def_id(e.hir_id)
|
&& let Some(def_id) = cx.typeck_results().type_dependent_def_id(e.hir_id)
|
||||||
&& cx.tcx.has_attr(def_id, sym::rustc_never_returns_null_ptr)
|
&& find_attr!(cx.tcx.get_all_attrs(def_id), AttributeKind::RustcNeverReturnsNullPointer)
|
||||||
&& let Some(fn_name) = cx.tcx.opt_item_ident(def_id)
|
&& let Some(fn_name) = cx.tcx.opt_item_ident(def_id)
|
||||||
{
|
{
|
||||||
return Some(UselessPtrNullChecksDiag::FnRet { fn_name });
|
return Some(UselessPtrNullChecksDiag::FnRet { fn_name });
|
||||||
} else if let ExprKind::Call(path, _args) = e.kind
|
} else if let ExprKind::Call(path, _args) = e.kind
|
||||||
&& let ExprKind::Path(ref qpath) = path.kind
|
&& let ExprKind::Path(ref qpath) = path.kind
|
||||||
&& let Some(def_id) = cx.qpath_res(qpath, path.hir_id).opt_def_id()
|
&& let Some(def_id) = cx.qpath_res(qpath, path.hir_id).opt_def_id()
|
||||||
&& cx.tcx.has_attr(def_id, sym::rustc_never_returns_null_ptr)
|
&& find_attr!(cx.tcx.get_all_attrs(def_id), AttributeKind::RustcNeverReturnsNullPointer)
|
||||||
&& let Some(fn_name) = cx.tcx.opt_item_ident(def_id)
|
&& let Some(fn_name) = cx.tcx.opt_item_ident(def_id)
|
||||||
{
|
{
|
||||||
return Some(UselessPtrNullChecksDiag::FnRet { fn_name });
|
return Some(UselessPtrNullChecksDiag::FnRet { fn_name });
|
||||||
|
|
|
||||||
|
|
@ -257,6 +257,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
|
||||||
| AttributeKind::NoLink
|
| AttributeKind::NoLink
|
||||||
| AttributeKind::RustcLayoutScalarValidRangeStart(..)
|
| AttributeKind::RustcLayoutScalarValidRangeStart(..)
|
||||||
| AttributeKind::RustcLayoutScalarValidRangeEnd(..)
|
| AttributeKind::RustcLayoutScalarValidRangeEnd(..)
|
||||||
|
| AttributeKind::RustcNeverReturnsNullPointer
|
||||||
| AttributeKind::RustcScalableVector { .. }
|
| AttributeKind::RustcScalableVector { .. }
|
||||||
| AttributeKind::RustcSimdMonomorphizeLaneLimit(..)
|
| AttributeKind::RustcSimdMonomorphizeLaneLimit(..)
|
||||||
| AttributeKind::RustcShouldNotBeCalledOnConstItems(..)
|
| AttributeKind::RustcShouldNotBeCalledOnConstItems(..)
|
||||||
|
|
@ -307,9 +308,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
|
||||||
[sym::rustc_no_implicit_autorefs, ..] => {
|
[sym::rustc_no_implicit_autorefs, ..] => {
|
||||||
self.check_applied_to_fn_or_method(hir_id, attr.span(), span, target)
|
self.check_applied_to_fn_or_method(hir_id, attr.span(), span, target)
|
||||||
}
|
}
|
||||||
[sym::rustc_never_returns_null_ptr, ..] => {
|
|
||||||
self.check_applied_to_fn_or_method(hir_id, attr.span(), span, target)
|
|
||||||
}
|
|
||||||
[sym::rustc_lint_query_instability, ..] => {
|
[sym::rustc_lint_query_instability, ..] => {
|
||||||
self.check_applied_to_fn_or_method(hir_id, attr.span(), span, target)
|
self.check_applied_to_fn_or_method(hir_id, attr.span(), span, target)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue