Associated consts are not object safe.

This commit is contained in:
Without Boats 2017-04-23 22:00:09 -07:00
parent 15ce54096a
commit 86b10671db

View File

@ -37,6 +37,9 @@ pub enum ObjectSafetyViolation {
/// Method has something illegal
Method(ast::Name, MethodViolationCode),
/// Associated const
AssociatedConst(ast::Name),
}
impl ObjectSafetyViolation {
@ -54,6 +57,8 @@ impl ObjectSafetyViolation {
in its arguments or return type", name).into(),
ObjectSafetyViolation::Method(name, MethodViolationCode::Generic) =>
format!("method `{}` has generic type parameters", name).into(),
ObjectSafetyViolation::AssociatedConst(name) =>
format!("the trait cannot contain associated consts, such as `{}`", name),
}
}
}
@ -141,6 +146,10 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
violations.push(ObjectSafetyViolation::SupertraitSelf);
}
violations.extend(self.associated_items(trait_def_id)
.filter(|item| item.kind == ty::AssociatedKind::Const)
.map(|item| ObjectSafetyViolation::AssociatedConst(item.name)));
debug!("object_safety_violations_for_trait(trait_def_id={:?}) = {:?}",
trait_def_id,
violations);