diff options
| author | clubby789 <jamie@hill-daniel.co.uk> | 2023-06-02 00:41:02 +0000 |
|---|---|---|
| committer | clubby789 <jamie@hill-daniel.co.uk> | 2023-06-02 01:18:59 +0000 |
| commit | 731601ccd1617a9ca4b1fe09fdb5906c2019110b (patch) | |
| tree | 57b2ca1344249aab4ac2db54d27d2bd4b665acbf /compiler | |
| parent | d59363ad0b6391b7fc5bbb02c9ccf9300eef3753 (diff) | |
| download | rust-731601ccd1617a9ca4b1fe09fdb5906c2019110b.tar.gz rust-731601ccd1617a9ca4b1fe09fdb5906c2019110b.zip | |
Check tuple elements are `Sized` in `offset_of`
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_hir_typeck/src/expr.rs | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/compiler/rustc_hir_typeck/src/expr.rs b/compiler/rustc_hir_typeck/src/expr.rs index 19ff77d8349..5e10add013b 100644 --- a/compiler/rustc_hir_typeck/src/expr.rs +++ b/compiler/rustc_hir_typeck/src/expr.rs @@ -3117,16 +3117,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } } ty::Tuple(tys) => { - let fstr = field.as_str(); - - if let Ok(index) = fstr.parse::<usize>() { - if fstr == index.to_string() { - if let Some(&field_ty) = tys.get(index) { - field_indices.push(index.into()); - current_container = field_ty; + if let Ok(index) = field.as_str().parse::<usize>() + && field.name == sym::integer(index) + { + for ty in tys.iter().take(index + 1) { + self.require_type_is_sized(ty, expr.span, traits::MiscObligation); + } + if let Some(&field_ty) = tys.get(index) { + field_indices.push(index.into()); + current_container = field_ty; - continue; - } + continue; } } } |
