address comments, add test for shadowed Box type

This commit is contained in:
Michael Goulet 2022-02-17 19:49:45 -08:00
parent de04c05dea
commit c74f7a310f
3 changed files with 32 additions and 7 deletions

View File

@ -2305,7 +2305,7 @@ pub fn recursive_type_with_infinite_size_error<'tcx>(
path,
);
if spans.len() <= 4 {
// FIXME: This suggestion might be erroneous if Option or Box are shadowed
// FIXME(compiler-errors): This suggestion might be erroneous if Box is shadowed
err.multipart_suggestion(
&msg,
spans
@ -2356,14 +2356,10 @@ fn get_option_generic_from_field_id(tcx: TyCtxt<'_>, field_id: Option<hir::HirId
}
// Match a single generic arg in the 0th path segment
let generic_arg = path.segments.get(0)?.args?.args.get(0);
let generic_arg = path.segments.last()?.args?.args.get(0)?;
// Take the span out of the type, if it's a type
if let Some(hir::GenericArg::Type(generic_ty)) = generic_arg {
Some(generic_ty.span)
} else {
None
}
if let hir::GenericArg::Type(generic_ty) = generic_arg { Some(generic_ty.span) } else { None }
}
/// Summarizes information

View File

@ -0,0 +1,12 @@
//FIXME(compiler-errors): This fixup should suggest the full box path, not just `Box`
struct Box<T> {
t: T,
}
struct Foo {
//~^ ERROR recursive type `Foo` has infinite size
inner: Foo,
}
fn main() {}

View File

@ -0,0 +1,17 @@
error[E0072]: recursive type `Foo` has infinite size
--> $DIR/type-recursive-box-shadowed.rs:7:1
|
LL | struct Foo {
| ^^^^^^^^^^ recursive type has infinite size
LL |
LL | inner: Foo,
| --- recursive without indirection
|
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `Foo` representable
|
LL | inner: Box<Foo>,
| ++++ +
error: aborting due to previous error
For more information about this error, try `rustc --explain E0072`.