Skip to content

Commit 92e3a35

Browse files
alexregJohnHeitmann
authored andcommitted
Changed resolution of enum variants to low priority.
1 parent 2445f43 commit 92e3a35

File tree

3 files changed

+53
-48
lines changed

3 files changed

+53
-48
lines changed

src/librustc_typeck/astconv.rs

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

12931293
self.prohibit_generics(slice::from_ref(item_segment));
12941294

1295-
// Check if we have an enum variant here.
1296-
match ty.sty {
1297-
ty::Adt(adt_def, _) if adt_def.is_enum() => {
1298-
let variant_def = adt_def.variants.iter().find(|vd| {
1299-
tcx.hygienic_eq(assoc_name, vd.ident, adt_def.did)
1300-
});
1301-
if let Some(variant_def) = variant_def {
1302-
check_type_alias_enum_variants_enabled(tcx, span);
1303-
1304-
let def = Def::Variant(variant_def.did);
1305-
tcx.check_stability(def.def_id(), Some(ref_id), span);
1306-
return (ty, def);
1307-
}
1308-
},
1309-
_ => (),
1310-
}
1311-
13121295
// Find the type of the associated item, and the trait where the associated
13131296
// item is declared.
13141297
let bound = match (&ty.sty, ty_path_def) {
13151298
(_, Def::SelfTy(Some(_), Some(impl_def_id))) => {
1316-
// `Self` in an impl of a trait -- we have a concrete `self` type and a
1299+
// `Self` in an impl of a trait -- we have a concrete self type and a
13171300
// trait reference.
13181301
let trait_ref = match tcx.impl_trait_ref(impl_def_id) {
13191302
Some(trait_ref) => trait_ref,
@@ -1365,6 +1348,23 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
13651348
return (tcx.types.err, Def::Err);
13661349
}
13671350
_ => {
1351+
// Check if we have an enum variant.
1352+
match ty.sty {
1353+
ty::Adt(adt_def, _) if adt_def.is_enum() => {
1354+
let variant_def = adt_def.variants.iter().find(|vd| {
1355+
tcx.hygienic_eq(assoc_name, vd.ident, adt_def.did)
1356+
});
1357+
if let Some(variant_def) = variant_def {
1358+
check_type_alias_enum_variants_enabled(tcx, span);
1359+
1360+
let def = Def::Variant(variant_def.did);
1361+
tcx.check_stability(def.def_id(), Some(ref_id), span);
1362+
return (ty, def);
1363+
}
1364+
},
1365+
_ => (),
1366+
}
1367+
13681368
// Don't print `TyErr` to the user.
13691369
if !ty.references_error() {
13701370
self.report_ambiguous_associated_type(span,

src/librustc_typeck/check/method/mod.rs

+33-28
Original file line numberDiff line numberDiff line change
@@ -371,38 +371,43 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
371371

372372
let tcx = self.tcx;
373373

374-
// Check if we have an enum variant here.
375-
match self_ty.sty {
376-
ty::Adt(adt_def, _) if adt_def.is_enum() => {
377-
let variant_def = adt_def.variants.iter().find(|vd| {
378-
tcx.hygienic_eq(method_name, vd.ident, adt_def.did)
379-
});
380-
if let Some(variant_def) = variant_def {
381-
check_type_alias_enum_variants_enabled(tcx, span);
382-
383-
let def = Def::VariantCtor(variant_def.did, variant_def.ctor_kind);
384-
tcx.check_stability(def.def_id(), Some(expr_id), span);
385-
return Ok(def);
374+
let mode = probe::Mode::Path;
375+
match self.probe_for_name(span, mode, method_name, IsSuggestion(false),
376+
self_ty, expr_id, ProbeScope::TraitsInScope) {
377+
Ok(pick) => {
378+
if let Some(import_id) = pick.import_id {
379+
let import_def_id = tcx.hir().local_def_id(import_id);
380+
debug!("resolve_ufcs: used_trait_import: {:?}", import_def_id);
381+
Lrc::get_mut(&mut self.tables.borrow_mut().used_trait_imports)
382+
.unwrap().insert(import_def_id);
386383
}
387-
},
388-
_ => (),
389-
}
390384

391-
let mode = probe::Mode::Path;
392-
let pick = self.probe_for_name(span, mode, method_name, IsSuggestion(false),
393-
self_ty, expr_id, ProbeScope::TraitsInScope)?;
385+
let def = pick.item.def();
386+
tcx.check_stability(def.def_id(), Some(expr_id), span);
394387

395-
if let Some(import_id) = pick.import_id {
396-
let import_def_id = tcx.hir().local_def_id(import_id);
397-
debug!("resolve_ufcs: used_trait_import: {:?}", import_def_id);
398-
Lrc::get_mut(&mut self.tables.borrow_mut().used_trait_imports)
399-
.unwrap().insert(import_def_id);
400-
}
401-
402-
let def = pick.item.def();
403-
tcx.check_stability(def.def_id(), Some(expr_id), span);
388+
Ok(def)
389+
}
390+
Err(err) => {
391+
// Check if we have an enum variant.
392+
match self_ty.sty {
393+
ty::Adt(adt_def, _) if adt_def.is_enum() => {
394+
let variant_def = adt_def.variants.iter().find(|vd| {
395+
tcx.hygienic_eq(method_name, vd.ident, adt_def.did)
396+
});
397+
if let Some(variant_def) = variant_def {
398+
check_type_alias_enum_variants_enabled(tcx, span);
399+
400+
let def = Def::VariantCtor(variant_def.did, variant_def.ctor_kind);
401+
tcx.check_stability(def.def_id(), Some(expr_id), span);
402+
return Ok(def);
403+
}
404+
},
405+
_ => (),
406+
}
404407

405-
Ok(def)
408+
Err(err)
409+
}
410+
}
406411
}
407412

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

src/test/ui/bogus-tag.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error[E0599]: no variant named `Hsl` found for type `Color` in the current scope
2-
--> $DIR/bogus-tag.rs:7:9
2+
--> $DIR/bogus-tag.rs:7:16
33
|
44
LL | enum Color { Rgb(isize, isize, isize), Rgba(isize, isize, isize, isize), }
55
| ---------- variant `Hsl` not found here
66
...
77
LL | Color::Hsl(h, s, l) => { println!("hsl"); }
8-
| ^^^^^^^^^^^^^^^^^^^ variant not found in `Color`
8+
| -------^^^--------- variant not found in `Color`
99

1010
error: aborting due to previous error
1111

0 commit comments

Comments
 (0)