-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also check the inner ty of arrays, slices, and tuples
- Loading branch information
Showing
9 changed files
with
184 additions
and
87 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
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
38 changes: 38 additions & 0 deletions
38
tests/ui/const-generics/adt_const_params/const_param_ty_impl_bad_inner_ty.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,38 @@ | ||
#![feature(adt_const_params)] | ||
#![allow(incomplete_features)] | ||
|
||
use std::marker::ConstParamTy; | ||
|
||
// #112124 | ||
|
||
struct Foo; | ||
|
||
impl ConstParamTy for &Foo {} | ||
//~^ ERROR the trait `ConstParamTy` cannot be implemented for this type | ||
|
||
impl ConstParamTy for &[Foo] {} | ||
//~^ ERROR only traits defined in the current crate can be implemented for arbitrary types | ||
//~| ERROR the trait `ConstParamTy` cannot be implemented for this type | ||
|
||
impl ConstParamTy for [Foo; 4] {} | ||
//~^ ERROR only traits defined in the current crate can be implemented for arbitrary types | ||
//~| ERROR the trait `ConstParamTy` cannot be implemented for this type | ||
|
||
impl ConstParamTy for (Foo, i32, *const u8) {} | ||
//~^ ERROR only traits defined in the current crate can be implemented for arbitrary types | ||
//~| ERROR the trait `ConstParamTy` cannot be implemented for this type | ||
|
||
// #119299 (ICE) | ||
|
||
#[derive(Eq, PartialEq)] | ||
struct Wrapper(*const i32, usize); | ||
|
||
impl ConstParamTy for &Wrapper {} | ||
//~^ ERROR the trait `ConstParamTy` cannot be implemented for this type | ||
|
||
const fn foo<const S: &'static Wrapper>() {} | ||
|
||
fn main() { | ||
const FOO: Wrapper = Wrapper(&42 as *const i32, 42); | ||
foo::<{ &FOO }>(); | ||
} |
106 changes: 106 additions & 0 deletions
106
tests/ui/const-generics/adt_const_params/const_param_ty_impl_bad_inner_ty.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,106 @@ | ||
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types | ||
--> $DIR/const_param_ty_impl_bad_inner_ty.rs:13:1 | ||
| | ||
LL | impl ConstParamTy for &[Foo] {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^------ | ||
| | | | ||
| | this is not defined in the current crate because slices are always foreign | ||
| impl doesn't use only types from inside the current crate | ||
| | ||
= note: define and implement a trait or new type instead | ||
|
||
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types | ||
--> $DIR/const_param_ty_impl_bad_inner_ty.rs:17:1 | ||
| | ||
LL | impl ConstParamTy for [Foo; 4] {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^-------- | ||
| | | | ||
| | this is not defined in the current crate because arrays are always foreign | ||
| impl doesn't use only types from inside the current crate | ||
| | ||
= note: define and implement a trait or new type instead | ||
|
||
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types | ||
--> $DIR/const_param_ty_impl_bad_inner_ty.rs:21:1 | ||
| | ||
LL | impl ConstParamTy for (Foo, i32, *const u8) {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^--------------------- | ||
| | | | ||
| | this is not defined in the current crate because tuples are always foreign | ||
| impl doesn't use only types from inside the current crate | ||
| | ||
= note: define and implement a trait or new type instead | ||
|
||
error: the trait `ConstParamTy` cannot be implemented for this type | ||
--> $DIR/const_param_ty_impl_bad_inner_ty.rs:10:23 | ||
| | ||
LL | struct Foo; | ||
| ---------- this struct does not implement `ConstParamTy` | ||
LL | | ||
LL | impl ConstParamTy for &Foo {} | ||
| ^^^^ | ||
| | ||
help: consider annotating this struct with `#[derive(ConstParamTy)]` | ||
| | ||
LL + #[derive(ConstParamTy)] | ||
LL | struct Foo; | ||
| | ||
|
||
error: the trait `ConstParamTy` cannot be implemented for this type | ||
--> $DIR/const_param_ty_impl_bad_inner_ty.rs:13:23 | ||
| | ||
LL | struct Foo; | ||
| ---------- this struct does not implement `ConstParamTy` | ||
... | ||
LL | impl ConstParamTy for &[Foo] {} | ||
| ^^^^^^ | ||
| | ||
help: consider annotating this struct with `#[derive(ConstParamTy)]` | ||
| | ||
LL + #[derive(ConstParamTy)] | ||
LL | struct Foo; | ||
| | ||
|
||
error: the trait `ConstParamTy` cannot be implemented for this type | ||
--> $DIR/const_param_ty_impl_bad_inner_ty.rs:17:23 | ||
| | ||
LL | struct Foo; | ||
| ---------- this struct does not implement `ConstParamTy` | ||
... | ||
LL | impl ConstParamTy for [Foo; 4] {} | ||
| ^^^^^^^^ | ||
| | ||
help: consider annotating this struct with `#[derive(ConstParamTy)]` | ||
| | ||
LL + #[derive(ConstParamTy)] | ||
LL | struct Foo; | ||
| | ||
|
||
error: the trait `ConstParamTy` cannot be implemented for this type | ||
--> $DIR/const_param_ty_impl_bad_inner_ty.rs:21:23 | ||
| | ||
LL | struct Foo; | ||
| ---------- this struct does not implement `ConstParamTy` | ||
... | ||
LL | impl ConstParamTy for (Foo, i32, *const u8) {} | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
help: consider annotating this struct with `#[derive(ConstParamTy)]` | ||
| | ||
LL + #[derive(ConstParamTy)] | ||
LL | struct Foo; | ||
| | ||
|
||
error[E0204]: the trait `ConstParamTy` cannot be implemented for this type | ||
--> $DIR/const_param_ty_impl_bad_inner_ty.rs:30:23 | ||
| | ||
LL | struct Wrapper(*const i32, usize); | ||
| ---------- this field does not implement `ConstParamTy` | ||
LL | | ||
LL | impl ConstParamTy for &Wrapper {} | ||
| ^^^^^^^^ | ||
|
||
error: aborting due to 8 previous errors | ||
|
||
Some errors have detailed explanations: E0117, E0204. | ||
For more information about an error, try `rustc --explain E0117`. |
26 changes: 0 additions & 26 deletions
26
tests/ui/const-generics/adt_const_params/const_param_ty_impl_bad_referee.rs
This file was deleted.
Oops, something went wrong.
27 changes: 0 additions & 27 deletions
27
tests/ui/const-generics/adt_const_params/const_param_ty_impl_bad_referee.stderr
This file was deleted.
Oops, something went wrong.