Skip to content

Commit c7d171d

Browse files
committed
On implicit Sized bound on fn argument, point at type instead of pattern
Instead of ``` error[E0277]: the size for values of type `(dyn ThriftService<(), AssocType = _> + 'static)` cannot be known at compilation time --> $DIR/issue-59324.rs:23:20 | LL | fn with_factory<H>(factory: dyn ThriftService<()>) {} | ^^^^^^^ doesn't have a size known at compile-time ``` output ``` error[E0277]: the size for values of type `(dyn ThriftService<(), AssocType = _> + 'static)` cannot be known at compilation time --> $DIR/issue-59324.rs:23:29 | LL | fn with_factory<H>(factory: dyn ThriftService<()>) {} | ^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time ```
1 parent 648d024 commit c7d171d

31 files changed

+110
-104
lines changed

compiler/rustc_hir_typeck/src/check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ pub(super) fn check_fn<'a, 'tcx>(
9999
if !params_can_be_unsized {
100100
fcx.require_type_is_sized(
101101
param_ty,
102-
param.pat.span,
102+
param.ty_span,
103103
// ty.span == binding_span iff this is a closure parameter with no type ascription,
104104
// or if it's an implicit `self` parameter
105105
ObligationCauseCode::SizedArgumentType(

compiler/rustc_hir_typeck/src/gather_locals.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ impl<'a, 'tcx> Visitor<'tcx> for GatherLocalsVisitor<'a, 'tcx> {
144144
if !self.fcx.tcx.features().unsized_fn_params {
145145
self.fcx.require_type_is_sized(
146146
var_ty,
147-
p.span,
147+
ty_span,
148148
// ty_span == ident.span iff this is a closure parameter with no type
149149
// ascription, or if it's an implicit `self` parameter
150150
ObligationCauseCode::SizedArgumentType(

src/tools/clippy/tests/ui/crashes/ice-6251.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
2-
--> tests/ui/crashes/ice-6251.rs:4:45
2+
--> tests/ui/crashes/ice-6251.rs:4:48
33
|
44
LL | fn bug<T>() -> impl Iterator<Item = [(); { |x: [u8]| x }]> {
5-
| ^ doesn't have a size known at compile-time
5+
| ^^^^ doesn't have a size known at compile-time
66
|
77
= help: the trait `std::marker::Sized` is not implemented for `[u8]`
88
= help: unsized fn params are gated as an unstable feature

tests/ui/associated-types/issue-59324.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ LL | pub trait Foo: NotFoo {
7979
| ^^^^^^^^^^^^^^^^^^^^^
8080

8181
error[E0277]: the size for values of type `(dyn ThriftService<(), AssocType = _> + 'static)` cannot be known at compilation time
82-
--> $DIR/issue-59324.rs:23:20
82+
--> $DIR/issue-59324.rs:23:29
8383
|
8484
LL | fn with_factory<H>(factory: dyn ThriftService<()>) {}
85-
| ^^^^^^^ doesn't have a size known at compile-time
85+
| ^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
8686
|
8787
= help: the trait `Sized` is not implemented for `(dyn ThriftService<(), AssocType = _> + 'static)`
8888
= help: unsized fn params are gated as an unstable feature

tests/ui/coherence/occurs-check/opaques.next.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ LL | impl<T> Trait<T> for defining_scope::Alias<T> {
88
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation
99

1010
error[E0282]: type annotations needed
11-
--> $DIR/opaques.rs:13:20
11+
--> $DIR/opaques.rs:13:23
1212
|
1313
LL | pub fn cast<T>(x: Container<Alias<T>, T>) -> Container<T, T> {
14-
| ^ cannot infer type
14+
| ^^^^^^^^^^^^^^^^^^^^^^ cannot infer type
1515

1616
error: aborting due to 2 previous errors
1717

tests/ui/did_you_mean/replace-impl-infer-ty-from-trait.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ LL | fn bar(i: i32, t: usize, s: &()) -> (usize, i32) {
1414
| ~~~ ~~~~~ ~~~ ~~~~~~~~~~~~
1515

1616
error[E0282]: type annotations needed
17-
--> $DIR/replace-impl-infer-ty-from-trait.rs:9:12
17+
--> $DIR/replace-impl-infer-ty-from-trait.rs:9:15
1818
|
1919
LL | fn bar(i: _, t: _, s: _) -> _ {
20-
| ^ cannot infer type
20+
| ^ cannot infer type
2121

2222
error: aborting due to 2 previous errors
2323

tests/ui/error-codes/E0277.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
2-
--> $DIR/E0277.rs:11:6
2+
--> $DIR/E0277.rs:11:9
33
|
44
LL | fn f(p: Path) { }
5-
| ^ doesn't have a size known at compile-time
5+
| ^^^^ doesn't have a size known at compile-time
66
|
77
= help: within `Path`, the trait `Sized` is not implemented for `[u8]`, which is required by `Path: Sized`
88
note: required because it appears within the type `Path`

tests/ui/feature-gates/feature-gate-unsized_fn_params.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0277]: the size for values of type `(dyn Foo + 'static)` cannot be known at compilation time
2-
--> $DIR/feature-gate-unsized_fn_params.rs:17:8
2+
--> $DIR/feature-gate-unsized_fn_params.rs:17:11
33
|
44
LL | fn foo(x: dyn Foo) {
5-
| ^ doesn't have a size known at compile-time
5+
| ^^^^^^^ doesn't have a size known at compile-time
66
|
77
= help: the trait `Sized` is not implemented for `(dyn Foo + 'static)`
88
= help: unsized fn params are gated as an unstable feature
@@ -16,10 +16,10 @@ LL | fn foo(x: &dyn Foo) {
1616
| +
1717

1818
error[E0277]: the size for values of type `(dyn Foo + 'static)` cannot be known at compilation time
19-
--> $DIR/feature-gate-unsized_fn_params.rs:21:8
19+
--> $DIR/feature-gate-unsized_fn_params.rs:21:11
2020
|
2121
LL | fn bar(x: Foo) {
22-
| ^ doesn't have a size known at compile-time
22+
| ^^^ doesn't have a size known at compile-time
2323
|
2424
= help: the trait `Sized` is not implemented for `(dyn Foo + 'static)`
2525
= help: unsized fn params are gated as an unstable feature
@@ -33,10 +33,10 @@ LL | fn bar(x: &dyn Foo) {
3333
| ++++
3434

3535
error[E0277]: the size for values of type `[()]` cannot be known at compilation time
36-
--> $DIR/feature-gate-unsized_fn_params.rs:25:8
36+
--> $DIR/feature-gate-unsized_fn_params.rs:25:11
3737
|
3838
LL | fn qux(_: [()]) {}
39-
| ^ doesn't have a size known at compile-time
39+
| ^^^^ doesn't have a size known at compile-time
4040
|
4141
= help: the trait `Sized` is not implemented for `[()]`
4242
= help: unsized fn params are gated as an unstable feature

tests/ui/feature-gates/feature-gate-unsized_locals.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0277]: the size for values of type `(dyn FnOnce() + 'static)` cannot be known at compilation time
2-
--> $DIR/feature-gate-unsized_locals.rs:1:6
2+
--> $DIR/feature-gate-unsized_locals.rs:1:9
33
|
44
LL | fn f(f: dyn FnOnce()) {}
5-
| ^ doesn't have a size known at compile-time
5+
| ^^^^^^^^^^^^ doesn't have a size known at compile-time
66
|
77
= help: the trait `Sized` is not implemented for `(dyn FnOnce() + 'static)`
88
= help: unsized fn params are gated as an unstable feature

tests/ui/inference/ice-ifer-var-leaked-out-of-rollback-122098.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ LL | struct Query<'q> {}
3636
= help: consider removing `'q`, referring to it in a field, or using a marker such as `PhantomData`
3737

3838
error[E0277]: the size for values of type `Self` cannot be known at compilation time
39-
--> $DIR/ice-ifer-var-leaked-out-of-rollback-122098.rs:7:17
39+
--> $DIR/ice-ifer-var-leaked-out-of-rollback-122098.rs:7:21
4040
|
4141
LL | fn for_each(mut self, mut f: Box<dyn FnMut(Self::Item<'_>) + 'static>) {}
42-
| ^^^^^^^^ doesn't have a size known at compile-time
42+
| ^^^^ doesn't have a size known at compile-time
4343
|
4444
= help: unsized fn params are gated as an unstable feature
4545
help: consider further restricting `Self`

0 commit comments

Comments
 (0)