Skip to content

Commit 8fd06e4

Browse files
Pass arg span to sized arg cause code
1 parent 92781ad commit 8fd06e4

File tree

6 files changed

+41
-31
lines changed

6 files changed

+41
-31
lines changed

compiler/rustc_typeck/src/check/expr.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -561,17 +561,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
561561
// We just want to check sizedness, so instead of introducing
562562
// placeholder lifetimes with probing, we just replace higher lifetimes
563563
// with fresh vars.
564-
let span = args.get(i).map(|a| a.span).unwrap_or(expr.span);
564+
let arg_span = args.get(i).map(|a| a.span);
565+
let span = arg_span.unwrap_or(expr.span);
565566
let input = self.replace_bound_vars_with_fresh_vars(
566567
span,
567568
infer::LateBoundRegionConversionTime::FnCall,
568569
fn_sig.input(i),
569570
);
570-
self.require_type_is_sized_deferred(
571-
input,
572-
span,
573-
traits::SizedArgumentType(None),
574-
);
571+
self.require_type_is_sized(input, span, traits::SizedArgumentType(arg_span));
575572
}
576573
}
577574
// Here we want to prevent struct constructors from returning unsized types.

src/test/ui/associated-types/associated-types-path-2.rs

-2
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,12 @@ pub fn f1_uint_uint() {
2929
f1(2u32, 4u32);
3030
//~^ ERROR `u32: Foo` is not satisfied
3131
//~| ERROR `u32: Foo` is not satisfied
32-
//~| ERROR `u32: Foo` is not satisfied
3332
}
3433

3534
pub fn f1_uint_int() {
3635
f1(2u32, 4i32);
3736
//~^ ERROR `u32: Foo` is not satisfied
3837
//~| ERROR `u32: Foo` is not satisfied
39-
//~| ERROR `u32: Foo` is not satisfied
4038
}
4139

4240
pub fn f2_int() {

src/test/ui/associated-types/associated-types-path-2.stderr

+14-20
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,21 @@ note: required by a bound in `f1`
3131
LL | pub fn f1<T: Foo>(a: T, x: T::A) {}
3232
| ^^^ required by this bound in `f1`
3333

34-
error[E0277]: the trait bound `u32: Foo` is not satisfied
35-
--> $DIR/associated-types-path-2.rs:29:5
36-
|
37-
LL | f1(2u32, 4u32);
38-
| ^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `u32`
39-
|
40-
= help: the trait `Foo` is implemented for `i32`
41-
4234
error[E0277]: the trait bound `u32: Foo` is not satisfied
4335
--> $DIR/associated-types-path-2.rs:29:14
4436
|
4537
LL | f1(2u32, 4u32);
4638
| ^^^^ the trait `Foo` is not implemented for `u32`
4739
|
4840
= help: the trait `Foo` is implemented for `i32`
41+
= help: unsized fn params are gated as an unstable feature
42+
help: function arguments must have a statically known size, borrowed types always have a known size
43+
|
44+
LL | f1(2u32, &4u32);
45+
| +
4946

5047
error[E0277]: the trait bound `u32: Foo` is not satisfied
51-
--> $DIR/associated-types-path-2.rs:36:8
48+
--> $DIR/associated-types-path-2.rs:35:8
5249
|
5350
LL | f1(2u32, 4i32);
5451
| -- ^^^^ the trait `Foo` is not implemented for `u32`
@@ -63,23 +60,20 @@ LL | pub fn f1<T: Foo>(a: T, x: T::A) {}
6360
| ^^^ required by this bound in `f1`
6461

6562
error[E0277]: the trait bound `u32: Foo` is not satisfied
66-
--> $DIR/associated-types-path-2.rs:36:5
67-
|
68-
LL | f1(2u32, 4i32);
69-
| ^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `u32`
70-
|
71-
= help: the trait `Foo` is implemented for `i32`
72-
73-
error[E0277]: the trait bound `u32: Foo` is not satisfied
74-
--> $DIR/associated-types-path-2.rs:36:14
63+
--> $DIR/associated-types-path-2.rs:35:14
7564
|
7665
LL | f1(2u32, 4i32);
7766
| ^^^^ the trait `Foo` is not implemented for `u32`
7867
|
7968
= help: the trait `Foo` is implemented for `i32`
69+
= help: unsized fn params are gated as an unstable feature
70+
help: function arguments must have a statically known size, borrowed types always have a known size
71+
|
72+
LL | f1(2u32, &4i32);
73+
| +
8074

8175
error[E0308]: mismatched types
82-
--> $DIR/associated-types-path-2.rs:43:18
76+
--> $DIR/associated-types-path-2.rs:41:18
8377
|
8478
LL | let _: i32 = f2(2i32);
8579
| --- ^^^^^^^^ expected `i32`, found `u32`
@@ -91,7 +85,7 @@ help: you can convert a `u32` to an `i32` and panic if the converted value doesn
9185
LL | let _: i32 = f2(2i32).try_into().unwrap();
9286
| ++++++++++++++++++++
9387

94-
error: aborting due to 8 previous errors
88+
error: aborting due to 6 previous errors
9589

9690
Some errors have detailed explanations: E0277, E0308.
9791
For more information about an error, try `rustc --explain E0277`.

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@ LL | foo(*x);
1818
| ^^ doesn't have a size known at compile-time
1919
|
2020
= help: the trait `Sized` is not implemented for `(dyn Foo + 'static)`
21-
= note: all function arguments must have a statically known size
2221
= help: unsized fn params are gated as an unstable feature
22+
help: function arguments must have a statically known size, borrowed types always have a known size
23+
|
24+
LL | foo(&*x);
25+
| +
2326

2427
error: aborting due to 2 previous errors
2528

src/test/ui/unsized/issue-30355.rs

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ pub static Y: &'static X = {
44
const Y: &'static [u8] = b"";
55
&X(*Y)
66
//~^ ERROR E0277
7+
//~| ERROR E0277
78
};
89

910
fn main() {}

src/test/ui/unsized/issue-30355.stderr

+19-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,26 @@ LL | &X(*Y)
55
| ^^ doesn't have a size known at compile-time
66
|
77
= help: the trait `Sized` is not implemented for `[u8]`
8-
= note: all function arguments must have a statically known size
98
= help: unsized fn params are gated as an unstable feature
9+
help: function arguments must have a statically known size, borrowed types always have a known size
10+
|
11+
LL | &X(&*Y)
12+
| +
13+
14+
error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
15+
--> $DIR/issue-30355.rs:5:6
16+
|
17+
LL | &X(*Y)
18+
| ^ doesn't have a size known at compile-time
19+
|
20+
= help: within `X`, the trait `Sized` is not implemented for `[u8]`
21+
note: required because it appears within the type `X`
22+
--> $DIR/issue-30355.rs:1:12
23+
|
24+
LL | pub struct X([u8]);
25+
| ^
26+
= note: the return type of a function must have a statically known size
1027

11-
error: aborting due to previous error
28+
error: aborting due to 2 previous errors
1229

1330
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)