Skip to content

Commit d159e6c

Browse files
committed
Tweak Sized obligation spans on fn argument impl Trait
Remove now unnecessary span label.
1 parent cacc00f commit d159e6c

File tree

2 files changed

+5
-10
lines changed

2 files changed

+5
-10
lines changed

compiler/rustc_middle/src/ty/diagnostics.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,9 @@ pub fn suggest_constraining_type_params<'a>(
266266
constraints.extract_if(|(_, def_id)| *def_id == tcx.lang_items().sized_trait());
267267
if let Some((_, def_id)) = sized_constraints.next() {
268268
applicability = Applicability::MaybeIncorrect;
269-
270-
err.span_label(param.span, "this type parameter needs to be `Sized`");
269+
if !param.name.ident().as_str().starts_with("impl ") {
270+
err.span_label(param.span, "this type parameter needs to be `Sized`");
271+
}
271272
suggest_changing_unsized_bound(generics, &mut suggestions, param, def_id);
272273
}
273274
}

tests/ui/trait-bounds/apit-unsized.stderr

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ error[E0277]: the size for values of type `impl Iterator<Item = i32> + ?Sized` c
22
--> $DIR/apit-unsized.rs:1:11
33
|
44
LL | fn foo(_: impl Iterator<Item = i32> + ?Sized) {}
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6-
| |
7-
| doesn't have a size known at compile-time
8-
| this type parameter needs to be `Sized`
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
96
|
107
= help: unsized fn params are gated as an unstable feature
118
help: consider removing the `?Sized` bound to make the type parameter `Sized`
@@ -22,10 +19,7 @@ error[E0277]: the size for values of type `impl ?Sized` cannot be known at compi
2219
--> $DIR/apit-unsized.rs:2:11
2320
|
2421
LL | fn bar(_: impl ?Sized) {}
25-
| ^^^^^^^^^^^
26-
| |
27-
| doesn't have a size known at compile-time
28-
| this type parameter needs to be `Sized`
22+
| ^^^^^^^^^^^ doesn't have a size known at compile-time
2923
|
3024
= help: unsized fn params are gated as an unstable feature
3125
help: consider replacing `?Sized` with `Sized`

0 commit comments

Comments
 (0)