diff options
| author | bors <bors@rust-lang.org> | 2021-06-17 06:34:12 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-06-17 06:34:12 +0000 |
| commit | cb3c4ee7187b045683cb9b86135dbbb766471091 (patch) | |
| tree | 0228ef60b25278fbda7c1159daec94fc96fb963a /src | |
| parent | 50a407200b970d8a48e4e58de37c94df355f5472 (diff) | |
| parent | 7dccce07066ea58d7f8d1dd8462347e91e51c67a (diff) | |
| download | rust-cb3c4ee7187b045683cb9b86135dbbb766471091.tar.gz rust-cb3c4ee7187b045683cb9b86135dbbb766471091.zip | |
Auto merge of #86164 - FabianWolff:issue-86053, r=davidtwco
Handle C-variadic arguments properly when reporting region errors
This pull request fixes #86053. The issue is that for a C-variadic function
```rust
#![feature(c_variadic)]
unsafe extern "C" fn foo(_: (), ...) {}
```
`foo`'s signature will contain only the first parameter (and have `c_variadic` set to `true`), whereas its body has a second argument (a `hir::Pat` for the `...`).
The code for reporting region errors iterates over the body's parameters and tries to fetch the corresponding parameter from the signature; this causes an out-of-bounds ICE for the `...` (though not in the example above, because there are no region errors to report).
I have simply restricted the iteration over the body parameters to exclude `...`, which is fine because `...` cannot cause a region error.
Diffstat (limited to 'src')
| -rw-r--r-- | src/test/ui/c-variadic/issue-86053-1.rs | 12 | ||||
| -rw-r--r-- | src/test/ui/c-variadic/issue-86053-1.stderr | 101 | ||||
| -rw-r--r-- | src/test/ui/c-variadic/issue-86053-2.rs | 11 | ||||
| -rw-r--r-- | src/test/ui/c-variadic/issue-86053-2.stderr | 16 | ||||
| -rw-r--r-- | src/test/ui/mir/issue-83499-input-output-iteration-ice.rs | 2 | ||||
| -rw-r--r-- | src/test/ui/mir/issue-83499-input-output-iteration-ice.stderr | 2 | ||||
| -rw-r--r-- | src/test/ui/parser/variadic-ffi-semantic-restrictions.rs | 40 | ||||
| -rw-r--r-- | src/test/ui/parser/variadic-ffi-semantic-restrictions.stderr | 40 |
8 files changed, 182 insertions, 42 deletions
diff --git a/src/test/ui/c-variadic/issue-86053-1.rs b/src/test/ui/c-variadic/issue-86053-1.rs new file mode 100644 index 00000000000..b30548e19f9 --- /dev/null +++ b/src/test/ui/c-variadic/issue-86053-1.rs @@ -0,0 +1,12 @@ +// Regression test for the ICE described in issue #86053. +// error-pattern:unexpected `self` parameter in function +// error-pattern:`...` must be the last argument of a C-variadic function +// error-pattern:cannot find type `F` in this scope +// error-pattern:in type `&'a &'b usize`, reference has a longer lifetime than the data it references + +#![feature(c_variadic)] +#![crate_type="lib"] + +fn ordering4 < 'a , 'b > ( a : , self , self , self , + self , ... , self , self , ... ) where F : FnOnce ( & 'a & 'b usize ) { +} diff --git a/src/test/ui/c-variadic/issue-86053-1.stderr b/src/test/ui/c-variadic/issue-86053-1.stderr new file mode 100644 index 00000000000..ec7ee74aef2 --- /dev/null +++ b/src/test/ui/c-variadic/issue-86053-1.stderr @@ -0,0 +1,101 @@ +error: expected type, found `,` + --> $DIR/issue-86053-1.rs:10:47 + | +LL | fn ordering4 < 'a , 'b > ( a : , self , self , self , + | ^ expected type + +error: unexpected `self` parameter in function + --> $DIR/issue-86053-1.rs:10:51 + | +LL | fn ordering4 < 'a , 'b > ( a : , self , self , self , + | ^^^^ must be the first parameter of an associated function + +error: unexpected `self` parameter in function + --> $DIR/issue-86053-1.rs:10:58 + | +LL | fn ordering4 < 'a , 'b > ( a : , self , self , self , + | ^^^^ must be the first parameter of an associated function + +error: unexpected `self` parameter in function + --> $DIR/issue-86053-1.rs:10:67 + | +LL | fn ordering4 < 'a , 'b > ( a : , self , self , self , + | ^^^^ must be the first parameter of an associated function + +error: unexpected `self` parameter in function + --> $DIR/issue-86053-1.rs:11:5 + | +LL | self , ... , self , self , ... ) where F : FnOnce ( & 'a & 'b usize ) { + | ^^^^ must be the first parameter of an associated function + +error: unexpected `self` parameter in function + --> $DIR/issue-86053-1.rs:11:20 + | +LL | self , ... , self , self , ... ) where F : FnOnce ( & 'a & 'b usize ) { + | ^^^^ must be the first parameter of an associated function + +error: unexpected `self` parameter in function + --> $DIR/issue-86053-1.rs:11:29 + | +LL | self , ... , self , self , ... ) where F : FnOnce ( & 'a & 'b usize ) { + | ^^^^ must be the first parameter of an associated function + +error: `...` must be the last argument of a C-variadic function + --> $DIR/issue-86053-1.rs:11:12 + | +LL | self , ... , self , self , ... ) where F : FnOnce ( & 'a & 'b usize ) { + | ^^^^ + +error: only foreign or `unsafe extern "C"` functions may be C-variadic + --> $DIR/issue-86053-1.rs:11:12 + | +LL | self , ... , self , self , ... ) where F : FnOnce ( & 'a & 'b usize ) { + | ^^^^ + +error: only foreign or `unsafe extern "C"` functions may be C-variadic + --> $DIR/issue-86053-1.rs:11:36 + | +LL | self , ... , self , self , ... ) where F : FnOnce ( & 'a & 'b usize ) { + | ^^^^ + +error[E0412]: cannot find type `F` in this scope + --> $DIR/issue-86053-1.rs:11:48 + | +LL | self , ... , self , self , ... ) where F : FnOnce ( & 'a & 'b usize ) { + | ^ + | + ::: $SRC_DIR/core/src/ops/function.rs:LL:COL + | +LL | pub trait Fn<Args>: FnMut<Args> { + | ------------------------------- similarly named trait `Fn` defined here + | +help: a trait with a similar name exists + | +LL | self , ... , self , self , ... ) where Fn : FnOnce ( & 'a & 'b usize ) { + | ^^ +help: you might be missing a type parameter + | +LL | fn ordering4 < 'a , 'b, F > ( a : , self , self , self , + | ^^^ + +error[E0491]: in type `&'a &'b usize`, reference has a longer lifetime than the data it references + --> $DIR/issue-86053-1.rs:11:52 + | +LL | self , ... , self , self , ... ) where F : FnOnce ( & 'a & 'b usize ) { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: the pointer is valid for the lifetime `'a` as defined on the function body at 10:16 + --> $DIR/issue-86053-1.rs:10:16 + | +LL | fn ordering4 < 'a , 'b > ( a : , self , self , self , + | ^^ +note: but the referenced data is only valid for the lifetime `'b` as defined on the function body at 10:21 + --> $DIR/issue-86053-1.rs:10:21 + | +LL | fn ordering4 < 'a , 'b > ( a : , self , self , self , + | ^^ + +error: aborting due to 12 previous errors + +Some errors have detailed explanations: E0412, E0491. +For more information about an error, try `rustc --explain E0412`. diff --git a/src/test/ui/c-variadic/issue-86053-2.rs b/src/test/ui/c-variadic/issue-86053-2.rs new file mode 100644 index 00000000000..c545831f717 --- /dev/null +++ b/src/test/ui/c-variadic/issue-86053-2.rs @@ -0,0 +1,11 @@ +// Regression test for the ICE caused by the example in +// https://github.com/rust-lang/rust/issues/86053#issuecomment-855672258 + +#![feature(c_variadic)] + +trait H<T> {} + +unsafe extern "C" fn ordering4<'a, F: H<&'static &'a ()>>(_: (), ...) {} +//~^ ERROR: in type `&'static &'a ()`, reference has a longer lifetime than the data it references [E0491] + +fn main() {} diff --git a/src/test/ui/c-variadic/issue-86053-2.stderr b/src/test/ui/c-variadic/issue-86053-2.stderr new file mode 100644 index 00000000000..4fc5e6315e4 --- /dev/null +++ b/src/test/ui/c-variadic/issue-86053-2.stderr @@ -0,0 +1,16 @@ +error[E0491]: in type `&'static &'a ()`, reference has a longer lifetime than the data it references + --> $DIR/issue-86053-2.rs:8:39 + | +LL | unsafe extern "C" fn ordering4<'a, F: H<&'static &'a ()>>(_: (), ...) {} + | ^^^^^^^^^^^^^^^^^^ + | + = note: the pointer is valid for the static lifetime +note: but the referenced data is only valid for the lifetime `'a` as defined on the function body at 8:32 + --> $DIR/issue-86053-2.rs:8:32 + | +LL | unsafe extern "C" fn ordering4<'a, F: H<&'static &'a ()>>(_: (), ...) {} + | ^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0491`. diff --git a/src/test/ui/mir/issue-83499-input-output-iteration-ice.rs b/src/test/ui/mir/issue-83499-input-output-iteration-ice.rs index 4d404d015ec..0086d2ec18c 100644 --- a/src/test/ui/mir/issue-83499-input-output-iteration-ice.rs +++ b/src/test/ui/mir/issue-83499-input-output-iteration-ice.rs @@ -5,6 +5,6 @@ fn main() {} fn foo(_: Bar, ...) -> impl {} -//~^ ERROR only foreign or `unsafe extern "C" functions may be C-variadic +//~^ ERROR only foreign or `unsafe extern "C"` functions may be C-variadic //~| ERROR cannot find type `Bar` in this scope //~| ERROR at least one trait must be specified diff --git a/src/test/ui/mir/issue-83499-input-output-iteration-ice.stderr b/src/test/ui/mir/issue-83499-input-output-iteration-ice.stderr index eb172684899..4eb3adc8b4f 100644 --- a/src/test/ui/mir/issue-83499-input-output-iteration-ice.stderr +++ b/src/test/ui/mir/issue-83499-input-output-iteration-ice.stderr @@ -1,4 +1,4 @@ -error: only foreign or `unsafe extern "C" functions may be C-variadic +error: only foreign or `unsafe extern "C"` functions may be C-variadic --> $DIR/issue-83499-input-output-iteration-ice.rs:7:16 | LL | fn foo(_: Bar, ...) -> impl {} diff --git a/src/test/ui/parser/variadic-ffi-semantic-restrictions.rs b/src/test/ui/parser/variadic-ffi-semantic-restrictions.rs index fe993a6ee13..0b61e267da8 100644 --- a/src/test/ui/parser/variadic-ffi-semantic-restrictions.rs +++ b/src/test/ui/parser/variadic-ffi-semantic-restrictions.rs @@ -4,32 +4,32 @@ fn main() {} fn f1_1(x: isize, ...) {} -//~^ ERROR only foreign or `unsafe extern "C" functions may be C-variadic +//~^ ERROR only foreign or `unsafe extern "C"` functions may be C-variadic fn f1_2(...) {} -//~^ ERROR only foreign or `unsafe extern "C" functions may be C-variadic +//~^ ERROR only foreign or `unsafe extern "C"` functions may be C-variadic //~| ERROR C-variadic function must be declared with at least one named argument extern "C" fn f2_1(x: isize, ...) {} -//~^ ERROR only foreign or `unsafe extern "C" functions may be C-variadic +//~^ ERROR only foreign or `unsafe extern "C"` functions may be C-variadic extern "C" fn f2_2(...) {} -//~^ ERROR only foreign or `unsafe extern "C" functions may be C-variadic +//~^ ERROR only foreign or `unsafe extern "C"` functions may be C-variadic //~| ERROR C-variadic function must be declared with at least one named argument extern "C" fn f2_3(..., x: isize) {} -//~^ ERROR only foreign or `unsafe extern "C" functions may be C-variadic +//~^ ERROR only foreign or `unsafe extern "C"` functions may be C-variadic //~| ERROR `...` must be the last argument of a C-variadic function extern "C" fn f3_1(x: isize, ...) {} -//~^ ERROR only foreign or `unsafe extern "C" functions may be C-variadic +//~^ ERROR only foreign or `unsafe extern "C"` functions may be C-variadic extern "C" fn f3_2(...) {} -//~^ ERROR only foreign or `unsafe extern "C" functions may be C-variadic +//~^ ERROR only foreign or `unsafe extern "C"` functions may be C-variadic //~| ERROR C-variadic function must be declared with at least one named argument extern "C" fn f3_3(..., x: isize) {} -//~^ ERROR only foreign or `unsafe extern "C" functions may be C-variadic +//~^ ERROR only foreign or `unsafe extern "C"` functions may be C-variadic //~| ERROR `...` must be the last argument of a C-variadic function extern "C" { @@ -43,35 +43,35 @@ struct X; impl X { fn i_f1(x: isize, ...) {} - //~^ ERROR only foreign or `unsafe extern "C" functions may be C-variadic + //~^ ERROR only foreign or `unsafe extern "C"` functions may be C-variadic fn i_f2(...) {} - //~^ ERROR only foreign or `unsafe extern "C" functions may be C-variadic + //~^ ERROR only foreign or `unsafe extern "C"` functions may be C-variadic //~| ERROR C-variadic function must be declared with at least one named argument fn i_f3(..., x: isize, ...) {} - //~^ ERROR only foreign or `unsafe extern "C" functions may be C-variadic - //~| ERROR only foreign or `unsafe extern "C" functions may be C-variadic + //~^ ERROR only foreign or `unsafe extern "C"` functions may be C-variadic + //~| ERROR only foreign or `unsafe extern "C"` functions may be C-variadic //~| ERROR `...` must be the last argument of a C-variadic function fn i_f4(..., x: isize, ...) {} - //~^ ERROR only foreign or `unsafe extern "C" functions may be C-variadic - //~| ERROR only foreign or `unsafe extern "C" functions may be C-variadic + //~^ ERROR only foreign or `unsafe extern "C"` functions may be C-variadic + //~| ERROR only foreign or `unsafe extern "C"` functions may be C-variadic //~| ERROR `...` must be the last argument of a C-variadic function } trait T { fn t_f1(x: isize, ...) {} - //~^ ERROR only foreign or `unsafe extern "C" functions may be C-variadic + //~^ ERROR only foreign or `unsafe extern "C"` functions may be C-variadic fn t_f2(x: isize, ...); - //~^ ERROR only foreign or `unsafe extern "C" functions may be C-variadic + //~^ ERROR only foreign or `unsafe extern "C"` functions may be C-variadic fn t_f3(...) {} - //~^ ERROR only foreign or `unsafe extern "C" functions may be C-variadic + //~^ ERROR only foreign or `unsafe extern "C"` functions may be C-variadic //~| ERROR C-variadic function must be declared with at least one named argument fn t_f4(...); - //~^ ERROR only foreign or `unsafe extern "C" functions may be C-variadic + //~^ ERROR only foreign or `unsafe extern "C"` functions may be C-variadic //~| ERROR C-variadic function must be declared with at least one named argument fn t_f5(..., x: isize) {} - //~^ ERROR only foreign or `unsafe extern "C" functions may be C-variadic + //~^ ERROR only foreign or `unsafe extern "C"` functions may be C-variadic //~| ERROR `...` must be the last argument of a C-variadic function fn t_f6(..., x: isize); - //~^ ERROR only foreign or `unsafe extern "C" functions may be C-variadic + //~^ ERROR only foreign or `unsafe extern "C"` functions may be C-variadic //~| ERROR `...` must be the last argument of a C-variadic function } diff --git a/src/test/ui/parser/variadic-ffi-semantic-restrictions.stderr b/src/test/ui/parser/variadic-ffi-semantic-restrictions.stderr index 10fd05c0bef..f1cbbb279c8 100644 --- a/src/test/ui/parser/variadic-ffi-semantic-restrictions.stderr +++ b/src/test/ui/parser/variadic-ffi-semantic-restrictions.stderr @@ -1,4 +1,4 @@ -error: only foreign or `unsafe extern "C" functions may be C-variadic +error: only foreign or `unsafe extern "C"` functions may be C-variadic --> $DIR/variadic-ffi-semantic-restrictions.rs:6:19 | LL | fn f1_1(x: isize, ...) {} @@ -10,13 +10,13 @@ error: C-variadic function must be declared with at least one named argument LL | fn f1_2(...) {} | ^^^ -error: only foreign or `unsafe extern "C" functions may be C-variadic +error: only foreign or `unsafe extern "C"` functions may be C-variadic --> $DIR/variadic-ffi-semantic-restrictions.rs:9:9 | LL | fn f1_2(...) {} | ^^^ -error: only foreign or `unsafe extern "C" functions may be C-variadic +error: only foreign or `unsafe extern "C"` functions may be C-variadic --> $DIR/variadic-ffi-semantic-restrictions.rs:13:30 | LL | extern "C" fn f2_1(x: isize, ...) {} @@ -28,7 +28,7 @@ error: C-variadic function must be declared with at least one named argument LL | extern "C" fn f2_2(...) {} | ^^^ -error: only foreign or `unsafe extern "C" functions may be C-variadic +error: only foreign or `unsafe extern "C"` functions may be C-variadic --> $DIR/variadic-ffi-semantic-restrictions.rs:16:20 | LL | extern "C" fn f2_2(...) {} @@ -40,13 +40,13 @@ error: `...` must be the last argument of a C-variadic function LL | extern "C" fn f2_3(..., x: isize) {} | ^^^ -error: only foreign or `unsafe extern "C" functions may be C-variadic +error: only foreign or `unsafe extern "C"` functions may be C-variadic --> $DIR/variadic-ffi-semantic-restrictions.rs:20:20 | LL | extern "C" fn f2_3(..., x: isize) {} | ^^^ -error: only foreign or `unsafe extern "C" functions may be C-variadic +error: only foreign or `unsafe extern "C"` functions may be C-variadic --> $DIR/variadic-ffi-semantic-restrictions.rs:24:30 | LL | extern "C" fn f3_1(x: isize, ...) {} @@ -58,7 +58,7 @@ error: C-variadic function must be declared with at least one named argument LL | extern "C" fn f3_2(...) {} | ^^^ -error: only foreign or `unsafe extern "C" functions may be C-variadic +error: only foreign or `unsafe extern "C"` functions may be C-variadic --> $DIR/variadic-ffi-semantic-restrictions.rs:27:20 | LL | extern "C" fn f3_2(...) {} @@ -70,7 +70,7 @@ error: `...` must be the last argument of a C-variadic function LL | extern "C" fn f3_3(..., x: isize) {} | ^^^ -error: only foreign or `unsafe extern "C" functions may be C-variadic +error: only foreign or `unsafe extern "C"` functions may be C-variadic --> $DIR/variadic-ffi-semantic-restrictions.rs:31:20 | LL | extern "C" fn f3_3(..., x: isize) {} @@ -88,7 +88,7 @@ error: `...` must be the last argument of a C-variadic function LL | fn e_f2(..., x: isize); | ^^^ -error: only foreign or `unsafe extern "C" functions may be C-variadic +error: only foreign or `unsafe extern "C"` functions may be C-variadic --> $DIR/variadic-ffi-semantic-restrictions.rs:45:23 | LL | fn i_f1(x: isize, ...) {} @@ -100,7 +100,7 @@ error: C-variadic function must be declared with at least one named argument LL | fn i_f2(...) {} | ^^^ -error: only foreign or `unsafe extern "C" functions may be C-variadic +error: only foreign or `unsafe extern "C"` functions may be C-variadic --> $DIR/variadic-ffi-semantic-restrictions.rs:47:13 | LL | fn i_f2(...) {} @@ -112,13 +112,13 @@ error: `...` must be the last argument of a C-variadic function LL | fn i_f3(..., x: isize, ...) {} | ^^^ -error: only foreign or `unsafe extern "C" functions may be C-variadic +error: only foreign or `unsafe extern "C"` functions may be C-variadic --> $DIR/variadic-ffi-semantic-restrictions.rs:50:13 | LL | fn i_f3(..., x: isize, ...) {} | ^^^ -error: only foreign or `unsafe extern "C" functions may be C-variadic +error: only foreign or `unsafe extern "C"` functions may be C-variadic --> $DIR/variadic-ffi-semantic-restrictions.rs:50:28 | LL | fn i_f3(..., x: isize, ...) {} @@ -130,25 +130,25 @@ error: `...` must be the last argument of a C-variadic function LL | fn i_f4(..., x: isize, ...) {} | ^^^ -error: only foreign or `unsafe extern "C" functions may be C-variadic +error: only foreign or `unsafe extern "C"` functions may be C-variadic --> $DIR/variadic-ffi-semantic-restrictions.rs:54:13 | LL | fn i_f4(..., x: isize, ...) {} | ^^^ -error: only foreign or `unsafe extern "C" functions may be C-variadic +error: only foreign or `unsafe extern "C"` functions may be C-variadic --> $DIR/variadic-ffi-semantic-restrictions.rs:54:28 | LL | fn i_f4(..., x: isize, ...) {} | ^^^ -error: only foreign or `unsafe extern "C" functions may be C-variadic +error: only foreign or `unsafe extern "C"` functions may be C-variadic --> $DIR/variadic-ffi-semantic-restrictions.rs:61:23 | LL | fn t_f1(x: isize, ...) {} | ^^^ -error: only foreign or `unsafe extern "C" functions may be C-variadic +error: only foreign or `unsafe extern "C"` functions may be C-variadic --> $DIR/variadic-ffi-semantic-restrictions.rs:63:23 | LL | fn t_f2(x: isize, ...); @@ -160,7 +160,7 @@ error: C-variadic function must be declared with at least one named argument LL | fn t_f3(...) {} | ^^^ -error: only foreign or `unsafe extern "C" functions may be C-variadic +error: only foreign or `unsafe extern "C"` functions may be C-variadic --> $DIR/variadic-ffi-semantic-restrictions.rs:65:13 | LL | fn t_f3(...) {} @@ -172,7 +172,7 @@ error: C-variadic function must be declared with at least one named argument LL | fn t_f4(...); | ^^^ -error: only foreign or `unsafe extern "C" functions may be C-variadic +error: only foreign or `unsafe extern "C"` functions may be C-variadic --> $DIR/variadic-ffi-semantic-restrictions.rs:68:13 | LL | fn t_f4(...); @@ -184,7 +184,7 @@ error: `...` must be the last argument of a C-variadic function LL | fn t_f5(..., x: isize) {} | ^^^ -error: only foreign or `unsafe extern "C" functions may be C-variadic +error: only foreign or `unsafe extern "C"` functions may be C-variadic --> $DIR/variadic-ffi-semantic-restrictions.rs:71:13 | LL | fn t_f5(..., x: isize) {} @@ -196,7 +196,7 @@ error: `...` must be the last argument of a C-variadic function LL | fn t_f6(..., x: isize); | ^^^ -error: only foreign or `unsafe extern "C" functions may be C-variadic +error: only foreign or `unsafe extern "C"` functions may be C-variadic --> $DIR/variadic-ffi-semantic-restrictions.rs:74:13 | LL | fn t_f6(..., x: isize); |
