use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::intravisit::{walk_generics, Visitor as _};
use rustc_hir::lang_items::LangItem;
-use rustc_hir::{Constness, GenericArg, GenericArgs};
-use rustc_middle::ty::subst::{self, InternalSubsts, Subst, SubstsRef};
+use rustc_hir::{GenericArg, GenericArgs};
+use rustc_middle::ty::subst::{self, GenericArgKind, InternalSubsts, Subst, SubstsRef};
use rustc_middle::ty::GenericParamDefKind;
use rustc_middle::ty::{self, Const, DefIdTree, Ty, TyCtxt, TypeFoldable};
use rustc_session::lint::builtin::AMBIGUOUS_ASSOCIATED_ITEMS;
fn item_def_id(&self) -> Option<DefId>;
- fn default_constness_for_trait_bounds(&self) -> Constness;
-
/// Returns predicates in scope of the form `X: Foo<T>`, where `X`
/// is a type parameter `X` with the given id `def_id` and T
/// matches `assoc_name`. This is a subset of the full set of
if self.is_object && has_default {
let default_ty = tcx.at(self.span).type_of(param.def_id);
let self_param = tcx.types.self_param;
- if default_ty.walk().any(|arg| arg == self_param.into()) {
+ if default_ty.walk(tcx).any(|arg| arg == self_param.into()) {
// There is no suitable inference default for a type parameter
// that references self, in an object type.
return true;
)
.into()
}
+ (&GenericParamDefKind::Const { has_default }, hir::GenericArg::Infer(inf)) => {
+ if has_default {
+ tcx.const_param_default(param.def_id).into()
+ } else if self.astconv.allow_ty_infer() {
+ // FIXME(const_generics): Actually infer parameter here?
+ todo!()
+ } else {
+ self.inferred_params.push(inf.span);
+ tcx.ty_error().into()
+ }
+ }
+ (
+ &GenericParamDefKind::Type { has_default, .. },
+ hir::GenericArg::Infer(inf),
+ ) => {
+ if has_default {
+ tcx.check_optional_stability(
+ param.def_id,
+ Some(arg.id()),
+ arg.span(),
+ None,
+ |_, _| {
+ // Default generic parameters may not be marked
+ // with stability attributes, i.e. when the
+ // default parameter was defined at the same time
+ // as the rest of the type. As such, we ignore missing
+ // stability attributes.
+ },
+ );
+ }
+ if self.astconv.allow_ty_infer() {
+ self.astconv.ast_ty_to_ty(&inf.to_ty()).into()
+ } else {
+ self.inferred_params.push(inf.span);
+ tcx.ty_error().into()
+ }
+ }
_ => unreachable!(),
}
}
tcx.ty_error().into()
} else {
// This is a default type parameter.
+ let substs = substs.unwrap();
+ if substs.iter().any(|arg| match arg.unpack() {
+ GenericArgKind::Type(ty) => ty.references_error(),
+ _ => false,
+ }) {
+ // Avoid ICE #86756 when type error recovery goes awry.
+ return tcx.ty_error().into();
+ }
self.astconv
.normalize_ty(
self.span,
tcx.at(self.span).type_of(param.def_id).subst_spanned(
tcx,
- substs.unwrap(),
+ substs,
Some(self.span),
),
)
&self,
trait_ref: &hir::TraitRef<'_>,
span: Span,
- constness: Constness,
+ constness: ty::BoundConstness,
self_ty: Ty<'tcx>,
bounds: &mut Bounds<'tcx>,
speculative: bool,
let bound_vars = tcx.late_bound_vars(hir_id);
let poly_trait_ref =
ty::Binder::bind_with_vars(ty::TraitRef::new(trait_def_id, substs), bound_vars);
- bounds.trait_bounds.push((poly_trait_ref, span, Constness::NotConst));
+ bounds.trait_bounds.push((poly_trait_ref, span, ty::BoundConstness::NotConst));
let mut dup_bindings = FxHashMap::default();
for binding in assoc_bindings {
bounds: &mut Bounds<'tcx>,
bound_vars: &'tcx ty::List<ty::BoundVariableKind>,
) {
- let constness = self.default_constness_for_trait_bounds();
for ast_bound in ast_bounds {
match *ast_bound {
hir::GenericBound::Trait(ref b, hir::TraitBoundModifier::None) => {
self.instantiate_poly_trait_ref(
&b.trait_ref,
b.span,
- constness,
+ ty::BoundConstness::NotConst,
param_ty,
bounds,
false,
self.instantiate_poly_trait_ref(
&b.trait_ref,
b.span,
- Constness::NotConst,
+ ty::BoundConstness::ConstIfConst,
param_ty,
bounds,
false,
);
}
- hir::GenericBound::Trait(_, hir::TraitBoundModifier::Maybe) => {}
+ hir::GenericBound::Trait(_, hir::TraitBoundModifier::Maybe)
+ | hir::GenericBound::Unsized(_) => {}
hir::GenericBound::LangItemTrait(lang_item, span, hir_id, args) => self
.instantiate_lang_item_trait_ref(
lang_item, span, hir_id, args, param_ty, bounds,
} = self.instantiate_poly_trait_ref(
&trait_bound.trait_ref,
trait_bound.span,
- Constness::NotConst,
+ ty::BoundConstness::NotConst,
dummy_self,
&mut bounds,
false,
.filter(|(trait_ref, _, _)| !tcx.trait_is_auto(trait_ref.def_id()));
for (base_trait_ref, span, constness) in regular_traits_refs_spans {
- assert_eq!(constness, Constness::NotConst);
+ assert_eq!(constness, ty::BoundConstness::NotConst);
for obligation in traits::elaborate_trait_ref(tcx, base_trait_ref) {
debug!(
let bound_predicate = obligation.predicate.kind();
match bound_predicate.skip_binder() {
- ty::PredicateKind::Trait(pred, _) => {
+ ty::PredicateKind::Trait(pred) => {
let pred = bound_predicate.rebind(pred);
associated_types.entry(span).or_default().extend(
tcx.associated_items(pred.def_id())
// A `Self` within the original bound will be substituted with a
// `trait_object_dummy_self`, so check for that.
let references_self =
- pred.skip_binder().ty.walk().any(|arg| arg == dummy_self.into());
+ pred.skip_binder().ty.walk(tcx).any(|arg| arg == dummy_self.into());
// If the projection output contains `Self`, force the user to
// elaborate it explicitly to avoid a lot of complexity.
has_err = true;
(ct.span, "const")
}
+ hir::GenericArg::Infer(inf) => {
+ if err_for_ty {
+ continue;
+ }
+ has_err = true;
+ err_for_ty = true;
+ (inf.span, "generic")
+ }
};
let mut err = struct_span_err!(
self.tcx().sess,
self.prohibit_generics(path.segments);
// Try to evaluate any array length constants.
let normalized_ty = self.normalize_ty(span, tcx.at(span).type_of(def_id));
- if forbid_generic && normalized_ty.needs_subst() {
+ if forbid_generic && normalized_ty.definitely_needs_subst(tcx) {
let mut err = tcx.sess.struct_span_err(
path.span,
"generic `Self` types are currently not permitted in anonymous constants",
}
hir::TyKind::Infer => {
// Infer also appears as the type of arguments or return
- // values in a ExprKind::Closure, or as
+ // values in an ExprKind::Closure, or as
// the type of local variables. Both of these cases are
// handled specially and will not descend into this routine.
self.ty_infer(None, ast_ty.span)
if let Some(i) = (param.index as usize).checked_sub(generics.parent_count) {
// Our own parameters are the resolved lifetimes.
match param.kind {
- GenericParamDefKind::Lifetime => {
- if let hir::GenericArg::Lifetime(lifetime) = &lifetimes[i] {
- self.ast_region_to_region(lifetime, None).into()
- } else {
- bug!()
- }
+ GenericParamDefKind::Lifetime
+ if let hir::GenericArg::Lifetime(lifetime) = &lifetimes[i] =>
+ {
+ self.ast_region_to_region(lifetime, None).into()
}
_ => bug!(),
}