Synthesize generics for bad auto traits in dyn types
This commit is contained in:
parent
d1449560e3
commit
19175e9b75
@ -722,8 +722,28 @@ pub fn with_self_ty(&self, tcx: TyCtxt<'tcx>, self_ty: Ty<'tcx>) -> ty::Predicat
|
||||
self.rebind(p.with_self_ty(tcx, self_ty)).to_predicate(tcx)
|
||||
}
|
||||
ExistentialPredicate::AutoTrait(did) => {
|
||||
let trait_ref = self.rebind(tcx.mk_trait_ref(did, [self_ty]));
|
||||
trait_ref.without_const().to_predicate(tcx)
|
||||
let generics = tcx.generics_of(did);
|
||||
let trait_ref = if generics.params.len() == 1 {
|
||||
tcx.mk_trait_ref(did, [self_ty])
|
||||
} else {
|
||||
// If this is an ill-formed auto trait, then synthesize
|
||||
// new error substs for the missing generics.
|
||||
let err_substs = ty::InternalSubsts::for_item(tcx, did, |def, substs| {
|
||||
if def.index == 0 {
|
||||
self_ty.into()
|
||||
} else {
|
||||
match &def.kind {
|
||||
ty::GenericParamDefKind::Lifetime => tcx.lifetimes.re_static.into(),
|
||||
ty::GenericParamDefKind::Type { .. } => tcx.ty_error().into(),
|
||||
ty::GenericParamDefKind::Const { .. } => tcx
|
||||
.const_error(tcx.bound_type_of(def.def_id).subst(tcx, substs))
|
||||
.into(),
|
||||
}
|
||||
}
|
||||
});
|
||||
tcx.mk_trait_ref(did, err_substs)
|
||||
};
|
||||
self.rebind(trait_ref).without_const().to_predicate(tcx)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
11
src/test/ui/auto-traits/bad-generics-on-dyn.rs
Normal file
11
src/test/ui/auto-traits/bad-generics-on-dyn.rs
Normal file
@ -0,0 +1,11 @@
|
||||
#![feature(auto_traits)]
|
||||
|
||||
auto trait Trait1<'a> {}
|
||||
//~^ ERROR auto traits cannot have generic parameters
|
||||
|
||||
fn f<'a>(x: &dyn Trait1<'a>)
|
||||
{}
|
||||
|
||||
fn main() {
|
||||
f(&1);
|
||||
}
|
11
src/test/ui/auto-traits/bad-generics-on-dyn.stderr
Normal file
11
src/test/ui/auto-traits/bad-generics-on-dyn.stderr
Normal file
@ -0,0 +1,11 @@
|
||||
error[E0567]: auto traits cannot have generic parameters
|
||||
--> $DIR/bad-generics-on-dyn.rs:3:18
|
||||
|
|
||||
LL | auto trait Trait1<'a> {}
|
||||
| ------^^^^ help: remove the parameters
|
||||
| |
|
||||
| auto trait cannot have generic parameters
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0567`.
|
Loading…
Reference in New Issue
Block a user