Skip to content

Commit 7951b3b

Browse files
Handle TooGeneric for expected ty
Signed-off-by: FedericoBruzzone <[email protected]>
1 parent 514360b commit 7951b3b

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

compiler/rustc_const_eval/src/const_eval/error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ where
140140
// Don't emit a new diagnostic for these errors, they are already reported elsewhere or
141141
// should remain silent.
142142
err_inval!(AlreadyReported(info)) => ErrorHandled::Reported(info, span),
143-
err_inval!(Layout(LayoutError::Unknown(_))) | err_inval!(TooGeneric) => {
143+
err_inval!(Layout(LayoutError::TooGeneric(_))) | err_inval!(TooGeneric) => {
144144
ErrorHandled::TooGeneric(span)
145145
}
146146
err_inval!(Layout(LayoutError::ReferencesError(guar))) => {

compiler/rustc_middle/src/ty/layout.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -356,12 +356,12 @@ impl<'tcx> SizeSkeleton<'tcx> {
356356
return Err(tcx.arena.alloc(LayoutError::Unknown(ty)));
357357
}
358358
}
359-
Err(err @ LayoutError::Unknown(_)) => err,
359+
Err(err @ LayoutError::TooGeneric(_)) => err,
360360
// We can't extract SizeSkeleton info from other layout errors
361361
Err(
362362
e @ LayoutError::Cycle(_)
363+
| e @ LayoutError::Unknown(_)
363364
| e @ LayoutError::SizeOverflow(_)
364-
| e @ LayoutError::TooGeneric(_)
365365
| e @ LayoutError::NormalizationFailure(..)
366366
| e @ LayoutError::ReferencesError(_),
367367
) => return Err(e),

compiler/rustc_ty_utils/src/layout.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,7 @@ fn map_error<'tcx>(
109109
"encountered unexpected unsized field in layout of {ty:?}: {field:#?}"
110110
));
111111
}
112-
if cx.tcx().features().trivial_bounds() {
113-
LayoutError::TooGeneric(ty)
114-
} else {
115-
LayoutError::Unknown(ty)
116-
}
112+
LayoutError::Unknown(ty)
117113
}
118114
LayoutCalculatorError::EmptyUnion => {
119115
// This is always a compile error.
@@ -327,7 +323,7 @@ fn layout_of_uncached<'tcx>(
327323

328324
let count = count
329325
.try_to_target_usize(tcx)
330-
.ok_or_else(|| error(cx, LayoutError::Unknown(ty)))?;
326+
.ok_or_else(|| error(cx, LayoutError::TooGeneric(ty)))?;
331327
let element = cx.layout_of(element)?;
332328
let size = element
333329
.size
@@ -677,6 +673,9 @@ fn layout_of_uncached<'tcx>(
677673

678674
// Types with no meaningful known layout.
679675
ty::Alias(..) => {
676+
if ty.has_param() {
677+
return Err(error(cx, LayoutError::TooGeneric(ty)));
678+
}
680679
// NOTE(eddyb) `layout_of` query should've normalized these away,
681680
// if that was possible, so there's no reason to try again here.
682681
return Err(error(cx, LayoutError::Unknown(ty)));
@@ -686,7 +685,11 @@ fn layout_of_uncached<'tcx>(
686685
bug!("Layout::compute: unexpected type `{}`", ty)
687686
}
688687

689-
ty::Placeholder(..) | ty::Param(_) => {
688+
ty::Param(_) => {
689+
return Err(error(cx, LayoutError::TooGeneric(ty)));
690+
}
691+
692+
ty::Placeholder(..) => {
690693
return Err(error(cx, LayoutError::Unknown(ty)));
691694
}
692695
})

0 commit comments

Comments
 (0)