mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
Trait aliases cannot be impl-restricted
This commit is contained in:
@@ -2422,6 +2422,14 @@ pub(crate) struct TraitAliasCannotBeUnsafe {
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag("trait aliases cannot be `impl`-restricted")]
|
||||
pub(crate) struct TraitAliasCannotBeImplRestricted {
|
||||
#[primary_span]
|
||||
#[label("trait aliases cannot be `impl`-restricted")]
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag("associated `static` items are not allowed")]
|
||||
pub(crate) struct AssociatedStaticItemNotAllowed {
|
||||
|
||||
@@ -1142,6 +1142,9 @@ fn parse_item_trait(&mut self, attrs: &mut AttrVec, lo: Span) -> PResult<'a, Ite
|
||||
if let Safety::Unsafe(_) = safety {
|
||||
self.dcx().emit_err(errors::TraitAliasCannotBeUnsafe { span: whole_span });
|
||||
}
|
||||
if let RestrictionKind::Restricted { .. } = impl_restriction.kind {
|
||||
self.dcx().emit_err(errors::TraitAliasCannotBeImplRestricted { span: whole_span });
|
||||
}
|
||||
|
||||
self.psess.gated_spans.gate(sym::trait_alias, whole_span);
|
||||
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
//@ compile-flags: --crate-type=lib
|
||||
//@ revisions: with_gate without_gate
|
||||
#![cfg_attr(with_gate, feature(impl_restriction))]
|
||||
//[with_gate]~^ WARN the feature `impl_restriction` is incomplete and may not be safe to use and/or cause compiler crashes
|
||||
#![feature(auto_traits, const_trait_impl, trait_alias)]
|
||||
|
||||
impl(crate) trait Alias = Copy; //~ ERROR trait aliases cannot be `impl`-restricted
|
||||
//[without_gate]~^ ERROR `impl` restrictions are experimental
|
||||
auto impl(in crate) trait AutoAlias = Copy; //~ ERROR trait aliases cannot be `impl`-restricted
|
||||
//~^ ERROR trait aliases cannot be `auto`
|
||||
//[without_gate]~| ERROR `impl` restrictions are experimental
|
||||
unsafe impl(self) trait UnsafeAlias = Copy; //~ ERROR trait aliases cannot be `impl`-restricted
|
||||
//~^ ERROR trait aliases cannot be `unsafe`
|
||||
//[without_gate]~| ERROR `impl` restrictions are experimental
|
||||
const impl(in self) trait ConstAlias = Copy; //~ ERROR trait aliases cannot be `impl`-restricted
|
||||
//[without_gate]~^ ERROR `impl` restrictions are experimental
|
||||
|
||||
mod foo {
|
||||
impl(super) trait InnerAlias = Copy; //~ ERROR trait aliases cannot be `impl`-restricted
|
||||
//[without_gate]~^ ERROR `impl` restrictions are experimental
|
||||
const unsafe impl(in crate::foo) trait InnerConstUnsafeAlias = Copy; //~ ERROR trait aliases cannot be `impl`-restricted
|
||||
//~^ ERROR trait aliases cannot be `unsafe`
|
||||
//[without_gate]~| ERROR `impl` restrictions are experimental
|
||||
unsafe auto impl(in crate::foo) trait InnerUnsafeAutoAlias = Copy; //~ ERROR trait aliases cannot be `impl`-restricted
|
||||
//~^ ERROR trait aliases cannot be `auto`
|
||||
//~^^ ERROR trait aliases cannot be `unsafe`
|
||||
//[without_gate]~| ERROR `impl` restrictions are experimental
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
error: trait aliases cannot be `impl`-restricted
|
||||
--> $DIR/trait-alias-cannot-be-impl-restricted.rs:7:1
|
||||
|
|
||||
LL | impl(crate) trait Alias = Copy;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait aliases cannot be `impl`-restricted
|
||||
|
||||
error: trait aliases cannot be `auto`
|
||||
--> $DIR/trait-alias-cannot-be-impl-restricted.rs:9:1
|
||||
|
|
||||
LL | auto impl(in crate) trait AutoAlias = Copy;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait aliases cannot be `auto`
|
||||
|
||||
error: trait aliases cannot be `impl`-restricted
|
||||
--> $DIR/trait-alias-cannot-be-impl-restricted.rs:9:1
|
||||
|
|
||||
LL | auto impl(in crate) trait AutoAlias = Copy;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait aliases cannot be `impl`-restricted
|
||||
|
||||
error: trait aliases cannot be `unsafe`
|
||||
--> $DIR/trait-alias-cannot-be-impl-restricted.rs:12:1
|
||||
|
|
||||
LL | unsafe impl(self) trait UnsafeAlias = Copy;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait aliases cannot be `unsafe`
|
||||
|
||||
error: trait aliases cannot be `impl`-restricted
|
||||
--> $DIR/trait-alias-cannot-be-impl-restricted.rs:12:1
|
||||
|
|
||||
LL | unsafe impl(self) trait UnsafeAlias = Copy;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait aliases cannot be `impl`-restricted
|
||||
|
||||
error: trait aliases cannot be `impl`-restricted
|
||||
--> $DIR/trait-alias-cannot-be-impl-restricted.rs:15:1
|
||||
|
|
||||
LL | const impl(in self) trait ConstAlias = Copy;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait aliases cannot be `impl`-restricted
|
||||
|
||||
error: trait aliases cannot be `impl`-restricted
|
||||
--> $DIR/trait-alias-cannot-be-impl-restricted.rs:19:5
|
||||
|
|
||||
LL | impl(super) trait InnerAlias = Copy;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait aliases cannot be `impl`-restricted
|
||||
|
||||
error: trait aliases cannot be `unsafe`
|
||||
--> $DIR/trait-alias-cannot-be-impl-restricted.rs:21:5
|
||||
|
|
||||
LL | const unsafe impl(in crate::foo) trait InnerConstUnsafeAlias = Copy;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait aliases cannot be `unsafe`
|
||||
|
||||
error: trait aliases cannot be `impl`-restricted
|
||||
--> $DIR/trait-alias-cannot-be-impl-restricted.rs:21:5
|
||||
|
|
||||
LL | const unsafe impl(in crate::foo) trait InnerConstUnsafeAlias = Copy;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait aliases cannot be `impl`-restricted
|
||||
|
||||
error: trait aliases cannot be `auto`
|
||||
--> $DIR/trait-alias-cannot-be-impl-restricted.rs:24:5
|
||||
|
|
||||
LL | unsafe auto impl(in crate::foo) trait InnerUnsafeAutoAlias = Copy;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait aliases cannot be `auto`
|
||||
|
||||
error: trait aliases cannot be `unsafe`
|
||||
--> $DIR/trait-alias-cannot-be-impl-restricted.rs:24:5
|
||||
|
|
||||
LL | unsafe auto impl(in crate::foo) trait InnerUnsafeAutoAlias = Copy;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait aliases cannot be `unsafe`
|
||||
|
||||
error: trait aliases cannot be `impl`-restricted
|
||||
--> $DIR/trait-alias-cannot-be-impl-restricted.rs:24:5
|
||||
|
|
||||
LL | unsafe auto impl(in crate::foo) trait InnerUnsafeAutoAlias = Copy;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait aliases cannot be `impl`-restricted
|
||||
|
||||
warning: the feature `impl_restriction` is incomplete and may not be safe to use and/or cause compiler crashes
|
||||
--> $DIR/trait-alias-cannot-be-impl-restricted.rs:3:32
|
||||
|
|
||||
LL | #![cfg_attr(with_gate, feature(impl_restriction))]
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: see issue #105077 <https://github.com/rust-lang/rust/issues/105077> for more information
|
||||
= note: `#[warn(incomplete_features)]` on by default
|
||||
|
||||
error: aborting due to 12 previous errors; 1 warning emitted
|
||||
|
||||
@@ -0,0 +1,145 @@
|
||||
error: trait aliases cannot be `impl`-restricted
|
||||
--> $DIR/trait-alias-cannot-be-impl-restricted.rs:7:1
|
||||
|
|
||||
LL | impl(crate) trait Alias = Copy;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait aliases cannot be `impl`-restricted
|
||||
|
||||
error: trait aliases cannot be `auto`
|
||||
--> $DIR/trait-alias-cannot-be-impl-restricted.rs:9:1
|
||||
|
|
||||
LL | auto impl(in crate) trait AutoAlias = Copy;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait aliases cannot be `auto`
|
||||
|
||||
error: trait aliases cannot be `impl`-restricted
|
||||
--> $DIR/trait-alias-cannot-be-impl-restricted.rs:9:1
|
||||
|
|
||||
LL | auto impl(in crate) trait AutoAlias = Copy;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait aliases cannot be `impl`-restricted
|
||||
|
||||
error: trait aliases cannot be `unsafe`
|
||||
--> $DIR/trait-alias-cannot-be-impl-restricted.rs:12:1
|
||||
|
|
||||
LL | unsafe impl(self) trait UnsafeAlias = Copy;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait aliases cannot be `unsafe`
|
||||
|
||||
error: trait aliases cannot be `impl`-restricted
|
||||
--> $DIR/trait-alias-cannot-be-impl-restricted.rs:12:1
|
||||
|
|
||||
LL | unsafe impl(self) trait UnsafeAlias = Copy;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait aliases cannot be `impl`-restricted
|
||||
|
||||
error: trait aliases cannot be `impl`-restricted
|
||||
--> $DIR/trait-alias-cannot-be-impl-restricted.rs:15:1
|
||||
|
|
||||
LL | const impl(in self) trait ConstAlias = Copy;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait aliases cannot be `impl`-restricted
|
||||
|
||||
error: trait aliases cannot be `impl`-restricted
|
||||
--> $DIR/trait-alias-cannot-be-impl-restricted.rs:19:5
|
||||
|
|
||||
LL | impl(super) trait InnerAlias = Copy;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait aliases cannot be `impl`-restricted
|
||||
|
||||
error: trait aliases cannot be `unsafe`
|
||||
--> $DIR/trait-alias-cannot-be-impl-restricted.rs:21:5
|
||||
|
|
||||
LL | const unsafe impl(in crate::foo) trait InnerConstUnsafeAlias = Copy;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait aliases cannot be `unsafe`
|
||||
|
||||
error: trait aliases cannot be `impl`-restricted
|
||||
--> $DIR/trait-alias-cannot-be-impl-restricted.rs:21:5
|
||||
|
|
||||
LL | const unsafe impl(in crate::foo) trait InnerConstUnsafeAlias = Copy;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait aliases cannot be `impl`-restricted
|
||||
|
||||
error: trait aliases cannot be `auto`
|
||||
--> $DIR/trait-alias-cannot-be-impl-restricted.rs:24:5
|
||||
|
|
||||
LL | unsafe auto impl(in crate::foo) trait InnerUnsafeAutoAlias = Copy;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait aliases cannot be `auto`
|
||||
|
||||
error: trait aliases cannot be `unsafe`
|
||||
--> $DIR/trait-alias-cannot-be-impl-restricted.rs:24:5
|
||||
|
|
||||
LL | unsafe auto impl(in crate::foo) trait InnerUnsafeAutoAlias = Copy;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait aliases cannot be `unsafe`
|
||||
|
||||
error: trait aliases cannot be `impl`-restricted
|
||||
--> $DIR/trait-alias-cannot-be-impl-restricted.rs:24:5
|
||||
|
|
||||
LL | unsafe auto impl(in crate::foo) trait InnerUnsafeAutoAlias = Copy;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait aliases cannot be `impl`-restricted
|
||||
|
||||
error[E0658]: `impl` restrictions are experimental
|
||||
--> $DIR/trait-alias-cannot-be-impl-restricted.rs:7:1
|
||||
|
|
||||
LL | impl(crate) trait Alias = Copy;
|
||||
| ^^^^^^^^^^^
|
||||
|
|
||||
= note: see issue #105077 <https://github.com/rust-lang/rust/issues/105077> for more information
|
||||
= help: add `#![feature(impl_restriction)]` to the crate attributes to enable
|
||||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
||||
|
||||
error[E0658]: `impl` restrictions are experimental
|
||||
--> $DIR/trait-alias-cannot-be-impl-restricted.rs:9:6
|
||||
|
|
||||
LL | auto impl(in crate) trait AutoAlias = Copy;
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: see issue #105077 <https://github.com/rust-lang/rust/issues/105077> for more information
|
||||
= help: add `#![feature(impl_restriction)]` to the crate attributes to enable
|
||||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
||||
|
||||
error[E0658]: `impl` restrictions are experimental
|
||||
--> $DIR/trait-alias-cannot-be-impl-restricted.rs:12:8
|
||||
|
|
||||
LL | unsafe impl(self) trait UnsafeAlias = Copy;
|
||||
| ^^^^^^^^^^
|
||||
|
|
||||
= note: see issue #105077 <https://github.com/rust-lang/rust/issues/105077> for more information
|
||||
= help: add `#![feature(impl_restriction)]` to the crate attributes to enable
|
||||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
||||
|
||||
error[E0658]: `impl` restrictions are experimental
|
||||
--> $DIR/trait-alias-cannot-be-impl-restricted.rs:15:7
|
||||
|
|
||||
LL | const impl(in self) trait ConstAlias = Copy;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
|
||||
= note: see issue #105077 <https://github.com/rust-lang/rust/issues/105077> for more information
|
||||
= help: add `#![feature(impl_restriction)]` to the crate attributes to enable
|
||||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
||||
|
||||
error[E0658]: `impl` restrictions are experimental
|
||||
--> $DIR/trait-alias-cannot-be-impl-restricted.rs:19:5
|
||||
|
|
||||
LL | impl(super) trait InnerAlias = Copy;
|
||||
| ^^^^^^^^^^^
|
||||
|
|
||||
= note: see issue #105077 <https://github.com/rust-lang/rust/issues/105077> for more information
|
||||
= help: add `#![feature(impl_restriction)]` to the crate attributes to enable
|
||||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
||||
|
||||
error[E0658]: `impl` restrictions are experimental
|
||||
--> $DIR/trait-alias-cannot-be-impl-restricted.rs:21:18
|
||||
|
|
||||
LL | const unsafe impl(in crate::foo) trait InnerConstUnsafeAlias = Copy;
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: see issue #105077 <https://github.com/rust-lang/rust/issues/105077> for more information
|
||||
= help: add `#![feature(impl_restriction)]` to the crate attributes to enable
|
||||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
||||
|
||||
error[E0658]: `impl` restrictions are experimental
|
||||
--> $DIR/trait-alias-cannot-be-impl-restricted.rs:24:17
|
||||
|
|
||||
LL | unsafe auto impl(in crate::foo) trait InnerUnsafeAutoAlias = Copy;
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: see issue #105077 <https://github.com/rust-lang/rust/issues/105077> for more information
|
||||
= help: add `#![feature(impl_restriction)]` to the crate attributes to enable
|
||||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
||||
|
||||
error: aborting due to 19 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0658`.
|
||||
Reference in New Issue
Block a user