Skip to content

Commit 3a22be9

Browse files
committed
Improve lint to check substs
1 parent 0c49893 commit 3a22be9

File tree

1 file changed

+17
-4
lines changed
  • src/librustc_typeck/check

1 file changed

+17
-4
lines changed

src/librustc_typeck/check/mod.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,21 +1149,34 @@ fn typeck_tables_of_with_fallback<'tcx>(
11491149

11501150
if let ty::FnDef(_, substs) = ty.kind {
11511151
debug!("Got substs: {:?}", substs);
1152-
let mut inhabited = true;
1152+
let mut args_inhabited = true;
1153+
let mut substs_inhabited = true;
1154+
11531155
for arg in &*path.args.unwrap() {
11541156
let resolved_arg = fcx.infcx.resolve_vars_if_possible(arg);
11551157

11561158
if resolved_arg.conservative_is_privately_uninhabited(tcx) {
11571159
debug!("Arg is uninhabited: {:?}", resolved_arg);
1158-
inhabited = false;
1160+
args_inhabited = false;
11591161
break;
11601162
} else {
11611163
debug!("Arg is inhabited: {:?}", resolved_arg);
11621164
}
11631165
}
11641166

1165-
if inhabited {
1166-
debug!("All arguments are inhabited!");
1167+
for subst_ty in substs.types() {
1168+
let resolved_subst = fcx.infcx.resolve_vars_if_possible(&subst_ty);
1169+
if resolved_subst.conservative_is_privately_uninhabited(tcx) {
1170+
debug!("Subst is uninhabited: {:?}", resolved_subst);
1171+
substs_inhabited = false;
1172+
break;
1173+
} else {
1174+
debug!("Subst is inhabited: {:?}", resolved_subst);
1175+
}
1176+
}
1177+
1178+
if args_inhabited && !substs_inhabited {
1179+
debug!("All arguments are inhabited, at least one subst is not inhabited!");
11671180
fcx.tcx()
11681181
.sess
11691182
.struct_span_warn(

0 commit comments

Comments
 (0)