diff options
| author | Michael Goulet <michael@errs.io> | 2022-02-17 19:49:45 -0800 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2022-03-31 08:04:53 -0700 |
| commit | c74f7a310fe8fcf9a2edf927cee0bc15a3abe399 (patch) | |
| tree | 5bf9cf232039b32c8bb2aec695fe7fa73fce4657 | |
| parent | de04c05dea10fc03cb626338ce1d55f4c90f58b0 (diff) | |
address comments, add test for shadowed Box type
3 files changed, 32 insertions, 7 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs index 53acffc5098..d83781170e8 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -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 diff --git a/src/test/ui/type/type-recursive-box-shadowed.rs b/src/test/ui/type/type-recursive-box-shadowed.rs new file mode 100644 index 00000000000..e141c2149ff --- /dev/null +++ b/src/test/ui/type/type-recursive-box-shadowed.rs @@ -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() {} diff --git a/src/test/ui/type/type-recursive-box-shadowed.stderr b/src/test/ui/type/type-recursive-box-shadowed.stderr new file mode 100644 index 00000000000..c22d848f379 --- /dev/null +++ b/src/test/ui/type/type-recursive-box-shadowed.stderr @@ -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`. |
