use crate::lint;
use crate::middle::resolve_lifetime as rl;
use crate::middle::weak_lang_items;
+use rustc::hir::map::blocks::FnLikeNode;
use rustc::hir::map::Map;
use rustc::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs};
use rustc::mir::mono::Linkage;
use rustc::ty::subst::{InternalSubsts, Subst};
use rustc::ty::util::Discr;
use rustc::ty::util::IntTypeExt;
-use rustc::ty::{self, AdtKind, Const, DefIdTree, ToPolyTraitRef, Ty, TyCtxt};
+use rustc::ty::{self, AdtKind, Const, DefIdTree, ToPolyTraitRef, Ty, TyCtxt, WithConstness};
use rustc::ty::{ReprOptions, ToPredicate};
use rustc_data_structures::captures::Captures;
use rustc_data_structures::fx::FxHashMap;
Some(self.item_def_id)
}
+ fn default_constness_for_trait_bounds(&self) -> ast::Constness {
+ // FIXME: refactor this into a method
+ let hir_id = self
+ .tcx
+ .hir()
+ .as_local_hir_id(self.item_def_id)
+ .expect("Non-local call to local provider is_const_fn");
+
+ let node = self.tcx.hir().get(hir_id);
+ if let Some(fn_like) = FnLikeNode::from_node(node) {
+ fn_like.constness()
+ } else {
+ ast::Constness::NotConst
+ }
+ }
+
fn get_type_parameter_bounds(&self, span: Span, def_id: DefId) -> ty::GenericPredicates<'tcx> {
self.tcx.at(span).type_param_predicates((self.item_def_id, def_id))
}
// Implied `Self: Trait` and supertrait bounds.
if param_id == item_hir_id {
let identity_trait_ref = ty::TraitRef::identity(tcx, item_def_id);
- extend = Some((identity_trait_ref.to_predicate(), item.span));
+ extend =
+ Some((identity_trait_ref.without_const().to_predicate(), item.span));
}
generics
}
icx.type_parameter_bounds_in_generics(ast_generics, param_id, ty, OnlySelfBounds(true))
.into_iter()
.filter(|(predicate, _)| match predicate {
- ty::Predicate::Trait(ref data) => data.skip_binder().self_ty().is_param(index),
+ ty::Predicate::Trait(ref data, _) => data.skip_binder().self_ty().is_param(index),
_ => false,
}),
);
ty: Ty<'tcx>,
only_self_bounds: OnlySelfBounds,
) -> Vec<(ty::Predicate<'tcx>, Span)> {
+ let constness = self.default_constness_for_trait_bounds();
let from_ty_params = ast_generics
.params
.iter()
_ => None,
})
.flat_map(|bounds| bounds.iter())
- .flat_map(|b| predicates_from_bound(self, ty, b));
+ .flat_map(|b| predicates_from_bound(self, ty, b, constness));
let from_where_clauses = ast_generics
.where_clause
};
bp.bounds.iter().filter_map(move |b| bt.map(|bt| (bt, b)))
})
- .flat_map(|(bt, b)| predicates_from_bound(self, bt, b));
+ .flat_map(|(bt, b)| predicates_from_bound(self, bt, b, constness));
from_ty_params.chain(from_where_clauses).collect()
}
// which will, in turn, reach indirect supertraits.
for &(pred, span) in superbounds {
debug!("superbound: {:?}", pred);
- if let ty::Predicate::Trait(bound) = pred {
+ if let ty::Predicate::Trait(bound, _) = pred {
tcx.at(span).super_predicates_of(bound.def_id());
}
}
let span = tcx.def_span(def_id);
result.predicates =
tcx.arena.alloc_from_iter(result.predicates.iter().copied().chain(std::iter::once((
- ty::TraitRef::identity(tcx, def_id).to_predicate(),
+ ty::TraitRef::identity(tcx, def_id).without_const().to_predicate(),
span,
))));
}
let mut is_default_impl_trait = None;
let icx = ItemCtxt::new(tcx, def_id);
+ let constness = icx.default_constness_for_trait_bounds();
const NO_GENERICS: &hir::Generics<'_> = &hir::Generics::empty();
// (see below). Recall that a default impl is not itself an impl, but rather a
// set of defaults that can be incorporated into another impl.
if let Some(trait_ref) = is_default_impl_trait {
- predicates.push((trait_ref.to_poly_trait_ref().to_predicate(), tcx.def_span(def_id)));
+ predicates.push((
+ trait_ref.to_poly_trait_ref().without_const().to_predicate(),
+ tcx.def_span(def_id),
+ ));
}
// Collect the region predicates that were declared inline as
for bound in bound_pred.bounds.iter() {
match bound {
- &hir::GenericBound::Trait(ref poly_trait_ref, _) => {
+ &hir::GenericBound::Trait(ref poly_trait_ref, modifier) => {
+ let constness = match modifier {
+ hir::TraitBoundModifier::MaybeConst => ast::Constness::NotConst,
+ hir::TraitBoundModifier::None => constness,
+ hir::TraitBoundModifier::Maybe => bug!("this wasn't handled"),
+ };
+
let mut bounds = Bounds::default();
let _ = AstConv::instantiate_poly_trait_ref(
&icx,
poly_trait_ref,
+ constness,
ty,
&mut bounds,
);
astconv: &dyn AstConv<'tcx>,
param_ty: Ty<'tcx>,
bound: &'tcx hir::GenericBound<'tcx>,
+ constness: ast::Constness,
) -> Vec<(ty::Predicate<'tcx>, Span)> {
match *bound {
- hir::GenericBound::Trait(ref tr, hir::TraitBoundModifier::None) => {
+ hir::GenericBound::Trait(ref tr, modifier) => {
+ let constness = match modifier {
+ hir::TraitBoundModifier::Maybe => return vec![],
+ hir::TraitBoundModifier::MaybeConst => ast::Constness::NotConst,
+ hir::TraitBoundModifier::None => constness,
+ };
+
let mut bounds = Bounds::default();
- let _ = astconv.instantiate_poly_trait_ref(tr, param_ty, &mut bounds);
+ let _ = astconv.instantiate_poly_trait_ref(tr, constness, param_ty, &mut bounds);
bounds.predicates(astconv.tcx(), param_ty)
}
hir::GenericBound::Outlives(ref lifetime) => {
let pred = ty::Binder::bind(ty::OutlivesPredicate(param_ty, region));
vec![(ty::Predicate::TypeOutlives(pred), lifetime.span)]
}
- hir::GenericBound::Trait(_, hir::TraitBoundModifier::Maybe) => vec![],
}
}