Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable] Fix an ICE that hid the related error message #61208

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 30 additions & 22 deletions src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5330,7 +5330,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
}

// Rewrite `SelfCtor` to `Ctor`
pub fn rewrite_self_ctor(&self, def: Def, span: Span) -> (Def, DefId, Ty<'tcx>) {
pub fn rewrite_self_ctor(&self, def: Def, span: Span) -> Def {
let tcx = self.tcx;
if let Def::SelfCtor(impl_def_id) = def {
let ty = self.impl_self_ty(span, impl_def_id).ty;
Expand All @@ -5340,8 +5340,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
Some(adt_def) if adt_def.has_ctor() => {
let variant = adt_def.non_enum_variant();
let ctor_def_id = variant.ctor_def_id.unwrap();
let def = Def::Ctor(ctor_def_id, CtorOf::Struct, variant.ctor_kind);
(def, ctor_def_id, tcx.type_of(ctor_def_id))
Def::Ctor(ctor_def_id, CtorOf::Struct, variant.ctor_kind)
}
_ => {
let mut err = tcx.sess.struct_span_err(span,
Expand All @@ -5364,16 +5363,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
}
err.emit();

(def, impl_def_id, tcx.types.err)
def
}
}
} else {
let def_id = def.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);
(def, def_id, ty)
def
}
}

Expand All @@ -5396,18 +5390,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {

let tcx = self.tcx;

match def {
Def::Local(nid) | Def::Upvar(nid, ..) => {
let hid = self.tcx.hir().node_to_hir_id(nid);
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, def);
}
_ => {}
}

let (def, def_id, ty) = self.rewrite_self_ctor(def, span);
let def = self.rewrite_self_ctor(def, span);
let path_segs = AstConv::def_ids_for_path_segments(self, segments, self_ty, def);

let mut user_self_ty = None;
Expand Down Expand Up @@ -5469,6 +5452,17 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
user_self_ty = None;
}

match def {
Def::Local(nid) | Def::Upvar(nid, ..) => {
let hid = self.tcx.hir().node_to_hir_id(nid);
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, def);
}
_ => {}
}

// Now we have to compare the types that the user *actually*
// provided against the types that were *expected*. If the user
// did not provide any types, then we want to substitute inference
Expand Down Expand Up @@ -5501,6 +5495,20 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
tcx.generics_of(*def_id).has_self
}).unwrap_or(false);

let (def_id, ty) = if let Def::SelfCtor(impl_def_id) = def {
// NOTE(eddyb) an error has already been emitted by `rewrite_self_ctor`,
// avoid using the wrong type here. This isn't in `rewrite_self_ctor`
// itself because that runs too early (see #60989).
(impl_def_id, tcx.types.err)
} else {
let def_id = def.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);
(def_id, ty)
};

let substs = AstConv::create_substs_for_generic_args(
tcx,
def_id,
Expand Down
18 changes: 18 additions & 0 deletions src/test/ui/issue-60989.rs
Original file line number Diff line number Diff line change
@@ -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
}
15 changes: 15 additions & 0 deletions src/test/ui/issue-60989.stderr
Original file line number Diff line number Diff line change
@@ -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`.