Turn ICE on type arguments on variables into an error
This commit is contained in:
parent
02f5786a32
commit
a15df94b69
|
@ -5194,7 +5194,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
&self,
|
&self,
|
||||||
res: Res,
|
res: Res,
|
||||||
span: Span,
|
span: Span,
|
||||||
) -> Result<(DefKind, DefId, Ty<'tcx>), ErrorReported> {
|
) -> Result<Res, ErrorReported> {
|
||||||
let tcx = self.tcx;
|
let tcx = self.tcx;
|
||||||
if let Res::SelfCtor(impl_def_id) = res {
|
if let Res::SelfCtor(impl_def_id) = res {
|
||||||
let ty = self.impl_self_ty(span, impl_def_id).ty;
|
let ty = self.impl_self_ty(span, impl_def_id).ty;
|
||||||
|
@ -5204,11 +5204,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
Some(adt_def) if adt_def.has_ctor() => {
|
Some(adt_def) if adt_def.has_ctor() => {
|
||||||
let variant = adt_def.non_enum_variant();
|
let variant = adt_def.non_enum_variant();
|
||||||
let ctor_def_id = variant.ctor_def_id.unwrap();
|
let ctor_def_id = variant.ctor_def_id.unwrap();
|
||||||
Ok((
|
Ok(Res::Def(DefKind::Ctor(CtorOf::Struct, variant.ctor_kind), ctor_def_id))
|
||||||
DefKind::Ctor(CtorOf::Struct, variant.ctor_kind),
|
|
||||||
ctor_def_id,
|
|
||||||
tcx.type_of(ctor_def_id),
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
let mut err = tcx.sess.struct_span_err(span,
|
let mut err = tcx.sess.struct_span_err(span,
|
||||||
|
@ -5235,15 +5231,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
match res {
|
Ok(res)
|
||||||
Res::Def(kind, def_id) => {
|
|
||||||
// The things we are substituting into the type should not contain
|
|
||||||
// escaping late-bound regions, and nor should the base type scheme.
|
|
||||||
let ty = tcx.type_of(def_id);
|
|
||||||
Ok((kind, def_id, ty))
|
|
||||||
}
|
|
||||||
_ => span_bug!(span, "unexpected res in rewrite_self_ctor: {:?}", res),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5266,27 +5254,21 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
|
|
||||||
let tcx = self.tcx;
|
let tcx = self.tcx;
|
||||||
|
|
||||||
match res {
|
let res = match self.rewrite_self_ctor(res, span) {
|
||||||
Res::Local(hid) | Res::Upvar(hid, ..) => {
|
Ok(res) => res,
|
||||||
let ty = self.local_ty(span, hid).decl_ty;
|
|
||||||
let ty = self.normalize_associated_types_in(span, &ty);
|
|
||||||
self.write_ty(hir_id, ty);
|
|
||||||
return (ty, res);
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
|
|
||||||
let (kind, def_id, ty) = match self.rewrite_self_ctor(res, span) {
|
|
||||||
Ok(result) => result,
|
|
||||||
Err(ErrorReported) => return (tcx.types.err, res),
|
Err(ErrorReported) => return (tcx.types.err, res),
|
||||||
};
|
};
|
||||||
let path_segs =
|
let path_segs = match res {
|
||||||
AstConv::def_ids_for_value_path_segments(self, segments, self_ty, kind, def_id);
|
Res::Local(_) | Res::Upvar(..) => Vec::new(),
|
||||||
|
Res::Def(kind, def_id) =>
|
||||||
|
AstConv::def_ids_for_value_path_segments(self, segments, self_ty, kind, def_id),
|
||||||
|
_ => bug!("instantiate_value_path on {:?}", res),
|
||||||
|
};
|
||||||
|
|
||||||
let mut user_self_ty = None;
|
let mut user_self_ty = None;
|
||||||
let mut is_alias_variant_ctor = false;
|
let mut is_alias_variant_ctor = false;
|
||||||
match kind {
|
match res {
|
||||||
DefKind::Ctor(CtorOf::Variant, _) => {
|
Res::Def(DefKind::Ctor(CtorOf::Variant, _), _) => {
|
||||||
if let Some(self_ty) = self_ty {
|
if let Some(self_ty) = self_ty {
|
||||||
let adt_def = self_ty.ty_adt_def().unwrap();
|
let adt_def = self_ty.ty_adt_def().unwrap();
|
||||||
user_self_ty = Some(UserSelfTy {
|
user_self_ty = Some(UserSelfTy {
|
||||||
|
@ -5296,8 +5278,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
is_alias_variant_ctor = true;
|
is_alias_variant_ctor = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DefKind::Method
|
Res::Def(DefKind::Method, def_id)
|
||||||
| DefKind::AssociatedConst => {
|
| Res::Def(DefKind::AssociatedConst, def_id) => {
|
||||||
let container = tcx.associated_item(def_id).container;
|
let container = tcx.associated_item(def_id).container;
|
||||||
debug!("instantiate_value_path: def_id={:?} container={:?}", def_id, container);
|
debug!("instantiate_value_path: def_id={:?} container={:?}", def_id, container);
|
||||||
match container {
|
match container {
|
||||||
|
@ -5337,6 +5319,17 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
match res {
|
||||||
|
Res::Local(hid) | Res::Upvar(hid, ..) => {
|
||||||
|
let ty = self.local_ty(span, hid).decl_ty;
|
||||||
|
let ty = self.normalize_associated_types_in(span, &ty);
|
||||||
|
self.write_ty(hir_id, ty);
|
||||||
|
return (ty, res);
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
|
||||||
if generics_has_err {
|
if generics_has_err {
|
||||||
// Don't try to infer type parameters when prohibited generic arguments were given.
|
// Don't try to infer type parameters when prohibited generic arguments were given.
|
||||||
user_self_ty = None;
|
user_self_ty = None;
|
||||||
|
@ -5374,6 +5367,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
tcx.generics_of(*def_id).has_self
|
tcx.generics_of(*def_id).has_self
|
||||||
}).unwrap_or(false);
|
}).unwrap_or(false);
|
||||||
|
|
||||||
|
let def_id = res.def_id();
|
||||||
|
|
||||||
|
// The things we are substituting into the type should not contain
|
||||||
|
// escaping late-bound regions, and nor should the base type scheme.
|
||||||
|
let ty = tcx.type_of(def_id);
|
||||||
|
|
||||||
let substs = AstConv::create_substs_for_generic_args(
|
let substs = AstConv::create_substs_for_generic_args(
|
||||||
tcx,
|
tcx,
|
||||||
def_id,
|
def_id,
|
||||||
|
@ -5490,7 +5489,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
ty_substituted);
|
ty_substituted);
|
||||||
self.write_substs(hir_id, substs);
|
self.write_substs(hir_id, substs);
|
||||||
|
|
||||||
(ty_substituted, Res::Def(kind, def_id))
|
(ty_substituted, res)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_rustc_args_require_const(&self,
|
fn check_rustc_args_require_const(&self,
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
struct A {}
|
||||||
|
struct B {}
|
||||||
|
|
||||||
|
impl From<A> for B {
|
||||||
|
fn from(a: A) -> B {
|
||||||
|
B{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let c1 = ();
|
||||||
|
c1::<()>;
|
||||||
|
//~^ ERROR type arguments are not allowed for this type
|
||||||
|
|
||||||
|
let c1 = A {};
|
||||||
|
c1::<Into<B>>;
|
||||||
|
//~^ ERROR type arguments are not allowed for this type
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
error[E0109]: type arguments are not allowed for this type
|
||||||
|
--> $DIR/issue-60989.rs:12:10
|
||||||
|
|
|
||||||
|
LL | c1::<()>;
|
||||||
|
| ^^ type argument not allowed
|
||||||
|
|
||||||
|
error[E0109]: type arguments are not allowed for this type
|
||||||
|
--> $DIR/issue-60989.rs:16:10
|
||||||
|
|
|
||||||
|
LL | c1::<Into<B>>;
|
||||||
|
| ^^^^^^^ type argument not allowed
|
||||||
|
|
||||||
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0109`.
|
Loading…
Reference in New Issue