mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
refactor(mgca): Change DefKind::Const and DefKind::AssocConst to have a is_type_const flag
* refactor: add `is_type_const` flag to `DefKind::Const` and `AssocConst` * refactor(cleanup) remove the `rhs_is_type_const` query * style: fix formatting * refactor: refactor stuff in librustdoc for new Const and AssocConst * refactor: refactor clippy for the changes * chore: formatting * fix: fix test * fix: fix suggestions * Update context.rs Co-authored-by: Boxy <rust@boxyuwu.dev> * changed AssocKind::Const to store data about being a type const
This commit is contained in:
@@ -112,7 +112,7 @@ pub(crate) fn lower_qpath(
|
||||
}
|
||||
// `a::b::Trait(Args)::TraitItem`
|
||||
Res::Def(DefKind::AssocFn, _)
|
||||
| Res::Def(DefKind::AssocConst, _)
|
||||
| Res::Def(DefKind::AssocConst { .. }, _)
|
||||
| Res::Def(DefKind::AssocTy, _)
|
||||
if i + 2 == proj_start =>
|
||||
{
|
||||
|
||||
@@ -1157,7 +1157,10 @@ fn suggest_cloning_on_functional_record_update(
|
||||
let hir::ExprKind::Path(hir::QPath::Resolved(None, path)) = base.kind else { return };
|
||||
let (hir::def::Res::Local(_)
|
||||
| hir::def::Res::Def(
|
||||
DefKind::Const | DefKind::ConstParam | DefKind::Static { .. } | DefKind::AssocConst,
|
||||
DefKind::Const { .. }
|
||||
| DefKind::ConstParam
|
||||
| DefKind::Static { .. }
|
||||
| DefKind::AssocConst { .. },
|
||||
_,
|
||||
)) = path.res
|
||||
else {
|
||||
|
||||
@@ -296,7 +296,8 @@ pub(crate) fn create(mut self) -> CreateResult<'tcx> {
|
||||
// - We must compute the normalized signature and then compute implied bounds from that
|
||||
// in order to connect any unconstrained region vars created during normalization to
|
||||
// the types of the locals corresponding to the inputs and outputs of the item. (#136547)
|
||||
if matches!(tcx.def_kind(defining_ty_def_id), DefKind::AssocFn | DefKind::AssocConst) {
|
||||
if matches!(tcx.def_kind(defining_ty_def_id), DefKind::AssocFn | DefKind::AssocConst { .. })
|
||||
{
|
||||
for &(ty, _) in tcx.assumed_wf_types(tcx.local_parent(defining_ty_def_id)) {
|
||||
let result: Result<_, ErrorGuaranteed> = param_env
|
||||
.and(DeeplyNormalize { value: ty })
|
||||
|
||||
@@ -34,12 +34,12 @@ fn setup_for_eval<'tcx>(
|
||||
cid.promoted.is_some()
|
||||
|| matches!(
|
||||
ecx.tcx.def_kind(cid.instance.def_id()),
|
||||
DefKind::Const
|
||||
DefKind::Const { .. }
|
||||
| DefKind::Static { .. }
|
||||
| DefKind::ConstParam
|
||||
| DefKind::AnonConst
|
||||
| DefKind::InlineConst
|
||||
| DefKind::AssocConst
|
||||
| DefKind::AssocConst { .. }
|
||||
),
|
||||
"Unexpected DefKind: {:?}",
|
||||
ecx.tcx.def_kind(cid.instance.def_id())
|
||||
|
||||
@@ -120,7 +120,9 @@ pub enum DefKind {
|
||||
|
||||
// Value namespace
|
||||
Fn,
|
||||
Const,
|
||||
Const {
|
||||
is_type_const: bool,
|
||||
},
|
||||
/// Constant generic parameter: `struct Foo<const N: usize> { ... }`
|
||||
ConstParam,
|
||||
Static {
|
||||
@@ -147,7 +149,9 @@ pub enum DefKind {
|
||||
/// or `trait Foo { fn associated() {} }`
|
||||
AssocFn,
|
||||
/// Associated constant: `trait MyTrait { const ASSOC: usize; }`
|
||||
AssocConst,
|
||||
AssocConst {
|
||||
is_type_const: bool,
|
||||
},
|
||||
|
||||
// Macro namespace
|
||||
Macro(MacroKinds),
|
||||
@@ -222,8 +226,8 @@ pub fn descr(self, def_id: DefId) -> &'static str {
|
||||
DefKind::Trait => "trait",
|
||||
DefKind::ForeignTy => "foreign type",
|
||||
DefKind::AssocFn => "associated function",
|
||||
DefKind::Const => "constant",
|
||||
DefKind::AssocConst => "associated constant",
|
||||
DefKind::Const { .. } => "constant",
|
||||
DefKind::AssocConst { .. } => "associated constant",
|
||||
DefKind::TyParam => "type parameter",
|
||||
DefKind::ConstParam => "const parameter",
|
||||
DefKind::Macro(kinds) => kinds.descr(),
|
||||
@@ -249,7 +253,7 @@ pub fn descr(self, def_id: DefId) -> &'static str {
|
||||
pub fn article(&self) -> &'static str {
|
||||
match *self {
|
||||
DefKind::AssocTy
|
||||
| DefKind::AssocConst
|
||||
| DefKind::AssocConst { .. }
|
||||
| DefKind::AssocFn
|
||||
| DefKind::Enum
|
||||
| DefKind::OpaqueTy
|
||||
@@ -277,12 +281,12 @@ pub fn ns(&self) -> Option<Namespace> {
|
||||
| DefKind::TyParam => Some(Namespace::TypeNS),
|
||||
|
||||
DefKind::Fn
|
||||
| DefKind::Const
|
||||
| DefKind::Const { .. }
|
||||
| DefKind::ConstParam
|
||||
| DefKind::Static { .. }
|
||||
| DefKind::Ctor(..)
|
||||
| DefKind::AssocFn
|
||||
| DefKind::AssocConst => Some(Namespace::ValueNS),
|
||||
| DefKind::AssocConst { .. } => Some(Namespace::ValueNS),
|
||||
|
||||
DefKind::Macro(..) => Some(Namespace::MacroNS),
|
||||
|
||||
@@ -323,11 +327,11 @@ pub fn def_path_data(self, name: Option<Symbol>) -> DefPathData {
|
||||
DefKind::AssocTy => DefPathData::TypeNs(name.unwrap()),
|
||||
|
||||
DefKind::Fn
|
||||
| DefKind::Const
|
||||
| DefKind::Const { .. }
|
||||
| DefKind::ConstParam
|
||||
| DefKind::Static { .. }
|
||||
| DefKind::AssocFn
|
||||
| DefKind::AssocConst
|
||||
| DefKind::AssocConst { .. }
|
||||
| DefKind::Field => DefPathData::ValueNs(name.unwrap()),
|
||||
DefKind::Macro(..) => DefPathData::MacroNs(name.unwrap()),
|
||||
DefKind::LifetimeParam => DefPathData::LifetimeNs(name.unwrap()),
|
||||
@@ -345,7 +349,7 @@ pub fn def_path_data(self, name: Option<Symbol>) -> DefPathData {
|
||||
}
|
||||
|
||||
pub fn is_assoc(self) -> bool {
|
||||
matches!(self, DefKind::AssocConst | DefKind::AssocFn | DefKind::AssocTy)
|
||||
matches!(self, DefKind::AssocConst { .. } | DefKind::AssocFn | DefKind::AssocTy)
|
||||
}
|
||||
|
||||
/// This is a "module" in name resolution sense.
|
||||
@@ -371,11 +375,11 @@ pub fn is_fn_like(self) -> bool {
|
||||
pub fn has_generics(self) -> bool {
|
||||
match self {
|
||||
DefKind::AnonConst
|
||||
| DefKind::AssocConst
|
||||
| DefKind::AssocConst { .. }
|
||||
| DefKind::AssocFn
|
||||
| DefKind::AssocTy
|
||||
| DefKind::Closure
|
||||
| DefKind::Const
|
||||
| DefKind::Const { .. }
|
||||
| DefKind::Ctor(..)
|
||||
| DefKind::Enum
|
||||
| DefKind::Field
|
||||
@@ -423,8 +427,8 @@ pub fn has_codegen_attrs(self) -> bool {
|
||||
| DefKind::ForeignTy
|
||||
| DefKind::TraitAlias
|
||||
| DefKind::AssocTy
|
||||
| DefKind::Const
|
||||
| DefKind::AssocConst
|
||||
| DefKind::Const { .. }
|
||||
| DefKind::AssocConst { .. }
|
||||
| DefKind::Macro(..)
|
||||
| DefKind::Use
|
||||
| DefKind::ForeignMod
|
||||
@@ -459,12 +463,12 @@ pub fn is_typeck_child(self) -> bool {
|
||||
| DefKind::AssocTy
|
||||
| DefKind::TyParam
|
||||
| DefKind::Fn
|
||||
| DefKind::Const
|
||||
| DefKind::Const { .. }
|
||||
| DefKind::ConstParam
|
||||
| DefKind::Static { .. }
|
||||
| DefKind::Ctor(_, _)
|
||||
| DefKind::AssocFn
|
||||
| DefKind::AssocConst
|
||||
| DefKind::AssocConst { .. }
|
||||
| DefKind::Macro(_)
|
||||
| DefKind::ExternCrate
|
||||
| DefKind::Use
|
||||
|
||||
@@ -148,7 +148,7 @@ pub fn from_def_kind(def_kind: DefKind) -> Target {
|
||||
DefKind::ExternCrate => Target::ExternCrate,
|
||||
DefKind::Use => Target::Use,
|
||||
DefKind::Static { .. } => Target::Static,
|
||||
DefKind::Const => Target::Const,
|
||||
DefKind::Const { .. } => Target::Const,
|
||||
DefKind::Fn => Target::Fn,
|
||||
DefKind::Macro(..) => Target::MacroDef,
|
||||
DefKind::Mod => Target::Mod,
|
||||
|
||||
@@ -900,7 +900,7 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(),
|
||||
// avoids this query from having a direct dependency edge on the HIR
|
||||
return res;
|
||||
}
|
||||
DefKind::Const => {
|
||||
DefKind::Const { .. } => {
|
||||
tcx.ensure_ok().generics_of(def_id);
|
||||
tcx.ensure_ok().type_of(def_id);
|
||||
tcx.ensure_ok().predicates_of(def_id);
|
||||
@@ -1062,7 +1062,7 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(),
|
||||
// avoids this query from having a direct dependency edge on the HIR
|
||||
return res;
|
||||
}
|
||||
DefKind::AssocConst => {
|
||||
DefKind::AssocConst { .. } => {
|
||||
tcx.ensure_ok().type_of(def_id);
|
||||
tcx.ensure_ok().predicates_of(def_id);
|
||||
res = res.and(check_associated_item(tcx, def_id));
|
||||
|
||||
@@ -545,7 +545,7 @@ fn suggestion_signature<'tcx>(
|
||||
);
|
||||
format!("type {}{generics} = /* Type */{where_clauses};", assoc.name())
|
||||
}
|
||||
ty::AssocKind::Const { name } => {
|
||||
ty::AssocKind::Const { name, .. } => {
|
||||
let ty = tcx.type_of(assoc.def_id).instantiate_identity();
|
||||
let val = tcx
|
||||
.infer_ctxt()
|
||||
|
||||
@@ -2360,11 +2360,11 @@ fn lint_redundant_lifetimes<'tcx>(
|
||||
| DefKind::Trait
|
||||
| DefKind::TraitAlias
|
||||
| DefKind::Fn
|
||||
| DefKind::Const
|
||||
| DefKind::Const { .. }
|
||||
| DefKind::Impl { of_trait: _ } => {
|
||||
// Proceed
|
||||
}
|
||||
DefKind::AssocFn | DefKind::AssocTy | DefKind::AssocConst => {
|
||||
DefKind::AssocFn | DefKind::AssocTy | DefKind::AssocConst { .. } => {
|
||||
if tcx.trait_impl_of_assoc(owner_id.to_def_id()).is_some() {
|
||||
// Don't check for redundant lifetimes for associated items of trait
|
||||
// implementations, since the signature is required to be compatible
|
||||
|
||||
@@ -92,7 +92,6 @@ pub(crate) fn provide(providers: &mut Providers) {
|
||||
const_param_default,
|
||||
anon_const_kind,
|
||||
const_of_item,
|
||||
is_rhs_type_const,
|
||||
..*providers
|
||||
};
|
||||
}
|
||||
@@ -1702,22 +1701,3 @@ fn const_of_item<'tcx>(
|
||||
ty::EarlyBinder::bind(ct)
|
||||
}
|
||||
}
|
||||
|
||||
/// Check if a Const or AssocConst is a type const (mgca)
|
||||
fn is_rhs_type_const<'tcx>(tcx: TyCtxt<'tcx>, def: LocalDefId) -> bool {
|
||||
match tcx.hir_node_by_def_id(def) {
|
||||
hir::Node::Item(hir::Item {
|
||||
kind: hir::ItemKind::Const(_, _, _, hir::ConstItemRhs::TypeConst(_)),
|
||||
..
|
||||
})
|
||||
| hir::Node::ImplItem(hir::ImplItem {
|
||||
kind: hir::ImplItemKind::Const(_, hir::ConstItemRhs::TypeConst(_)),
|
||||
..
|
||||
})
|
||||
| hir::Node::TraitItem(hir::TraitItem {
|
||||
kind: hir::TraitItemKind::Const(_, _, hir::IsTypeConst::Yes),
|
||||
..
|
||||
}) => return true,
|
||||
_ => return false,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -265,10 +265,11 @@ fn assoc_tag(self) -> ty::AssocTag {
|
||||
}
|
||||
}
|
||||
|
||||
fn def_kind(self) -> DefKind {
|
||||
///NOTE: use `assoc_tag` for any important logic
|
||||
fn def_kind_for_diagnostics(self) -> DefKind {
|
||||
match self {
|
||||
Self::Type(_) => DefKind::AssocTy,
|
||||
Self::Const => DefKind::AssocConst,
|
||||
Self::Const => DefKind::AssocConst { is_type_const: false },
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1547,7 +1548,7 @@ fn lower_type_relative_path(
|
||||
};
|
||||
|
||||
could_refer_to(DefKind::Variant, variant_def_id, "");
|
||||
could_refer_to(mode.def_kind(), item_def_id, " also");
|
||||
could_refer_to(mode.def_kind_for_diagnostics(), item_def_id, " also");
|
||||
|
||||
lint.span_suggestion(
|
||||
span,
|
||||
@@ -2080,12 +2081,12 @@ pub fn probe_generic_path_segments(
|
||||
}
|
||||
|
||||
// Case 3. Reference to a top-level value.
|
||||
DefKind::Fn | DefKind::Const | DefKind::ConstParam | DefKind::Static { .. } => {
|
||||
DefKind::Fn | DefKind::Const { .. } | DefKind::ConstParam | DefKind::Static { .. } => {
|
||||
generic_segments.push(GenericPathSegment(def_id, last));
|
||||
}
|
||||
|
||||
// Case 4. Reference to a method or associated const.
|
||||
DefKind::AssocFn | DefKind::AssocConst => {
|
||||
DefKind::AssocFn | DefKind::AssocConst { .. } => {
|
||||
if segments.len() >= 2 {
|
||||
let generics = tcx.generics_of(def_id);
|
||||
generic_segments.push(GenericPathSegment(generics.parent.unwrap(), last - 1));
|
||||
@@ -2658,7 +2659,7 @@ fn lower_resolved_const_path(
|
||||
);
|
||||
self.lower_const_param(def_id, hir_id)
|
||||
}
|
||||
Res::Def(DefKind::Const, did) => {
|
||||
Res::Def(DefKind::Const { .. }, did) => {
|
||||
if let Err(guar) = self.require_type_const_attribute(did, span) {
|
||||
return Const::new_error(self.tcx(), guar);
|
||||
}
|
||||
@@ -2699,7 +2700,7 @@ fn lower_resolved_const_path(
|
||||
let args = self.lower_generic_args_of_path_segment(span, generics_did, segment);
|
||||
ty::Const::zero_sized(tcx, Ty::new_fn_def(tcx, did, args))
|
||||
}
|
||||
Res::Def(DefKind::AssocConst, did) => {
|
||||
Res::Def(DefKind::AssocConst { .. }, did) => {
|
||||
let trait_segment = if let [modules @ .., trait_, _item] = path.segments {
|
||||
let _ = self.prohibit_generic_args(modules.iter(), GenericsArgsErrExtend::None);
|
||||
Some(trait_)
|
||||
|
||||
@@ -104,7 +104,7 @@ fn visit_ty(&mut self, ty: &'tcx hir::Ty<'tcx, AmbigArg>) {
|
||||
if self.depth >= self.cause_depth {
|
||||
self.cause = Some(error.obligation.cause);
|
||||
if let hir::TyKind::TraitObject(..) = ty.kind
|
||||
&& let DefKind::AssocTy | DefKind::AssocConst | DefKind::AssocFn =
|
||||
&& let DefKind::AssocTy | DefKind::AssocConst { .. } | DefKind::AssocFn =
|
||||
self.tcx.def_kind(self.def_id)
|
||||
{
|
||||
self.cause = Some(ObligationCause::new(
|
||||
|
||||
@@ -231,7 +231,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) {
|
||||
tcx.ensure_ok().eval_static_initializer(item_def_id);
|
||||
check::maybe_check_static_with_link_section(tcx, item_def_id);
|
||||
}
|
||||
DefKind::Const
|
||||
DefKind::Const { .. }
|
||||
if !tcx.generics_of(item_def_id).own_requires_monomorphization()
|
||||
&& !tcx.is_type_const(item_def_id) =>
|
||||
{
|
||||
|
||||
@@ -723,7 +723,8 @@ fn annotate_expected_due_to_let_ty(
|
||||
hir::Path {
|
||||
res:
|
||||
hir::def::Res::Def(
|
||||
hir::def::DefKind::Static { .. } | hir::def::DefKind::Const,
|
||||
hir::def::DefKind::Static { .. }
|
||||
| hir::def::DefKind::Const { .. },
|
||||
def_id,
|
||||
),
|
||||
..
|
||||
|
||||
@@ -908,7 +908,8 @@ fn walk_pat(
|
||||
|
||||
let res = self.cx.typeck_results().qpath_res(qpath, *hir_id);
|
||||
match res {
|
||||
Res::Def(DefKind::Const, _) | Res::Def(DefKind::AssocConst, _) => {
|
||||
Res::Def(DefKind::Const { .. }, _)
|
||||
| Res::Def(DefKind::AssocConst { .. }, _) => {
|
||||
// Named constants have to be equated with the value
|
||||
// being matched, so that's a read of the value being matched.
|
||||
//
|
||||
@@ -1405,9 +1406,9 @@ fn cat_res(
|
||||
match res {
|
||||
Res::Def(
|
||||
DefKind::Ctor(..)
|
||||
| DefKind::Const
|
||||
| DefKind::Const { .. }
|
||||
| DefKind::ConstParam
|
||||
| DefKind::AssocConst
|
||||
| DefKind::AssocConst { .. }
|
||||
| DefKind::Fn
|
||||
| DefKind::AssocFn,
|
||||
_,
|
||||
|
||||
@@ -988,7 +988,7 @@ pub(crate) fn instantiate_value_path(
|
||||
Res::Def(DefKind::Ctor(CtorOf::Variant, _), _) => {
|
||||
err_extend = GenericsArgsErrExtend::DefVariant(segments);
|
||||
}
|
||||
Res::Def(DefKind::AssocFn | DefKind::AssocConst, def_id) => {
|
||||
Res::Def(DefKind::AssocFn | DefKind::AssocConst { .. }, def_id) => {
|
||||
let assoc_item = tcx.associated_item(def_id);
|
||||
let container = assoc_item.container;
|
||||
let container_id = assoc_item.container_id(tcx);
|
||||
@@ -1314,7 +1314,7 @@ fn inferred_kind(
|
||||
)
|
||||
});
|
||||
|
||||
let args_for_user_type = if let Res::Def(DefKind::AssocConst, def_id) = res {
|
||||
let args_for_user_type = if let Res::Def(DefKind::AssocConst { .. }, def_id) = res {
|
||||
self.transform_args_for_inherent_type_const(def_id, args_raw)
|
||||
} else {
|
||||
args_raw
|
||||
@@ -1362,7 +1362,7 @@ fn inferred_kind(
|
||||
|
||||
debug!("instantiate_value_path: type of {:?} is {:?}", hir_id, ty_instantiated);
|
||||
|
||||
let args = if let Res::Def(DefKind::AssocConst, def_id) = res {
|
||||
let args = if let Res::Def(DefKind::AssocConst { .. }, def_id) = res {
|
||||
self.transform_args_for_inherent_type_const(def_id, args)
|
||||
} else {
|
||||
args
|
||||
|
||||
@@ -82,7 +82,8 @@ pub(in super::super) fn check_repeat_exprs(&self) {
|
||||
hir::ExprKind::ConstBlock(..) => return None,
|
||||
hir::ExprKind::Path(qpath) => {
|
||||
let res = self.typeck_results.borrow().qpath_res(qpath, element.hir_id);
|
||||
if let Res::Def(DefKind::Const | DefKind::AssocConst, _) = res {
|
||||
if let Res::Def(DefKind::Const { .. } | DefKind::AssocConst { .. }, _) = res
|
||||
{
|
||||
return None;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1834,7 +1834,9 @@ pub(crate) fn suggest_associated_const(
|
||||
}
|
||||
_ => return false,
|
||||
};
|
||||
if item.def_id == old_def_id || self.tcx.def_kind(item.def_id) != DefKind::AssocConst {
|
||||
if item.def_id == old_def_id
|
||||
|| !matches!(self.tcx.def_kind(item.def_id), DefKind::AssocConst { .. })
|
||||
{
|
||||
// Same item
|
||||
return false;
|
||||
}
|
||||
@@ -2379,7 +2381,7 @@ pub(crate) fn suggest_semicolon_in_repeat_expr(
|
||||
&& match expr.kind {
|
||||
ExprKind::Path(QPath::Resolved(
|
||||
None,
|
||||
Path { res: Res::Def(DefKind::Const, _), .. },
|
||||
Path { res: Res::Def(DefKind::Const { .. }, _), .. },
|
||||
)) => true,
|
||||
ExprKind::Call(
|
||||
Expr {
|
||||
|
||||
@@ -1846,7 +1846,7 @@ pub(crate) fn maybe_emit_unstable_name_collision_hint(
|
||||
tcx.def_path_str(self.item.def_id),
|
||||
));
|
||||
}
|
||||
(ty::AssocKind::Const { name }, ty::AssocContainer::Trait) => {
|
||||
(ty::AssocKind::Const { name, .. }, ty::AssocContainer::Trait) => {
|
||||
let def_id = self.item.container_id(tcx);
|
||||
lint.span_suggestion(
|
||||
span,
|
||||
|
||||
@@ -312,7 +312,7 @@ enum ResolvedPatKind<'tcx> {
|
||||
impl<'tcx> ResolvedPat<'tcx> {
|
||||
fn adjust_mode(&self) -> AdjustMode {
|
||||
if let ResolvedPatKind::Path { res, .. } = self.kind
|
||||
&& matches!(res, Res::Def(DefKind::Const | DefKind::AssocConst, _))
|
||||
&& matches!(res, Res::Def(DefKind::Const { .. } | DefKind::AssocConst { .. }, _))
|
||||
{
|
||||
// These constants can be of a reference type, e.g. `const X: &u8 = &0;`.
|
||||
// Peeling the reference types too early will cause type checking failures.
|
||||
@@ -1567,8 +1567,8 @@ fn resolve_pat_path(
|
||||
}
|
||||
Res::Def(
|
||||
DefKind::Ctor(_, CtorKind::Const)
|
||||
| DefKind::Const
|
||||
| DefKind::AssocConst
|
||||
| DefKind::Const { .. }
|
||||
| DefKind::AssocConst { .. }
|
||||
| DefKind::ConstParam,
|
||||
_,
|
||||
) => {} // OK
|
||||
@@ -1660,7 +1660,9 @@ fn emit_bad_pat_path(
|
||||
_ => {
|
||||
let (type_def_id, item_def_id) = match resolved_pat.ty.kind() {
|
||||
ty::Adt(def, _) => match res {
|
||||
Res::Def(DefKind::Const, def_id) => (Some(def.did()), Some(def_id)),
|
||||
Res::Def(DefKind::Const { .. }, def_id) => {
|
||||
(Some(def.did()), Some(def_id))
|
||||
}
|
||||
_ => (None, None),
|
||||
},
|
||||
_ => (None, None),
|
||||
@@ -1733,7 +1735,7 @@ fn resolve_pat_tuple_struct(
|
||||
Res::Err => {
|
||||
self.dcx().span_bug(pat.span, "`Res::Err` but no error emitted");
|
||||
}
|
||||
Res::Def(DefKind::AssocConst | DefKind::AssocFn, _) => {
|
||||
Res::Def(DefKind::AssocConst { .. } | DefKind::AssocFn, _) => {
|
||||
return report_unexpected_res(res);
|
||||
}
|
||||
Res::Def(DefKind::Ctor(_, CtorKind::Fn), _) => tcx.expect_variant_res(res),
|
||||
|
||||
@@ -75,7 +75,7 @@ fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
|
||||
};
|
||||
|
||||
if let ExprKind::Path(qpath) = &receiver.kind
|
||||
&& let Res::Def(DefKind::Const | DefKind::AssocConst, const_did) =
|
||||
&& let Res::Def(DefKind::Const { .. } | DefKind::AssocConst { .. }, const_did) =
|
||||
typeck.qpath_res(qpath, receiver.hir_id)
|
||||
// Don't consider derefs as those can do arbitrary things
|
||||
// like using thread local (see rust-lang/rust#150157)
|
||||
|
||||
@@ -78,7 +78,7 @@ fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) {
|
||||
|
||||
// Per RFC we (currently) ignore anon-const (`const _: Ty = ...`) in top-level module.
|
||||
if self.body_depth == 1
|
||||
&& parent_def_kind == DefKind::Const
|
||||
&& matches!(parent_def_kind, DefKind::Const { .. })
|
||||
&& parent_opt_item_name == Some(kw::Underscore)
|
||||
{
|
||||
return;
|
||||
@@ -159,7 +159,7 @@ fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) {
|
||||
// for impl, otherwise the item-def and impl-def won't have the same parent.
|
||||
let outermost_impl_parent = peel_parent_while(cx.tcx, parent, |tcx, did| {
|
||||
tcx.def_kind(did) == DefKind::Mod
|
||||
|| (tcx.def_kind(did) == DefKind::Const
|
||||
|| (matches!(tcx.def_kind(did), DefKind::Const { .. })
|
||||
&& tcx.opt_item_name(did) == Some(kw::Underscore))
|
||||
});
|
||||
|
||||
@@ -179,20 +179,22 @@ fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) {
|
||||
// Get the span of the parent const item ident (if it's a not a const anon).
|
||||
//
|
||||
// Used to suggest changing the const item to a const anon.
|
||||
let span_for_const_anon_suggestion = if parent_def_kind == DefKind::Const
|
||||
&& parent_opt_item_name != Some(kw::Underscore)
|
||||
&& let Some(parent) = parent.as_local()
|
||||
&& let Node::Item(item) = cx.tcx.hir_node_by_def_id(parent)
|
||||
&& let ItemKind::Const(ident, _, ty, _) = item.kind
|
||||
&& let TyKind::Tup(&[]) = ty.kind
|
||||
{
|
||||
Some(ident.span)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let span_for_const_anon_suggestion =
|
||||
if matches!(parent_def_kind, DefKind::Const { .. })
|
||||
&& parent_opt_item_name != Some(kw::Underscore)
|
||||
&& let Some(parent) = parent.as_local()
|
||||
&& let Node::Item(item) = cx.tcx.hir_node_by_def_id(parent)
|
||||
&& let ItemKind::Const(ident, _, ty, _) = item.kind
|
||||
&& let TyKind::Tup(&[]) = ty.kind
|
||||
{
|
||||
Some(ident.span)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let const_anon = matches!(parent_def_kind, DefKind::Const | DefKind::Static { .. })
|
||||
.then_some(span_for_const_anon_suggestion);
|
||||
let const_anon =
|
||||
matches!(parent_def_kind, DefKind::Const { .. } | DefKind::Static { .. })
|
||||
.then_some(span_for_const_anon_suggestion);
|
||||
|
||||
let impl_span = item.span.shrink_to_lo().to(impl_.self_ty.span);
|
||||
let mut ms = MultiSpan::from_span(impl_span);
|
||||
@@ -315,7 +317,7 @@ fn did_has_local_parent(
|
||||
|
||||
peel_parent_while(tcx, parent_did, |tcx, did| {
|
||||
tcx.def_kind(did) == DefKind::Mod
|
||||
|| (tcx.def_kind(did) == DefKind::Const
|
||||
|| (matches!(tcx.def_kind(did), DefKind::Const { .. })
|
||||
&& tcx.opt_item_name(did) == Some(kw::Underscore))
|
||||
})
|
||||
.map(|parent_did| parent_did == impl_parent || Some(parent_did) == outermost_impl_parent)
|
||||
|
||||
@@ -587,7 +587,7 @@ fn check_pat(&mut self, cx: &LateContext<'_>, p: &hir::Pat<'_>) {
|
||||
..
|
||||
}) = p.kind
|
||||
{
|
||||
if let Res::Def(DefKind::Const, _) = path.res
|
||||
if let Res::Def(DefKind::Const { .. }, _) = path.res
|
||||
&& let [segment] = path.segments
|
||||
{
|
||||
NonUpperCaseGlobals::check_upper_case(
|
||||
|
||||
@@ -216,7 +216,7 @@ fn check_ptr_transmute_in_const<'tcx>(
|
||||
dst: Ty<'tcx>,
|
||||
) {
|
||||
if matches!(const_context, Some(hir::ConstContext::ConstFn))
|
||||
|| matches!(cx.tcx.def_kind(body_owner_def_id), DefKind::AssocConst)
|
||||
|| matches!(cx.tcx.def_kind(body_owner_def_id), DefKind::AssocConst { .. })
|
||||
{
|
||||
if src.is_raw_ptr() && dst.is_integral() {
|
||||
cx.tcx.emit_node_span_lint(
|
||||
|
||||
@@ -1329,7 +1329,9 @@ fn get_associated_item_or_field_def_ids(
|
||||
|
||||
fn get_associated_item(self, tcx: TyCtxt<'_>, id: DefIndex) -> ty::AssocItem {
|
||||
let kind = match self.def_kind(tcx, id) {
|
||||
DefKind::AssocConst => ty::AssocKind::Const { name: self.item_name(id) },
|
||||
DefKind::AssocConst { is_type_const } => {
|
||||
ty::AssocKind::Const { name: self.item_name(id), is_type_const }
|
||||
}
|
||||
DefKind::AssocFn => ty::AssocKind::Fn {
|
||||
name: self.item_name(id),
|
||||
has_self: self.get_fn_has_self_parameter(tcx, id),
|
||||
|
||||
@@ -418,7 +418,6 @@ fn into_args(self) -> (DefId, SimplifiedType) {
|
||||
}
|
||||
anon_const_kind => { table }
|
||||
const_of_item => { table }
|
||||
is_rhs_type_const => { table }
|
||||
}
|
||||
|
||||
pub(in crate::rmeta) fn provide(providers: &mut Providers) {
|
||||
|
||||
@@ -904,11 +904,11 @@ fn should_encode_span(def_kind: DefKind) -> bool {
|
||||
| DefKind::ConstParam
|
||||
| DefKind::LifetimeParam
|
||||
| DefKind::Fn
|
||||
| DefKind::Const
|
||||
| DefKind::Const { .. }
|
||||
| DefKind::Static { .. }
|
||||
| DefKind::Ctor(..)
|
||||
| DefKind::AssocFn
|
||||
| DefKind::AssocConst
|
||||
| DefKind::AssocConst { .. }
|
||||
| DefKind::Macro(_)
|
||||
| DefKind::ExternCrate
|
||||
| DefKind::Use
|
||||
@@ -936,10 +936,10 @@ fn should_encode_attrs(def_kind: DefKind) -> bool {
|
||||
| DefKind::TraitAlias
|
||||
| DefKind::AssocTy
|
||||
| DefKind::Fn
|
||||
| DefKind::Const
|
||||
| DefKind::Const { .. }
|
||||
| DefKind::Static { nested: false, .. }
|
||||
| DefKind::AssocFn
|
||||
| DefKind::AssocConst
|
||||
| DefKind::AssocConst { .. }
|
||||
| DefKind::Macro(_)
|
||||
| DefKind::Field
|
||||
| DefKind::Impl { .. } => true,
|
||||
@@ -979,12 +979,12 @@ fn should_encode_expn_that_defined(def_kind: DefKind) -> bool {
|
||||
| DefKind::AssocTy
|
||||
| DefKind::TyParam
|
||||
| DefKind::Fn
|
||||
| DefKind::Const
|
||||
| DefKind::Const { .. }
|
||||
| DefKind::ConstParam
|
||||
| DefKind::Static { .. }
|
||||
| DefKind::Ctor(..)
|
||||
| DefKind::AssocFn
|
||||
| DefKind::AssocConst
|
||||
| DefKind::AssocConst { .. }
|
||||
| DefKind::Macro(_)
|
||||
| DefKind::ExternCrate
|
||||
| DefKind::Use
|
||||
@@ -1013,11 +1013,11 @@ fn should_encode_visibility(def_kind: DefKind) -> bool {
|
||||
| DefKind::TraitAlias
|
||||
| DefKind::AssocTy
|
||||
| DefKind::Fn
|
||||
| DefKind::Const
|
||||
| DefKind::Const { .. }
|
||||
| DefKind::Static { nested: false, .. }
|
||||
| DefKind::Ctor(..)
|
||||
| DefKind::AssocFn
|
||||
| DefKind::AssocConst
|
||||
| DefKind::AssocConst { .. }
|
||||
| DefKind::Macro(..)
|
||||
| DefKind::Field => true,
|
||||
DefKind::Use
|
||||
@@ -1046,11 +1046,11 @@ fn should_encode_stability(def_kind: DefKind) -> bool {
|
||||
| DefKind::Struct
|
||||
| DefKind::AssocTy
|
||||
| DefKind::AssocFn
|
||||
| DefKind::AssocConst
|
||||
| DefKind::AssocConst { .. }
|
||||
| DefKind::TyParam
|
||||
| DefKind::ConstParam
|
||||
| DefKind::Static { .. }
|
||||
| DefKind::Const
|
||||
| DefKind::Const { .. }
|
||||
| DefKind::Fn
|
||||
| DefKind::ForeignMod
|
||||
| DefKind::TyAlias
|
||||
@@ -1102,9 +1102,10 @@ fn should_encode_mir(
|
||||
// instance_mir uses mir_for_ctfe rather than optimized_mir for constructors
|
||||
DefKind::Ctor(_, _) => (true, false),
|
||||
// Constants
|
||||
DefKind::AnonConst | DefKind::InlineConst | DefKind::AssocConst | DefKind::Const => {
|
||||
(true, false)
|
||||
}
|
||||
DefKind::AnonConst { .. }
|
||||
| DefKind::InlineConst
|
||||
| DefKind::AssocConst { .. }
|
||||
| DefKind::Const { .. } => (true, false),
|
||||
// Coroutines require optimized MIR to compute layout.
|
||||
DefKind::Closure if tcx.is_coroutine(def_id.to_def_id()) => (false, true),
|
||||
DefKind::SyntheticCoroutineBody => (false, true),
|
||||
@@ -1140,11 +1141,11 @@ fn should_encode_variances<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, def_kind: Def
|
||||
DefKind::Mod
|
||||
| DefKind::Variant
|
||||
| DefKind::Field
|
||||
| DefKind::AssocConst
|
||||
| DefKind::AssocConst { .. }
|
||||
| DefKind::TyParam
|
||||
| DefKind::ConstParam
|
||||
| DefKind::Static { .. }
|
||||
| DefKind::Const
|
||||
| DefKind::Const { .. }
|
||||
| DefKind::ForeignMod
|
||||
| DefKind::Impl { .. }
|
||||
| DefKind::Trait
|
||||
@@ -1175,11 +1176,11 @@ fn should_encode_generics(def_kind: DefKind) -> bool {
|
||||
| DefKind::TraitAlias
|
||||
| DefKind::AssocTy
|
||||
| DefKind::Fn
|
||||
| DefKind::Const
|
||||
| DefKind::Const { .. }
|
||||
| DefKind::Static { .. }
|
||||
| DefKind::Ctor(..)
|
||||
| DefKind::AssocFn
|
||||
| DefKind::AssocConst
|
||||
| DefKind::AssocConst { .. }
|
||||
| DefKind::AnonConst
|
||||
| DefKind::InlineConst
|
||||
| DefKind::OpaqueTy
|
||||
@@ -1208,13 +1209,13 @@ fn should_encode_type(tcx: TyCtxt<'_>, def_id: LocalDefId, def_kind: DefKind) ->
|
||||
| DefKind::Ctor(..)
|
||||
| DefKind::Field
|
||||
| DefKind::Fn
|
||||
| DefKind::Const
|
||||
| DefKind::Const { .. }
|
||||
| DefKind::Static { nested: false, .. }
|
||||
| DefKind::TyAlias
|
||||
| DefKind::ForeignTy
|
||||
| DefKind::Impl { .. }
|
||||
| DefKind::AssocFn
|
||||
| DefKind::AssocConst
|
||||
| DefKind::AssocConst { .. }
|
||||
| DefKind::Closure
|
||||
| DefKind::ConstParam
|
||||
| DefKind::AnonConst
|
||||
@@ -1269,14 +1270,14 @@ fn should_encode_fn_sig(def_kind: DefKind) -> bool {
|
||||
| DefKind::Enum
|
||||
| DefKind::Variant
|
||||
| DefKind::Field
|
||||
| DefKind::Const
|
||||
| DefKind::Const { .. }
|
||||
| DefKind::Static { .. }
|
||||
| DefKind::Ctor(..)
|
||||
| DefKind::TyAlias
|
||||
| DefKind::OpaqueTy
|
||||
| DefKind::ForeignTy
|
||||
| DefKind::Impl { .. }
|
||||
| DefKind::AssocConst
|
||||
| DefKind::AssocConst { .. }
|
||||
| DefKind::Closure
|
||||
| DefKind::ConstParam
|
||||
| DefKind::AnonConst
|
||||
@@ -1308,8 +1309,8 @@ fn should_encode_constness(def_kind: DefKind) -> bool {
|
||||
| DefKind::Union
|
||||
| DefKind::Enum
|
||||
| DefKind::Field
|
||||
| DefKind::Const
|
||||
| DefKind::AssocConst
|
||||
| DefKind::Const { .. }
|
||||
| DefKind::AssocConst { .. }
|
||||
| DefKind::AnonConst
|
||||
| DefKind::Static { .. }
|
||||
| DefKind::TyAlias
|
||||
@@ -1338,7 +1339,10 @@ fn should_encode_constness(def_kind: DefKind) -> bool {
|
||||
fn should_encode_const(def_kind: DefKind) -> bool {
|
||||
match def_kind {
|
||||
// FIXME(mgca): should we remove Const and AssocConst here?
|
||||
DefKind::Const | DefKind::AssocConst | DefKind::AnonConst | DefKind::InlineConst => true,
|
||||
DefKind::Const { .. }
|
||||
| DefKind::AssocConst { .. }
|
||||
| DefKind::AnonConst
|
||||
| DefKind::InlineConst => true,
|
||||
|
||||
DefKind::Struct
|
||||
| DefKind::Union
|
||||
@@ -1373,7 +1377,7 @@ fn should_encode_const(def_kind: DefKind) -> bool {
|
||||
fn should_encode_const_of_item<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, def_kind: DefKind) -> bool {
|
||||
// AssocConst ==> assoc item has value
|
||||
tcx.is_type_const(def_id)
|
||||
&& (!matches!(def_kind, DefKind::AssocConst) || assoc_item_has_value(tcx, def_id))
|
||||
&& (!matches!(def_kind, DefKind::AssocConst { .. }) || assoc_item_has_value(tcx, def_id))
|
||||
}
|
||||
|
||||
fn assoc_item_has_value<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> bool {
|
||||
@@ -1627,9 +1631,6 @@ fn encode_def_ids(&mut self) {
|
||||
let table = tcx.associated_types_for_impl_traits_in_trait_or_impl(def_id);
|
||||
record!(self.tables.associated_types_for_impl_traits_in_trait_or_impl[def_id] <- table);
|
||||
}
|
||||
if let DefKind::AssocConst | DefKind::Const = def_kind {
|
||||
record!(self.tables.is_rhs_type_const[def_id] <- self.tcx.is_rhs_type_const(def_id));
|
||||
}
|
||||
}
|
||||
|
||||
for (def_id, impls) in &tcx.crate_inherent_impls(()).0.inherent_impls {
|
||||
|
||||
@@ -476,7 +476,6 @@ fn encode(&self, buf: &mut FileEncoder) -> LazyTables {
|
||||
anon_const_kind: Table<DefIndex, LazyValue<ty::AnonConstKind>>,
|
||||
const_of_item: Table<DefIndex, LazyValue<ty::EarlyBinder<'static, ty::Const<'static>>>>,
|
||||
associated_types_for_impl_traits_in_trait_or_impl: Table<DefIndex, LazyValue<DefIdMap<Vec<DefId>>>>,
|
||||
is_rhs_type_const: Table<DefIndex, LazyValue<bool>>,
|
||||
}
|
||||
|
||||
#[derive(TyEncodable, TyDecodable)]
|
||||
|
||||
@@ -175,10 +175,12 @@ macro_rules! const_macro_kinds {
|
||||
( AssocTy )
|
||||
( TyParam )
|
||||
( Fn )
|
||||
( Const )
|
||||
( Const { is_type_const: true} )
|
||||
( Const { is_type_const: false} )
|
||||
( ConstParam )
|
||||
( AssocFn )
|
||||
( AssocConst )
|
||||
( AssocConst { is_type_const:true } )
|
||||
( AssocConst { is_type_const:false } )
|
||||
( ExternCrate )
|
||||
( Use )
|
||||
( ForeignMod )
|
||||
|
||||
@@ -289,7 +289,7 @@ pub fn hir_body_param_idents(self, id: BodyId) -> impl Iterator<Item = Option<Id
|
||||
pub fn hir_body_owner_kind(self, def_id: impl Into<DefId>) -> BodyOwnerKind {
|
||||
let def_id = def_id.into();
|
||||
match self.def_kind(def_id) {
|
||||
DefKind::Const | DefKind::AssocConst | DefKind::AnonConst => {
|
||||
DefKind::Const { .. } | DefKind::AssocConst { .. } | DefKind::AnonConst => {
|
||||
BodyOwnerKind::Const { inline: false }
|
||||
}
|
||||
DefKind::InlineConst => BodyOwnerKind::Const { inline: true },
|
||||
|
||||
@@ -623,7 +623,7 @@ fn write_mir_sig(tcx: TyCtxt<'_>, body: &Body<'_>, w: &mut dyn io::Write) -> io:
|
||||
};
|
||||
match (kind, body.source.promoted) {
|
||||
(_, Some(_)) => write!(w, "const ")?, // promoteds are the closest to consts
|
||||
(DefKind::Const | DefKind::AssocConst, _) => write!(w, "const ")?,
|
||||
(DefKind::Const { .. } | DefKind::AssocConst { .. }, _) => write!(w, "const ")?,
|
||||
(DefKind::Static { safety: _, mutability: hir::Mutability::Not, nested: false }, _) => {
|
||||
write!(w, "static ")?
|
||||
}
|
||||
|
||||
@@ -2771,12 +2771,6 @@
|
||||
cache_on_disk_if { *cnum == LOCAL_CRATE }
|
||||
separate_provide_extern
|
||||
}
|
||||
|
||||
query is_rhs_type_const(def_id: DefId) -> bool {
|
||||
desc { "checking whether `{}` is a rhs type const", tcx.def_path_str(def_id) }
|
||||
cache_on_disk_if { def_id.is_local() }
|
||||
separate_provide_extern
|
||||
}
|
||||
}
|
||||
|
||||
rustc_with_all_queries! { define_callbacks! }
|
||||
|
||||
@@ -30,7 +30,7 @@ pub fn opt_name(&self) -> Option<Symbol> {
|
||||
match self.kind {
|
||||
ty::AssocKind::Type { data: AssocTypeData::Normal(name) } => Some(name),
|
||||
ty::AssocKind::Type { data: AssocTypeData::Rpitit(_) } => None,
|
||||
ty::AssocKind::Const { name } => Some(name),
|
||||
ty::AssocKind::Const { name, .. } => Some(name),
|
||||
ty::AssocKind::Fn { name, .. } => Some(name),
|
||||
}
|
||||
}
|
||||
@@ -119,7 +119,7 @@ pub fn signature(&self, tcx: TyCtxt<'_>) -> String {
|
||||
tcx.fn_sig(self.def_id).instantiate_identity().skip_binder().to_string()
|
||||
}
|
||||
ty::AssocKind::Type { .. } => format!("type {};", self.name()),
|
||||
ty::AssocKind::Const { name } => {
|
||||
ty::AssocKind::Const { name, .. } => {
|
||||
format!("const {}: {:?};", name, tcx.type_of(self.def_id).instantiate_identity())
|
||||
}
|
||||
}
|
||||
@@ -173,7 +173,7 @@ pub enum AssocTypeData {
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Debug, HashStable, Eq, Hash, Encodable, Decodable)]
|
||||
pub enum AssocKind {
|
||||
Const { name: Symbol },
|
||||
Const { name: Symbol, is_type_const: bool },
|
||||
Fn { name: Symbol, has_self: bool },
|
||||
Type { data: AssocTypeData },
|
||||
}
|
||||
@@ -196,7 +196,9 @@ pub fn tag(&self) -> AssocTag {
|
||||
|
||||
pub fn as_def_kind(&self) -> DefKind {
|
||||
match self {
|
||||
Self::Const { .. } => DefKind::AssocConst,
|
||||
Self::Const { is_type_const, .. } => {
|
||||
DefKind::AssocConst { is_type_const: *is_type_const }
|
||||
}
|
||||
Self::Fn { .. } => DefKind::AssocFn,
|
||||
Self::Type { .. } => DefKind::AssocTy,
|
||||
}
|
||||
|
||||
@@ -914,8 +914,8 @@ pub fn body_codegen_attrs(self, def_id: DefId) -> &'tcx CodegenFnAttrs {
|
||||
} else if matches!(
|
||||
def_kind,
|
||||
DefKind::AnonConst
|
||||
| DefKind::AssocConst
|
||||
| DefKind::Const
|
||||
| DefKind::AssocConst { .. }
|
||||
| DefKind::Const { .. }
|
||||
| DefKind::InlineConst
|
||||
| DefKind::GlobalAsm
|
||||
) {
|
||||
@@ -1114,13 +1114,13 @@ pub fn type_const_span(self, def_id: DefId) -> Option<Span> {
|
||||
/// Check if the given `def_id` is a `type const` (mgca)
|
||||
pub fn is_type_const<I: Copy + IntoQueryParam<DefId>>(self, def_id: I) -> bool {
|
||||
// No need to call the query directly in this case always false.
|
||||
if !(matches!(
|
||||
self.def_kind(def_id.into_query_param()),
|
||||
DefKind::Const | DefKind::AssocConst
|
||||
)) {
|
||||
return false;
|
||||
let def_kind = self.def_kind(def_id.into_query_param());
|
||||
match def_kind {
|
||||
DefKind::Const { is_type_const } | DefKind::AssocConst { is_type_const } => {
|
||||
is_type_const
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
self.is_rhs_type_const(def_id)
|
||||
}
|
||||
|
||||
/// Returns the movability of the coroutine of `def_id`, or panics
|
||||
@@ -2151,9 +2151,9 @@ fn check_args_compatible_inner(
|
||||
// ATPITs) do not.
|
||||
let is_inherent_assoc_ty = matches!(self.def_kind(def_id), DefKind::AssocTy)
|
||||
&& matches!(self.def_kind(self.parent(def_id)), DefKind::Impl { of_trait: false });
|
||||
let is_inherent_assoc_type_const = matches!(self.def_kind(def_id), DefKind::AssocConst)
|
||||
&& matches!(self.def_kind(self.parent(def_id)), DefKind::Impl { of_trait: false })
|
||||
&& self.is_type_const(def_id);
|
||||
let is_inherent_assoc_type_const =
|
||||
matches!(self.def_kind(def_id), DefKind::AssocConst { is_type_const: true })
|
||||
&& matches!(self.def_kind(self.parent(def_id)), DefKind::Impl { of_trait: false });
|
||||
let own_args = if !nested && (is_inherent_assoc_ty || is_inherent_assoc_type_const) {
|
||||
if generics.own_params.len() + 1 != args.len() {
|
||||
return false;
|
||||
@@ -2198,9 +2198,12 @@ pub fn debug_assert_args_compatible(self, def_id: DefId, args: &'tcx [ty::Generi
|
||||
if cfg!(debug_assertions) && !self.check_args_compatible(def_id, args) {
|
||||
let is_inherent_assoc_ty = matches!(self.def_kind(def_id), DefKind::AssocTy)
|
||||
&& matches!(self.def_kind(self.parent(def_id)), DefKind::Impl { of_trait: false });
|
||||
let is_inherent_assoc_type_const = matches!(self.def_kind(def_id), DefKind::AssocConst)
|
||||
&& matches!(self.def_kind(self.parent(def_id)), DefKind::Impl { of_trait: false })
|
||||
&& self.is_type_const(def_id);
|
||||
let is_inherent_assoc_type_const =
|
||||
matches!(self.def_kind(def_id), DefKind::AssocConst { is_type_const: true })
|
||||
&& matches!(
|
||||
self.def_kind(self.parent(def_id)),
|
||||
DefKind::Impl { of_trait: false }
|
||||
);
|
||||
if is_inherent_assoc_ty || is_inherent_assoc_type_const {
|
||||
bug!(
|
||||
"args not compatible with generics for {}: args={:#?}, generics={:#?}",
|
||||
|
||||
@@ -214,7 +214,7 @@ fn alias_term_kind(self, alias: ty::AliasTerm<'tcx>) -> ty::AliasTermKind {
|
||||
ty::AliasTermKind::ProjectionTy
|
||||
}
|
||||
}
|
||||
DefKind::AssocConst => {
|
||||
DefKind::AssocConst { .. } => {
|
||||
if let DefKind::Impl { of_trait: false } = self.def_kind(self.parent(alias.def_id))
|
||||
{
|
||||
ty::AliasTermKind::InherentConst
|
||||
@@ -224,7 +224,7 @@ fn alias_term_kind(self, alias: ty::AliasTerm<'tcx>) -> ty::AliasTermKind {
|
||||
}
|
||||
DefKind::OpaqueTy => ty::AliasTermKind::OpaqueTy,
|
||||
DefKind::TyAlias => ty::AliasTermKind::FreeTy,
|
||||
DefKind::Const => ty::AliasTermKind::FreeConst,
|
||||
DefKind::Const { .. } => ty::AliasTermKind::FreeConst,
|
||||
DefKind::AnonConst | DefKind::Ctor(_, CtorKind::Const) => {
|
||||
ty::AliasTermKind::UnevaluatedConst
|
||||
}
|
||||
@@ -237,7 +237,7 @@ fn trait_ref_and_own_args_for_alias(
|
||||
def_id: DefId,
|
||||
args: ty::GenericArgsRef<'tcx>,
|
||||
) -> (ty::TraitRef<'tcx>, &'tcx [ty::GenericArg<'tcx>]) {
|
||||
debug_assert_matches!(self.def_kind(def_id), DefKind::AssocTy | DefKind::AssocConst);
|
||||
debug_assert_matches!(self.def_kind(def_id), DefKind::AssocTy | DefKind::AssocConst { .. });
|
||||
let trait_def_id = self.parent(def_id);
|
||||
debug_assert_matches!(self.def_kind(trait_def_id), DefKind::Trait);
|
||||
let trait_ref = ty::TraitRef::from_assoc(self, trait_def_id, args);
|
||||
|
||||
@@ -508,8 +508,8 @@ pub fn try_resolve(
|
||||
tcx.def_kind(def_id),
|
||||
DefKind::Fn
|
||||
| DefKind::AssocFn
|
||||
| DefKind::Const
|
||||
| DefKind::AssocConst
|
||||
| DefKind::Const { .. }
|
||||
| DefKind::AssocConst { .. }
|
||||
| DefKind::AnonConst
|
||||
| DefKind::InlineConst
|
||||
| DefKind::Static { .. }
|
||||
|
||||
@@ -1577,7 +1577,9 @@ pub fn item_ident(self, def_id: impl IntoQueryParam<DefId>) -> Ident {
|
||||
}
|
||||
|
||||
pub fn opt_associated_item(self, def_id: DefId) -> Option<AssocItem> {
|
||||
if let DefKind::AssocConst | DefKind::AssocFn | DefKind::AssocTy = self.def_kind(def_id) {
|
||||
if let DefKind::AssocConst { .. } | DefKind::AssocFn | DefKind::AssocTy =
|
||||
self.def_kind(def_id)
|
||||
{
|
||||
Some(self.associated_item(def_id))
|
||||
} else {
|
||||
None
|
||||
@@ -1679,9 +1681,9 @@ pub fn instance_mir(self, instance: ty::InstanceKind<'tcx>) -> &'tcx Body<'tcx>
|
||||
let def_kind = self.def_kind(def);
|
||||
debug!("returned from def_kind: {:?}", def_kind);
|
||||
match def_kind {
|
||||
DefKind::Const
|
||||
DefKind::Const { .. }
|
||||
| DefKind::Static { .. }
|
||||
| DefKind::AssocConst
|
||||
| DefKind::AssocConst { .. }
|
||||
| DefKind::Ctor(..)
|
||||
| DefKind::AnonConst
|
||||
| DefKind::InlineConst => self.mir_for_ctfe(def),
|
||||
@@ -2128,10 +2130,10 @@ pub fn is_conditionally_const(self, def_id: impl Into<DefId>) -> bool {
|
||||
| DefKind::TyAlias
|
||||
| DefKind::ForeignTy
|
||||
| DefKind::TyParam
|
||||
| DefKind::Const
|
||||
| DefKind::Const { .. }
|
||||
| DefKind::ConstParam
|
||||
| DefKind::Static { .. }
|
||||
| DefKind::AssocConst
|
||||
| DefKind::AssocConst { .. }
|
||||
| DefKind::Macro(_)
|
||||
| DefKind::ExternCrate
|
||||
| DefKind::Use
|
||||
|
||||
@@ -404,7 +404,7 @@ fn force_print_trimmed_def_path(&mut self, def_id: DefId) -> Result<bool, PrintE
|
||||
return Ok(true);
|
||||
}
|
||||
if let Some(symbol) = key.get_opt_name() {
|
||||
if let DefKind::AssocConst | DefKind::AssocFn | DefKind::AssocTy = kind
|
||||
if let DefKind::AssocConst { .. } | DefKind::AssocFn | DefKind::AssocTy = kind
|
||||
&& let Some(parent) = self.tcx().opt_parent(def_id)
|
||||
&& let parent_key = self.tcx().def_key(parent)
|
||||
&& let Some(symbol) = parent_key.get_opt_name()
|
||||
@@ -429,7 +429,7 @@ fn force_print_trimmed_def_path(&mut self, def_id: DefId) -> Result<bool, PrintE
|
||||
| DefKind::Trait
|
||||
| DefKind::TyAlias
|
||||
| DefKind::Fn
|
||||
| DefKind::Const
|
||||
| DefKind::Const { .. }
|
||||
| DefKind::Static { .. } = kind
|
||||
{
|
||||
} else {
|
||||
@@ -1541,7 +1541,7 @@ fn pretty_print_const(
|
||||
match ct.kind() {
|
||||
ty::ConstKind::Unevaluated(ty::UnevaluatedConst { def, args }) => {
|
||||
match self.tcx().def_kind(def) {
|
||||
DefKind::Const | DefKind::AssocConst => {
|
||||
DefKind::Const { .. } | DefKind::AssocConst { .. } => {
|
||||
self.pretty_print_value_path(def, args)?;
|
||||
}
|
||||
DefKind::AnonConst => {
|
||||
|
||||
@@ -613,12 +613,12 @@ pub fn new_adt(tcx: TyCtxt<'tcx>, def: AdtDef<'tcx>, args: GenericArgsRef<'tcx>)
|
||||
| DefKind::AssocTy
|
||||
| DefKind::TyParam
|
||||
| DefKind::Fn
|
||||
| DefKind::Const
|
||||
| DefKind::Const { .. }
|
||||
| DefKind::ConstParam
|
||||
| DefKind::Static { .. }
|
||||
| DefKind::Ctor(..)
|
||||
| DefKind::AssocFn
|
||||
| DefKind::AssocConst
|
||||
| DefKind::AssocConst { .. }
|
||||
| DefKind::Macro(..)
|
||||
| DefKind::ExternCrate
|
||||
| DefKind::Use
|
||||
|
||||
@@ -165,7 +165,7 @@ pub fn res_generics_def_id(self, res: Res) -> Option<DefId> {
|
||||
| DefKind::AssocTy
|
||||
| DefKind::Fn
|
||||
| DefKind::AssocFn
|
||||
| DefKind::AssocConst
|
||||
| DefKind::AssocConst { .. }
|
||||
| DefKind::Impl { .. },
|
||||
def_id,
|
||||
) => Some(def_id),
|
||||
|
||||
@@ -618,8 +618,8 @@ fn construct_error(tcx: TyCtxt<'_>, def_id: LocalDefId, guar: ErrorGuaranteed) -
|
||||
let hir_id = tcx.local_def_id_to_hir_id(def_id);
|
||||
|
||||
let (inputs, output, coroutine) = match tcx.def_kind(def_id) {
|
||||
DefKind::Const
|
||||
| DefKind::AssocConst
|
||||
DefKind::Const { .. }
|
||||
| DefKind::AssocConst { .. }
|
||||
| DefKind::AnonConst
|
||||
| DefKind::InlineConst
|
||||
| DefKind::Static { .. }
|
||||
|
||||
@@ -1117,8 +1117,8 @@ fn user_args_applied_to_res(
|
||||
Res::Def(DefKind::Fn, _)
|
||||
| Res::Def(DefKind::AssocFn, _)
|
||||
| Res::Def(DefKind::Ctor(_, CtorKind::Fn), _)
|
||||
| Res::Def(DefKind::Const, _)
|
||||
| Res::Def(DefKind::AssocConst, _) => {
|
||||
| Res::Def(DefKind::Const { .. }, _)
|
||||
| Res::Def(DefKind::AssocConst { .. }, _) => {
|
||||
self.typeck_results.user_provided_types().get(hir_id).copied().map(Box::new)
|
||||
}
|
||||
|
||||
@@ -1207,7 +1207,8 @@ fn convert_path_expr(&mut self, expr: &'tcx hir::Expr<'tcx>, res: Res) -> ExprKi
|
||||
ExprKind::ConstParam { param, def_id }
|
||||
}
|
||||
|
||||
Res::Def(DefKind::Const, def_id) | Res::Def(DefKind::AssocConst, def_id) => {
|
||||
Res::Def(DefKind::Const { .. }, def_id)
|
||||
| Res::Def(DefKind::AssocConst { .. }, def_id) => {
|
||||
let user_ty = self.user_args_applied_to_res(expr.hir_id, res);
|
||||
ExprKind::NamedConst { def_id, args, user_ty }
|
||||
}
|
||||
|
||||
@@ -957,7 +957,7 @@ fn find_fallback_pattern_typo<'tcx>(
|
||||
continue;
|
||||
};
|
||||
if let Some(value_ns) = path.res.value_ns
|
||||
&& let Res::Def(DefKind::Const, id) = value_ns
|
||||
&& let Res::Def(DefKind::Const { .. }, id) = value_ns
|
||||
&& infcx.can_eq(param_env, ty, cx.tcx.type_of(id).instantiate_identity())
|
||||
{
|
||||
if cx.tcx.visibility(id).is_accessible_from(parent, cx.tcx) {
|
||||
@@ -974,7 +974,7 @@ fn find_fallback_pattern_typo<'tcx>(
|
||||
}
|
||||
}
|
||||
}
|
||||
if let DefKind::Const = cx.tcx.def_kind(item.owner_id)
|
||||
if let DefKind::Const { .. } = cx.tcx.def_kind(item.owner_id)
|
||||
&& infcx.can_eq(param_env, ty, cx.tcx.type_of(item.owner_id).instantiate_identity())
|
||||
{
|
||||
// Look for local consts.
|
||||
@@ -1114,7 +1114,7 @@ fn is_const_pat_that_looks_like_binding<'tcx>(tcx: TyCtxt<'tcx>, pat: &Pat<'tcx>
|
||||
// the pattern's source text must resemble a plain identifier without any
|
||||
// `::` namespace separators or other non-identifier characters.
|
||||
if let Some(def_id) = try { pat.extra.as_deref()?.expanded_const? }
|
||||
&& matches!(tcx.def_kind(def_id), DefKind::Const)
|
||||
&& matches!(tcx.def_kind(def_id), DefKind::Const { .. })
|
||||
&& let Ok(snippet) = tcx.sess.source_map().span_to_snippet(pat.span)
|
||||
&& snippet.chars().all(|c| c.is_alphanumeric() || c == '_')
|
||||
{
|
||||
|
||||
@@ -74,13 +74,14 @@ fn type_marked_structural(&self, ty: Ty<'tcx>) -> bool {
|
||||
fn mk_err(&self, mut err: Diag<'_>, ty: Ty<'tcx>) -> Box<Pat<'tcx>> {
|
||||
if let ty::ConstKind::Unevaluated(uv) = self.c.kind() {
|
||||
let def_kind = self.tcx.def_kind(uv.def);
|
||||
if let hir::def::DefKind::AssocConst = def_kind
|
||||
if let hir::def::DefKind::AssocConst { .. } = def_kind
|
||||
&& let Some(def_id) = uv.def.as_local()
|
||||
{
|
||||
// Include the container item in the output.
|
||||
err.span_label(self.tcx.def_span(self.tcx.local_parent(def_id)), "");
|
||||
}
|
||||
if let hir::def::DefKind::Const | hir::def::DefKind::AssocConst = def_kind {
|
||||
if let hir::def::DefKind::Const { .. } | hir::def::DefKind::AssocConst { .. } = def_kind
|
||||
{
|
||||
err.span_label(self.tcx.def_span(uv.def), msg!("constant defined here"));
|
||||
}
|
||||
}
|
||||
@@ -116,7 +117,7 @@ fn unevaluated_to_pat(
|
||||
// We've emitted an error on the original const, it would be redundant to complain
|
||||
// on its use as well.
|
||||
if let ty::ConstKind::Unevaluated(uv) = self.c.kind()
|
||||
&& let hir::def::DefKind::Const | hir::def::DefKind::AssocConst =
|
||||
&& let hir::def::DefKind::Const { .. } | hir::def::DefKind::AssocConst { .. } =
|
||||
self.tcx.def_kind(uv.def)
|
||||
{
|
||||
err.downgrade_to_delayed_bug();
|
||||
|
||||
@@ -635,7 +635,8 @@ fn lower_path(
|
||||
let res = self.typeck_results.qpath_res(qpath, id);
|
||||
|
||||
let (def_id, user_ty) = match res {
|
||||
Res::Def(DefKind::Const, def_id) | Res::Def(DefKind::AssocConst, def_id) => {
|
||||
Res::Def(DefKind::Const { .. }, def_id)
|
||||
| Res::Def(DefKind::AssocConst { .. }, def_id) => {
|
||||
(def_id, self.typeck_results.user_provided_types().get(id))
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ fn run_lint(&self, tcx: TyCtxt<'tcx>, body: &Body<'tcx>) {
|
||||
let def_id = body.source.def_id().expect_local();
|
||||
let def_kind = tcx.def_kind(def_id);
|
||||
let is_fn_like = def_kind.is_fn_like();
|
||||
let is_assoc_const = def_kind == DefKind::AssocConst;
|
||||
let is_assoc_const = matches!(def_kind, DefKind::AssocConst { .. });
|
||||
|
||||
// Only run const prop on functions, methods, closures and associated constants
|
||||
if !is_fn_like && !is_assoc_const {
|
||||
|
||||
@@ -444,8 +444,8 @@ fn mir_promoted(
|
||||
{
|
||||
tcx.mir_const_qualif(def)
|
||||
}
|
||||
DefKind::AssocConst
|
||||
| DefKind::Const
|
||||
DefKind::AssocConst { .. }
|
||||
| DefKind::Const { .. }
|
||||
| DefKind::Static { .. }
|
||||
| DefKind::InlineConst
|
||||
| DefKind::AnonConst => tcx.mir_const_qualif(def),
|
||||
@@ -562,8 +562,8 @@ fn mir_drops_elaborated_and_const_checked(tcx: TyCtxt<'_>, def: LocalDefId) -> &
|
||||
DefKind::Fn
|
||||
| DefKind::AssocFn
|
||||
| DefKind::Static { .. }
|
||||
| DefKind::Const
|
||||
| DefKind::AssocConst => {
|
||||
| DefKind::Const { .. }
|
||||
| DefKind::AssocConst { .. } => {
|
||||
if let Err(guar) = tcx.ensure_ok().check_well_formed(root.expect_local()) {
|
||||
body.tainted_by_errors = Some(guar);
|
||||
}
|
||||
|
||||
@@ -201,7 +201,7 @@ fn maybe_suggest_unit_pattern_typo<'tcx>(
|
||||
let constants = tcx
|
||||
.hir_body_owners()
|
||||
.filter(|&def_id| {
|
||||
matches!(tcx.def_kind(def_id), DefKind::Const)
|
||||
matches!(tcx.def_kind(def_id), DefKind::Const { .. })
|
||||
&& tcx.type_of(def_id).instantiate_identity() == ty
|
||||
&& tcx.visibility(def_id).is_accessible_from(body_def_id, tcx)
|
||||
})
|
||||
|
||||
@@ -52,7 +52,10 @@ pub(crate) fn trivial_const<'a, 'tcx: 'a, F, B>(
|
||||
F: FnOnce() -> B,
|
||||
B: Deref<Target = Body<'tcx>>,
|
||||
{
|
||||
if !matches!(tcx.def_kind(def), DefKind::AssocConst | DefKind::Const | DefKind::AnonConst) {
|
||||
if !matches!(
|
||||
tcx.def_kind(def),
|
||||
DefKind::AssocConst { .. } | DefKind::Const { .. } | DefKind::AnonConst
|
||||
) {
|
||||
return None;
|
||||
}
|
||||
|
||||
|
||||
@@ -1559,7 +1559,7 @@ fn process_item(&mut self, id: hir::ItemId) {
|
||||
debug!("RootCollector: ItemKind::Static({})", self.tcx.def_path_str(def_id));
|
||||
self.output.push(dummy_spanned(MonoItem::Static(def_id)));
|
||||
}
|
||||
DefKind::Const => {
|
||||
DefKind::Const { .. } => {
|
||||
// Const items only generate mono items if they are actually used somewhere.
|
||||
// Just declaring them is insufficient.
|
||||
|
||||
|
||||
@@ -43,10 +43,10 @@ fn should_explore(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
|
||||
| DefKind::TraitAlias
|
||||
| DefKind::AssocTy
|
||||
| DefKind::Fn
|
||||
| DefKind::Const
|
||||
| DefKind::Const { .. }
|
||||
| DefKind::Static { .. }
|
||||
| DefKind::AssocFn
|
||||
| DefKind::AssocConst
|
||||
| DefKind::AssocConst { .. }
|
||||
| DefKind::Macro(_)
|
||||
| DefKind::GlobalAsm
|
||||
| DefKind::Impl { .. }
|
||||
@@ -120,7 +120,10 @@ fn insert_def_id(&mut self, def_id: DefId) {
|
||||
fn handle_res(&mut self, res: Res) {
|
||||
match res {
|
||||
Res::Def(
|
||||
DefKind::Const | DefKind::AssocConst | DefKind::AssocTy | DefKind::TyAlias,
|
||||
DefKind::Const { .. }
|
||||
| DefKind::AssocConst { .. }
|
||||
| DefKind::AssocTy
|
||||
| DefKind::TyAlias,
|
||||
def_id,
|
||||
) => {
|
||||
self.check_def_id(def_id);
|
||||
@@ -485,7 +488,7 @@ fn mark_as_used_if_union(&mut self, adt: ty::AdtDef<'tcx>, fields: &[hir::ExprFi
|
||||
fn check_impl_or_impl_item_live(&mut self, local_def_id: LocalDefId) -> bool {
|
||||
let (impl_block_id, trait_def_id) = match self.tcx.def_kind(local_def_id) {
|
||||
// assoc impl items of traits are live if the corresponding trait items are live
|
||||
DefKind::AssocConst | DefKind::AssocTy | DefKind::AssocFn => {
|
||||
DefKind::AssocConst { .. } | DefKind::AssocTy | DefKind::AssocFn => {
|
||||
let trait_item_id =
|
||||
self.tcx.trait_item_of(local_def_id).and_then(|def_id| def_id.as_local());
|
||||
(self.tcx.local_parent(local_def_id), trait_item_id)
|
||||
@@ -766,7 +769,7 @@ fn maybe_record_as_seed<'tcx>(
|
||||
);
|
||||
}
|
||||
}
|
||||
DefKind::AssocFn | DefKind::AssocConst | DefKind::AssocTy => {
|
||||
DefKind::AssocFn | DefKind::AssocConst { .. } | DefKind::AssocTy => {
|
||||
if allow_dead_code.is_none() {
|
||||
let parent = tcx.local_parent(owner_id.def_id);
|
||||
match tcx.def_kind(parent) {
|
||||
@@ -809,7 +812,7 @@ fn maybe_record_as_seed<'tcx>(
|
||||
// global_asm! is always live.
|
||||
worklist.push((owner_id.def_id, ComesFromAllowExpect::No));
|
||||
}
|
||||
DefKind::Const => {
|
||||
DefKind::Const { .. } => {
|
||||
if tcx.item_name(owner_id.def_id) == kw::Underscore {
|
||||
// `const _` is always live, as that syntax only exists for the side effects
|
||||
// of type checking and evaluating the constant expression, and marking them
|
||||
@@ -1069,7 +1072,7 @@ fn lint_at_single_level(
|
||||
let enum_variants_with_same_name = dead_codes
|
||||
.iter()
|
||||
.filter_map(|dead_item| {
|
||||
if let DefKind::AssocFn | DefKind::AssocConst =
|
||||
if let DefKind::AssocFn | DefKind::AssocConst { .. } =
|
||||
tcx.def_kind(dead_item.def_id)
|
||||
&& let impl_did = tcx.local_parent(dead_item.def_id)
|
||||
&& let DefKind::Impl { of_trait: false } = tcx.def_kind(impl_did)
|
||||
@@ -1142,12 +1145,12 @@ fn check_definition(&mut self, def_id: LocalDefId) {
|
||||
return;
|
||||
}
|
||||
match self.tcx.def_kind(def_id) {
|
||||
DefKind::AssocConst
|
||||
DefKind::AssocConst { .. }
|
||||
| DefKind::AssocTy
|
||||
| DefKind::AssocFn
|
||||
| DefKind::Fn
|
||||
| DefKind::Static { .. }
|
||||
| DefKind::Const
|
||||
| DefKind::Const { .. }
|
||||
| DefKind::TyAlias
|
||||
| DefKind::Enum
|
||||
| DefKind::Union
|
||||
|
||||
@@ -360,7 +360,7 @@ fn propagate_item(&mut self, res: Res) {
|
||||
}
|
||||
// Reachable constants and reachable statics can have their contents inlined
|
||||
// into other crates. Mark them as reachable and recurse into their body.
|
||||
DefKind::Const | DefKind::AssocConst | DefKind::Static { .. } => {
|
||||
DefKind::Const { .. } | DefKind::AssocConst { .. } | DefKind::Static { .. } => {
|
||||
self.worklist.push(def_id);
|
||||
}
|
||||
_ => {
|
||||
|
||||
@@ -52,7 +52,7 @@ fn inherit_deprecation(def_kind: DefKind) -> bool {
|
||||
fn inherit_const_stability(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
|
||||
let def_kind = tcx.def_kind(def_id);
|
||||
match def_kind {
|
||||
DefKind::AssocFn | DefKind::AssocTy | DefKind::AssocConst => {
|
||||
DefKind::AssocFn | DefKind::AssocTy | DefKind::AssocConst { .. } => {
|
||||
match tcx.def_kind(tcx.local_parent(def_id)) {
|
||||
DefKind::Impl { .. } => true,
|
||||
_ => false,
|
||||
@@ -84,7 +84,7 @@ fn annotation_kind(tcx: TyCtxt<'_>, def_id: LocalDefId) -> AnnotationKind {
|
||||
}
|
||||
|
||||
// Impl items in trait impls cannot have stability.
|
||||
DefKind::AssocTy | DefKind::AssocFn | DefKind::AssocConst => {
|
||||
DefKind::AssocTy | DefKind::AssocFn | DefKind::AssocConst { .. } => {
|
||||
match tcx.def_kind(tcx.local_parent(def_id)) {
|
||||
DefKind::Impl { of_trait: true } => AnnotationKind::Prohibited,
|
||||
_ => AnnotationKind::Required,
|
||||
|
||||
@@ -574,7 +574,10 @@ fn update_macro_reachable_def(
|
||||
self.update(def_id, macro_ev, Level::Reachable);
|
||||
match def_kind {
|
||||
// No type privacy, so can be directly marked as reachable.
|
||||
DefKind::Const | DefKind::Static { .. } | DefKind::TraitAlias | DefKind::TyAlias => {
|
||||
DefKind::Const { .. }
|
||||
| DefKind::Static { .. }
|
||||
| DefKind::TraitAlias
|
||||
| DefKind::TyAlias => {
|
||||
if vis.is_accessible_from(module, self.tcx) {
|
||||
self.update(def_id, macro_ev, Level::Reachable);
|
||||
}
|
||||
@@ -621,7 +624,7 @@ fn update_macro_reachable_def(
|
||||
|
||||
// These have type privacy, so are not reachable unless they're
|
||||
// public, or are not namespaced at all.
|
||||
DefKind::AssocConst
|
||||
DefKind::AssocConst { .. }
|
||||
| DefKind::AssocTy
|
||||
| DefKind::ConstParam
|
||||
| DefKind::Ctor(_, _)
|
||||
@@ -679,7 +682,7 @@ fn check_def_id(&mut self, owner_id: OwnerId) {
|
||||
}
|
||||
}
|
||||
DefKind::ForeignTy
|
||||
| DefKind::Const
|
||||
| DefKind::Const { .. }
|
||||
| DefKind::Static { .. }
|
||||
| DefKind::Fn
|
||||
| DefKind::TyAlias => {
|
||||
@@ -801,7 +804,7 @@ fn check_def_id(&mut self, owner_id: OwnerId) {
|
||||
| DefKind::Variant
|
||||
| DefKind::AssocFn
|
||||
| DefKind::AssocTy
|
||||
| DefKind::AssocConst
|
||||
| DefKind::AssocConst { .. }
|
||||
| DefKind::TyParam
|
||||
| DefKind::AnonConst
|
||||
| DefKind::InlineConst
|
||||
@@ -1287,7 +1290,10 @@ fn visit_qpath(&mut self, qpath: &'tcx hir::QPath<'tcx>, id: hir::HirId, span: S
|
||||
let def = def.filter(|(kind, _)| {
|
||||
matches!(
|
||||
kind,
|
||||
DefKind::AssocFn | DefKind::AssocConst | DefKind::AssocTy | DefKind::Static { .. }
|
||||
DefKind::AssocFn
|
||||
| DefKind::AssocConst { .. }
|
||||
| DefKind::AssocTy
|
||||
| DefKind::Static { .. }
|
||||
)
|
||||
});
|
||||
if let Some((kind, def_id)) = def {
|
||||
@@ -1613,7 +1619,7 @@ fn check_item(&self, id: ItemId) {
|
||||
let def_kind = tcx.def_kind(def_id);
|
||||
|
||||
match def_kind {
|
||||
DefKind::Const | DefKind::Static { .. } | DefKind::Fn | DefKind::TyAlias => {
|
||||
DefKind::Const { .. } | DefKind::Static { .. } | DefKind::Fn | DefKind::TyAlias => {
|
||||
if let DefKind::TyAlias = def_kind {
|
||||
self.check_unnameable(def_id, effective_vis);
|
||||
}
|
||||
|
||||
@@ -1054,7 +1054,7 @@ fn stable<'cx>(
|
||||
) -> Self::T {
|
||||
use crate::ty::{AssocKind, AssocTypeData};
|
||||
match *self {
|
||||
ty::AssocKind::Const { name } => AssocKind::Const { name: name.to_string() },
|
||||
ty::AssocKind::Const { name, .. } => AssocKind::Const { name: name.to_string() },
|
||||
ty::AssocKind::Fn { name, has_self } => {
|
||||
AssocKind::Fn { name: name.to_string(), has_self }
|
||||
}
|
||||
|
||||
@@ -121,9 +121,10 @@ pub(crate) fn new_item_kind(kind: DefKind) -> ItemKind {
|
||||
DefKind::Closure | DefKind::AssocFn | DefKind::Fn | DefKind::SyntheticCoroutineBody => {
|
||||
ItemKind::Fn
|
||||
}
|
||||
DefKind::Const | DefKind::InlineConst | DefKind::AssocConst | DefKind::AnonConst => {
|
||||
ItemKind::Const
|
||||
}
|
||||
DefKind::Const { .. }
|
||||
| DefKind::InlineConst
|
||||
| DefKind::AssocConst { .. }
|
||||
| DefKind::AnonConst => ItemKind::Const,
|
||||
DefKind::Static { .. } => ItemKind::Static,
|
||||
DefKind::Ctor(_, rustc_hir::def::CtorKind::Const) => ItemKind::Ctor(CtorKind::Const),
|
||||
DefKind::Ctor(_, rustc_hir::def::CtorKind::Fn) => ItemKind::Ctor(CtorKind::Fn),
|
||||
|
||||
@@ -331,8 +331,8 @@ fn build_reduced_graph_for_external_crate_res(
|
||||
DefKind::Fn
|
||||
| DefKind::AssocFn
|
||||
| DefKind::Static { .. }
|
||||
| DefKind::Const
|
||||
| DefKind::AssocConst
|
||||
| DefKind::Const { .. }
|
||||
| DefKind::AssocConst { .. }
|
||||
| DefKind::Ctor(..),
|
||||
_,
|
||||
) => define_extern(ValueNS),
|
||||
|
||||
@@ -131,7 +131,11 @@ fn visit_item(&mut self, i: &'a Item) {
|
||||
mutability: s.mutability,
|
||||
nested: false,
|
||||
},
|
||||
ItemKind::Const(..) | ItemKind::ConstBlock(..) => DefKind::Const,
|
||||
ItemKind::Const(citem) => {
|
||||
let is_type_const = matches!(citem.rhs_kind, ConstItemRhsKind::TypeConst { .. });
|
||||
DefKind::Const { is_type_const }
|
||||
}
|
||||
ItemKind::ConstBlock(..) => DefKind::Const { is_type_const: false },
|
||||
ItemKind::Fn(..) | ItemKind::Delegation(..) => DefKind::Fn,
|
||||
ItemKind::MacroDef(ident, def) => {
|
||||
let edition = i.span.edition();
|
||||
@@ -347,7 +351,12 @@ fn visit_assoc_item(&mut self, i: &'a AssocItem, ctxt: visit::AssocCtxt) {
|
||||
let (ident, def_kind) = match &i.kind {
|
||||
AssocItemKind::Fn(box Fn { ident, .. })
|
||||
| AssocItemKind::Delegation(box Delegation { ident, .. }) => (*ident, DefKind::AssocFn),
|
||||
AssocItemKind::Const(box ConstItem { ident, .. }) => (*ident, DefKind::AssocConst),
|
||||
AssocItemKind::Const(box ConstItem { ident, rhs_kind, .. }) => (
|
||||
*ident,
|
||||
DefKind::AssocConst {
|
||||
is_type_const: matches!(rhs_kind, ConstItemRhsKind::TypeConst { .. }),
|
||||
},
|
||||
),
|
||||
AssocItemKind::Type(box TyAlias { ident, .. }) => (*ident, DefKind::AssocTy),
|
||||
AssocItemKind::MacCall(..) | AssocItemKind::DelegationMac(..) => {
|
||||
return self.visit_macro_invoc(i.id);
|
||||
|
||||
@@ -557,7 +557,9 @@ pub(crate) fn into_struct_error(
|
||||
DefKind::Static { .. } => {
|
||||
Some(errs::GenericParamsFromOuterItemStaticOrConst::Static)
|
||||
}
|
||||
DefKind::Const => Some(errs::GenericParamsFromOuterItemStaticOrConst::Const),
|
||||
DefKind::Const { .. } => {
|
||||
Some(errs::GenericParamsFromOuterItemStaticOrConst::Const)
|
||||
}
|
||||
_ => None,
|
||||
};
|
||||
let is_self =
|
||||
@@ -720,8 +722,8 @@ pub(crate) fn into_struct_error(
|
||||
Res::Def(
|
||||
DefKind::Ctor(CtorOf::Variant, CtorKind::Const)
|
||||
| DefKind::Ctor(CtorOf::Struct, CtorKind::Const)
|
||||
| DefKind::Const
|
||||
| DefKind::AssocConst,
|
||||
| DefKind::Const { .. }
|
||||
| DefKind::AssocConst { .. },
|
||||
_,
|
||||
)
|
||||
)
|
||||
@@ -729,11 +731,11 @@ pub(crate) fn into_struct_error(
|
||||
);
|
||||
|
||||
if import_suggestions.is_empty() && !suggested_typo {
|
||||
let kinds = [
|
||||
DefKind::Ctor(CtorOf::Variant, CtorKind::Const),
|
||||
DefKind::Ctor(CtorOf::Struct, CtorKind::Const),
|
||||
DefKind::Const,
|
||||
DefKind::AssocConst,
|
||||
let kind_matches: [fn(DefKind) -> bool; 4] = [
|
||||
|kind| matches!(kind, DefKind::Ctor(CtorOf::Variant, CtorKind::Const)),
|
||||
|kind| matches!(kind, DefKind::Ctor(CtorOf::Struct, CtorKind::Const)),
|
||||
|kind| matches!(kind, DefKind::Const { .. }),
|
||||
|kind| matches!(kind, DefKind::AssocConst { .. }),
|
||||
];
|
||||
let mut local_names = vec![];
|
||||
self.add_module_candidates(
|
||||
@@ -752,13 +754,13 @@ pub(crate) fn into_struct_error(
|
||||
|
||||
let mut local_suggestions = vec![];
|
||||
let mut suggestions = vec![];
|
||||
for kind in kinds {
|
||||
for matches_kind in kind_matches {
|
||||
if let Some(suggestion) = self.early_lookup_typo_candidate(
|
||||
ScopeSet::All(Namespace::ValueNS),
|
||||
&parent_scope,
|
||||
name,
|
||||
&|res: Res| match res {
|
||||
Res::Def(k, _) => k == kind,
|
||||
Res::Def(k, _) => matches_kind(k),
|
||||
_ => false,
|
||||
},
|
||||
) && let Res::Def(kind, mut def_id) = suggestion.res
|
||||
|
||||
@@ -577,11 +577,11 @@ pub(crate) fn is_expected(self, res: Res) -> bool {
|
||||
res,
|
||||
Res::Def(
|
||||
DefKind::Ctor(_, CtorKind::Const | CtorKind::Fn)
|
||||
| DefKind::Const
|
||||
| DefKind::Const { .. }
|
||||
| DefKind::Static { .. }
|
||||
| DefKind::Fn
|
||||
| DefKind::AssocFn
|
||||
| DefKind::AssocConst
|
||||
| DefKind::AssocConst { .. }
|
||||
| DefKind::ConstParam,
|
||||
_,
|
||||
) | Res::Local(..)
|
||||
@@ -589,7 +589,10 @@ pub(crate) fn is_expected(self, res: Res) -> bool {
|
||||
),
|
||||
PathSource::Pat => {
|
||||
res.expected_in_unit_struct_pat()
|
||||
|| matches!(res, Res::Def(DefKind::Const | DefKind::AssocConst, _))
|
||||
|| matches!(
|
||||
res,
|
||||
Res::Def(DefKind::Const { .. } | DefKind::AssocConst { .. }, _)
|
||||
)
|
||||
}
|
||||
PathSource::TupleStruct(..) => res.expected_in_tuple_struct_pat(),
|
||||
PathSource::Struct(_) => matches!(
|
||||
@@ -605,7 +608,7 @@ pub(crate) fn is_expected(self, res: Res) -> bool {
|
||||
| Res::SelfTyAlias { .. }
|
||||
),
|
||||
PathSource::TraitItem(ns, _) => match res {
|
||||
Res::Def(DefKind::AssocConst | DefKind::AssocFn, _) if ns == ValueNS => true,
|
||||
Res::Def(DefKind::AssocConst { .. } | DefKind::AssocFn, _) if ns == ValueNS => true,
|
||||
Res::Def(DefKind::AssocTy, _) if ns == TypeNS => true,
|
||||
_ => false,
|
||||
},
|
||||
@@ -3739,7 +3742,7 @@ fn check_trait_item<F>(
|
||||
match (def_kind, kind) {
|
||||
(DefKind::AssocTy, AssocItemKind::Type(..))
|
||||
| (DefKind::AssocFn, AssocItemKind::Fn(..))
|
||||
| (DefKind::AssocConst, AssocItemKind::Const(..))
|
||||
| (DefKind::AssocConst { .. }, AssocItemKind::Const(..))
|
||||
| (DefKind::AssocFn, AssocItemKind::Delegation(..)) => {
|
||||
self.r.record_partial_res(id, PartialRes::new(res));
|
||||
return;
|
||||
@@ -4321,7 +4324,7 @@ fn try_resolve_as_non_binding(
|
||||
match res {
|
||||
Res::SelfCtor(_) // See #70549.
|
||||
| Res::Def(
|
||||
DefKind::Ctor(_, CtorKind::Const) | DefKind::Const | DefKind::AssocConst | DefKind::ConstParam,
|
||||
DefKind::Ctor(_, CtorKind::Const) | DefKind::Const { .. } | DefKind::AssocConst { .. } | DefKind::ConstParam,
|
||||
_,
|
||||
) if is_syntactic_ambiguity => {
|
||||
// Disambiguate in favor of a unit struct/variant or constant pattern.
|
||||
@@ -4330,7 +4333,7 @@ fn try_resolve_as_non_binding(
|
||||
}
|
||||
Some(res)
|
||||
}
|
||||
Res::Def(DefKind::Ctor(..) | DefKind::Const | DefKind::AssocConst | DefKind::Static { .. }, _) => {
|
||||
Res::Def(DefKind::Ctor(..) | DefKind::Const { .. } | DefKind::AssocConst { .. } | DefKind::Static { .. }, _) => {
|
||||
// This is unambiguously a fresh binding, either syntactically
|
||||
// (e.g., `IDENT @ PAT` or `ref IDENT`) or because `IDENT` resolves
|
||||
// to something unusable as a pattern (e.g., constructor function),
|
||||
@@ -4351,7 +4354,7 @@ fn try_resolve_as_non_binding(
|
||||
None
|
||||
}
|
||||
Res::Def(DefKind::ConstParam, def_id) => {
|
||||
// Same as for DefKind::Const above, but here, `binding` is `None`, so we
|
||||
// Same as for DefKind::Const { .. } above, but here, `binding` is `None`, so we
|
||||
// have to construct the error differently
|
||||
self.report_error(
|
||||
ident.span,
|
||||
|
||||
@@ -414,7 +414,10 @@ fn make_base_error(
|
||||
.is_ok_and(|snippet| snippet.ends_with(')'))
|
||||
}
|
||||
Res::Def(
|
||||
DefKind::Ctor(..) | DefKind::AssocFn | DefKind::Const | DefKind::AssocConst,
|
||||
DefKind::Ctor(..)
|
||||
| DefKind::AssocFn
|
||||
| DefKind::Const { .. }
|
||||
| DefKind::AssocConst { .. },
|
||||
_,
|
||||
)
|
||||
| Res::SelfCtor(_)
|
||||
@@ -2732,7 +2735,7 @@ pub(crate) fn find_similarly_named_assoc_item(
|
||||
.iter()
|
||||
.filter_map(|(key, res)| res.borrow().best_decl().map(|binding| (key, binding.res())))
|
||||
.filter(|(_, res)| match (kind, res) {
|
||||
(AssocItemKind::Const(..), Res::Def(DefKind::AssocConst, _)) => true,
|
||||
(AssocItemKind::Const(..), Res::Def(DefKind::AssocConst { .. }, _)) => true,
|
||||
(AssocItemKind::Fn(_), Res::Def(DefKind::AssocFn, _)) => true,
|
||||
(AssocItemKind::Type(..), Res::Def(DefKind::AssocTy, _)) => true,
|
||||
(AssocItemKind::Delegation(_), Res::Def(DefKind::AssocFn, _)) => true,
|
||||
@@ -2840,7 +2843,7 @@ fn extract_node_id(t: &Ty) -> Option<NodeId> {
|
||||
return Some(AssocSuggestion::AssocFn { called });
|
||||
}
|
||||
}
|
||||
Res::Def(DefKind::AssocConst, _) => {
|
||||
Res::Def(DefKind::AssocConst { .. }, _) => {
|
||||
return Some(AssocSuggestion::AssocConst);
|
||||
}
|
||||
Res::Def(DefKind::AssocTy, _) => {
|
||||
|
||||
@@ -1051,7 +1051,10 @@ fn is_glob_import(&self) -> bool {
|
||||
}
|
||||
|
||||
fn is_assoc_item(&self) -> bool {
|
||||
matches!(self.res(), Res::Def(DefKind::AssocConst | DefKind::AssocFn | DefKind::AssocTy, _))
|
||||
matches!(
|
||||
self.res(),
|
||||
Res::Def(DefKind::AssocConst { .. } | DefKind::AssocFn | DefKind::AssocTy, _)
|
||||
)
|
||||
}
|
||||
|
||||
fn macro_kinds(&self) -> Option<MacroKinds> {
|
||||
|
||||
@@ -357,9 +357,9 @@ fn foo(&self, x: T) -> T { x }
|
||||
tcx.def_kind(body_owner_def_id),
|
||||
DefKind::Fn
|
||||
| DefKind::Static { .. }
|
||||
| DefKind::Const
|
||||
| DefKind::Const { .. }
|
||||
| DefKind::AssocFn
|
||||
| DefKind::AssocConst
|
||||
| DefKind::AssocConst { .. }
|
||||
)
|
||||
&& matches!(
|
||||
tcx.opaque_ty_origin(opaque_ty.def_id),
|
||||
|
||||
@@ -745,7 +745,7 @@ fn visit_goal(&mut self, goal: &InspectGoal<'_, 'tcx>) {
|
||||
ty::PredicateKind::Clause(ty::ClauseKind::Projection(proj))
|
||||
if matches!(
|
||||
infcx.tcx.def_kind(proj.projection_term.def_id),
|
||||
DefKind::AssocTy | DefKind::AssocConst
|
||||
DefKind::AssocTy | DefKind::AssocConst { .. }
|
||||
) =>
|
||||
{
|
||||
proj.projection_term.trait_ref(infcx.tcx)
|
||||
|
||||
@@ -327,7 +327,7 @@ pub fn dyn_compatibility_violations_for_assoc_item(
|
||||
let span = || item.ident(tcx).span;
|
||||
|
||||
match item.kind {
|
||||
ty::AssocKind::Const { name } => {
|
||||
ty::AssocKind::Const { name, is_type_const } => {
|
||||
// We will permit type associated consts if they are explicitly mentioned in the
|
||||
// trait object type. We can't check this here, as here we only check if it is
|
||||
// guaranteed to not be possible.
|
||||
@@ -337,7 +337,7 @@ pub fn dyn_compatibility_violations_for_assoc_item(
|
||||
if tcx.features().min_generic_const_args() {
|
||||
if !tcx.generics_of(item.def_id).is_own_empty() {
|
||||
errors.push(AssocConstViolation::Generic);
|
||||
} else if !tcx.is_type_const(item.def_id) {
|
||||
} else if !is_type_const {
|
||||
errors.push(AssocConstViolation::NonType);
|
||||
}
|
||||
|
||||
|
||||
@@ -685,7 +685,11 @@ fn process_obligation(
|
||||
use rustc_hir::def::DefKind;
|
||||
match (c1.kind(), c2.kind()) {
|
||||
(ty::ConstKind::Unevaluated(a), ty::ConstKind::Unevaluated(b))
|
||||
if a.def == b.def && tcx.def_kind(a.def) == DefKind::AssocConst =>
|
||||
if a.def == b.def
|
||||
&& matches!(
|
||||
tcx.def_kind(a.def),
|
||||
DefKind::AssocConst { .. }
|
||||
) =>
|
||||
{
|
||||
if let Ok(new_obligations) = infcx
|
||||
.at(&obligation.cause, obligation.param_env)
|
||||
|
||||
@@ -456,7 +456,7 @@ fn fold_const(&mut self, ct: ty::Const<'tcx>) -> ty::Const<'tcx> {
|
||||
// if it was marked with `type const`. Using this attribute without the mgca
|
||||
// feature gate causes a parse error.
|
||||
let ct = match tcx.def_kind(uv.def) {
|
||||
DefKind::AssocConst => match tcx.def_kind(tcx.parent(uv.def)) {
|
||||
DefKind::AssocConst { .. } => match tcx.def_kind(tcx.parent(uv.def)) {
|
||||
DefKind::Trait => self.normalize_trait_projection(uv.into()).expect_const(),
|
||||
DefKind::Impl { of_trait: false } => {
|
||||
self.normalize_inherent_projection(uv.into()).expect_const()
|
||||
@@ -466,7 +466,7 @@ fn fold_const(&mut self, ct: ty::Const<'tcx>) -> ty::Const<'tcx> {
|
||||
kind
|
||||
),
|
||||
},
|
||||
DefKind::Const => self.normalize_free_alias(uv.into()).expect_const(),
|
||||
DefKind::Const { .. } => self.normalize_free_alias(uv.into()).expect_const(),
|
||||
DefKind::AnonConst => {
|
||||
let ct = ct.super_fold_with(self);
|
||||
super::with_replaced_escaping_bound_vars(
|
||||
|
||||
@@ -99,7 +99,7 @@ fn relate_mir_and_user_args<'tcx>(
|
||||
|
||||
// For IACs, the user args are in the format [SelfTy, GAT_args...] but type_of expects [impl_args..., GAT_args...].
|
||||
// We need to infer the impl args by equating the impl's self type with the user-provided self type.
|
||||
let is_inherent_assoc_const = tcx.def_kind(def_id) == DefKind::AssocConst
|
||||
let is_inherent_assoc_const = matches!(tcx.def_kind(def_id), DefKind::AssocConst { .. })
|
||||
&& tcx.def_kind(tcx.parent(def_id)) == DefKind::Impl { of_trait: false }
|
||||
&& tcx.is_type_const(def_id);
|
||||
|
||||
|
||||
@@ -877,7 +877,11 @@ fn evaluate_predicate_recursively<'o>(
|
||||
use rustc_hir::def::DefKind;
|
||||
match (c1.kind(), c2.kind()) {
|
||||
(ty::ConstKind::Unevaluated(a), ty::ConstKind::Unevaluated(b))
|
||||
if a.def == b.def && tcx.def_kind(a.def) == DefKind::AssocConst =>
|
||||
if a.def == b.def
|
||||
&& matches!(
|
||||
tcx.def_kind(a.def),
|
||||
DefKind::AssocConst { .. }
|
||||
) =>
|
||||
{
|
||||
if let Ok(InferOk { obligations, value: () }) = self
|
||||
.infcx
|
||||
|
||||
@@ -1028,7 +1028,7 @@ fn visit_const(&mut self, c: ty::Const<'tcx>) -> Self::Result {
|
||||
predicate,
|
||||
));
|
||||
|
||||
if tcx.def_kind(uv.def) == DefKind::AssocConst
|
||||
if matches!(tcx.def_kind(uv.def), DefKind::AssocConst { .. })
|
||||
&& tcx.def_kind(tcx.parent(uv.def)) == (DefKind::Impl { of_trait: false })
|
||||
{
|
||||
self.add_wf_preds_for_inherent_projection(uv.into());
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
use rustc_hir::def_id::{DefId, DefIdMap, LocalDefId};
|
||||
use rustc_hir::definitions::{DefPathData, DisambiguatorState};
|
||||
use rustc_hir::intravisit::{self, Visitor};
|
||||
use rustc_hir::{self as hir, ImplItemImplKind, ItemKind};
|
||||
use rustc_hir::{self as hir, ConstItemRhs, ImplItemImplKind, ItemKind};
|
||||
use rustc_middle::query::Providers;
|
||||
use rustc_middle::ty::{self, ImplTraitInTraitData, TyCtxt};
|
||||
use rustc_middle::{bug, span_bug};
|
||||
@@ -88,7 +88,9 @@ fn associated_item_from_trait_item(
|
||||
let owner_id = trait_item.owner_id;
|
||||
let name = trait_item.ident.name;
|
||||
let kind = match trait_item.kind {
|
||||
hir::TraitItemKind::Const { .. } => ty::AssocKind::Const { name },
|
||||
hir::TraitItemKind::Const(_, _, is_type_const) => {
|
||||
ty::AssocKind::Const { name, is_type_const: is_type_const.into() }
|
||||
}
|
||||
hir::TraitItemKind::Fn { .. } => {
|
||||
ty::AssocKind::Fn { name, has_self: fn_has_self_parameter(tcx, owner_id) }
|
||||
}
|
||||
@@ -104,7 +106,9 @@ fn associated_item_from_impl_item(tcx: TyCtxt<'_>, impl_item: &hir::ImplItem<'_>
|
||||
let owner_id = impl_item.owner_id;
|
||||
let name = impl_item.ident.name;
|
||||
let kind = match impl_item.kind {
|
||||
hir::ImplItemKind::Const { .. } => ty::AssocKind::Const { name },
|
||||
hir::ImplItemKind::Const(_, rhs) => {
|
||||
ty::AssocKind::Const { name, is_type_const: matches!(rhs, ConstItemRhs::TypeConst(_)) }
|
||||
}
|
||||
hir::ImplItemKind::Fn { .. } => {
|
||||
ty::AssocKind::Fn { name, has_self: fn_has_self_parameter(tcx, owner_id) }
|
||||
}
|
||||
|
||||
@@ -123,9 +123,11 @@ fn assumed_wf_types<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> &'tcx [(Ty<'
|
||||
}
|
||||
}
|
||||
}
|
||||
DefKind::AssocConst | DefKind::AssocTy => tcx.assumed_wf_types(tcx.local_parent(def_id)),
|
||||
DefKind::AssocConst { .. } | DefKind::AssocTy => {
|
||||
tcx.assumed_wf_types(tcx.local_parent(def_id))
|
||||
}
|
||||
DefKind::Static { .. }
|
||||
| DefKind::Const
|
||||
| DefKind::Const { .. }
|
||||
| DefKind::AnonConst
|
||||
| DefKind::InlineConst
|
||||
| DefKind::Struct
|
||||
|
||||
@@ -40,7 +40,7 @@ enum CollectionMode {
|
||||
impl<'tcx> OpaqueTypeCollector<'tcx> {
|
||||
fn new(tcx: TyCtxt<'tcx>, item: LocalDefId) -> Self {
|
||||
let mode = match tcx.def_kind(item) {
|
||||
DefKind::AssocConst | DefKind::AssocFn | DefKind::AssocTy => {
|
||||
DefKind::AssocConst { .. } | DefKind::AssocFn | DefKind::AssocTy => {
|
||||
CollectionMode::ImplTraitInAssocTypes
|
||||
}
|
||||
DefKind::TyAlias => CollectionMode::Taits,
|
||||
@@ -302,8 +302,8 @@ fn opaque_types_defined_by<'tcx>(
|
||||
DefKind::AssocFn
|
||||
| DefKind::Fn
|
||||
| DefKind::Static { .. }
|
||||
| DefKind::Const
|
||||
| DefKind::AssocConst
|
||||
| DefKind::Const { .. }
|
||||
| DefKind::AssocConst { .. }
|
||||
| DefKind::AnonConst => {
|
||||
collector.collect_taits_declared_in_body();
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ pub fn walk_types<'tcx, V: SpannedTypeVisitor<'tcx>>(
|
||||
// Walk over the type behind the alias
|
||||
DefKind::TyAlias { .. } | DefKind::AssocTy |
|
||||
// Walk over the type of the item
|
||||
DefKind::Static { .. } | DefKind::Const | DefKind::AssocConst | DefKind::AnonConst => {
|
||||
DefKind::Static { .. } | DefKind::Const { .. } | DefKind::AssocConst { .. } | DefKind::AnonConst => {
|
||||
if let Some(ty) = tcx.hir_node_by_def_id(item).ty() {
|
||||
// If the type of the item uses `_`, we're gonna error out anyway, but
|
||||
// typeck (which type_of invokes below), will call back into opaque_types_defined_by
|
||||
|
||||
@@ -129,7 +129,7 @@ pub(crate) fn try_inline(
|
||||
clean::StaticItem(build_static(cx, did, cx.tcx.is_mutable_static(did)))
|
||||
})
|
||||
}
|
||||
Res::Def(DefKind::Const, did) => {
|
||||
Res::Def(DefKind::Const { .. }, did) => {
|
||||
record_extern_fqn(cx, did, ItemType::Constant);
|
||||
cx.with_param_env(did, |cx| {
|
||||
let ct = build_const_item(cx, did);
|
||||
|
||||
@@ -504,7 +504,7 @@ pub(crate) fn register_res(cx: &mut DocContext<'_>, res: Res) -> DefId {
|
||||
Res::Def(
|
||||
AssocTy
|
||||
| AssocFn
|
||||
| AssocConst
|
||||
| AssocConst { .. }
|
||||
| Variant
|
||||
| Fn
|
||||
| TyAlias
|
||||
@@ -514,7 +514,7 @@ pub(crate) fn register_res(cx: &mut DocContext<'_>, res: Res) -> DefId {
|
||||
| Union
|
||||
| Mod
|
||||
| ForeignTy
|
||||
| Const
|
||||
| Const { .. }
|
||||
| Static { .. }
|
||||
| Macro(..)
|
||||
| TraitAlias,
|
||||
|
||||
@@ -156,7 +156,7 @@ pub(crate) fn from_def_id(def_id: DefId, tcx: TyCtxt<'_>) -> Self {
|
||||
DefKind::Enum => Self::Enum,
|
||||
DefKind::Fn => Self::Function,
|
||||
DefKind::Mod => Self::Module,
|
||||
DefKind::Const => Self::Constant,
|
||||
DefKind::Const { .. } => Self::Constant,
|
||||
DefKind::Static { .. } => Self::Static,
|
||||
DefKind::Struct => Self::Struct,
|
||||
DefKind::Union => Self::Union,
|
||||
@@ -180,7 +180,7 @@ pub(crate) fn from_def_id(def_id: DefId, tcx: TyCtxt<'_>) -> Self {
|
||||
}
|
||||
DefKind::Ctor(CtorOf::Struct, _) => Self::Struct,
|
||||
DefKind::Ctor(CtorOf::Variant, _) => Self::Variant,
|
||||
DefKind::AssocConst => Self::AssocConst,
|
||||
DefKind::AssocConst { .. } => Self::AssocConst,
|
||||
DefKind::TyParam
|
||||
| DefKind::ConstParam
|
||||
| DefKind::ExternCrate
|
||||
|
||||
@@ -545,7 +545,7 @@ pub(crate) fn href_with_root_path(
|
||||
let tcx = cx.tcx();
|
||||
let def_kind = tcx.def_kind(original_did);
|
||||
let did = match def_kind {
|
||||
DefKind::AssocTy | DefKind::AssocFn | DefKind::AssocConst | DefKind::Variant => {
|
||||
DefKind::AssocTy | DefKind::AssocFn | DefKind::AssocConst { .. } | DefKind::Variant => {
|
||||
// documented on their parent's page
|
||||
tcx.parent(original_did)
|
||||
}
|
||||
@@ -837,7 +837,7 @@ pub(crate) fn fragment(did: DefId, tcx: TyCtxt<'_>) -> impl Display {
|
||||
fmt::from_fn(move |f| {
|
||||
let def_kind = tcx.def_kind(did);
|
||||
match def_kind {
|
||||
DefKind::AssocTy | DefKind::AssocFn | DefKind::AssocConst | DefKind::Variant => {
|
||||
DefKind::AssocTy | DefKind::AssocFn | DefKind::AssocConst { .. } | DefKind::Variant => {
|
||||
let item_type = ItemType::from_def_id(did, tcx);
|
||||
write!(f, "#{}.{}", item_type.as_str(), tcx.item_name(did))
|
||||
}
|
||||
|
||||
@@ -125,9 +125,10 @@ fn disambiguator_suggestion(self) -> Suggestion {
|
||||
DefKind::Trait => "trait",
|
||||
DefKind::Union => "union",
|
||||
DefKind::Mod => "mod",
|
||||
DefKind::Const | DefKind::ConstParam | DefKind::AssocConst | DefKind::AnonConst => {
|
||||
"const"
|
||||
}
|
||||
DefKind::Const { .. }
|
||||
| DefKind::ConstParam
|
||||
| DefKind::AssocConst { .. }
|
||||
| DefKind::AnonConst => "const",
|
||||
DefKind::Static { .. } => "static",
|
||||
DefKind::Field => "field",
|
||||
DefKind::Variant | DefKind::Ctor(..) => "variant",
|
||||
@@ -393,7 +394,10 @@ fn resolve<'path>(
|
||||
if let Some(res) = self.resolve_path(path_str, ns, item_id, module_id) {
|
||||
return Ok(match res {
|
||||
Res::Def(
|
||||
DefKind::AssocFn | DefKind::AssocConst | DefKind::AssocTy | DefKind::Variant,
|
||||
DefKind::AssocFn
|
||||
| DefKind::AssocConst { .. }
|
||||
| DefKind::AssocTy
|
||||
| DefKind::Variant,
|
||||
def_id,
|
||||
) => {
|
||||
vec![(Res::from_def_id(self.cx.tcx, self.cx.tcx.parent(def_id)), Some(def_id))]
|
||||
@@ -490,7 +494,7 @@ fn resolve_self_ty<'tcx>(
|
||||
|
||||
let self_id = match tcx.def_kind(item_id) {
|
||||
def_kind @ (DefKind::AssocFn
|
||||
| DefKind::AssocConst
|
||||
| DefKind::AssocConst { .. }
|
||||
| DefKind::AssocTy
|
||||
| DefKind::Variant
|
||||
| DefKind::Field) => {
|
||||
@@ -1210,7 +1214,7 @@ fn validate_link(&self, original_did: DefId) -> bool {
|
||||
let tcx = self.cx.tcx;
|
||||
let def_kind = tcx.def_kind(original_did);
|
||||
let did = match def_kind {
|
||||
DefKind::AssocTy | DefKind::AssocFn | DefKind::AssocConst | DefKind::Variant => {
|
||||
DefKind::AssocTy | DefKind::AssocFn | DefKind::AssocConst { .. } | DefKind::Variant => {
|
||||
// documented on their parent's page
|
||||
tcx.parent(original_did)
|
||||
}
|
||||
@@ -1398,7 +1402,13 @@ fn verify_disambiguator(
|
||||
// Disallow e.g. linking to enums with `struct@`
|
||||
debug!("saw kind {kind:?} with disambiguator {disambiguator:?}");
|
||||
match (kind, disambiguator) {
|
||||
| (DefKind::Const | DefKind::ConstParam | DefKind::AssocConst | DefKind::AnonConst, Some(Disambiguator::Kind(DefKind::Const)))
|
||||
| (
|
||||
DefKind::Const { .. }
|
||||
| DefKind::ConstParam
|
||||
| DefKind::AssocConst { .. }
|
||||
| DefKind::AnonConst,
|
||||
Some(Disambiguator::Kind(DefKind::Const { .. })),
|
||||
)
|
||||
// NOTE: this allows 'method' to mean both normal functions and associated functions
|
||||
// This can't cause ambiguity because both are in the same namespace.
|
||||
| (DefKind::Fn | DefKind::AssocFn, Some(Disambiguator::Kind(DefKind::Fn)))
|
||||
@@ -1721,7 +1731,7 @@ fn from_str(link: &str) -> Result<Option<(Self, &str, &str)>, (String, Range<usi
|
||||
"trait" => Kind(DefKind::Trait),
|
||||
"union" => Kind(DefKind::Union),
|
||||
"module" | "mod" => Kind(DefKind::Mod),
|
||||
"const" | "constant" => Kind(DefKind::Const),
|
||||
"const" | "constant" => Kind(DefKind::Const { is_type_const: false }),
|
||||
"static" => Kind(DefKind::Static {
|
||||
mutability: Mutability::Not,
|
||||
nested: false,
|
||||
@@ -2122,11 +2132,11 @@ fn resolution_failure(
|
||||
| Field
|
||||
| Closure
|
||||
| AssocTy
|
||||
| AssocConst
|
||||
| AssocConst { .. }
|
||||
| AssocFn
|
||||
| Fn
|
||||
| Macro(_)
|
||||
| Const
|
||||
| Const { .. }
|
||||
| ConstParam
|
||||
| ExternCrate
|
||||
| Use
|
||||
|
||||
@@ -308,7 +308,7 @@ fn check(&mut self, idx: &'tcx Expr<'_>, seqexpr: &'tcx Expr<'_>, expr: &'tcx Ex
|
||||
}
|
||||
return false; // no need to walk further *on the variable*
|
||||
},
|
||||
Res::Def(DefKind::Static { .. } | DefKind::Const, ..) => {
|
||||
Res::Def(DefKind::Static { .. } | DefKind::Const { .. }, ..) => {
|
||||
if index_used_directly {
|
||||
self.indexed_directly.insert(
|
||||
seqvar.segments[0].ident.name,
|
||||
|
||||
@@ -82,7 +82,7 @@ fn emit_lint(cx: &LateContext<'_>, vec: &Expr<'_>, pushed_item: &Expr<'_>, ctxt:
|
||||
ExprKind::Lit(..) => emit_lint(cx, vec, pushed_item, ctxt, msrv),
|
||||
// immutable bindings that are initialized with constant
|
||||
ExprKind::Path(ref path) => {
|
||||
if let Res::Def(DefKind::Const, ..) = cx.qpath_res(path, init.hir_id) {
|
||||
if let Res::Def(DefKind::Const { .. }, ..) = cx.qpath_res(path, init.hir_id) {
|
||||
emit_lint(cx, vec, pushed_item, ctxt, msrv);
|
||||
}
|
||||
},
|
||||
@@ -91,7 +91,7 @@ fn emit_lint(cx: &LateContext<'_>, vec: &Expr<'_>, pushed_item: &Expr<'_>, ctxt:
|
||||
}
|
||||
},
|
||||
// constant
|
||||
Res::Def(DefKind::Const, ..) => emit_lint(cx, vec, pushed_item, ctxt, msrv),
|
||||
Res::Def(DefKind::Const { .. }, ..) => emit_lint(cx, vec, pushed_item, ctxt, msrv),
|
||||
_ => {},
|
||||
}
|
||||
},
|
||||
|
||||
@@ -121,11 +121,11 @@ fn is_not_const(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
|
||||
|
||||
DefKind::AnonConst
|
||||
| DefKind::InlineConst
|
||||
| DefKind::Const
|
||||
| DefKind::Const { .. }
|
||||
| DefKind::ConstParam
|
||||
| DefKind::Static { .. }
|
||||
| DefKind::Ctor(..)
|
||||
| DefKind::AssocConst => false,
|
||||
| DefKind::AssocConst { .. } => false,
|
||||
|
||||
DefKind::Fn | DefKind::AssocFn | DefKind::Closure => tcx.constness(def_id) == Constness::NotConst,
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use clippy_config::Conf;
|
||||
use clippy_utils::diagnostics::span_lint_and_sugg;
|
||||
use clippy_utils::msrvs::{self, Msrv};
|
||||
use clippy_utils::{peel_hir_expr_refs, sym};
|
||||
use clippy_utils::res::{MaybeDef, MaybeTypeckRes};
|
||||
use clippy_utils::{peel_hir_expr_refs, sym};
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir::def::{DefKind, Res};
|
||||
use rustc_hir::{Expr, ExprKind, Mutability, QPath};
|
||||
@@ -51,7 +51,7 @@ fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) {
|
||||
if let ExprKind::MethodCall(path, receiver, &[], _) = target.kind
|
||||
&& path.ident.name == sym::to_string
|
||||
&& let ExprKind::Path(QPath::Resolved(None, path)) = receiver.kind
|
||||
&& let Res::Def(DefKind::Const, receiver_def_id) = path.res
|
||||
&& let Res::Def(DefKind::Const { .. }, receiver_def_id) = path.res
|
||||
&& cx.ty_based_def(target).opt_parent(cx).is_diag_item(cx, sym::ToString)
|
||||
&& cx.tcx.is_diagnostic_item(sym::path_main_separator, receiver_def_id)
|
||||
&& let ty::Ref(_, ty, Mutability::Not) = cx.typeck_results().expr_ty_adjusted(expr).kind()
|
||||
|
||||
@@ -68,7 +68,7 @@ pub(crate) fn check(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>]) {
|
||||
// FIXME(clippy): don't you want to use the hir id of the peeled pat?
|
||||
let id = match cx.qpath_res(path, *hir_id) {
|
||||
Res::Def(
|
||||
DefKind::Const | DefKind::ConstParam | DefKind::AnonConst | DefKind::InlineConst,
|
||||
DefKind::Const { .. } | DefKind::ConstParam | DefKind::AnonConst | DefKind::InlineConst,
|
||||
_,
|
||||
) => return,
|
||||
Res::Def(_, id) => id,
|
||||
|
||||
@@ -20,10 +20,10 @@
|
||||
use clippy_config::Conf;
|
||||
use clippy_utils::consts::{ConstEvalCtxt, Constant, const_item_rhs_to_expr};
|
||||
use clippy_utils::diagnostics::{span_lint, span_lint_and_then};
|
||||
use clippy_utils::{is_in_const_context, sym};
|
||||
use clippy_utils::macros::macro_backtrace;
|
||||
use clippy_utils::paths::{PathNS, lookup_path_str};
|
||||
use clippy_utils::ty::{get_field_idx_by_name, implements_trait};
|
||||
use clippy_utils::{is_in_const_context, sym};
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_hir::def::{DefKind, Res};
|
||||
use rustc_hir::def_id::{DefId, DefIdSet};
|
||||
@@ -394,14 +394,14 @@ fn is_init_expr_freeze(
|
||||
let res = typeck.qpath_res(p, e.hir_id);
|
||||
let gen_args = EarlyBinder::bind(typeck.node_args(e.hir_id)).instantiate(tcx, gen_args);
|
||||
match res {
|
||||
Res::Def(DefKind::Const | DefKind::AssocConst, did)
|
||||
Res::Def(DefKind::Const { .. } | DefKind::AssocConst { .. }, did)
|
||||
if let Ok(val) =
|
||||
tcx.const_eval_resolve(typing_env, UnevaluatedConst::new(did, gen_args), DUMMY_SP)
|
||||
&& let Ok(is_freeze) = self.is_value_freeze(tcx, typing_env, ty, val) =>
|
||||
{
|
||||
is_freeze
|
||||
},
|
||||
Res::Def(DefKind::Const | DefKind::AssocConst, did)
|
||||
Res::Def(DefKind::Const { .. } | DefKind::AssocConst { .. }, did)
|
||||
if let Some((typeck, init)) = get_const_hir_value(tcx, typing_env, did, gen_args) =>
|
||||
{
|
||||
self.is_init_expr_freeze(tcx, typing_env, typeck, gen_args, init)
|
||||
@@ -588,7 +588,7 @@ fn is_non_freeze_init_borrowed(
|
||||
EarlyBinder::bind(init_typeck.node_args(init_expr.hir_id)).instantiate(tcx, init_args);
|
||||
match init_typeck.qpath_res(init_path, init_expr.hir_id) {
|
||||
Res::Def(DefKind::Ctor(..), _) => return None,
|
||||
Res::Def(DefKind::Const | DefKind::AssocConst, did)
|
||||
Res::Def(DefKind::Const { .. } | DefKind::AssocConst { .. }, did)
|
||||
if let Ok(val) = tcx.const_eval_resolve(
|
||||
typing_env,
|
||||
UnevaluatedConst::new(did, next_init_args),
|
||||
@@ -598,7 +598,7 @@ fn is_non_freeze_init_borrowed(
|
||||
{
|
||||
return res;
|
||||
},
|
||||
Res::Def(DefKind::Const | DefKind::AssocConst, did)
|
||||
Res::Def(DefKind::Const { .. } | DefKind::AssocConst { .. }, did)
|
||||
if let Some((next_typeck, value)) =
|
||||
get_const_hir_value(tcx, typing_env, did, next_init_args) =>
|
||||
{
|
||||
@@ -831,7 +831,7 @@ fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx ImplItem<'_>)
|
||||
fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) {
|
||||
if let ExprKind::Path(qpath) = &e.kind
|
||||
&& let typeck = cx.typeck_results()
|
||||
&& let Res::Def(DefKind::Const | DefKind::AssocConst, did) = typeck.qpath_res(qpath, e.hir_id)
|
||||
&& let Res::Def(DefKind::Const { .. } | DefKind::AssocConst { .. }, did) = typeck.qpath_res(qpath, e.hir_id)
|
||||
// As of `1.80` constant contexts can't borrow any type with interior mutability
|
||||
&& !is_in_const_context(cx)
|
||||
&& !self.is_ty_freeze(cx.tcx, cx.typing_env(), typeck.expr_ty(e)).is_freeze()
|
||||
|
||||
@@ -35,7 +35,7 @@ pub(crate) fn check<'tcx>(
|
||||
|
||||
// right hand side matches _::EPSILON
|
||||
&& let ExprKind::Path(ref epsilon_path) = rhs.kind
|
||||
&& let Res::Def(DefKind::AssocConst, def_id) = cx.qpath_res(epsilon_path, rhs.hir_id)
|
||||
&& let Res::Def(DefKind::AssocConst { .. }, def_id) = cx.qpath_res(epsilon_path, rhs.hir_id)
|
||||
&& let Some(sym) = cx.tcx.get_diagnostic_name(def_id)
|
||||
&& matches!(sym, sym::f16_epsilon | sym::f32_epsilon | sym::f64_epsilon | sym::f128_epsilon)
|
||||
|
||||
|
||||
@@ -113,7 +113,7 @@ fn check_crate(&mut self, cx: &LateContext<'_>) {
|
||||
}
|
||||
|
||||
for item in cx.tcx.module_children(def_id) {
|
||||
if let Res::Def(DefKind::Const, item_def_id) = item.res
|
||||
if let Res::Def(DefKind::Const { .. }, item_def_id) = item.res
|
||||
&& let ty = cx.tcx.type_of(item_def_id).instantiate_identity()
|
||||
&& internal_paths::SYMBOL.matches_ty(cx, ty)
|
||||
&& let Ok(ConstValue::Scalar(value)) = cx.tcx.const_eval_poly(item_def_id)
|
||||
|
||||
@@ -820,8 +820,8 @@ pub fn eq_defaultness(l: Defaultness, r: Defaultness) -> bool {
|
||||
matches!(
|
||||
(l, r),
|
||||
(Defaultness::Implicit, Defaultness::Implicit)
|
||||
| (Defaultness::Default(_), Defaultness::Default(_))
|
||||
| (Defaultness::Final(_), Defaultness::Final(_))
|
||||
| (Defaultness::Default(_), Defaultness::Default(_))
|
||||
| (Defaultness::Final(_), Defaultness::Final(_))
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -753,7 +753,7 @@ fn fetch_path(&self, qpath: &QPath<'_>, id: HirId) -> Option<ConstValue> {
|
||||
QPath::Resolved(None, path)
|
||||
if path.span.ctxt() == self.ctxt.get()
|
||||
&& path.segments.iter().all(|s| self.ctxt.get() == s.ident.span.ctxt())
|
||||
&& let Res::Def(DefKind::Const, did) = path.res
|
||||
&& let Res::Def(DefKind::Const { .. }, did) = path.res
|
||||
&& (matches!(
|
||||
self.tcx.get_diagnostic_name(did),
|
||||
Some(
|
||||
@@ -841,11 +841,13 @@ fn fetch_path(&self, qpath: &QPath<'_>, id: HirId) -> Option<ConstValue> {
|
||||
&& ty.span.ctxt() == self.ctxt.get()
|
||||
&& ty_name.ident.span.ctxt() == self.ctxt.get()
|
||||
&& matches!(ty_path.res, Res::PrimTy(_))
|
||||
&& let Some((DefKind::AssocConst, did)) = self.typeck.type_dependent_def(id) =>
|
||||
&& let Some((DefKind::AssocConst { .. }, did)) = self.typeck.type_dependent_def(id) =>
|
||||
{
|
||||
did
|
||||
},
|
||||
_ if let Res::Def(DefKind::Const | DefKind::AssocConst, did) = self.typeck.qpath_res(qpath, id) => {
|
||||
_ if let Res::Def(DefKind::Const { .. } | DefKind::AssocConst { .. }, did) =
|
||||
self.typeck.qpath_res(qpath, id) =>
|
||||
{
|
||||
self.source.set(ConstantSource::NonLocal);
|
||||
did
|
||||
},
|
||||
|
||||
@@ -799,7 +799,7 @@ pub fn eq_path(&mut self, left: &Path<'_>, right: &Path<'_>) -> bool {
|
||||
(Res::Local(_), _) | (_, Res::Local(_)) => false,
|
||||
(Res::Def(l_kind, l), Res::Def(r_kind, r))
|
||||
if l_kind == r_kind
|
||||
&& let DefKind::Const
|
||||
&& let DefKind::Const { .. }
|
||||
| DefKind::Static { .. }
|
||||
| DefKind::Fn
|
||||
| DefKind::TyAlias
|
||||
@@ -1035,7 +1035,7 @@ pub fn eq_expr_value(cx: &LateContext<'_>, left: &Expr<'_>, right: &Expr<'_>) ->
|
||||
/// item, in which case it is the last two
|
||||
fn generic_path_segments<'tcx>(segments: &'tcx [PathSegment<'tcx>]) -> Option<&'tcx [PathSegment<'tcx>]> {
|
||||
match segments.last()?.res {
|
||||
Res::Def(DefKind::AssocConst | DefKind::AssocFn | DefKind::AssocTy, _) => {
|
||||
Res::Def(DefKind::AssocConst { .. } | DefKind::AssocFn | DefKind::AssocTy, _) => {
|
||||
// <Ty as module::Trait<T>>::assoc::<U>
|
||||
// ^^^^^^^^^^^^^^^^ ^^^^^^^^^^ segments: [module, Trait<T>, assoc<U>]
|
||||
Some(&segments[segments.len().checked_sub(2)?..])
|
||||
|
||||
@@ -2337,7 +2337,7 @@ fn with_test_item_names(tcx: TyCtxt<'_>, module: LocalModDefId, f: impl FnOnce(&
|
||||
Entry::Vacant(entry) => {
|
||||
let mut names = Vec::new();
|
||||
for id in tcx.hir_module_free_items(module) {
|
||||
if matches!(tcx.def_kind(id.owner_id), DefKind::Const)
|
||||
if matches!(tcx.def_kind(id.owner_id), DefKind::Const { .. })
|
||||
&& let item = tcx.hir_item(id)
|
||||
&& let ItemKind::Const(ident, _generics, ty, _body) = item.kind
|
||||
&& let TyKind::Path(QPath::Resolved(_, path)) = ty.kind
|
||||
|
||||
@@ -519,7 +519,7 @@ fn ctor_parent<'tcx>(self, tcx: &impl HasTyCtxt<'tcx>) -> Option<DefId> {
|
||||
#[inline]
|
||||
fn assoc_parent<'tcx>(self, tcx: &impl HasTyCtxt<'tcx>) -> Option<DefId> {
|
||||
match self.opt_def(tcx) {
|
||||
Some((DefKind::AssocConst | DefKind::AssocFn | DefKind::AssocTy, id)) => tcx.tcx().opt_parent(id),
|
||||
Some((DefKind::AssocConst { .. } | DefKind::AssocFn | DefKind::AssocTy, id)) => tcx.tcx().opt_parent(id),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -367,8 +367,8 @@ fn visit_expr(&mut self, e: &'tcx Expr<'_>) -> Self::Result {
|
||||
if matches!(
|
||||
self.cx.qpath_res(p, e.hir_id),
|
||||
Res::Def(
|
||||
DefKind::Const
|
||||
| DefKind::AssocConst
|
||||
DefKind::Const { .. }
|
||||
| DefKind::AssocConst { .. }
|
||||
| DefKind::AnonConst
|
||||
| DefKind::ConstParam
|
||||
| DefKind::Ctor(..)
|
||||
|
||||
@@ -139,7 +139,8 @@ fn test_stable_mir() -> ControlFlow<()> {
|
||||
}
|
||||
}
|
||||
|
||||
let foo_const = get_item(&items, (DefKind::Const, "input::FOO")).unwrap();
|
||||
let foo_const =
|
||||
get_item(&items, (DefKind::Const { is_type_const: false }, "input::FOO")).unwrap();
|
||||
// Ensure we don't panic trying to get the body of a constant.
|
||||
foo_const.expect_body();
|
||||
|
||||
@@ -181,7 +182,8 @@ fn get_item<'a>(
|
||||
items.iter().find(|crate_item| {
|
||||
matches!(
|
||||
(item.0, crate_item.kind()),
|
||||
(DefKind::Fn, ItemKind::Fn) | (DefKind::Const, ItemKind::Const)
|
||||
(DefKind::Fn, ItemKind::Fn)
|
||||
| (DefKind::Const { is_type_const: false }, ItemKind::Const)
|
||||
) && crate_item.name() == item.1
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user