Add constness
to TraitDef
This commit is contained in:
parent
f92a6c41e6
commit
46af987072
9 changed files with 42 additions and 31 deletions
|
@ -7,7 +7,7 @@ use rustc_hir::LangItem;
|
|||
use rustc_middle::ty::fold::FnMutDelegate;
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt, Upcast};
|
||||
use rustc_span::def_id::DefId;
|
||||
use rustc_span::{sym, Span};
|
||||
use rustc_span::Span;
|
||||
|
||||
/// Collects together a list of type bounds. These lists of bounds occur in many places
|
||||
/// in Rust's syntax:
|
||||
|
@ -80,7 +80,7 @@ impl<'tcx> Bounds<'tcx> {
|
|||
}
|
||||
|
||||
(_, ty::BoundConstness::NotConst) => {
|
||||
if !tcx.has_attr(bound_trait_ref.def_id(), sym::const_trait) {
|
||||
if !tcx.is_const_trait(bound_trait_ref.def_id()) {
|
||||
return;
|
||||
}
|
||||
tcx.consts.true_
|
||||
|
|
|
@ -1194,6 +1194,11 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef {
|
|||
_ => span_bug!(item.span, "trait_def_of_item invoked on non-trait"),
|
||||
};
|
||||
|
||||
let constness = if tcx.has_attr(def_id, sym::const_trait) {
|
||||
hir::Constness::Const
|
||||
} else {
|
||||
hir::Constness::NotConst
|
||||
};
|
||||
let paren_sugar = tcx.has_attr(def_id, sym::rustc_paren_sugar);
|
||||
if paren_sugar && !tcx.features().unboxed_closures {
|
||||
tcx.dcx().emit_err(errors::ParenSugarAttribute { span: item.span });
|
||||
|
@ -1348,6 +1353,7 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef {
|
|||
ty::TraitDef {
|
||||
def_id: def_id.to_def_id(),
|
||||
safety,
|
||||
constness,
|
||||
paren_sugar,
|
||||
has_auto_impl: is_auto,
|
||||
is_marker,
|
||||
|
@ -1680,7 +1686,7 @@ fn check_impl_constness(
|
|||
}
|
||||
|
||||
let trait_def_id = hir_trait_ref.trait_def_id()?;
|
||||
if tcx.has_attr(trait_def_id, sym::const_trait) {
|
||||
if tcx.is_const_trait(trait_def_id) {
|
||||
return None;
|
||||
}
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ use rustc_middle::{bug, span_bug};
|
|||
use rustc_session::lint::builtin::AMBIGUOUS_ASSOCIATED_ITEMS;
|
||||
use rustc_span::edit_distance::find_best_match_for_name;
|
||||
use rustc_span::symbol::{kw, Ident, Symbol};
|
||||
use rustc_span::{sym, Span, DUMMY_SP};
|
||||
use rustc_span::{Span, DUMMY_SP};
|
||||
use rustc_target::spec::abi;
|
||||
use rustc_trait_selection::traits::wf::object_region_bounds;
|
||||
use rustc_trait_selection::traits::{self, ObligationCtxt};
|
||||
|
@ -559,7 +559,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||
}
|
||||
if let ty::BoundConstness::Const | ty::BoundConstness::ConstIfConst = constness
|
||||
&& generics.has_self
|
||||
&& !tcx.has_attr(def_id, sym::const_trait)
|
||||
&& !tcx.is_const_trait(def_id)
|
||||
{
|
||||
let reported = tcx.dcx().emit_err(crate::errors::ConstBoundForNonConstTrait {
|
||||
span,
|
||||
|
@ -1847,19 +1847,13 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||
path.segments[..path.segments.len() - 2].iter(),
|
||||
GenericsArgsErrExtend::None,
|
||||
);
|
||||
// HACK: until we support `<Type as ~const Trait>`, assume all of them are.
|
||||
let constness = if tcx.has_attr(tcx.parent(def_id), sym::const_trait) {
|
||||
ty::BoundConstness::ConstIfConst
|
||||
} else {
|
||||
ty::BoundConstness::NotConst
|
||||
};
|
||||
self.lower_qpath(
|
||||
span,
|
||||
opt_self_ty,
|
||||
def_id,
|
||||
&path.segments[path.segments.len() - 2],
|
||||
path.segments.last().unwrap(),
|
||||
constness,
|
||||
ty::BoundConstness::NotConst,
|
||||
)
|
||||
}
|
||||
Res::PrimTy(prim_ty) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue