Rollup merge of #155442 - CoCo-Japan-pan:impl-restriction-reorder, r=Urgau,fmease,jhpratt

Change keyword order for `impl` restrictions

Based on rust-lang/rust#155222, this PR reorders keywords in trait definitions to group restrictions with visibility. It changes the order from `pub(...) const unsafe auto impl(...) trait Foo {...}`  to `pub(...) impl(...) const unsafe auto trait Foo {...}`.

Tracking issue for restrictions: rust-lang/rust#105077

r? @Urgau
cc @jhpratt
This commit is contained in:
Guillaume Gomez
2026-04-23 14:42:47 +02:00
committed by GitHub
29 changed files with 269 additions and 595 deletions
+1 -1
View File
@@ -3786,10 +3786,10 @@ pub struct TraitAlias {
#[derive(Clone, Encodable, Decodable, Debug, Walkable)]
pub struct Trait {
pub impl_restriction: ImplRestriction,
pub constness: Const,
pub safety: Safety,
pub is_auto: IsAuto,
pub impl_restriction: ImplRestriction,
pub ident: Ident,
pub generics: Generics,
#[visitable(extra = BoundKind::SuperTraits)]
+2 -2
View File
@@ -556,10 +556,10 @@ fn lower_item_kind(
})
}
ItemKind::Trait(box Trait {
impl_restriction,
constness,
is_auto,
safety,
impl_restriction,
ident,
generics,
bounds,
@@ -586,10 +586,10 @@ fn lower_item_kind(
},
);
hir::ItemKind::Trait(
impl_restriction,
constness,
*is_auto,
safety,
impl_restriction,
ident,
generics,
bounds,
@@ -371,10 +371,10 @@ pub(crate) fn print_item(&mut self, item: &ast::Item) {
self.bclose(item.span, empty, cb);
}
ast::ItemKind::Trait(box ast::Trait {
impl_restriction,
constness,
safety,
is_auto,
impl_restriction,
ident,
generics,
bounds,
@@ -382,10 +382,10 @@ pub(crate) fn print_item(&mut self, item: &ast::Item) {
}) => {
let (cb, ib) = self.head("");
self.print_visibility(&item.vis);
self.print_impl_restriction(impl_restriction);
self.print_constness(*constness);
self.print_safety(*safety);
self.print_is_auto(*is_auto);
self.print_impl_restriction(impl_restriction);
self.word_nbsp("trait");
self.print_ident(*ident);
self.print_generic_params(&generics.params);
+4 -4
View File
@@ -4457,17 +4457,17 @@ pub fn is_struct_or_union(&self) -> bool {
expect_trait,
(
&'hir ImplRestriction<'hir>,
Constness,
IsAuto,
Safety,
&'hir ImplRestriction<'hir>,
Ident,
&'hir Generics<'hir>,
GenericBounds<'hir>,
&'hir [TraitItemId]
),
ItemKind::Trait(constness, is_auto, safety, impl_restriction, ident, generics, bounds, items),
(*constness, *is_auto, *safety, impl_restriction, *ident, generics, bounds, items);
ItemKind::Trait(impl_restriction, constness, is_auto, safety, ident, generics, bounds, items),
(impl_restriction, *constness, *is_auto, *safety, *ident, generics, bounds, items);
expect_trait_alias, (Constness, Ident, &'hir Generics<'hir>, GenericBounds<'hir>),
ItemKind::TraitAlias(constness, ident, generics, bounds), (*constness, *ident, generics, bounds);
@@ -4659,10 +4659,10 @@ pub enum ItemKind<'hir> {
Union(Ident, &'hir Generics<'hir>, VariantData<'hir>),
/// A trait definition.
Trait(
&'hir ImplRestriction<'hir>,
Constness,
IsAuto,
Safety,
&'hir ImplRestriction<'hir>,
Ident,
&'hir Generics<'hir>,
GenericBounds<'hir>,
+1 -1
View File
@@ -619,10 +619,10 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) -> V::
try_visit!(visitor.visit_variant_data(struct_definition));
}
ItemKind::Trait(
ref impl_restriction,
_constness,
_is_auto,
_safety,
ref impl_restriction,
ident,
ref generics,
bounds,
+2 -2
View File
@@ -895,7 +895,7 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef {
let item = tcx.hir_expect_item(def_id);
let (constness, is_alias, is_auto, safety, impl_restriction) = match item.kind {
hir::ItemKind::Trait(constness, is_auto, safety, impl_restriction, ..) => (
hir::ItemKind::Trait(impl_restriction, constness, is_auto, safety, ..) => (
constness,
false,
is_auto == hir::IsAuto::Yes,
@@ -959,9 +959,9 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef {
ty::TraitDef {
def_id: def_id.to_def_id(),
impl_restriction,
safety,
constness,
impl_restriction,
paren_sugar,
has_auto_impl: is_auto,
is_marker,
+2 -2
View File
@@ -758,20 +758,20 @@ fn print_item(&mut self, item: &hir::Item<'_>) {
self.bclose(item.span, cb);
}
hir::ItemKind::Trait(
impl_restriction,
constness,
is_auto,
safety,
impl_restriction,
ident,
generics,
bounds,
trait_items,
) => {
let (cb, ib) = self.head("");
self.print_impl_restriction(impl_restriction);
self.print_constness(constness);
self.print_is_auto(is_auto);
self.print_safety(safety);
self.print_impl_restriction(impl_restriction);
self.word_nbsp("trait");
self.print_ident(ident);
self.print_generic_params(generics.params);
@@ -1900,7 +1900,7 @@ fn handle_unsatisfied_predicates(
entry.1.insert((self_ty.span, String::new()));
}
Some(Node::Item(hir::Item {
kind: hir::ItemKind::Trait(_, rustc_ast::ast::IsAuto::Yes, ..),
kind: hir::ItemKind::Trait(_, _, rustc_ast::ast::IsAuto::Yes, ..),
span: item_span,
..
})) => {
+3 -3
View File
@@ -20,14 +20,14 @@
pub struct TraitDef {
pub def_id: DefId,
/// Restrictions on trait implementations.
pub impl_restriction: ImplRestrictionKind,
pub safety: hir::Safety,
/// Whether this trait is `const`.
pub constness: hir::Constness,
/// Restrictions on trait implementations.
pub impl_restriction: ImplRestrictionKind,
/// If `true`, then this trait had the `#[rustc_paren_sugar]`
/// attribute, indicating that it should be used with `Foo()`
/// sugar. This is a temporary thing -- eventually any trait will
+60 -73
View File
@@ -1052,80 +1052,69 @@ fn parse_defaultness(&mut self) -> Defaultness {
}
}
/// Is there an `[ impl(in? path) ]? trait` item `dist` tokens ahead?
fn is_trait_with_maybe_impl_restriction_in_front(&self, dist: usize) -> bool {
// `trait`
if self.is_keyword_ahead(dist, &[kw::Trait]) {
return true;
}
// `impl(`
if !self.is_keyword_ahead(dist, &[kw::Impl])
|| !self.look_ahead(dist + 1, |t| t == &token::OpenParen)
{
return false;
}
// `crate | super | self) trait`
if self.is_keyword_ahead(dist + 2, &[kw::Crate, kw::Super, kw::SelfLower])
&& self.look_ahead(dist + 3, |t| t == &token::CloseParen)
&& self.is_keyword_ahead(dist + 4, &[kw::Trait])
{
return true;
}
// `impl(in? something) trait`
// We catch cases where the `in` keyword is missing to provide a
// better error message. This is handled later in
// `self.recover_incorrect_impl_restriction`.
self.tree_look_ahead(dist + 2, |t| {
if let TokenTree::Token(token, _) = t { token.is_keyword(kw::Trait) } else { false }
})
.unwrap_or(false)
}
/// Is this an `(const unsafe? auto? [ impl(in? path) ]? | unsafe auto? [ impl(in? path) ]? | auto [ impl(in? path) ]? | [ impl(in? path) ]?) trait` item?
/// Is this an `[impl(in? path)]? const? unsafe? auto? trait` item?
fn check_trait_front_matter(&mut self) -> bool {
// `[ impl(in? path) ]? trait`
if self.is_trait_with_maybe_impl_restriction_in_front(0) {
return true;
const SUFFIXES: &[&[Symbol]] = &[
&[kw::Trait],
&[kw::Auto, kw::Trait],
&[kw::Unsafe, kw::Trait],
&[kw::Unsafe, kw::Auto, kw::Trait],
&[kw::Const, kw::Trait],
&[kw::Const, kw::Auto, kw::Trait],
&[kw::Const, kw::Unsafe, kw::Trait],
&[kw::Const, kw::Unsafe, kw::Auto, kw::Trait],
];
// `impl(`
if self.check_keyword(exp!(Impl)) && self.look_ahead(1, |t| t == &token::OpenParen) {
// `impl(in` unambiguously introduces an `impl` restriction
if self.is_keyword_ahead(2, &[kw::In]) {
return true;
}
// `impl(crate | self | super)` + SUFFIX
if self.is_keyword_ahead(2, &[kw::Crate, kw::SelfLower, kw::Super])
&& self.look_ahead(3, |t| t == &token::CloseParen)
&& SUFFIXES.iter().any(|suffix| {
suffix.iter().enumerate().all(|(i, kw)| self.is_keyword_ahead(i + 4, &[*kw]))
})
{
return true;
}
// Recover cases like `impl(path::to::module)` + SUFFIX to suggest inserting `in`.
SUFFIXES.iter().any(|suffix| {
suffix.iter().enumerate().all(|(i, kw)| {
self.tree_look_ahead(i + 2, |t| {
if let TokenTree::Token(token, _) = t {
token.is_keyword(*kw)
} else {
false
}
})
.unwrap_or(false)
})
})
} else {
SUFFIXES.iter().any(|suffix| {
suffix.iter().enumerate().all(|(i, kw)| {
// We use `check_keyword` for the first token to include it in the expected tokens.
if i == 0 {
match *kw {
kw::Const => self.check_keyword(exp!(Const)),
kw::Unsafe => self.check_keyword(exp!(Unsafe)),
kw::Auto => self.check_keyword(exp!(Auto)),
kw::Trait => self.check_keyword(exp!(Trait)),
_ => unreachable!(),
}
} else {
self.is_keyword_ahead(i, &[*kw])
}
})
})
}
// `auto [ impl(in? path) ]? trait`
if self.check_keyword(exp!(Auto)) && self.is_trait_with_maybe_impl_restriction_in_front(1) {
return true;
}
// `unsafe auto? [ impl(in? path) ]? trait`
if self.check_keyword(exp!(Unsafe))
&& (self.is_trait_with_maybe_impl_restriction_in_front(1)
|| self.is_keyword_ahead(1, &[kw::Auto])
&& self.is_trait_with_maybe_impl_restriction_in_front(2))
{
return true;
}
// `const` ...
if !self.check_keyword(exp!(Const)) {
return false;
}
// `const [ impl(in? path) ]? trait`
if self.is_trait_with_maybe_impl_restriction_in_front(1) {
return true;
}
// `const (unsafe | auto) [ impl(in? path) ]? trait`
if self.is_keyword_ahead(1, &[kw::Unsafe, kw::Auto])
&& self.is_trait_with_maybe_impl_restriction_in_front(2)
{
return true;
}
// `const unsafe auto [ impl(in? path) ]? trait`
self.is_keyword_ahead(1, &[kw::Unsafe])
&& self.is_keyword_ahead(2, &[kw::Auto])
&& self.is_trait_with_maybe_impl_restriction_in_front(3)
}
/// Parses `const? unsafe? auto? [impl(in? path)]? trait Foo { ... }` or `trait Foo = Bar;`.
///
/// FIXME(restrictions): The current keyword order follows the grammar specified in RFC 3323.
/// However, whether the restriction should be grouped closer to the visibility modifier
/// (e.g., `pub impl(crate) const unsafe auto trait`) remains an unresolved design question.
/// This ordering must be kept in sync with the logic in `check_trait_front_matter`.
/// Parses `[impl(in? path)]? const? unsafe? auto? trait Foo { ... }` or `trait Foo = Bar;`.
fn parse_item_trait(&mut self, attrs: &mut AttrVec, lo: Span) -> PResult<'a, ItemKind> {
let impl_restriction = self.parse_impl_restriction()?;
let constness = self.parse_constness(Case::Sensitive);
if let Const::Yes(span) = constness {
self.psess.gated_spans.gate(sym::const_trait_impl, span);
@@ -1139,8 +1128,6 @@ fn parse_item_trait(&mut self, attrs: &mut AttrVec, lo: Span) -> PResult<'a, Ite
IsAuto::No
};
let impl_restriction = self.parse_impl_restriction()?;
self.expect_keyword(exp!(Trait))?;
let ident = self.parse_ident()?;
let mut generics = self.parse_generics()?;
@@ -1181,10 +1168,10 @@ fn parse_item_trait(&mut self, attrs: &mut AttrVec, lo: Span) -> PResult<'a, Ite
generics.where_clause = self.parse_where_clause()?;
let items = self.parse_item_list(attrs, |p| p.parse_trait_item(ForceCollect::No))?;
Ok(ItemKind::Trait(Box::new(Trait {
impl_restriction,
constness,
is_auto,
safety,
impl_restriction,
ident,
generics,
bounds,
@@ -2966,7 +2953,7 @@ pub(super) fn check_fn_front_matter(&mut self, check_pub: bool, case: Case) -> b
&& !self.is_unsafe_foreign_mod()
// Rule out `async gen {` and `async gen move {`
&& !self.is_async_gen_block()
// Rule out `const unsafe auto` and `const unsafe trait` and `const unsafe impl`.
// Rule out `const unsafe auto` and `const unsafe trait` and `const unsafe impl`
&& !self.is_keyword_ahead(2, &[kw::Auto, kw::Trait, kw::Impl])
)
})
@@ -4142,7 +4142,7 @@ pub(super) fn note_obligation_cause_code<G: EmissionGuarantee, T>(
let mut is_auto_trait = false;
match tcx.hir_get_if_local(data.impl_or_alias_def_id) {
Some(Node::Item(hir::Item {
kind: hir::ItemKind::Trait(_, is_auto, _, _, ident, _, _, _),
kind: hir::ItemKind::Trait(_, _, is_auto, _, ident, _, _, _),
..
})) => {
// FIXME: we should do something else so that it works even on crate foreign
+1 -1
View File
@@ -2942,7 +2942,7 @@ fn get_name(tcx: TyCtxt<'_>, item: &hir::Item<'_>, renamed: Option<Symbol>) -> O
clean_fn_or_proc_macro(item, sig, generics, body_id, &mut name, cx)
}
// FIXME: rustdoc will need to handle `impl` restrictions at some point
ItemKind::Trait(_, _, _, _impl_restriction, _, generics, bounds, item_ids) => {
ItemKind::Trait(_impl_restriction, _, _, _, _, generics, bounds, item_ids) => {
let items = item_ids
.iter()
.map(|&ti| clean_trait_item(cx.tcx.hir_trait_item(ti), cx))
@@ -307,10 +307,10 @@ fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) {
}
},
ItemKind::Trait(
_impl_restriction,
_constness,
is_auto,
_safety,
_impl_restriction,
_ident,
_generics,
_generic_bounds,
+1 -1
View File
@@ -769,7 +769,7 @@ fn check_attributes(&mut self, cx: &LateContext<'tcx>, attrs: &'tcx [Attribute])
{
missing_headers::check(cx, item.owner_id, sig, headers, Some(body), self.check_private_items);
},
ItemKind::Trait(_, _, unsafety, ..) => match (headers.safety, unsafety) {
ItemKind::Trait(_, _, _, unsafety, ..) => match (headers.safety, unsafety) {
(false, Safety::Unsafe) => span_lint(
cx,
MISSING_SAFETY_DOC,
@@ -448,30 +448,30 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool {
},
(
Trait(box ast::Trait {
impl_restriction: liprt,
constness: lc,
is_auto: la,
safety: lu,
impl_restriction: liprt,
ident: li,
generics: lg,
bounds: lb,
items: lis,
}),
Trait(box ast::Trait {
impl_restriction: riprt,
constness: rc,
is_auto: ra,
safety: ru,
impl_restriction: riprt,
ident: ri,
generics: rg,
bounds: rb,
items: ris,
}),
) => {
matches!(lc, ast::Const::No) == matches!(rc, ast::Const::No)
eq_impl_restriction(liprt, riprt)
&& matches!(lc, ast::Const::No) == matches!(rc, ast::Const::No)
&& la == ra
&& matches!(lu, Safety::Default) == matches!(ru, Safety::Default)
&& eq_impl_restriction(liprt, riprt)
&& eq_id(*li, *ri)
&& eq_generics(lg, rg)
&& over(lb, rb, eq_generic_bound)
@@ -265,14 +265,14 @@ fn item_search_pat(item: &Item<'_>) -> (Pat, Pat) {
ItemKind::Struct(_, _, VariantData::Struct { .. }) => (Pat::Str("struct"), Pat::Str("}")),
ItemKind::Struct(..) => (Pat::Str("struct"), Pat::Str(";")),
ItemKind::Union(..) => (Pat::Str("union"), Pat::Str("}")),
ItemKind::Trait(_, _, Safety::Unsafe, ..)
ItemKind::Trait(_, _, _, Safety::Unsafe, ..)
| ItemKind::Impl(Impl {
of_trait: Some(TraitImplHeader {
safety: Safety::Unsafe, ..
}),
..
}) => (Pat::Str("unsafe"), Pat::Str("}")),
ItemKind::Trait(_, IsAuto::Yes, ..) => (Pat::Str("auto"), Pat::Str("}")),
ItemKind::Trait(_, _, IsAuto::Yes, ..) => (Pat::Str("auto"), Pat::Str("}")),
ItemKind::Trait(..) => (Pat::Str("trait"), Pat::Str("}")),
ItemKind::Impl(_) => (Pat::Str("impl"), Pat::Str("}")),
ItemKind::Mod(..) => (Pat::Str("mod"), Pat::Str("")),
+2 -2
View File
@@ -1155,10 +1155,10 @@ pub(crate) fn format_trait(
offset: Indent,
) -> RewriteResult {
let ast::Trait {
ref impl_restriction,
constness,
is_auto,
safety,
ref impl_restriction,
ident,
ref generics,
ref bounds,
@@ -1169,10 +1169,10 @@ pub(crate) fn format_trait(
let header = format!(
"{}{}{}{}{}trait ",
format_visibility(context, &item.vis),
format_impl_restriction(context, impl_restriction),
format_constness(constness),
format_safety(safety),
format_auto(is_auto),
format_impl_restriction(context, impl_restriction),
);
result.push_str(&header);
@@ -18,24 +18,25 @@ impl ( in foo
trait Baz {}
pub
const
impl
(self)
const
trait QuxConst {}
pub
auto impl(
pub
impl(
super
)
) auto
trait QuxAuto {}
pub
unsafe impl
(in crate)
pub
impl
(in crate) unsafe
trait QuxUnsafe {}
pub const
unsafe impl
pub
impl
(in super
::foo)
const unsafe
trait QuxConstUnsafe {}
@@ -6,10 +6,10 @@
pub impl(in foo::bar) trait Baz {}
pub const impl(self) trait QuxConst {}
pub impl(self) const trait QuxConst {}
pub auto impl(super) trait QuxAuto {}
pub impl(super) auto trait QuxAuto {}
pub unsafe impl(in crate) trait QuxUnsafe {}
pub impl(in crate) unsafe trait QuxUnsafe {}
pub const unsafe impl(in super::foo) trait QuxConstUnsafe {}
pub impl(in super::foo) const unsafe trait QuxConstUnsafe {}
@@ -11,14 +11,14 @@
mod foo {
pub impl(in crate::foo) trait Baz {} //[without_gate]~ ERROR `impl` restrictions are experimental
pub unsafe impl(super) trait BazUnsafeSuper {} //[without_gate]~ ERROR `impl` restrictions are experimental
pub auto impl(self) trait BazAutoSelf {} //[without_gate]~ ERROR `impl` restrictions are experimental
pub const impl(in self) trait BazConst {} //[without_gate]~ ERROR `impl` restrictions are experimental
pub impl(super) unsafe trait BazUnsafeSuper {} //[without_gate]~ ERROR `impl` restrictions are experimental
pub impl(self) auto trait BazAutoSelf {} //[without_gate]~ ERROR `impl` restrictions are experimental
pub impl(in self) const trait BazConst {} //[without_gate]~ ERROR `impl` restrictions are experimental
mod foo_inner {
pub impl(in crate::foo::foo_inner) trait Qux {} //[without_gate]~ ERROR `impl` restrictions are experimental
pub unsafe auto impl(in crate::foo::foo_inner) trait QuxAutoUnsafe {} //[without_gate]~ ERROR `impl` restrictions are experimental
pub const unsafe impl(in crate::foo::foo_inner) trait QuxConstUnsafe {} //[without_gate]~ ERROR `impl` restrictions are experimental
pub impl(in crate::foo::foo_inner) unsafe auto trait QuxAutoUnsafe {} //[without_gate]~ ERROR `impl` restrictions are experimental
pub impl(in crate::foo::foo_inner) const unsafe trait QuxConstUnsafe {} //[without_gate]~ ERROR `impl` restrictions are experimental
}
#[cfg(false)]
@@ -26,17 +26,17 @@ mod foo_inner {
#[cfg(false)]
pub impl(in crate) trait BarInCrate {} //[without_gate]~ ERROR `impl` restrictions are experimental
#[cfg(false)]
pub unsafe impl(self) trait BazUnsafeSelf {} //[without_gate]~ ERROR `impl` restrictions are experimental
pub impl(self) unsafe trait BazUnsafeSelf {} //[without_gate]~ ERROR `impl` restrictions are experimental
#[cfg(false)]
pub auto impl(in super) trait BazAutoSuper {} //[without_gate]~ ERROR `impl` restrictions are experimental
pub impl(in super) auto trait BazAutoSuper {} //[without_gate]~ ERROR `impl` restrictions are experimental
#[cfg(false)]
pub const impl(super) trait BazConstSuper {} //[without_gate]~ ERROR `impl` restrictions are experimental
pub impl(super) const trait BazConstSuper {} //[without_gate]~ ERROR `impl` restrictions are experimental
#[cfg(false)]
mod cfged_out_foo {
pub impl(in crate::foo::cfged_out_foo) trait CfgedOutQux {} //[without_gate]~ ERROR `impl` restrictions are experimental
pub unsafe auto impl(in crate::foo::cfged_out_foo) trait CfgedOutQuxUnsafeAuto {} //[without_gate]~ ERROR `impl` restrictions are experimental
pub const unsafe impl(in crate::foo::cfged_out_foo) trait CfgedOutQuxConstUnsafe {} //[without_gate]~ ERROR `impl` restrictions are experimental
pub impl(in crate::foo::cfged_out_foo) unsafe auto trait CfgedOutQuxUnsafeAuto {} //[without_gate]~ ERROR `impl` restrictions are experimental
pub impl(in crate::foo::cfged_out_foo) const unsafe trait CfgedOutQuxConstUnsafe {} //[without_gate]~ ERROR `impl` restrictions are experimental
}
// auto traits cannot be const, so we do not include these combinations in the test.
@@ -29,30 +29,30 @@ LL | pub impl(in crate::foo) trait Baz {}
= 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/feature-gate-impl-restriction.rs:14:16
--> $DIR/feature-gate-impl-restriction.rs:14:9
|
LL | pub unsafe impl(super) trait BazUnsafeSuper {}
| ^^^^^^^^^^^
LL | pub impl(super) unsafe trait BazUnsafeSuper {}
| ^^^^^^^^^^^
|
= 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/feature-gate-impl-restriction.rs:15:14
--> $DIR/feature-gate-impl-restriction.rs:15:9
|
LL | pub auto impl(self) trait BazAutoSelf {}
| ^^^^^^^^^^
LL | pub impl(self) auto trait BazAutoSelf {}
| ^^^^^^^^^^
|
= 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/feature-gate-impl-restriction.rs:16:15
--> $DIR/feature-gate-impl-restriction.rs:16:9
|
LL | pub const impl(in self) trait BazConst {}
| ^^^^^^^^^^^^^
LL | pub impl(in self) const trait BazConst {}
| ^^^^^^^^^^^^^
|
= 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
@@ -69,20 +69,20 @@ LL | pub impl(in crate::foo::foo_inner) trait Qux {}
= 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/feature-gate-impl-restriction.rs:20:25
--> $DIR/feature-gate-impl-restriction.rs:20:13
|
LL | ... pub unsafe auto impl(in crate::foo::foo_inner) trait QuxAutoUnsafe {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | ... pub impl(in crate::foo::foo_inner) unsafe auto trait QuxAutoUnsafe {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= 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/feature-gate-impl-restriction.rs:21:26
--> $DIR/feature-gate-impl-restriction.rs:21:13
|
LL | ... pub const unsafe impl(in crate::foo::foo_inner) trait QuxConstUnsafe {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | ... pub impl(in crate::foo::foo_inner) const unsafe trait QuxConstUnsafe {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= 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
@@ -109,30 +109,30 @@ LL | pub impl(in crate) trait BarInCrate {}
= 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/feature-gate-impl-restriction.rs:29:16
--> $DIR/feature-gate-impl-restriction.rs:29:9
|
LL | pub unsafe impl(self) trait BazUnsafeSelf {}
| ^^^^^^^^^^
LL | pub impl(self) unsafe trait BazUnsafeSelf {}
| ^^^^^^^^^^
|
= 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/feature-gate-impl-restriction.rs:31:14
--> $DIR/feature-gate-impl-restriction.rs:31:9
|
LL | pub auto impl(in super) trait BazAutoSuper {}
| ^^^^^^^^^^^^^^
LL | pub impl(in super) auto trait BazAutoSuper {}
| ^^^^^^^^^^^^^^
|
= 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/feature-gate-impl-restriction.rs:33:15
--> $DIR/feature-gate-impl-restriction.rs:33:9
|
LL | pub const impl(super) trait BazConstSuper {}
| ^^^^^^^^^^^
LL | pub impl(super) const trait BazConstSuper {}
| ^^^^^^^^^^^
|
= 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
@@ -149,20 +149,20 @@ LL | pub impl(in crate::foo::cfged_out_foo) trait CfgedOutQux {}
= 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/feature-gate-impl-restriction.rs:38:25
--> $DIR/feature-gate-impl-restriction.rs:38:13
|
LL | ... pub unsafe auto impl(in crate::foo::cfged_out_foo) trait CfgedOutQuxUnsafeAuto {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | ... pub impl(in crate::foo::cfged_out_foo) unsafe auto trait CfgedOutQuxUnsafeAuto {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= 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/feature-gate-impl-restriction.rs:39:26
--> $DIR/feature-gate-impl-restriction.rs:39:13
|
LL | ... pub const unsafe impl(in crate::foo::cfged_out_foo) trait CfgedOutQuxConstUnsafe {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | ... pub impl(in crate::foo::cfged_out_foo) const unsafe trait CfgedOutQuxConstUnsafe {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= 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
@@ -1,21 +1,30 @@
//@ compile-flags: --crate-type=lib
//@ revisions: with_gate without_gate
#![warn(incomplete_features)]
#![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)]
#![feature(impl_restriction, auto_traits, const_trait_impl)]
#![expect(incomplete_features)]
mod foo {
pub impl(crate::foo) trait Baz {} //~ ERROR incorrect `impl` restriction
//[without_gate]~^ ERROR `impl` restrictions are experimental
pub unsafe impl(crate::foo) trait BazUnsafe {} //~ ERROR incorrect `impl` restriction
//[without_gate]~^ ERROR `impl` restrictions are experimental
pub auto impl(crate::foo) trait BazAuto {} //~ ERROR incorrect `impl` restriction
//[without_gate]~^ ERROR `impl` restrictions are experimental
pub const impl(crate::foo) trait BazConst {} //~ ERROR incorrect `impl` restriction
//[without_gate]~^ ERROR `impl` restrictions are experimental
pub const unsafe impl(crate::foo) trait BazConstUnsafe {} //~ ERROR incorrect `impl` restriction
//[without_gate]~^ ERROR `impl` restrictions are experimental
pub unsafe auto impl(crate::foo) trait BazUnsafeAuto {} //~ ERROR incorrect `impl` restriction
//[without_gate]~^ ERROR `impl` restrictions are experimental
pub impl(crate::foo) unsafe trait BazUnsafe {} //~ ERROR incorrect `impl` restriction
pub impl(crate::foo) auto trait BazAuto {} //~ ERROR incorrect `impl` restriction
pub impl(crate::foo) const trait BazConst {} //~ ERROR incorrect `impl` restriction
pub impl(crate::foo) const unsafe trait BazConstUnsafe {} //~ ERROR incorrect `impl` restriction
pub impl(crate::foo) unsafe auto trait BazUnsafeAuto {} //~ ERROR incorrect `impl` restriction
// FIXME: The positioning of `impl(..)` may be confusing.
// When users get the keyword order wrong, the compiler currently emits
// a generic "unexpected token" error, which is not very helpful.
// In the future, we could improve diagnostics by detecting misordered
// keywords and suggesting the correct order.
pub unsafe impl(crate::foo) trait BadOrder1 {} //~ ERROR expected one of `for`, `where`, or `{`, found keyword `trait`
// FIXME: The following cases are not checked for now,
// as the compiler aborts due to the previous syntax error in `BadOrder1`.
// In the future, we could recover from such errors and continue compilation.
pub auto impl(crate::foo) trait BadOrder2 {}
pub const impl(crate::foo) trait BadOrder3 {}
pub unsafe auto impl(crate::foo) trait BadOrder4 {}
pub const unsafe impl(crate::foo) trait BadOrder5 {}
pub unsafe impl(crate::foo) auto trait BadOrder6 {}
pub const impl(crate::foo) unsafe trait BadOrder7 {}
}
fn main() {}
@@ -1,5 +1,5 @@
error: incorrect `impl` restriction
--> $DIR/recover-incorrect-impl-restriction.rs:9:14
--> $DIR/recover-incorrect-impl-restriction.rs:5:14
|
LL | pub impl(crate::foo) trait Baz {}
| ^^^^^^^^^^
@@ -15,10 +15,10 @@ LL | pub impl(in crate::foo) trait Baz {}
| ++
error: incorrect `impl` restriction
--> $DIR/recover-incorrect-impl-restriction.rs:11:21
--> $DIR/recover-incorrect-impl-restriction.rs:6:14
|
LL | pub unsafe impl(crate::foo) trait BazUnsafe {}
| ^^^^^^^^^^
LL | pub impl(crate::foo) unsafe trait BazUnsafe {}
| ^^^^^^^^^^
|
= help: some possible `impl` restrictions are:
`impl(crate)`: can only be implemented in the current crate
@@ -27,14 +27,14 @@ LL | pub unsafe impl(crate::foo) trait BazUnsafe {}
`impl(in path::to::module)`: can only be implemented in the specified path
help: help: use `in` to restrict implementations to the path `crate::foo`
|
LL | pub unsafe impl(in crate::foo) trait BazUnsafe {}
| ++
LL | pub impl(in crate::foo) unsafe trait BazUnsafe {}
| ++
error: incorrect `impl` restriction
--> $DIR/recover-incorrect-impl-restriction.rs:13:19
--> $DIR/recover-incorrect-impl-restriction.rs:7:14
|
LL | pub auto impl(crate::foo) trait BazAuto {}
| ^^^^^^^^^^
LL | pub impl(crate::foo) auto trait BazAuto {}
| ^^^^^^^^^^
|
= help: some possible `impl` restrictions are:
`impl(crate)`: can only be implemented in the current crate
@@ -43,14 +43,14 @@ LL | pub auto impl(crate::foo) trait BazAuto {}
`impl(in path::to::module)`: can only be implemented in the specified path
help: help: use `in` to restrict implementations to the path `crate::foo`
|
LL | pub auto impl(in crate::foo) trait BazAuto {}
| ++
LL | pub impl(in crate::foo) auto trait BazAuto {}
| ++
error: incorrect `impl` restriction
--> $DIR/recover-incorrect-impl-restriction.rs:15:20
--> $DIR/recover-incorrect-impl-restriction.rs:8:14
|
LL | pub const impl(crate::foo) trait BazConst {}
| ^^^^^^^^^^
LL | pub impl(crate::foo) const trait BazConst {}
| ^^^^^^^^^^
|
= help: some possible `impl` restrictions are:
`impl(crate)`: can only be implemented in the current crate
@@ -59,14 +59,14 @@ LL | pub const impl(crate::foo) trait BazConst {}
`impl(in path::to::module)`: can only be implemented in the specified path
help: help: use `in` to restrict implementations to the path `crate::foo`
|
LL | pub const impl(in crate::foo) trait BazConst {}
| ++
LL | pub impl(in crate::foo) const trait BazConst {}
| ++
error: incorrect `impl` restriction
--> $DIR/recover-incorrect-impl-restriction.rs:17:27
--> $DIR/recover-incorrect-impl-restriction.rs:9:14
|
LL | pub const unsafe impl(crate::foo) trait BazConstUnsafe {}
| ^^^^^^^^^^
LL | pub impl(crate::foo) const unsafe trait BazConstUnsafe {}
| ^^^^^^^^^^
|
= help: some possible `impl` restrictions are:
`impl(crate)`: can only be implemented in the current crate
@@ -75,14 +75,14 @@ LL | pub const unsafe impl(crate::foo) trait BazConstUnsafe {}
`impl(in path::to::module)`: can only be implemented in the specified path
help: help: use `in` to restrict implementations to the path `crate::foo`
|
LL | pub const unsafe impl(in crate::foo) trait BazConstUnsafe {}
| ++
LL | pub impl(in crate::foo) const unsafe trait BazConstUnsafe {}
| ++
error: incorrect `impl` restriction
--> $DIR/recover-incorrect-impl-restriction.rs:19:26
--> $DIR/recover-incorrect-impl-restriction.rs:10:14
|
LL | pub unsafe auto impl(crate::foo) trait BazUnsafeAuto {}
| ^^^^^^^^^^
LL | pub impl(crate::foo) unsafe auto trait BazUnsafeAuto {}
| ^^^^^^^^^^
|
= help: some possible `impl` restrictions are:
`impl(crate)`: can only be implemented in the current crate
@@ -91,21 +91,14 @@ LL | pub unsafe auto impl(crate::foo) trait BazUnsafeAuto {}
`impl(in path::to::module)`: can only be implemented in the specified path
help: help: use `in` to restrict implementations to the path `crate::foo`
|
LL | pub unsafe auto impl(in crate::foo) trait BazUnsafeAuto {}
| ++
LL | pub impl(in crate::foo) unsafe auto trait BazUnsafeAuto {}
| ++
warning: the feature `impl_restriction` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/recover-incorrect-impl-restriction.rs:4:32
error: expected one of `for`, `where`, or `{`, found keyword `trait`
--> $DIR/recover-incorrect-impl-restriction.rs:17:33
|
LL | #![cfg_attr(with_gate, feature(impl_restriction))]
| ^^^^^^^^^^^^^^^^
|
= note: see issue #105077 <https://github.com/rust-lang/rust/issues/105077> for more information
note: the lint level is defined here
--> $DIR/recover-incorrect-impl-restriction.rs:3:9
|
LL | #![warn(incomplete_features)]
| ^^^^^^^^^^^^^^^^^^^
LL | pub unsafe impl(crate::foo) trait BadOrder1 {}
| ^^^^^ expected one of `for`, `where`, or `{`
error: aborting due to 6 previous errors; 1 warning emitted
error: aborting due to 7 previous errors
@@ -1,159 +0,0 @@
error: incorrect `impl` restriction
--> $DIR/recover-incorrect-impl-restriction.rs:9:14
|
LL | pub impl(crate::foo) trait Baz {}
| ^^^^^^^^^^
|
= help: some possible `impl` restrictions are:
`impl(crate)`: can only be implemented in the current crate
`impl(super)`: can only be implemented in the parent module
`impl(self)`: can only be implemented in current module
`impl(in path::to::module)`: can only be implemented in the specified path
help: help: use `in` to restrict implementations to the path `crate::foo`
|
LL | pub impl(in crate::foo) trait Baz {}
| ++
error: incorrect `impl` restriction
--> $DIR/recover-incorrect-impl-restriction.rs:11:21
|
LL | pub unsafe impl(crate::foo) trait BazUnsafe {}
| ^^^^^^^^^^
|
= help: some possible `impl` restrictions are:
`impl(crate)`: can only be implemented in the current crate
`impl(super)`: can only be implemented in the parent module
`impl(self)`: can only be implemented in current module
`impl(in path::to::module)`: can only be implemented in the specified path
help: help: use `in` to restrict implementations to the path `crate::foo`
|
LL | pub unsafe impl(in crate::foo) trait BazUnsafe {}
| ++
error: incorrect `impl` restriction
--> $DIR/recover-incorrect-impl-restriction.rs:13:19
|
LL | pub auto impl(crate::foo) trait BazAuto {}
| ^^^^^^^^^^
|
= help: some possible `impl` restrictions are:
`impl(crate)`: can only be implemented in the current crate
`impl(super)`: can only be implemented in the parent module
`impl(self)`: can only be implemented in current module
`impl(in path::to::module)`: can only be implemented in the specified path
help: help: use `in` to restrict implementations to the path `crate::foo`
|
LL | pub auto impl(in crate::foo) trait BazAuto {}
| ++
error: incorrect `impl` restriction
--> $DIR/recover-incorrect-impl-restriction.rs:15:20
|
LL | pub const impl(crate::foo) trait BazConst {}
| ^^^^^^^^^^
|
= help: some possible `impl` restrictions are:
`impl(crate)`: can only be implemented in the current crate
`impl(super)`: can only be implemented in the parent module
`impl(self)`: can only be implemented in current module
`impl(in path::to::module)`: can only be implemented in the specified path
help: help: use `in` to restrict implementations to the path `crate::foo`
|
LL | pub const impl(in crate::foo) trait BazConst {}
| ++
error: incorrect `impl` restriction
--> $DIR/recover-incorrect-impl-restriction.rs:17:27
|
LL | pub const unsafe impl(crate::foo) trait BazConstUnsafe {}
| ^^^^^^^^^^
|
= help: some possible `impl` restrictions are:
`impl(crate)`: can only be implemented in the current crate
`impl(super)`: can only be implemented in the parent module
`impl(self)`: can only be implemented in current module
`impl(in path::to::module)`: can only be implemented in the specified path
help: help: use `in` to restrict implementations to the path `crate::foo`
|
LL | pub const unsafe impl(in crate::foo) trait BazConstUnsafe {}
| ++
error: incorrect `impl` restriction
--> $DIR/recover-incorrect-impl-restriction.rs:19:26
|
LL | pub unsafe auto impl(crate::foo) trait BazUnsafeAuto {}
| ^^^^^^^^^^
|
= help: some possible `impl` restrictions are:
`impl(crate)`: can only be implemented in the current crate
`impl(super)`: can only be implemented in the parent module
`impl(self)`: can only be implemented in current module
`impl(in path::to::module)`: can only be implemented in the specified path
help: help: use `in` to restrict implementations to the path `crate::foo`
|
LL | pub unsafe auto impl(in crate::foo) trait BazUnsafeAuto {}
| ++
error[E0658]: `impl` restrictions are experimental
--> $DIR/recover-incorrect-impl-restriction.rs:9:9
|
LL | pub impl(crate::foo) trait Baz {}
| ^^^^^^^^^^^^^^^^
|
= 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/recover-incorrect-impl-restriction.rs:11:16
|
LL | pub unsafe impl(crate::foo) trait BazUnsafe {}
| ^^^^^^^^^^^^^^^^
|
= 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/recover-incorrect-impl-restriction.rs:13:14
|
LL | pub auto impl(crate::foo) trait BazAuto {}
| ^^^^^^^^^^^^^^^^
|
= 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/recover-incorrect-impl-restriction.rs:15:15
|
LL | pub const impl(crate::foo) trait BazConst {}
| ^^^^^^^^^^^^^^^^
|
= 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/recover-incorrect-impl-restriction.rs:17:22
|
LL | pub const unsafe impl(crate::foo) trait BazConstUnsafe {}
| ^^^^^^^^^^^^^^^^
|
= 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/recover-incorrect-impl-restriction.rs:19:21
|
LL | pub unsafe auto impl(crate::foo) trait BazUnsafeAuto {}
| ^^^^^^^^^^^^^^^^
|
= 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 12 previous errors
For more information about this error, try `rustc --explain E0658`.
@@ -1,29 +1,20 @@
//@ compile-flags: --crate-type=lib
//@ revisions: with_gate without_gate
#![warn(incomplete_features)]
#![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)]
#![feature(impl_restriction, auto_traits, const_trait_impl, trait_alias)]
#![expect(incomplete_features)]
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
impl(in crate) auto 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
impl(self) unsafe 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
impl(in self) const trait ConstAlias = Copy; //~ ERROR trait aliases cannot be `impl`-restricted
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
impl(in crate::foo) const unsafe 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
impl(in crate::foo) unsafe auto 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
}
fn main() {}
@@ -1,87 +1,74 @@
error: trait aliases cannot be `impl`-restricted
--> $DIR/trait-alias-cannot-be-impl-restricted.rs:8:1
--> $DIR/trait-alias-cannot-be-impl-restricted.rs:4: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:10:1
--> $DIR/trait-alias-cannot-be-impl-restricted.rs:5:1
|
LL | auto impl(in crate) trait AutoAlias = Copy;
LL | impl(in crate) auto trait AutoAlias = Copy;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait aliases cannot be `auto`
error: trait aliases cannot be `impl`-restricted
--> $DIR/trait-alias-cannot-be-impl-restricted.rs:10:1
--> $DIR/trait-alias-cannot-be-impl-restricted.rs:5:1
|
LL | auto impl(in crate) trait AutoAlias = Copy;
LL | impl(in crate) auto trait AutoAlias = Copy;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait aliases cannot be `impl`-restricted
error: trait aliases cannot be `unsafe`
--> $DIR/trait-alias-cannot-be-impl-restricted.rs:13:1
--> $DIR/trait-alias-cannot-be-impl-restricted.rs:7:1
|
LL | unsafe impl(self) trait UnsafeAlias = Copy;
LL | impl(self) unsafe trait UnsafeAlias = Copy;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait aliases cannot be `unsafe`
error: trait aliases cannot be `impl`-restricted
--> $DIR/trait-alias-cannot-be-impl-restricted.rs:13:1
--> $DIR/trait-alias-cannot-be-impl-restricted.rs:7:1
|
LL | unsafe impl(self) trait UnsafeAlias = Copy;
LL | impl(self) unsafe trait UnsafeAlias = Copy;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait aliases cannot be `impl`-restricted
error: trait aliases cannot be `impl`-restricted
--> $DIR/trait-alias-cannot-be-impl-restricted.rs:16:1
--> $DIR/trait-alias-cannot-be-impl-restricted.rs:9:1
|
LL | const impl(in self) trait ConstAlias = Copy;
LL | impl(in self) const trait ConstAlias = Copy;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait aliases cannot be `impl`-restricted
error: trait aliases cannot be `impl`-restricted
--> $DIR/trait-alias-cannot-be-impl-restricted.rs:20:5
--> $DIR/trait-alias-cannot-be-impl-restricted.rs:12: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:22:5
--> $DIR/trait-alias-cannot-be-impl-restricted.rs:13:5
|
LL | const unsafe impl(in crate::foo) trait InnerConstUnsafeAlias = Copy;
LL | impl(in crate::foo) const unsafe trait InnerConstUnsafeAlias = Copy;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait aliases cannot be `unsafe`
error: trait aliases cannot be `impl`-restricted
--> $DIR/trait-alias-cannot-be-impl-restricted.rs:22:5
--> $DIR/trait-alias-cannot-be-impl-restricted.rs:13:5
|
LL | const unsafe impl(in crate::foo) trait InnerConstUnsafeAlias = Copy;
LL | impl(in crate::foo) const unsafe trait InnerConstUnsafeAlias = Copy;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait aliases cannot be `impl`-restricted
error: trait aliases cannot be `auto`
--> $DIR/trait-alias-cannot-be-impl-restricted.rs:25:5
--> $DIR/trait-alias-cannot-be-impl-restricted.rs:15:5
|
LL | unsafe auto impl(in crate::foo) trait InnerUnsafeAutoAlias = Copy;
LL | impl(in crate::foo) unsafe auto trait InnerUnsafeAutoAlias = Copy;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait aliases cannot be `auto`
error: trait aliases cannot be `unsafe`
--> $DIR/trait-alias-cannot-be-impl-restricted.rs:25:5
--> $DIR/trait-alias-cannot-be-impl-restricted.rs:15:5
|
LL | unsafe auto impl(in crate::foo) trait InnerUnsafeAutoAlias = Copy;
LL | impl(in crate::foo) unsafe auto trait InnerUnsafeAutoAlias = Copy;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait aliases cannot be `unsafe`
error: trait aliases cannot be `impl`-restricted
--> $DIR/trait-alias-cannot-be-impl-restricted.rs:25:5
--> $DIR/trait-alias-cannot-be-impl-restricted.rs:15:5
|
LL | unsafe auto impl(in crate::foo) trait InnerUnsafeAutoAlias = Copy;
LL | impl(in crate::foo) unsafe auto 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:4: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: the lint level is defined here
--> $DIR/trait-alias-cannot-be-impl-restricted.rs:3:9
|
LL | #![warn(incomplete_features)]
| ^^^^^^^^^^^^^^^^^^^
error: aborting due to 12 previous errors; 1 warning emitted
error: aborting due to 12 previous errors
@@ -1,145 +0,0 @@
error: trait aliases cannot be `impl`-restricted
--> $DIR/trait-alias-cannot-be-impl-restricted.rs:8: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:10: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:10: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:13: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:13: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:16: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:20: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:22: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:22: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:25: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:25: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:25: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:8: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:10: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:13: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:16: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:20: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:22: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:25: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`.
+26 -26
View File
@@ -864,56 +864,56 @@ fn test_impl_restriction() {
);
assert_eq!(
stringify!(pub auto impl(crate) trait Foo {}),
"pub auto impl(crate) trait Foo {}"
stringify!(pub impl(crate) auto trait Foo {}),
"pub impl(crate) auto trait Foo {}"
);
assert_eq!(
stringify!(pub auto impl(in crate::path::to) trait Foo {}),
"pub auto impl(in crate::path::to) trait Foo {}"
stringify!(pub impl(in crate::path::to) auto trait Foo {}),
"pub impl(in crate::path::to) auto trait Foo {}"
);
assert_eq!(
stringify!(pub unsafe impl(crate) trait Foo {}),
"pub unsafe impl(crate) trait Foo {}"
stringify!(pub impl(crate) unsafe trait Foo {}),
"pub impl(crate) unsafe trait Foo {}"
);
assert_eq!(
stringify!(pub unsafe impl(in crate::path::to) trait Foo {}),
"pub unsafe impl(in crate::path::to) trait Foo {}"
stringify!(pub impl(in crate::path::to) unsafe trait Foo {}),
"pub impl(in crate::path::to) unsafe trait Foo {}"
);
assert_eq!(
stringify!(pub const impl(crate) trait Foo {}),
"pub const impl(crate) trait Foo {}"
stringify!(pub impl(crate) const trait Foo {}),
"pub impl(crate) const trait Foo {}"
);
assert_eq!(
stringify!(pub const impl(in crate::path::to) trait Foo {}),
"pub const impl(in crate::path::to) trait Foo {}"
stringify!(pub impl(in crate::path::to) const trait Foo {}),
"pub impl(in crate::path::to) const trait Foo {}"
);
assert_eq!(
stringify!(pub unsafe auto impl(crate) trait Foo {}),
"pub unsafe auto impl(crate) trait Foo {}"
stringify!(pub impl(crate) unsafe auto trait Foo {}),
"pub impl(crate) unsafe auto trait Foo {}"
);
assert_eq!(
stringify!(pub unsafe auto impl(in crate::path::to) trait Foo {}),
"pub unsafe auto impl(in crate::path::to) trait Foo {}"
stringify!(pub impl(in crate::path::to) unsafe auto trait Foo {}),
"pub impl(in crate::path::to) unsafe auto trait Foo {}"
);
assert_eq!(
stringify!(pub const auto impl(crate) trait Foo {}),
"pub const auto impl(crate) trait Foo {}"
stringify!(pub impl(crate) const auto trait Foo {}),
"pub impl(crate) const auto trait Foo {}"
);
assert_eq!(
stringify!(pub const auto impl(in crate::path::to) trait Foo {}),
"pub const auto impl(in crate::path::to) trait Foo {}"
stringify!(pub impl(in crate::path::to) const auto trait Foo {}),
"pub impl(in crate::path::to) const auto trait Foo {}"
);
assert_eq!(
stringify!(pub const unsafe impl(crate) trait Foo {}),
"pub const unsafe impl(crate) trait Foo {}"
stringify!(pub impl(crate) const unsafe trait Foo {}),
"pub impl(crate) const unsafe trait Foo {}"
);
assert_eq!(
stringify!(pub const unsafe impl(in crate::path::to) trait Foo {}),
"pub const unsafe impl(in crate::path::to) trait Foo {}"
stringify!(pub impl(in crate::path::to) const unsafe trait Foo {}),
"pub impl(in crate::path::to) const unsafe trait Foo {}"
);
assert_eq!(
stringify!(pub const unsafe auto impl(crate) trait Foo {}),
"pub const unsafe auto impl(crate) trait Foo {}"
stringify!(pub impl(crate) const unsafe auto trait Foo {}),
"pub impl(crate) const unsafe auto trait Foo {}"
);
assert_eq!(
stringify!(pub const unsafe auto impl(in crate::path::to) trait Foo {}),
@@ -0,0 +1,10 @@
// Reported in <https://github.com/rust-lang/rust/pull/148434#issuecomment-3621280430>.
//@ check-pass
#![feature(const_trait_impl)]
const unsafe impl Trait for () {}
const unsafe trait Trait {}
fn main() {}