MaybeDef in clippy_utils::res - Rust
Description: A type which may either contain a `DefId` or be referred to by a `DefId`.

Skip to main content

## MaybeDef

# Trait MaybeDef

Source

    pub trait MaybeDef: Copy {
        // Required methods
        fn opt_def_id(self) -> Option<DefId>;
        fn opt_def<'tcx>(
            self,
            tcx: &impl HasTyCtxt<'tcx>,
        ) -> Option<(DefKind, DefId)>;

        // Provided methods
        fn opt_diag_name<'tcx>(self, tcx: &impl HasTyCtxt<'tcx>) -> Option<Symbol> { ... }
        fn is_diag_item<'tcx>(
            self,
            tcx: &impl HasTyCtxt<'tcx>,
            name: Symbol,
        ) -> bool { ... }
        fn is_lang_item<'tcx>(
            self,
            tcx: &impl HasTyCtxt<'tcx>,
            item: LangItem,
        ) -> bool { ... }
        fn opt_impl_ty<'tcx>(
            self,
            tcx: &impl HasTyCtxt<'tcx>,
        ) -> Option<EarlyBinder<'tcx, Ty<'tcx>>> { ... }
        fn opt_parent<'tcx>(self, tcx: &impl HasTyCtxt<'tcx>) -> Option<DefId> { ... }
        fn is_impl<'tcx>(self, tcx: &impl HasTyCtxt<'tcx>) -> bool { ... }
        fn ctor_parent<'tcx>(self, tcx: &impl HasTyCtxt<'tcx>) -> Option<DefId> { ... }
        fn assoc_parent<'tcx>(self, tcx: &impl HasTyCtxt<'tcx>) -> Option<DefId> { ... }
        fn assoc_fn_parent<'tcx>(self, tcx: &impl HasTyCtxt<'tcx>) -> Option<DefId> { ... }
    }

Expand description

A type which may either contain a `DefId` or be referred to by a `DefId`.

## Required Methods§

Source

#### fn opt_def_id(self) -> Option<DefId>

Source

#### fn opt_def<'tcx>(self, tcx: &impl HasTyCtxt<'tcx>) -> Option<(DefKind, DefId)>

Gets this definition’s id and kind. This will lookup the kind in the def tree if needed.

## Provided Methods§

Source

#### fn opt_diag_name<'tcx>(self, tcx: &impl HasTyCtxt<'tcx>) -> Option<Symbol>

Gets the diagnostic name of this definition if it has one.

Source

#### fn is_diag_item<'tcx>(self, tcx: &impl HasTyCtxt<'tcx>, name: Symbol) -> bool

Checks if this definition has the specified diagnostic name.

Source

#### fn is_lang_item<'tcx>(self, tcx: &impl HasTyCtxt<'tcx>, item: LangItem) -> bool

Checks if this definition is the specified `LangItem`.

Source

#### fn opt_impl_ty<'tcx>( self, tcx: &impl HasTyCtxt<'tcx>, ) -> Option<EarlyBinder<'tcx, Ty<'tcx>>>

If this definition is an impl block gets its type.

Source

#### fn opt_parent<'tcx>(self, tcx: &impl HasTyCtxt<'tcx>) -> Option<DefId>

Gets the parent of this definition if it has one.

Source

#### fn is_impl<'tcx>(self, tcx: &impl HasTyCtxt<'tcx>) -> bool

Checks if this definition is an impl block.

Source

#### fn ctor_parent<'tcx>(self, tcx: &impl HasTyCtxt<'tcx>) -> Option<DefId>

If this definition is a constructor gets the `DefId` of it’s type or variant.

Source

#### fn assoc_parent<'tcx>(self, tcx: &impl HasTyCtxt<'tcx>) -> Option<DefId>

If this definition is an associated item of an impl or trait gets the `DefId` of its parent.

Source

#### fn assoc_fn_parent<'tcx>(self, tcx: &impl HasTyCtxt<'tcx>) -> Option<DefId>

If this definition is an associated function of an impl or trait gets the `DefId` of its parent.

## Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

## Implementations on Foreign Types§

Source§

### impl MaybeDef for (DefKind, DefId)

Source§

#### fn opt_def_id(self) -> Option<DefId>

Source§

#### fn opt_def<'tcx>(self, _: &impl HasTyCtxt<'tcx>) -> Option<(DefKind, DefId)>

Source§

### impl MaybeDef for Res

Source§

#### fn opt_def_id(self) -> Option<DefId>

Source§

#### fn opt_def<'tcx>(self, _: &impl HasTyCtxt<'tcx>) -> Option<(DefKind, DefId)>

Source§

### impl MaybeDef for AdtDef<'_>

Source§

#### fn opt_def_id(self) -> Option<DefId>

Source§

#### fn opt_def<'tcx>(self, _: &impl HasTyCtxt<'tcx>) -> Option<(DefKind, DefId)>

Source§

### impl MaybeDef for Ty<'_>

Source§

#### fn opt_def_id(self) -> Option<DefId>

Source§

#### fn opt_def<'tcx>(self, tcx: &impl HasTyCtxt<'tcx>) -> Option<(DefKind, DefId)>

Source§

### impl MaybeDef for DefId

Source§

#### fn opt_def_id(self) -> Option<DefId>

Source§

#### fn opt_def<'tcx>(self, tcx: &impl HasTyCtxt<'tcx>) -> Option<(DefKind, DefId)>

Source§

### impl<T: MaybeDef> MaybeDef for Option<T>

Source§

#### fn opt_def_id(self) -> Option<DefId>

Source§

#### fn opt_def<'tcx>(self, tcx: &impl HasTyCtxt<'tcx>) -> Option<(DefKind, DefId)>

Source§

### impl<T: MaybeDef> MaybeDef for Binder<'_, T>

Source§

#### fn opt_def_id(self) -> Option<DefId>

Source§

#### fn opt_def<'tcx>(self, tcx: &impl HasTyCtxt<'tcx>) -> Option<(DefKind, DefId)>

Source§

### impl<T: MaybeDef> MaybeDef for EarlyBinder<'_, T>

Source§

#### fn opt_def_id(self) -> Option<DefId>

Source§

#### fn opt_def<'tcx>(self, tcx: &impl HasTyCtxt<'tcx>) -> Option<(DefKind, DefId)>

## Implementors§