Skip to content

Commit 797eff9

Browse files
committed
Revert "Changed resolution of enum variants to low priority."
This reverts commit 5adf8c3.
1 parent 6ecad33 commit 797eff9

File tree

2 files changed

+46
-53
lines changed

2 files changed

+46
-53
lines changed

src/librustc_typeck/astconv.rs

+18-18
Original file line numberDiff line numberDiff line change
@@ -1298,11 +1298,28 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
12981298

12991299
self.prohibit_generics(slice::from_ref(item_segment));
13001300

1301+
// Check if we have an enum variant here.
1302+
match ty.sty {
1303+
ty::Adt(adt_def, _) if adt_def.is_enum() => {
1304+
let variant_def = adt_def.variants.iter().find(|vd| {
1305+
tcx.hygienic_eq(assoc_name, vd.ident, adt_def.did)
1306+
});
1307+
if let Some(variant_def) = variant_def {
1308+
check_type_alias_enum_variants_enabled(tcx, span);
1309+
1310+
let def = Def::Variant(variant_def.did);
1311+
tcx.check_stability(def.def_id(), Some(ref_id), span);
1312+
return (ty, def);
1313+
}
1314+
},
1315+
_ => (),
1316+
}
1317+
13011318
// Find the type of the associated item, and the trait where the associated
13021319
// item is declared.
13031320
let bound = match (&ty.sty, ty_path_def) {
13041321
(_, Def::SelfTy(Some(_), Some(impl_def_id))) => {
1305-
// `Self` in an impl of a trait -- we have a concrete self type and a
1322+
// `Self` in an impl of a trait -- we have a concrete `self` type and a
13061323
// trait reference.
13071324
let trait_ref = match tcx.impl_trait_ref(impl_def_id) {
13081325
Some(trait_ref) => trait_ref,
@@ -1354,23 +1371,6 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
13541371
return (tcx.types.err, Def::Err);
13551372
}
13561373
_ => {
1357-
// Check if we have an enum variant.
1358-
match ty.sty {
1359-
ty::Adt(adt_def, _) if adt_def.is_enum() => {
1360-
let variant_def = adt_def.variants.iter().find(|vd| {
1361-
tcx.hygienic_eq(assoc_name, vd.ident, adt_def.did)
1362-
});
1363-
if let Some(variant_def) = variant_def {
1364-
check_type_alias_enum_variants_enabled(tcx, span);
1365-
1366-
let def = Def::Variant(variant_def.did);
1367-
tcx.check_stability(def.def_id(), Some(ref_id), span);
1368-
return (ty, def);
1369-
}
1370-
},
1371-
_ => (),
1372-
}
1373-
13741374
// Don't print `TyErr` to the user.
13751375
if !ty.references_error() {
13761376
self.report_ambiguous_associated_type(span,

src/librustc_typeck/check/method/mod.rs

+28-35
Original file line numberDiff line numberDiff line change
@@ -408,45 +408,38 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
408408

409409
let tcx = self.tcx;
410410

411-
let mode = probe::Mode::Path;
412-
match self.probe_for_name(span, mode, method_name, IsSuggestion(false),
413-
self_ty, expr_id, ProbeScope::TraitsInScope) {
414-
Ok(pick) => {
415-
debug!("resolve_ufcs: pick={:?}", pick);
416-
if let Some(import_id) = pick.import_id {
417-
let import_def_id = tcx.hir().local_def_id(import_id);
418-
debug!("resolve_ufcs: used_trait_import: {:?}", import_def_id);
419-
Lrc::get_mut(&mut self.tables.borrow_mut().used_trait_imports)
420-
.unwrap().insert(import_def_id);
411+
// Check if we have an enum variant here.
412+
match self_ty.sty {
413+
ty::Adt(adt_def, _) if adt_def.is_enum() => {
414+
let variant_def = adt_def.variants.iter().find(|vd| {
415+
tcx.hygienic_eq(method_name, vd.ident, adt_def.did)
416+
});
417+
if let Some(variant_def) = variant_def {
418+
check_type_alias_enum_variants_enabled(tcx, span);
419+
420+
let def = Def::VariantCtor(variant_def.did, variant_def.ctor_kind);
421+
tcx.check_stability(def.def_id(), Some(expr_id), span);
422+
return Ok(def);
421423
}
424+
},
425+
_ => (),
426+
}
422427

423-
let def = pick.item.def();
424-
debug!("resolve_ufcs: def={:?}", def);
425-
tcx.check_stability(def.def_id(), Some(expr_id), span);
426-
427-
Ok(def)
428-
}
429-
Err(err) => {
430-
// Check if we have an enum variant.
431-
match self_ty.sty {
432-
ty::Adt(adt_def, _) if adt_def.is_enum() => {
433-
let variant_def = adt_def.variants.iter().find(|vd| {
434-
tcx.hygienic_eq(method_name, vd.ident, adt_def.did)
435-
});
436-
if let Some(variant_def) = variant_def {
437-
check_type_alias_enum_variants_enabled(tcx, span);
438-
439-
let def = Def::VariantCtor(variant_def.did, variant_def.ctor_kind);
440-
tcx.check_stability(def.def_id(), Some(expr_id), span);
441-
return Ok(def);
442-
}
443-
},
444-
_ => (),
445-
}
428+
let mode = probe::Mode::Path;
429+
let pick = self.probe_for_name(span, mode, method_name, IsSuggestion(false),
430+
self_ty, expr_id, ProbeScope::TraitsInScope)?;
446431

447-
Err(err)
448-
}
432+
if let Some(import_id) = pick.import_id {
433+
let import_def_id = tcx.hir().local_def_id(import_id);
434+
debug!("resolve_ufcs: used_trait_import: {:?}", import_def_id);
435+
Lrc::get_mut(&mut self.tables.borrow_mut().used_trait_imports)
436+
.unwrap().insert(import_def_id);
449437
}
438+
439+
let def = pick.item.def();
440+
tcx.check_stability(def.def_id(), Some(expr_id), span);
441+
442+
Ok(def)
450443
}
451444

452445
/// Find item with name `item_name` defined in impl/trait `def_id`

0 commit comments

Comments
 (0)