Skip to content

Commit b463bd1

Browse files
Rollup merge of #130912 - estebank:point-at-arg-type, r=compiler-errors
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 ```
2 parents 6b0c897 + c7d171d commit b463bd1

31 files changed

+110
-104
lines changed

compiler/rustc_hir_typeck/src/check.rs

+1-1
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

+1-1
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

+2-2
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

+2-2
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

+2-2
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

+2-2
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

+2-2
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

+6-6
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

+2-2
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

+2-2
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`

tests/ui/issues/issue-38954.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0277]: the size for values of type `str` cannot be known at compilation time
2-
--> $DIR/issue-38954.rs:1:10
2+
--> $DIR/issue-38954.rs:1:18
33
|
44
LL | fn _test(ref _p: str) {}
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 `str`
88
= help: unsized fn params are gated as an unstable feature

tests/ui/issues/issue-41229-ref-str.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0277]: the size for values of type `str` cannot be known at compilation time
2-
--> $DIR/issue-41229-ref-str.rs:1:16
2+
--> $DIR/issue-41229-ref-str.rs:1:23
33
|
44
LL | pub fn example(ref s: str) {}
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 `str`
88
= help: unsized fn params are gated as an unstable feature

tests/ui/issues/issue-42312.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0277]: the size for values of type `<Self as Deref>::Target` cannot be known at compilation time
2-
--> $DIR/issue-42312.rs:4:12
2+
--> $DIR/issue-42312.rs:4:15
33
|
44
LL | fn baz(_: Self::Target) where Self: Deref {}
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 `<Self as Deref>::Target`
88
= help: unsized fn params are gated as an unstable feature
@@ -16,10 +16,10 @@ LL | fn baz(_: &Self::Target) where Self: Deref {}
1616
| +
1717

1818
error[E0277]: the size for values of type `(dyn ToString + 'static)` cannot be known at compilation time
19-
--> $DIR/issue-42312.rs:8:10
19+
--> $DIR/issue-42312.rs:8:13
2020
|
2121
LL | pub fn f(_: dyn ToString) {}
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 ToString + 'static)`
2525
= help: unsized fn params are gated as an unstable feature

tests/ui/issues/issue-5883.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0277]: the size for values of type `(dyn A + 'static)` cannot be known at compilation time
2-
--> $DIR/issue-5883.rs:8:5
2+
--> $DIR/issue-5883.rs:8:8
33
|
44
LL | r: dyn A + 'static
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 A + 'static)`
88
= help: unsized fn params are gated as an unstable feature

tests/ui/issues/issue-66706.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ LL | [0; match [|f @ &ref _| () ] {} ]
2929
| while parsing this `match` expression
3030

3131
error[E0282]: type annotations needed
32-
--> $DIR/issue-66706.rs:2:11
32+
--> $DIR/issue-66706.rs:2:14
3333
|
3434
LL | [0; [|_: _ &_| ()].len()]
35-
| ^ cannot infer type
35+
| ^ cannot infer type
3636

3737
error[E0282]: type annotations needed
3838
--> $DIR/issue-66706.rs:13:11

tests/ui/object-safety/avoid-ice-on-warning-2.new.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ LL | f()
1919
| call expression requires function
2020

2121
error[E0277]: the size for values of type `(dyn Copy + 'static)` cannot be known at compilation time
22-
--> $DIR/avoid-ice-on-warning-2.rs:4:10
22+
--> $DIR/avoid-ice-on-warning-2.rs:4:13
2323
|
2424
LL | fn id<F>(f: Copy) -> usize {
25-
| ^ doesn't have a size known at compile-time
25+
| ^^^^ doesn't have a size known at compile-time
2626
|
2727
= help: the trait `Sized` is not implemented for `(dyn Copy + 'static)`
2828
= help: unsized fn params are gated as an unstable feature

tests/ui/object-safety/avoid-ice-on-warning-2.old.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ LL | f()
4747
| call expression requires function
4848

4949
error[E0277]: the size for values of type `(dyn Copy + 'static)` cannot be known at compilation time
50-
--> $DIR/avoid-ice-on-warning-2.rs:4:10
50+
--> $DIR/avoid-ice-on-warning-2.rs:4:13
5151
|
5252
LL | fn id<F>(f: Copy) -> usize {
53-
| ^ doesn't have a size known at compile-time
53+
| ^^^^ doesn't have a size known at compile-time
5454
|
5555
= help: the trait `Sized` is not implemented for `(dyn Copy + 'static)`
5656
= help: unsized fn params are gated as an unstable feature

tests/ui/resolve/issue-3907-2.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ LL | fn bar();
1111
| ^^^ the trait cannot be made into an object because associated function `bar` has no `self` parameter
1212

1313
error[E0277]: the size for values of type `(dyn issue_3907::Foo + 'static)` cannot be known at compilation time
14-
--> $DIR/issue-3907-2.rs:11:8
14+
--> $DIR/issue-3907-2.rs:11:12
1515
|
1616
LL | fn bar(_x: Foo) {}
17-
| ^^ doesn't have a size known at compile-time
17+
| ^^^ doesn't have a size known at compile-time
1818
|
1919
= help: the trait `Sized` is not implemented for `(dyn issue_3907::Foo + 'static)`
2020
= help: unsized fn params are gated as an unstable feature

tests/ui/resolve/issue-5035-2.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0277]: the size for values of type `(dyn I + 'static)` cannot be known at compilation time
2-
--> $DIR/issue-5035-2.rs:4:8
2+
--> $DIR/issue-5035-2.rs:4:12
33
|
44
LL | fn foo(_x: K) {}
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 I + 'static)`
88
= help: unsized fn params are gated as an unstable feature

tests/ui/suggestions/object-unsafe-trait-references-self.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ LL | trait Other: Sized {}
3232
| this trait cannot be made into an object...
3333

3434
error[E0277]: the size for values of type `Self` cannot be known at compilation time
35-
--> $DIR/object-unsafe-trait-references-self.rs:2:19
35+
--> $DIR/object-unsafe-trait-references-self.rs:2:22
3636
|
3737
LL | fn baz(&self, _: Self) {}
38-
| ^ doesn't have a size known at compile-time
38+
| ^^^^ doesn't have a size known at compile-time
3939
|
4040
= help: unsized fn params are gated as an unstable feature
4141
help: consider further restricting `Self`

tests/ui/suggestions/path-by-value.stderr

+2-2
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/path-by-value.rs:3:6
2+
--> $DIR/path-by-value.rs:3: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/suggestions/unsized-function-parameter.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0277]: the size for values of type `str` cannot be known at compilation time
2-
--> $DIR/unsized-function-parameter.rs:5:9
2+
--> $DIR/unsized-function-parameter.rs:5:14
33
|
44
LL | fn foo1(bar: str) {}
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 `str`
88
= help: unsized fn params are gated as an unstable feature
@@ -12,10 +12,10 @@ LL | fn foo1(bar: &str) {}
1212
| +
1313

1414
error[E0277]: the size for values of type `str` cannot be known at compilation time
15-
--> $DIR/unsized-function-parameter.rs:11:9
15+
--> $DIR/unsized-function-parameter.rs:11:15
1616
|
1717
LL | fn foo2(_bar: str) {}
18-
| ^^^^ doesn't have a size known at compile-time
18+
| ^^^ doesn't have a size known at compile-time
1919
|
2020
= help: the trait `Sized` is not implemented for `str`
2121
= help: unsized fn params are gated as an unstable feature
@@ -25,10 +25,10 @@ LL | fn foo2(_bar: &str) {}
2525
| +
2626

2727
error[E0277]: the size for values of type `str` cannot be known at compilation time
28-
--> $DIR/unsized-function-parameter.rs:17:9
28+
--> $DIR/unsized-function-parameter.rs:17:12
2929
|
3030
LL | fn foo3(_: str) {}
31-
| ^ doesn't have a size known at compile-time
31+
| ^^^ doesn't have a size known at compile-time
3232
|
3333
= help: the trait `Sized` is not implemented for `str`
3434
= help: unsized fn params are gated as an unstable feature

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

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
error[E0277]: the size for values of type `impl Iterator<Item = i32> + ?Sized` cannot be known at compilation time
2-
--> $DIR/apit-unsized.rs:1:8
2+
--> $DIR/apit-unsized.rs:1:11
33
|
44
LL | fn foo(_: impl Iterator<Item = i32> + ?Sized) {}
5-
| ^ ---------------------------------- this type parameter needs to be `Sized`
6-
| |
7-
| doesn't have a size known at compile-time
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
| |
7+
| doesn't have a size known at compile-time
8+
| this type parameter needs to be `Sized`
89
|
910
= help: unsized fn params are gated as an unstable feature
1011
help: consider removing the `?Sized` bound to make the type parameter `Sized`
@@ -18,12 +19,13 @@ LL | fn foo(_: &impl Iterator<Item = i32> + ?Sized) {}
1819
| +
1920

2021
error[E0277]: the size for values of type `impl ?Sized` cannot be known at compilation time
21-
--> $DIR/apit-unsized.rs:2:8
22+
--> $DIR/apit-unsized.rs:2:11
2223
|
2324
LL | fn bar(_: impl ?Sized) {}
24-
| ^ ----------- this type parameter needs to be `Sized`
25-
| |
26-
| doesn't have a size known at compile-time
25+
| ^^^^^^^^^^^
26+
| |
27+
| doesn't have a size known at compile-time
28+
| this type parameter needs to be `Sized`
2729
|
2830
= help: unsized fn params are gated as an unstable feature
2931
help: consider replacing `?Sized` with `Sized`

0 commit comments

Comments
 (0)