Skip to content

Commit b690901

Browse files
committed
Suggest full enum variant for local modules
1 parent 9c10781 commit b690901

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

compiler/rustc_typeck/src/check/demand.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use rustc_hir::lang_items::LangItem;
1010
use rustc_hir::{is_range_literal, Node};
1111
use rustc_middle::lint::in_external_macro;
1212
use rustc_middle::ty::adjustment::AllowTwoPhase;
13+
use rustc_middle::ty::print::with_no_trimmed_paths;
1314
use rustc_middle::ty::{self, AssocItem, Ty, TypeAndMut};
1415
use rustc_span::symbol::sym;
1516
use rustc_span::Span;
@@ -201,7 +202,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
201202
let sole_field = &variant.fields[0];
202203
let sole_field_ty = sole_field.ty(self.tcx, substs);
203204
if self.can_coerce(expr_ty, sole_field_ty) {
204-
let variant_path = self.tcx.def_path_str(variant.def_id);
205+
let variant_path =
206+
with_no_trimmed_paths(|| self.tcx.def_path_str(variant.def_id));
205207
// FIXME #56861: DRYer prelude filtering
206208
if let Some(path) = variant_path.strip_prefix("std::prelude::") {
207209
if let Some((_, path)) = path.split_once("::") {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
mod option {
2+
pub enum O<T> {
3+
Some(T),
4+
None,
5+
}
6+
}
7+
8+
fn main() {
9+
let _: option::O<()> = (); //~ ERROR 9:28: 9:30: mismatched types [E0308]
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/suggest-full-enum-variant-for-local-module.rs:9:28
3+
|
4+
LL | let _: option::O<()> = ();
5+
| ------------- ^^
6+
| | |
7+
| | expected enum `O`, found `()`
8+
| | help: try using a variant of the expected enum: `option::O::Some(())`
9+
| expected due to this
10+
|
11+
= note: expected enum `O<()>`
12+
found unit type `()`
13+
14+
error: aborting due to previous error
15+
16+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)