-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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 #108138 - compiler-errors:malformed-fn-trait, r=TaKO8Ki
Move `Fn*` traits malformedness protections to typeck I found it strange that we were doing a custom well-formedness check just for the `Fn*` traits' `call_*` fn items. My understanding from the git history is that this is just to avoid ICEs later on in typeck. Well, that well-formedness check isn't even implemented correctly for `FnOnce::call_once`, or `FnMut::call_mut` for that matter. Instead, this PR just makes the typeck checks more robust, and leaves it up to the call-site to report errors when lang items are implemented in funny ways. This coincidentally fixes another ICE where a the `Add` lang item is implemented with a `add` item that's a const instead of a method.
- Loading branch information
Showing
16 changed files
with
221 additions
and
74 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
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,18 @@ | ||
#![feature(no_core)] | ||
#![feature(lang_items)] | ||
#![no_core] | ||
|
||
#[lang = "sized"] | ||
trait Sized {} | ||
|
||
#[lang = "add"] | ||
trait Add<T> { | ||
const add: u32 = 1u32; | ||
} | ||
|
||
impl Add<u32> for u32 {} | ||
|
||
fn main() { | ||
1u32 + 1u32; | ||
//~^ ERROR cannot add `u32` to `u32` | ||
} |
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 @@ | ||
error[E0369]: cannot add `u32` to `u32` | ||
--> $DIR/bad-add-impl.rs:16:10 | ||
| | ||
LL | 1u32 + 1u32; | ||
| ---- ^ ---- u32 | ||
| | | ||
| u32 | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0369`. |
18 changes: 18 additions & 0 deletions
18
tests/ui/lang-items/fn-fn_mut-call-ill-formed.bad_item.stderr
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,18 @@ | ||
error: failed to find an overloaded call trait for closure call | ||
--> $DIR/fn-fn_mut-call-ill-formed.rs:39:5 | ||
| | ||
LL | a(); | ||
| ^^^ | ||
| | ||
= help: make sure the `fn`/`fn_mut`/`fn_once` lang items are defined and have correctly defined `call`/`call_mut`/`call_once` methods | ||
|
||
error: failed to find an overloaded call trait for closure call | ||
--> $DIR/fn-fn_mut-call-ill-formed.rs:43:5 | ||
| | ||
LL | b(); | ||
| ^^^ | ||
| | ||
= help: make sure the `fn`/`fn_mut`/`fn_once` lang items are defined and have correctly defined `call`/`call_mut`/`call_once` methods | ||
|
||
error: aborting due to 2 previous errors | ||
|
18 changes: 18 additions & 0 deletions
18
tests/ui/lang-items/fn-fn_mut-call-ill-formed.bad_sig.stderr
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,18 @@ | ||
error: failed to find an overloaded call trait for closure call | ||
--> $DIR/fn-fn_mut-call-ill-formed.rs:39:5 | ||
| | ||
LL | a(); | ||
| ^^^ | ||
| | ||
= help: make sure the `fn`/`fn_mut`/`fn_once` lang items are defined and have correctly defined `call`/`call_mut`/`call_once` methods | ||
|
||
error: failed to find an overloaded call trait for closure call | ||
--> $DIR/fn-fn_mut-call-ill-formed.rs:43:5 | ||
| | ||
LL | b(); | ||
| ^^^ | ||
| | ||
= help: make sure the `fn`/`fn_mut`/`fn_once` lang items are defined and have correctly defined `call`/`call_mut`/`call_once` methods | ||
|
||
error: aborting due to 2 previous errors | ||
|
18 changes: 18 additions & 0 deletions
18
tests/ui/lang-items/fn-fn_mut-call-ill-formed.fn_bad_item.stderr
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,18 @@ | ||
error: failed to find an overloaded call trait for closure call | ||
--> $DIR/fn-fn_mut-call-ill-formed.rs:42:5 | ||
| | ||
LL | a(); | ||
| ^^^ | ||
| | ||
= help: make sure the `fn`/`fn_mut`/`fn_once` lang items are defined and have correctly defined `call`/`call_mut`/`call_once` methods | ||
|
||
error: failed to find an overloaded call trait for closure call | ||
--> $DIR/fn-fn_mut-call-ill-formed.rs:47:5 | ||
| | ||
LL | b(); | ||
| ^^^ | ||
| | ||
= help: make sure the `fn`/`fn_mut`/`fn_once` lang items are defined and have correctly defined `call`/`call_mut`/`call_once` methods | ||
|
||
error: aborting due to 2 previous errors | ||
|
18 changes: 18 additions & 0 deletions
18
tests/ui/lang-items/fn-fn_mut-call-ill-formed.fn_bad_sig.stderr
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,18 @@ | ||
error: failed to find an overloaded call trait for closure call | ||
--> $DIR/fn-fn_mut-call-ill-formed.rs:42:5 | ||
| | ||
LL | a(); | ||
| ^^^ | ||
| | ||
= help: make sure the `fn`/`fn_mut`/`fn_once` lang items are defined and have correctly defined `call`/`call_mut`/`call_once` methods | ||
|
||
error: failed to find an overloaded call trait for closure call | ||
--> $DIR/fn-fn_mut-call-ill-formed.rs:47:5 | ||
| | ||
LL | b(); | ||
| ^^^ | ||
| | ||
= help: make sure the `fn`/`fn_mut`/`fn_once` lang items are defined and have correctly defined `call`/`call_mut`/`call_once` methods | ||
|
||
error: aborting due to 2 previous errors | ||
|
18 changes: 18 additions & 0 deletions
18
tests/ui/lang-items/fn-fn_mut-call-ill-formed.fn_mut_bad_item.stderr
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,18 @@ | ||
error: failed to find an overloaded call trait for closure call | ||
--> $DIR/fn-fn_mut-call-ill-formed.rs:42:5 | ||
| | ||
LL | a(); | ||
| ^^^ | ||
| | ||
= help: make sure the `fn`/`fn_mut`/`fn_once` lang items are defined and have correctly defined `call`/`call_mut`/`call_once` methods | ||
|
||
error: failed to find an overloaded call trait for closure call | ||
--> $DIR/fn-fn_mut-call-ill-formed.rs:47:5 | ||
| | ||
LL | b(); | ||
| ^^^ | ||
| | ||
= help: make sure the `fn`/`fn_mut`/`fn_once` lang items are defined and have correctly defined `call`/`call_mut`/`call_once` methods | ||
|
||
error: aborting due to 2 previous errors | ||
|
18 changes: 18 additions & 0 deletions
18
tests/ui/lang-items/fn-fn_mut-call-ill-formed.fn_mut_bad_sig.stderr
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,18 @@ | ||
error: failed to find an overloaded call trait for closure call | ||
--> $DIR/fn-fn_mut-call-ill-formed.rs:42:5 | ||
| | ||
LL | a(); | ||
| ^^^ | ||
| | ||
= help: make sure the `fn`/`fn_mut`/`fn_once` lang items are defined and have correctly defined `call`/`call_mut`/`call_once` methods | ||
|
||
error: failed to find an overloaded call trait for closure call | ||
--> $DIR/fn-fn_mut-call-ill-formed.rs:47:5 | ||
| | ||
LL | b(); | ||
| ^^^ | ||
| | ||
= help: make sure the `fn`/`fn_mut`/`fn_once` lang items are defined and have correctly defined `call`/`call_mut`/`call_once` methods | ||
|
||
error: aborting due to 2 previous errors | ||
|
18 changes: 18 additions & 0 deletions
18
tests/ui/lang-items/fn-fn_mut-call-ill-formed.fn_once_bad_item.stderr
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,18 @@ | ||
error: failed to find an overloaded call trait for closure call | ||
--> $DIR/fn-fn_mut-call-ill-formed.rs:42:5 | ||
| | ||
LL | a(); | ||
| ^^^ | ||
| | ||
= help: make sure the `fn`/`fn_mut`/`fn_once` lang items are defined and have correctly defined `call`/`call_mut`/`call_once` methods | ||
|
||
error: failed to find an overloaded call trait for closure call | ||
--> $DIR/fn-fn_mut-call-ill-formed.rs:47:5 | ||
| | ||
LL | b(); | ||
| ^^^ | ||
| | ||
= help: make sure the `fn`/`fn_mut`/`fn_once` lang items are defined and have correctly defined `call`/`call_mut`/`call_once` methods | ||
|
||
error: aborting due to 2 previous errors | ||
|
18 changes: 18 additions & 0 deletions
18
tests/ui/lang-items/fn-fn_mut-call-ill-formed.fn_once_bad_sig.stderr
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,18 @@ | ||
error: failed to find an overloaded call trait for closure call | ||
--> $DIR/fn-fn_mut-call-ill-formed.rs:42:5 | ||
| | ||
LL | a(); | ||
| ^^^ | ||
| | ||
= help: make sure the `fn`/`fn_mut`/`fn_once` lang items are defined and have correctly defined `call`/`call_mut`/`call_once` methods | ||
|
||
error: failed to find an overloaded call trait for closure call | ||
--> $DIR/fn-fn_mut-call-ill-formed.rs:47:5 | ||
| | ||
LL | b(); | ||
| ^^^ | ||
| | ||
= help: make sure the `fn`/`fn_mut`/`fn_once` lang items are defined and have correctly defined `call`/`call_mut`/`call_once` methods | ||
|
||
error: aborting due to 2 previous errors | ||
|
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 |
---|---|---|
@@ -1,27 +1,49 @@ | ||
// Make sure that an error is reported if the `call` function of the | ||
// `fn`/`fn_mut` lang item is grossly ill-formed. | ||
// revisions: fn_once_bad_item fn_once_bad_sig fn_mut_bad_item fn_mut_bad_sig fn_bad_item fn_bad_sig | ||
|
||
#![feature(lang_items)] | ||
#![feature(no_core)] | ||
#![no_core] | ||
|
||
#[lang = "sized"] | ||
trait Sized {} | ||
|
||
#[cfg(any(fn_bad_item, fn_bad_sig))] | ||
#[lang = "fn"] | ||
trait MyFn<T> { | ||
#[cfg(fn_bad_sig)] | ||
fn call(i: i32) -> i32 { 0 } | ||
|
||
#[cfg(fn_bad_item)] | ||
const call: i32 = 42; | ||
//~^ ERROR: `call` trait item in `fn` lang item must be a function | ||
} | ||
|
||
#[cfg(any(fn_mut_bad_item, fn_mut_bad_sig))] | ||
#[lang = "fn_mut"] | ||
trait MyFnMut<T> { | ||
fn call(i: i32, j: i32) -> i32 { i + j } | ||
//~^ ERROR: first argument of `call` in `fn_mut` lang item must be a reference | ||
#[cfg(fn_mut_bad_sig)] | ||
fn call_mut(i: i32) -> i32 { 0 } | ||
|
||
#[cfg(fn_mut_bad_item)] | ||
const call_mut: i32 = 42; | ||
} | ||
|
||
#[cfg(any(fn_once_bad_item, fn_once_bad_sig))] | ||
#[lang = "fn_once"] | ||
trait MyFnOnce<T> { | ||
#[cfg(fn_once_bad_sig)] | ||
fn call_once(i: i32) -> i32 { 0 } | ||
|
||
#[cfg(fn_once_bad_item)] | ||
const call_once: i32 = 42; | ||
} | ||
|
||
fn main() { | ||
let a = || 42; | ||
a(); | ||
//~^ ERROR failed to find an overloaded call trait for closure call | ||
|
||
let mut i = 0; | ||
let mut b = || { i += 1; }; | ||
let mut b = || { }; | ||
b(); | ||
//~^ ERROR failed to find an overloaded call trait for closure call | ||
} |
This file was deleted.
Oops, something went wrong.
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