diff options
author | Alexander Regueiro <alexreg@me.com> | 2018-12-26 16:38:35 +0000 |
---|---|---|
committer | Alexander Regueiro <alexreg@me.com> | 2018-12-26 21:56:47 +0000 |
commit | 5adf8c358ad70f9a50536a0bd47f938cb0aaea18 (patch) | |
tree | 2f44bec55577a5b88b36d0b57a4899629638ea2e | |
parent | ab239f37aaade0764ee1ace12828d2f766600296 (diff) | |
download | rust-5adf8c358ad70f9a50536a0bd47f938cb0aaea18.tar.gz |
Changed resolution of enum variants to low priority.
-rw-r--r-- | src/librustc_typeck/astconv.rs | 36 | ||||
-rw-r--r-- | src/librustc_typeck/check/method/mod.rs | 61 | ||||
-rw-r--r-- | src/test/ui/bogus-tag.stderr | 4 |
3 files changed, 53 insertions, 48 deletions
diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 80583a58558..1db7141917f 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -1292,28 +1292,11 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o { self.prohibit_generics(slice::from_ref(item_segment)); - // Check if we have an enum variant here. - match ty.sty { - ty::Adt(adt_def, _) if adt_def.is_enum() => { - let variant_def = adt_def.variants.iter().find(|vd| { - tcx.hygienic_eq(assoc_name, vd.ident, adt_def.did) - }); - if let Some(variant_def) = variant_def { - check_type_alias_enum_variants_enabled(tcx, span); - - let def = Def::Variant(variant_def.did); - tcx.check_stability(def.def_id(), Some(ref_id), span); - return (ty, def); - } - }, - _ => (), - } - // Find the type of the associated item, and the trait where the associated // item is declared. let bound = match (&ty.sty, ty_path_def) { (_, Def::SelfTy(Some(_), Some(impl_def_id))) => { - // `Self` in an impl of a trait -- we have a concrete `self` type and a + // `Self` in an impl of a trait -- we have a concrete self type and a // trait reference. let trait_ref = match tcx.impl_trait_ref(impl_def_id) { Some(trait_ref) => trait_ref, @@ -1365,6 +1348,23 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o { return (tcx.types.err, Def::Err); } _ => { + // Check if we have an enum variant. + match ty.sty { + ty::Adt(adt_def, _) if adt_def.is_enum() => { + let variant_def = adt_def.variants.iter().find(|vd| { + tcx.hygienic_eq(assoc_name, vd.ident, adt_def.did) + }); + if let Some(variant_def) = variant_def { + check_type_alias_enum_variants_enabled(tcx, span); + + let def = Def::Variant(variant_def.did); + tcx.check_stability(def.def_id(), Some(ref_id), span); + return (ty, def); + } + }, + _ => (), + } + // Don't print `TyErr` to the user. if !ty.references_error() { self.report_ambiguous_associated_type(span, diff --git a/src/librustc_typeck/check/method/mod.rs b/src/librustc_typeck/check/method/mod.rs index a039835b88f..fe5f43e3c01 100644 --- a/src/librustc_typeck/check/method/mod.rs +++ b/src/librustc_typeck/check/method/mod.rs @@ -371,38 +371,43 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { let tcx = self.tcx; - // Check if we have an enum variant here. - match self_ty.sty { - ty::Adt(adt_def, _) 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); + let mode = probe::Mode::Path; + match self.probe_for_name(span, mode, method_name, IsSuggestion(false), + self_ty, expr_id, ProbeScope::TraitsInScope) { + Ok(pick) => { + if let Some(import_id) = pick.import_id { + let import_def_id = tcx.hir().local_def_id(import_id); + debug!("resolve_ufcs: used_trait_import: {:?}", import_def_id); + Lrc::get_mut(&mut self.tables.borrow_mut().used_trait_imports) + .unwrap().insert(import_def_id); } - }, - _ => (), - } - let mode = probe::Mode::Path; - let pick = self.probe_for_name(span, mode, method_name, IsSuggestion(false), - self_ty, expr_id, ProbeScope::TraitsInScope)?; + let def = pick.item.def(); + tcx.check_stability(def.def_id(), Some(expr_id), span); - if let Some(import_id) = pick.import_id { - let import_def_id = tcx.hir().local_def_id(import_id); - debug!("resolve_ufcs: used_trait_import: {:?}", import_def_id); - Lrc::get_mut(&mut self.tables.borrow_mut().used_trait_imports) - .unwrap().insert(import_def_id); - } - - let def = pick.item.def(); - tcx.check_stability(def.def_id(), Some(expr_id), span); + Ok(def) + } + Err(err) => { + // Check if we have an enum variant. + match self_ty.sty { + ty::Adt(adt_def, _) 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); + } + }, + _ => (), + } - Ok(def) + Err(err) + } + } } /// Find item with name `item_name` defined in impl/trait `def_id` diff --git a/src/test/ui/bogus-tag.stderr b/src/test/ui/bogus-tag.stderr index 1cb5ee9b630..3750df84172 100644 --- a/src/test/ui/bogus-tag.stderr +++ b/src/test/ui/bogus-tag.stderr @@ -1,11 +1,11 @@ error[E0599]: no variant named `Hsl` found for type `Color` in the current scope - --> $DIR/bogus-tag.rs:7:9 + --> $DIR/bogus-tag.rs:7:16 | LL | enum Color { Rgb(isize, isize, isize), Rgba(isize, isize, isize, isize), } | ---------- variant `Hsl` not found here ... LL | Color::Hsl(h, s, l) => { println!("hsl"); } - | ^^^^^^^^^^^^^^^^^^^ variant not found in `Color` + | -------^^^--------- variant not found in `Color` error: aborting due to previous error |