Skip to content

Commit

Permalink
Rollup merge of rust-lang#88782 - asquared31415:issue-79559, r=cjgillot
Browse files Browse the repository at this point in the history
Fix ICE when `start` lang item has wrong generics

In my previous pr rust-lang#87875 I missed the requirements on the `start` lang item due to its relative difficulty to test and opting for more conservative estimates.  This fixes that by updating the requirement to be exactly one generic type.

The `start` lang item should have exactly one generic type for the return type of the `main` fn ptr passed to it.  I believe having zero would previously *sometimes* compile (often with the use of `fn() -> ()` as the fn ptr but it was likely UB to call if the return type of `main` was not `()` as far as I know) however it also sometimes would not for various errors including ICEs and LLVM errors depending on exact situations.  Having more than 1 generic has always failed with an ICE because only the one generic type is expected and provided.

Fixes rust-lang#79559, fixes rust-lang#73584, fixes rust-lang#83117 (all duplicates)
Relevant to rust-lang#9307

r? ````@cjgillot````
  • Loading branch information
Manishearth committed Oct 1, 2021
2 parents 23d5457 + 87ba8d2 commit 730d86f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions tests/ui/def_id_nocore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ pub trait Copy {}
pub unsafe trait Freeze {}

#[lang = "start"]
#[start]
fn start(_argc: isize, _argv: *const *const u8) -> isize {
fn start<T>(_main: fn() -> T, _argc: isize, _argv: *const *const u8) -> isize {
0
}

fn main() {}

struct A;

impl A {
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/def_id_nocore.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: methods called `as_*` usually take `self` by reference or `self` by mutable reference
--> $DIR/def_id_nocore.rs:26:19
--> $DIR/def_id_nocore.rs:27:19
|
LL | pub fn as_ref(self) -> &'static str {
| ^^^^
Expand Down

0 comments on commit 730d86f

Please sign in to comment.