Skip to content

Commit 62acf7f

Browse files
committed
feedback
1 parent f980f81 commit 62acf7f

File tree

6 files changed

+19
-18
lines changed

6 files changed

+19
-18
lines changed

compiler/rustc_typeck/src/check/check.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -371,14 +371,12 @@ fn check_union_fields(tcx: TyCtxt<'_>, span: Span, item_def_id: LocalDefId) -> b
371371
let param_env = tcx.param_env(item_def_id);
372372
for field in fields {
373373
let field_ty = field.ty(tcx, substs);
374-
let (field_span, ty_span) =
375-
// We are currently checking the type this field came from, so it must be local.
376-
if let Node::Field(field) = tcx.hir().get_if_local(field.did).unwrap() {
377-
(field.span, field.ty.span)
378-
} else {
379-
unreachable!("mir field has to correspond to hir field");
380-
};
381374
if field_ty.needs_drop(tcx, param_env) {
375+
let (field_span, ty_span) = match tcx.hir().get_if_local(field.did) {
376+
// We are currently checking the type this field came from, so it must be local.
377+
Some(Node::Field(field)) => (field.span, field.ty.span),
378+
_ => unreachable!("mir field has to correspond to hir field"),
379+
};
382380
struct_span_err!(
383381
tcx.sess,
384382
field_span,
@@ -387,7 +385,10 @@ fn check_union_fields(tcx: TyCtxt<'_>, span: Span, item_def_id: LocalDefId) -> b
387385
)
388386
.multipart_suggestion_verbose(
389387
"wrap the type with `std::mem::ManuallyDrop` and ensure it is manually dropped",
390-
vec![(ty_span, format!("std::mem::ManuallyDrop<{}>", field_ty))],
388+
vec![
389+
(ty_span.shrink_to_lo(), format!("std::mem::ManuallyDrop<")),
390+
(ty_span.shrink_to_hi(), ">".into()),
391+
],
391392
Applicability::MaybeIncorrect,
392393
)
393394
.emit();

src/test/ui/feature-gates/feature-gate-untagged_unions.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ LL | a: String,
1616
help: wrap the type with `std::mem::ManuallyDrop` and ensure it is manually dropped
1717
|
1818
LL | a: std::mem::ManuallyDrop<String>,
19-
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
19+
| +++++++++++++++++++++++ +
2020

2121
error[E0740]: unions may not contain fields that need dropping
2222
--> $DIR/feature-gate-untagged_unions.rs:24:5
@@ -27,7 +27,7 @@ LL | a: T,
2727
help: wrap the type with `std::mem::ManuallyDrop` and ensure it is manually dropped
2828
|
2929
LL | a: std::mem::ManuallyDrop<T>,
30-
| ~~~~~~~~~~~~~~~~~~~~~~~~~
30+
| +++++++++++++++++++++++ +
3131

3232
error: aborting due to 3 previous errors
3333

src/test/ui/union/issue-41073.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | a: A,
77
help: wrap the type with `std::mem::ManuallyDrop` and ensure it is manually dropped
88
|
99
LL | a: std::mem::ManuallyDrop<A>,
10-
| ~~~~~~~~~~~~~~~~~~~~~~~~~
10+
| +++++++++++++++++++++++ +
1111

1212
error: aborting due to previous error
1313

src/test/ui/union/union-custom-drop.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | bar: Bar,
77
help: wrap the type with `std::mem::ManuallyDrop` and ensure it is manually dropped
88
|
99
LL | bar: std::mem::ManuallyDrop<Bar>,
10-
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~
10+
| +++++++++++++++++++++++ +
1111

1212
error: aborting due to previous error
1313

src/test/ui/union/union-with-drop-fields.mirunsafeck.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | a: String,
77
help: wrap the type with `std::mem::ManuallyDrop` and ensure it is manually dropped
88
|
99
LL | a: std::mem::ManuallyDrop<String>,
10-
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10+
| +++++++++++++++++++++++ +
1111

1212
error[E0740]: unions may not contain fields that need dropping
1313
--> $DIR/union-with-drop-fields.rs:19:5
@@ -18,7 +18,7 @@ LL | a: S,
1818
help: wrap the type with `std::mem::ManuallyDrop` and ensure it is manually dropped
1919
|
2020
LL | a: std::mem::ManuallyDrop<S>,
21-
| ~~~~~~~~~~~~~~~~~~~~~~~~~
21+
| +++++++++++++++++++++++ +
2222

2323
error[E0740]: unions may not contain fields that need dropping
2424
--> $DIR/union-with-drop-fields.rs:24:5
@@ -29,7 +29,7 @@ LL | a: T,
2929
help: wrap the type with `std::mem::ManuallyDrop` and ensure it is manually dropped
3030
|
3131
LL | a: std::mem::ManuallyDrop<T>,
32-
| ~~~~~~~~~~~~~~~~~~~~~~~~~
32+
| +++++++++++++++++++++++ +
3333

3434
error: aborting due to 3 previous errors
3535

src/test/ui/union/union-with-drop-fields.thirunsafeck.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | a: String,
77
help: wrap the type with `std::mem::ManuallyDrop` and ensure it is manually dropped
88
|
99
LL | a: std::mem::ManuallyDrop<String>,
10-
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10+
| +++++++++++++++++++++++ +
1111

1212
error[E0740]: unions may not contain fields that need dropping
1313
--> $DIR/union-with-drop-fields.rs:19:5
@@ -18,7 +18,7 @@ LL | a: S,
1818
help: wrap the type with `std::mem::ManuallyDrop` and ensure it is manually dropped
1919
|
2020
LL | a: std::mem::ManuallyDrop<S>,
21-
| ~~~~~~~~~~~~~~~~~~~~~~~~~
21+
| +++++++++++++++++++++++ +
2222

2323
error[E0740]: unions may not contain fields that need dropping
2424
--> $DIR/union-with-drop-fields.rs:24:5
@@ -29,7 +29,7 @@ LL | a: T,
2929
help: wrap the type with `std::mem::ManuallyDrop` and ensure it is manually dropped
3030
|
3131
LL | a: std::mem::ManuallyDrop<T>,
32-
| ~~~~~~~~~~~~~~~~~~~~~~~~~
32+
| +++++++++++++++++++++++ +
3333

3434
error: aborting due to 3 previous errors
3535

0 commit comments

Comments
 (0)