Skip to content

Commit 6e81f82

Browse files
committed
rustc_typeck: don't produce a DefId or Ty from rewrite_self_ctor, only a Def.
1 parent 97f204e commit 6e81f82

File tree

4 files changed

+52
-15
lines changed

4 files changed

+52
-15
lines changed

src/librustc_typeck/check/mod.rs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5330,7 +5330,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
53305330
}
53315331

53325332
// Rewrite `SelfCtor` to `Ctor`
5333-
pub fn rewrite_self_ctor(&self, def: Def, span: Span) -> (Def, DefId, Ty<'tcx>) {
5333+
pub fn rewrite_self_ctor(&self, def: Def, span: Span) -> Def {
53345334
let tcx = self.tcx;
53355335
if let Def::SelfCtor(impl_def_id) = def {
53365336
let ty = self.impl_self_ty(span, impl_def_id).ty;
@@ -5340,8 +5340,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
53405340
Some(adt_def) if adt_def.has_ctor() => {
53415341
let variant = adt_def.non_enum_variant();
53425342
let ctor_def_id = variant.ctor_def_id.unwrap();
5343-
let def = Def::Ctor(ctor_def_id, CtorOf::Struct, variant.ctor_kind);
5344-
(def, ctor_def_id, tcx.type_of(ctor_def_id))
5343+
Def::Ctor(ctor_def_id, CtorOf::Struct, variant.ctor_kind)
53455344
}
53465345
_ => {
53475346
let mut err = tcx.sess.struct_span_err(span,
@@ -5364,16 +5363,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
53645363
}
53655364
err.emit();
53665365

5367-
(def, impl_def_id, tcx.types.err)
5366+
def
53685367
}
53695368
}
53705369
} else {
5371-
let def_id = def.def_id();
5372-
5373-
// The things we are substituting into the type should not contain
5374-
// escaping late-bound regions, and nor should the base type scheme.
5375-
let ty = tcx.type_of(def_id);
5376-
(def, def_id, ty)
5370+
def
53775371
}
53785372
}
53795373

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

53975391
let tcx = self.tcx;
53985392

5399-
let (def, def_id, ty) = self.rewrite_self_ctor(def, span);
5393+
let def = self.rewrite_self_ctor(def, span);
54005394
let path_segs = AstConv::def_ids_for_path_segments(self, segments, self_ty, def);
54015395

54025396
let mut user_self_ty = None;
@@ -5501,6 +5495,20 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
55015495
tcx.generics_of(*def_id).has_self
55025496
}).unwrap_or(false);
55035497

5498+
let (def_id, ty) = if let Def::SelfCtor(impl_def_id) = def {
5499+
// NOTE(eddyb) an error has already been emitted by `rewrite_self_ctor`,
5500+
// avoid using the wrong type here. This isn't in `rewrite_self_ctor`
5501+
// itself because that runs too early (see #60989).
5502+
(impl_def_id, tcx.types.err)
5503+
} else {
5504+
let def_id = def.def_id();
5505+
5506+
// The things we are substituting into the type should not contain
5507+
// escaping late-bound regions, and nor should the base type scheme.
5508+
let ty = tcx.type_of(def_id);
5509+
(def_id, ty)
5510+
};
5511+
55045512
let substs = AstConv::create_substs_for_generic_args(
55055513
tcx,
55065514
def_id,

src/test/compile-fail/issue-60989.rs

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/test/ui/issue-60989.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
struct A {}
2+
struct B {}
3+
4+
impl From<A> for B {
5+
fn from(a: A) -> B {
6+
B{}
7+
}
8+
}
9+
10+
fn main() {
11+
let c1 = ();
12+
c1::<()>;
13+
//~^ ERROR type arguments are not allowed for this type
14+
15+
let c1 = A {};
16+
c1::<Into<B>>;
17+
//~^ ERROR type arguments are not allowed for this type
18+
}

src/test/ui/issue-60989.stderr

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0109]: type arguments are not allowed for this type
2+
--> $DIR/issue-60989.rs:12:10
3+
|
4+
LL | c1::<()>;
5+
| ^^ type argument not allowed
6+
7+
error[E0109]: type arguments are not allowed for this type
8+
--> $DIR/issue-60989.rs:16:10
9+
|
10+
LL | c1::<Into<B>>;
11+
| ^^^^^^^ type argument not allowed
12+
13+
error: aborting due to 2 previous errors
14+
15+
For more information about this error, try `rustc --explain E0109`.

0 commit comments

Comments
 (0)