Stream: t-compiler

Topic: #56225 type alias enum variants


nikomatsakis (Dec 19 2018 at 19:30, on Zulip):

@Alexander Regueiro continuing from privmsg...

...is this the sort of "heart" of your PR?

+        debug!("resolve_ufcs: method_name={:?} self_ty={:?} expr_id={:?}",
+            method_name,
+            self_ty,
+            expr_id
+        );
+
+        let tcx = self.tcx;
+
+        // Check if we have an enum variant here.
+        if let ty::Adt(adt_def, _) = self_ty.sty {
+            if adt_def.is_enum() {
+                let variant_def = adt_def.variants.iter().find(|vd| {
+                    tcx.hygienic_eq(method_name, vd.ident, adt_def.did)
+                });
+                if let Some(variant_def) = variant_def {
+                    check_type_alias_enum_variants_enabled(tcx, span);
+
+                    let def = Def::VariantCtor(variant_def.did, variant_def.ctor_kind);
+                    tcx.check_stability(def.def_id(), Some(expr_id), span);
+                    return Ok(def);
+                }
+            }
+        }

(i've been skimming the diff, trying to figure out what changed here=)

nikomatsakis (Dec 19 2018 at 19:31, on Zulip):

I'm not really sure I guess what this CtorKind::Fictive thing is

nikomatsakis (Dec 19 2018 at 19:31, on Zulip):

maybe that's pre-existing

nikomatsakis (Dec 19 2018 at 19:31, on Zulip):

I'm specifically wondering about the purpose of this diff

-            hir::ExprKind::Path(ref qpath) => {
+            ExprKind::Path(ref qpath) => {
                 let (def, opt_ty, segs) = self.resolve_ty_and_def_ufcs(qpath, expr.id, expr.span);
-                let ty = if def != Def::Err {
-                    self.instantiate_value_path(segs, opt_ty, def, expr.span, id).0
-                } else {
-                    self.set_tainted_by_errors();
-                    tcx.types.err
+                let ty = match def {
+                    Def::Err => {
+                        self.set_tainted_by_errors();
+                        tcx.types.err
+                    }
+                    Def::VariantCtor(_, CtorKind::Fictive) => {
+                        report_unexpected_variant_def(tcx, &def, expr.span, qpath);
+                        tcx.types.err
+                    }
+                    _ => self.instantiate_value_path(segs, opt_ty, def, expr.span, id).0,
                 };
Alexander Regueiro (Dec 19 2018 at 19:40, on Zulip):

@nikomatsakis kind of. that, associated_path_def_to_ty, def_to_ty, and instantiate_value_path

Alexander Regueiro (Dec 19 2018 at 19:41, on Zulip):

ah, that's needed to avoid an ICE... I forget which one

Alexander Regueiro (Dec 19 2018 at 19:41, on Zulip):

but you can infer it from the error message it reports

Alexander Regueiro (Dec 19 2018 at 19:41, on Zulip):

anyway even without that diff, the two issues I mentioned to you still occur

Alexander Regueiro (Dec 19 2018 at 19:47, on Zulip):

Hope that makes sense anyway...

Alexander Regueiro (Dec 19 2018 at 19:50, on Zulip):

both issues could possibly be related to inference, in fact. The problem with Self is that the type parameter in the Self alias is being treated as inferrable, when it shouldn't be.

Alexander Regueiro (Dec 19 2018 at 19:50, on Zulip):

and conversely in the Alias case, it's not being treated as inferrable, I think!

nikomatsakis (Dec 19 2018 at 19:58, on Zulip):

ok well I didn't quite figure out the problem before I ran out of time but I'm still poking at it a bit amongst other things

Alexander Regueiro (Dec 19 2018 at 20:58, on Zulip):

@nikomatsakis sorry, didn't see your reply here. the UX for Zulip on mobile is even worse than the desktop one :-P

nikomatsakis (Dec 19 2018 at 21:03, on Zulip):

no worries, I'll try to come back to it, I'm kind of mulling what I think about modifying that code for method search in any case

Alexander Regueiro (Dec 19 2018 at 21:04, on Zulip):

mhm

Alexander Regueiro (Dec 19 2018 at 21:05, on Zulip):

I have a suspicion it could be that the infctxt it's scoped correctly or something like that...

Alexander Regueiro (Dec 19 2018 at 22:05, on Zulip):

did you get the build working at least?

nikomatsakis (Dec 19 2018 at 22:15, on Zulip):

yes

Alexander Regueiro (Dec 19 2018 at 22:26, on Zulip):

ah good

Alexander Regueiro (Dec 19 2018 at 22:28, on Zulip):

I'm still inclined to think it's an issue with inference rather than the code I've touched

Alexander Regueiro (Dec 19 2018 at 22:28, on Zulip):

but far from sure.

Alexander Regueiro (Dec 19 2018 at 22:33, on Zulip):

aha, @Vadim Petrochenkov has replied with an idea.

Alexander Regueiro (Dec 20 2018 at 15:35, on Zulip):

@nikomatsakis BTW this is basically fixed now. only issue is I'm getting an ICE after a normal error due to trying to infer generic args where they're already prohibited. not sure the best way to fix this.

nikomatsakis (Dec 20 2018 at 15:37, on Zulip):

ah, cool

Last update: Nov 20 2019 at 01:10UTC