-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
10 changed files
with
217 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.