diff options
| author | Nathan Fenner <nfenneremail@gmail.com> | 2023-02-28 14:58:14 -0800 |
|---|---|---|
| committer | Nathan Fenner <nfenneremail@gmail.com> | 2023-02-28 14:58:14 -0800 |
| commit | f0212e65321cf4e6a05ac78d44ec242829ffa289 (patch) | |
| tree | 3572a0e0367f5af64990dbd0ef760a8ff9de8799 /compiler | |
| parent | 2566b4105d60a422229c645a784186b52e15fde6 (diff) | |
| download | rust-f0212e65321cf4e6a05ac78d44ec242829ffa289.tar.gz rust-f0212e65321cf4e6a05ac78d44ec242829ffa289.zip | |
Fix error spans for arguments to tuple enum constructors
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs index 3b72326be7c..778e0bdaefd 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs @@ -714,12 +714,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.tcx.parent(expr_ctor_def_id) } hir::def::DefKind::Ctor(hir::def::CtorOf::Variant, hir::def::CtorKind::Fn) => { - if in_ty_adt.did() == self.tcx.parent(expr_ctor_def_id) { - // The constructor definition refers to the variant: - // For example, for a local type `MyEnum::MyVariant` triggers this case. - expr_ctor_def_id - } else if in_ty_adt.did() == self.tcx.parent(self.tcx.parent(expr_ctor_def_id)) - { + // For a typical enum like + // `enum Blah<T> { Variant(T) }` + // we get the following resolutions: + // - expr_ctor_def_id ::: DefId(0:29 ~ source_file[b442]::Blah::Variant::{constructor#0}) + // - self.tcx.parent(expr_ctor_def_id) ::: DefId(0:28 ~ source_file[b442]::Blah::Variant) + // - self.tcx.parent(self.tcx.parent(expr_ctor_def_id)) ::: DefId(0:26 ~ source_file[b442]::Blah) + + // Therefore, we need to go up once to obtain the variant and up twice to obtain the type. + // Note that this pattern still holds even when we `use` a variant or `use` an enum type to rename it, or chain `use` expressions + // together; this resolution is handled automatically by `qpath_res`. + + // FIXME: Deal with type aliases? + if in_ty_adt.did() == self.tcx.parent(self.tcx.parent(expr_ctor_def_id)) { // The constructor definition refers to the "constructor" of the variant: // For example, `Some(5)` triggers this case. self.tcx.parent(expr_ctor_def_id) |
