Skip to content

Commit 906c9bc

Browse files
Rollup merge of rust-lang#42251 - nikomatsakis:issue-42210-regr-unsized-tail, r=eddyb
extend `struct_tail` to operate over tuples Not 100% sure why this got exposed when it wasn't before, but this struct definitely seems wrong. Fixes rust-lang#42110 r? @eddyb
2 parents 4e5812c + 9d01840 commit 906c9bc

File tree

2 files changed

+52
-7
lines changed

2 files changed

+52
-7
lines changed

src/librustc/ty/util.rs

+23-7
Original file line numberDiff line numberDiff line change
@@ -266,13 +266,29 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
266266
/// if not a structure at all. Corresponds to the only possible unsized
267267
/// field, and its type can be used to determine unsizing strategy.
268268
pub fn struct_tail(self, mut ty: Ty<'tcx>) -> Ty<'tcx> {
269-
while let TyAdt(def, substs) = ty.sty {
270-
if !def.is_struct() {
271-
break;
272-
}
273-
match def.struct_variant().fields.last() {
274-
Some(f) => ty = f.ty(self, substs),
275-
None => break,
269+
loop {
270+
match ty.sty {
271+
ty::TyAdt(def, substs) => {
272+
if !def.is_struct() {
273+
break;
274+
}
275+
match def.struct_variant().fields.last() {
276+
Some(f) => ty = f.ty(self, substs),
277+
None => break,
278+
}
279+
}
280+
281+
ty::TyTuple(tys, _) => {
282+
if let Some((&last_ty, _)) = tys.split_last() {
283+
ty = last_ty;
284+
} else {
285+
break;
286+
}
287+
}
288+
289+
_ => {
290+
break;
291+
}
276292
}
277293
}
278294
ty

src/test/run-pass/issue-42210.rs

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Regression test for #42210.
12+
13+
// compile-flags: -g
14+
15+
trait Foo {
16+
fn foo() { }
17+
}
18+
19+
struct Bar;
20+
21+
trait Baz {
22+
}
23+
24+
impl Foo for (Bar, Baz) { }
25+
26+
27+
fn main() {
28+
<(Bar, Baz) as Foo>::foo()
29+
}

0 commit comments

Comments
 (0)