forked from rust-lang/rust
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#86750 - fee1-dead:impl-const-test, r=jonas-…
…schievink Test cross-crate usage of `feature(const_trait_impl)` This PR does two things: - Fixes metadata not encoded properly for functions in const trait impls. - Adds tests for using const trait impls cross-crate with the feature gate on the user crate either enabled or disabled. AFAIK, this means we can now constify some trait impls in the standard library 🎉 See rust-lang#67792 for the tracking issue, cc `@oli-obk`
- Loading branch information
Showing
6 changed files
with
90 additions
and
1 deletion.
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
22 changes: 22 additions & 0 deletions
22
src/test/ui/rfc-2632-const-trait-impl/auxiliary/cross-crate.rs
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,22 @@ | ||
#![feature(const_trait_impl)] | ||
#![allow(incomplete_features)] | ||
|
||
pub trait MyTrait { | ||
fn func(self); | ||
} | ||
|
||
pub struct NonConst; | ||
|
||
impl MyTrait for NonConst { | ||
fn func(self) { | ||
|
||
} | ||
} | ||
|
||
pub struct Const; | ||
|
||
impl const MyTrait for Const { | ||
fn func(self) { | ||
|
||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/test/ui/rfc-2632-const-trait-impl/cross-crate-feature-disabled.rs
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 @@ | ||
// aux-build: cross-crate.rs | ||
extern crate cross_crate; | ||
|
||
use cross_crate::*; | ||
|
||
fn non_const_context() { | ||
NonConst.func(); | ||
Const.func(); | ||
} | ||
|
||
const fn const_context() { | ||
NonConst.func(); | ||
//~^ ERROR: calls in constant functions are limited to constant functions, tuple structs and tuple variants | ||
Const.func(); | ||
//~^ ERROR: calls in constant functions are limited to constant functions, tuple structs and tuple variants | ||
} | ||
|
||
fn main() {} |
15 changes: 15 additions & 0 deletions
15
src/test/ui/rfc-2632-const-trait-impl/cross-crate-feature-disabled.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,15 @@ | ||
error[E0015]: calls in constant functions are limited to constant functions, tuple structs and tuple variants | ||
--> $DIR/cross-crate-feature-disabled.rs:12:5 | ||
| | ||
LL | NonConst.func(); | ||
| ^^^^^^^^^^^^^^^ | ||
|
||
error[E0015]: calls in constant functions are limited to constant functions, tuple structs and tuple variants | ||
--> $DIR/cross-crate-feature-disabled.rs:14:5 | ||
| | ||
LL | Const.func(); | ||
| ^^^^^^^^^^^^ | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0015`. |
20 changes: 20 additions & 0 deletions
20
src/test/ui/rfc-2632-const-trait-impl/cross-crate-feature-enabled.rs
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,20 @@ | ||
#![feature(const_trait_impl)] | ||
#![allow(incomplete_features)] | ||
|
||
// aux-build: cross-crate.rs | ||
extern crate cross_crate; | ||
|
||
use cross_crate::*; | ||
|
||
fn non_const_context() { | ||
NonConst.func(); | ||
Const.func(); | ||
} | ||
|
||
const fn const_context() { | ||
NonConst.func(); | ||
//~^ ERROR: calls in constant functions are limited to constant functions, tuple structs and tuple variants | ||
Const.func(); | ||
} | ||
|
||
fn main() {} |
9 changes: 9 additions & 0 deletions
9
src/test/ui/rfc-2632-const-trait-impl/cross-crate-feature-enabled.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,9 @@ | ||
error[E0015]: calls in constant functions are limited to constant functions, tuple structs and tuple variants | ||
--> $DIR/cross-crate-feature-enabled.rs:15:5 | ||
| | ||
LL | NonConst.func(); | ||
| ^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0015`. |