Skip to content

Commit c74f7a3

Browse files
address comments, add test for shadowed Box type
1 parent de04c05 commit c74f7a3

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -2305,7 +2305,7 @@ pub fn recursive_type_with_infinite_size_error<'tcx>(
23052305
path,
23062306
);
23072307
if spans.len() <= 4 {
2308-
// FIXME: This suggestion might be erroneous if Option or Box are shadowed
2308+
// FIXME(compiler-errors): This suggestion might be erroneous if Box is shadowed
23092309
err.multipart_suggestion(
23102310
&msg,
23112311
spans
@@ -2356,14 +2356,10 @@ fn get_option_generic_from_field_id(tcx: TyCtxt<'_>, field_id: Option<hir::HirId
23562356
}
23572357

23582358
// Match a single generic arg in the 0th path segment
2359-
let generic_arg = path.segments.get(0)?.args?.args.get(0);
2359+
let generic_arg = path.segments.last()?.args?.args.get(0)?;
23602360

23612361
// Take the span out of the type, if it's a type
2362-
if let Some(hir::GenericArg::Type(generic_ty)) = generic_arg {
2363-
Some(generic_ty.span)
2364-
} else {
2365-
None
2366-
}
2362+
if let hir::GenericArg::Type(generic_ty) = generic_arg { Some(generic_ty.span) } else { None }
23672363
}
23682364

23692365
/// Summarizes information
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//FIXME(compiler-errors): This fixup should suggest the full box path, not just `Box`
2+
3+
struct Box<T> {
4+
t: T,
5+
}
6+
7+
struct Foo {
8+
//~^ ERROR recursive type `Foo` has infinite size
9+
inner: Foo,
10+
}
11+
12+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0072]: recursive type `Foo` has infinite size
2+
--> $DIR/type-recursive-box-shadowed.rs:7:1
3+
|
4+
LL | struct Foo {
5+
| ^^^^^^^^^^ recursive type has infinite size
6+
LL |
7+
LL | inner: Foo,
8+
| --- recursive without indirection
9+
|
10+
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `Foo` representable
11+
|
12+
LL | inner: Box<Foo>,
13+
| ++++ +
14+
15+
error: aborting due to previous error
16+
17+
For more information about this error, try `rustc --explain E0072`.

0 commit comments

Comments
 (0)