let extra_predicates = extend.into_iter().chain(
icx.type_parameter_bounds_in_generics(ast_generics, param_id, ty, OnlySelfBounds(true))
.into_iter()
- .filter(|(predicate, _)| match predicate.kind() {
- ty::PredicateKind::Trait(ref data, _) => {
- data.skip_binder().self_ty().is_param(index)
- }
+ .filter(|(predicate, _)| match predicate.skip_binders() {
+ ty::PredicateAtom::Trait(data, _) => data.self_ty().is_param(index),
_ => false,
}),
);
placeholder_type_error(tcx, None, &[], visitor.0, false);
}
- hir::TraitItemKind::Type(_, None) => {}
+ hir::TraitItemKind::Type(_, None) => {
+ // #74612: Visit and try to find bad placeholders
+ // even if there is no concrete type.
+ let mut visitor = PlaceholderHirTyCollector::default();
+ visitor.visit_trait_item(trait_item);
+ placeholder_type_error(tcx, None, &[], visitor.0, false);
+ }
};
tcx.ensure().predicates_of(def_id);
// which will, in turn, reach indirect supertraits.
for &(pred, span) in superbounds {
debug!("superbound: {:?}", pred);
- if let ty::PredicateKind::Trait(bound, _) = pred.kind() {
+ if let ty::PredicateAtom::Trait(bound, _) = pred.skip_binders() {
tcx.at(span).super_predicates_of(bound.def_id());
}
}
let type_start = own_start - has_self as u32 + params.len() as u32;
let mut i = 0;
- // FIXME(const_generics): a few places in the compiler expect generic params
- // to be in the order lifetimes, then type params, then const params.
- //
- // To prevent internal errors in case const parameters are supplied before
- // type parameters we first add all type params, then all const params.
- params.extend(ast_generics.params.iter().filter_map(|param| {
- if let GenericParamKind::Type { ref default, synthetic, .. } = param.kind {
+ params.extend(ast_generics.params.iter().filter_map(|param| match param.kind {
+ GenericParamKind::Lifetime { .. } => None,
+ GenericParamKind::Type { ref default, synthetic, .. } => {
if !allow_defaults && default.is_some() {
if !tcx.features().default_type_parameter_fallback {
tcx.struct_span_lint_hir(
|lint| {
lint.build(
"defaults for type parameters are only allowed in \
- `struct`, `enum`, `type`, or `trait` definitions.",
+ `struct`, `enum`, `type`, or `trait` definitions.",
)
.emit();
},
};
i += 1;
Some(param_def)
- } else {
- None
}
- }));
-
- params.extend(ast_generics.params.iter().filter_map(|param| {
- if let GenericParamKind::Const { .. } = param.kind {
+ GenericParamKind::Const { .. } => {
let param_def = ty::GenericParamDef {
index: type_start + i as u32,
name: param.name.ident().name,
};
i += 1;
Some(param_def)
- } else {
- None
}
}));
// Collect the predicates that were written inline by the user on each
// type parameter (e.g., `<T: Foo>`).
for param in ast_generics.params {
- if let GenericParamKind::Type { .. } = param.kind {
- let name = param.name.ident().name;
- let param_ty = ty::ParamTy::new(index, name).to_ty(tcx);
- index += 1;
-
- let sized = SizedByDefault::Yes;
- let bounds = AstConv::compute_bounds(&icx, param_ty, ¶m.bounds, sized, param.span);
- predicates.extend(bounds.predicates(tcx, param_ty));
+ match param.kind {
+ // We already dealt with early bound lifetimes above.
+ GenericParamKind::Lifetime { .. } => (),
+ GenericParamKind::Type { .. } => {
+ let name = param.name.ident().name;
+ let param_ty = ty::ParamTy::new(index, name).to_ty(tcx);
+ index += 1;
+
+ let sized = SizedByDefault::Yes;
+ let bounds =
+ AstConv::compute_bounds(&icx, param_ty, ¶m.bounds, sized, param.span);
+ predicates.extend(bounds.predicates(tcx, param_ty));
+ }
+ GenericParamKind::Const { .. } => {
+ // Bounds on const parameters are currently not possible.
+ debug_assert!(param.bounds.is_empty());
+ index += 1;
+ }
}
}
let re_root_empty = tcx.lifetimes.re_root_empty;
let predicate = ty::OutlivesPredicate(ty, re_root_empty);
predicates.push((
- ty::PredicateKind::TypeOutlives(ty::Binder::dummy(predicate))
+ ty::PredicateKind::TypeOutlives(ty::Binder::bind(predicate))
.to_predicate(tcx),
span,
));
&hir::GenericBound::Outlives(ref lifetime) => {
let region = AstConv::ast_region_to_region(&icx, lifetime, None);
- let pred = ty::Binder::bind(ty::OutlivesPredicate(ty, region));
predicates.push((
- ty::PredicateKind::TypeOutlives(pred).to_predicate(tcx),
+ ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(ty, region))
+ .to_predicate(tcx)
+ .potentially_quantified(tcx, ty::PredicateKind::ForAll),
lifetime.span,
))
}
}
_ => bug!(),
};
- let pred = ty::Binder::bind(ty::OutlivesPredicate(r1, r2));
+ let pred = ty::PredicateAtom::RegionOutlives(ty::OutlivesPredicate(r1, r2))
+ .to_predicate(icx.tcx);
- (ty::PredicateKind::RegionOutlives(pred).to_predicate(icx.tcx), span)
+ (pred.potentially_quantified(icx.tcx, ty::PredicateKind::ForAll), span)
}))
}
}
hir::GenericBound::Outlives(ref lifetime) => {
let region = astconv.ast_region_to_region(lifetime, None);
- let pred = ty::Binder::bind(ty::OutlivesPredicate(param_ty, region));
- vec![(ty::PredicateKind::TypeOutlives(pred).to_predicate(astconv.tcx()), lifetime.span)]
+ let pred = ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(param_ty, region))
+ .to_predicate(astconv.tcx())
+ .potentially_quantified(astconv.tcx(), ty::PredicateKind::ForAll);
+ vec![(pred, lifetime.span)]
}
}
}