Skip to content

Commit b522ba0

Browse files
committed
review comments
1 parent 542be6f commit b522ba0

File tree

1 file changed

+34
-16
lines changed
  • src/librustc/infer/error_reporting

1 file changed

+34
-16
lines changed

src/librustc/infer/error_reporting/mod.rs

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,10 +1303,39 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
13031303
_ => {}
13041304
}
13051305

1306+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1307+
enum TyKind {
1308+
Closure,
1309+
Opaque,
1310+
Generator,
1311+
Foreign,
1312+
}
1313+
1314+
impl TyKind {
1315+
fn descr(&self) -> &'static str {
1316+
match self {
1317+
Self::Closure => "closure",
1318+
Self::Opaque => "opaque type",
1319+
Self::Generator => "generator",
1320+
Self::Foreign => "foreign type",
1321+
}
1322+
}
1323+
1324+
fn from_ty(ty: Ty<'_>) -> Option<(Self, DefId)> {
1325+
match ty.kind {
1326+
ty::Closure(def_id, _) => Some((Self::Closure, def_id)),
1327+
ty::Opaque(def_id, _) => Some((Self::Opaque, def_id)),
1328+
ty::Generator(def_id, ..) => Some((Self::Generator, def_id)),
1329+
ty::Foreign(def_id) => Some((Self::Foreign, def_id)),
1330+
_ => None,
1331+
}
1332+
}
1333+
}
1334+
13061335
struct OpaqueTypesVisitor<'tcx> {
1307-
types: FxHashMap<&'static str, FxHashSet<Span>>,
1308-
expected: FxHashMap<&'static str, FxHashSet<Span>>,
1309-
found: FxHashMap<&'static str, FxHashSet<Span>>,
1336+
types: FxHashMap<TyKind, FxHashSet<Span>>,
1337+
expected: FxHashMap<TyKind, FxHashSet<Span>>,
1338+
found: FxHashMap<TyKind, FxHashSet<Span>>,
13101339
ignore_span: Span,
13111340
tcx: TyCtxt<'tcx>,
13121341
}
@@ -1350,7 +1379,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
13501379
},
13511380
if count > 1 { "one of the " } else { "" },
13521381
target,
1353-
key,
1382+
key.descr(),
13541383
pluralize!(count),
13551384
),
13561385
);
@@ -1362,18 +1391,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
13621391

13631392
impl<'tcx> ty::fold::TypeVisitor<'tcx> for OpaqueTypesVisitor<'tcx> {
13641393
fn visit_ty(&mut self, t: Ty<'tcx>) -> bool {
1365-
let kind = match t.kind {
1366-
ty::Closure(..) => "closure",
1367-
ty::Opaque(..) => "opaque type",
1368-
ty::Generator(..) => "generator",
1369-
ty::Foreign(..) => "foreign type",
1370-
_ => "",
1371-
};
1372-
if let ty::Closure(def_id, _)
1373-
| ty::Opaque(def_id, _)
1374-
| ty::Generator(def_id, ..)
1375-
| ty::Foreign(def_id) = t.kind
1376-
{
1394+
if let Some((kind, def_id)) = TyKind::from_ty(t) {
13771395
let span = self.tcx.def_span(def_id);
13781396
// Avoid cluttering the output when the "found" and error span overlap:
13791397
//

0 commit comments

Comments
 (0)