mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-29 18:23:49 +00:00
address comments, add test for shadowed Box type
This commit is contained in:
parent
de04c05dea
commit
c74f7a310f
@ -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
|
||||
|
12
src/test/ui/type/type-recursive-box-shadowed.rs
Normal file
12
src/test/ui/type/type-recursive-box-shadowed.rs
Normal 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() {}
|
17
src/test/ui/type/type-recursive-box-shadowed.stderr
Normal file
17
src/test/ui/type/type-recursive-box-shadowed.stderr
Normal 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`.
|
Loading…
Reference in New Issue
Block a user