Fix error spans for arguments to tuple enum constructors
This commit is contained in:
parent
2566b4105d
commit
f0212e6532
3 changed files with 371 additions and 11 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue