From b69090102e409fd8139ab554fcd38e567fda470f Mon Sep 17 00:00:00 2001 From: Alik Aslanyan Date: Thu, 15 Jul 2021 16:34:45 +0400 Subject: [PATCH] Suggest full enum variant for local modules --- compiler/rustc_typeck/src/check/demand.rs | 4 +++- ...suggest-full-enum-variant-for-local-module.rs | 10 ++++++++++ ...est-full-enum-variant-for-local-module.stderr | 16 ++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/suggestions/suggest-full-enum-variant-for-local-module.rs create mode 100644 src/test/ui/suggestions/suggest-full-enum-variant-for-local-module.stderr diff --git a/compiler/rustc_typeck/src/check/demand.rs b/compiler/rustc_typeck/src/check/demand.rs index 33bc25accb319..3ea59906d3dcd 100644 --- a/compiler/rustc_typeck/src/check/demand.rs +++ b/compiler/rustc_typeck/src/check/demand.rs @@ -10,6 +10,7 @@ use rustc_hir::lang_items::LangItem; use rustc_hir::{is_range_literal, Node}; use rustc_middle::lint::in_external_macro; use rustc_middle::ty::adjustment::AllowTwoPhase; +use rustc_middle::ty::print::with_no_trimmed_paths; use rustc_middle::ty::{self, AssocItem, Ty, TypeAndMut}; use rustc_span::symbol::sym; use rustc_span::Span; @@ -201,7 +202,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let sole_field = &variant.fields[0]; let sole_field_ty = sole_field.ty(self.tcx, substs); if self.can_coerce(expr_ty, sole_field_ty) { - let variant_path = self.tcx.def_path_str(variant.def_id); + let variant_path = + with_no_trimmed_paths(|| self.tcx.def_path_str(variant.def_id)); // FIXME #56861: DRYer prelude filtering if let Some(path) = variant_path.strip_prefix("std::prelude::") { if let Some((_, path)) = path.split_once("::") { diff --git a/src/test/ui/suggestions/suggest-full-enum-variant-for-local-module.rs b/src/test/ui/suggestions/suggest-full-enum-variant-for-local-module.rs new file mode 100644 index 0000000000000..1dfc0786668f2 --- /dev/null +++ b/src/test/ui/suggestions/suggest-full-enum-variant-for-local-module.rs @@ -0,0 +1,10 @@ +mod option { + pub enum O { + Some(T), + None, + } +} + +fn main() { + let _: option::O<()> = (); //~ ERROR 9:28: 9:30: mismatched types [E0308] +} diff --git a/src/test/ui/suggestions/suggest-full-enum-variant-for-local-module.stderr b/src/test/ui/suggestions/suggest-full-enum-variant-for-local-module.stderr new file mode 100644 index 0000000000000..22a0ce1e91d72 --- /dev/null +++ b/src/test/ui/suggestions/suggest-full-enum-variant-for-local-module.stderr @@ -0,0 +1,16 @@ +error[E0308]: mismatched types + --> $DIR/suggest-full-enum-variant-for-local-module.rs:9:28 + | +LL | let _: option::O<()> = (); + | ------------- ^^ + | | | + | | expected enum `O`, found `()` + | | help: try using a variant of the expected enum: `option::O::Some(())` + | expected due to this + | + = note: expected enum `O<()>` + found unit type `()` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`.