Rollup merge of #101681 - compiler-errors:rpitit-obj-safety, r=lcnr

Deny return-position `impl Trait` in traits for object safety

Fixes #101667
This commit is contained in:
Dylan DPC
2022-09-12 15:21:33 +05:30
committed by GitHub
4 changed files with 107 additions and 0 deletions

View File

@@ -915,6 +915,12 @@ impl ObjectSafetyViolation {
ObjectSafetyViolation::Method(name, MethodViolationCode::ReferencesSelfOutput, _) => {
format!("method `{}` references the `Self` type in its return type", name).into()
}
ObjectSafetyViolation::Method(
name,
MethodViolationCode::ReferencesImplTraitInTrait,
_,
) => format!("method `{}` references an `impl Trait` type in its return type", name)
.into(),
ObjectSafetyViolation::Method(
name,
MethodViolationCode::WhereClauseReferencesSelf,
@@ -1021,6 +1027,9 @@ pub enum MethodViolationCode {
/// e.g., `fn foo(&self) -> Self`
ReferencesSelfOutput,
/// e.g., `fn foo(&self) -> impl Sized`
ReferencesImplTraitInTrait,
/// e.g., `fn foo(&self) where Self: Clone`
WhereClauseReferencesSelf,