Skip to content

Commit 2fbc413

Browse files
author
Lukas Markeffsky
committed
cosmetic changes
- change function parameter order to `cx, ty, ...` to match the other functions in this file - use `ct` identifier for `ty::Const` to match the majority of the compiler codebase - remove useless return - bring match arms in a more natural order
1 parent 67345f9 commit 2fbc413

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

Diff for: compiler/rustc_ty_utils/src/layout.rs

+22-18
Original file line numberDiff line numberDiff line change
@@ -141,25 +141,25 @@ fn univariant_uninterned<'tcx>(
141141
}
142142

143143
fn extract_const_value<'tcx>(
144-
const_: ty::Const<'tcx>,
145-
ty: Ty<'tcx>,
146144
cx: &LayoutCx<'tcx>,
145+
ty: Ty<'tcx>,
146+
ct: ty::Const<'tcx>,
147147
) -> Result<ty::Value<'tcx>, &'tcx LayoutError<'tcx>> {
148-
match const_.kind() {
148+
match ct.kind() {
149149
ty::ConstKind::Value(cv) => Ok(cv),
150150
ty::ConstKind::Param(_) | ty::ConstKind::Expr(_) | ty::ConstKind::Unevaluated(_) => {
151-
if !const_.has_param() {
152-
bug!("failed to normalize const, but it is not generic: {const_:?}");
151+
if !ct.has_param() {
152+
bug!("failed to normalize const, but it is not generic: {ct:?}");
153153
}
154-
return Err(error(cx, LayoutError::TooGeneric(ty)));
154+
Err(error(cx, LayoutError::TooGeneric(ty)))
155155
}
156156
ty::ConstKind::Infer(_)
157157
| ty::ConstKind::Bound(..)
158158
| ty::ConstKind::Placeholder(_)
159159
| ty::ConstKind::Error(_) => {
160160
// `ty::ConstKind::Error` is handled at the top of `layout_of_uncached`
161161
// (via `ty.error_reported()`).
162-
bug!("layout_of: unexpected const: {const_:?}");
162+
bug!("layout_of: unexpected const: {ct:?}");
163163
}
164164
}
165165
}
@@ -199,12 +199,12 @@ fn layout_of_uncached<'tcx>(
199199
&mut layout.backend_repr
200200
{
201201
if let Some(start) = start {
202-
scalar.valid_range_mut().start = extract_const_value(start, ty, cx)?
202+
scalar.valid_range_mut().start = extract_const_value(cx, ty, start)?
203203
.try_to_bits(tcx, cx.typing_env)
204204
.ok_or_else(|| error(cx, LayoutError::Unknown(ty)))?;
205205
}
206206
if let Some(end) = end {
207-
let mut end = extract_const_value(end, ty, cx)?
207+
let mut end = extract_const_value(cx, ty, end)?
208208
.try_to_bits(tcx, cx.typing_env)
209209
.ok_or_else(|| error(cx, LayoutError::Unknown(ty)))?;
210210
if !include_end {
@@ -338,7 +338,7 @@ fn layout_of_uncached<'tcx>(
338338

339339
// Arrays and slices.
340340
ty::Array(element, count) => {
341-
let count = extract_const_value(count, ty, cx)?
341+
let count = extract_const_value(cx, ty, count)?
342342
.try_to_target_usize(tcx)
343343
.ok_or_else(|| error(cx, LayoutError::Unknown(ty)))?;
344344

@@ -690,13 +690,21 @@ fn layout_of_uncached<'tcx>(
690690
}
691691

692692
// Types with no meaningful known layout.
693+
ty::Param(_) => {
694+
return Err(error(cx, LayoutError::TooGeneric(ty)));
695+
}
696+
693697
ty::Alias(..) => {
694-
if ty.has_param() {
695-
return Err(error(cx, LayoutError::TooGeneric(ty)));
696-
}
697698
// NOTE(eddyb) `layout_of` query should've normalized these away,
698699
// if that was possible, so there's no reason to try again here.
699-
return Err(error(cx, LayoutError::Unknown(ty)));
700+
let err = if ty.has_param() {
701+
LayoutError::TooGeneric(ty)
702+
} else {
703+
// This is only reachable with unsatisfiable predicates. For example, if we have
704+
// `u8: Iterator`, then we can't compute the layout of `<u8 as Iterator>::Item`.
705+
LayoutError::Unknown(ty)
706+
};
707+
return Err(error(cx, err));
700708
}
701709

702710
ty::Placeholder(..)
@@ -707,10 +715,6 @@ fn layout_of_uncached<'tcx>(
707715
// `ty::Error` is handled at the top of this function.
708716
bug!("layout_of: unexpected type `{ty}`")
709717
}
710-
711-
ty::Param(_) => {
712-
return Err(error(cx, LayoutError::TooGeneric(ty)));
713-
}
714718
})
715719
}
716720

0 commit comments

Comments
 (0)