Skip to content

Commit 52aed95

Browse files
authored
Rollup merge of #139063 - fmease:fix-tait-atpit-gating, r=oli-obk
Fix TAIT & ATPIT feature gating in the presence of anon consts Fixes #139055 (#119924 (comment)). r? oli-obk or anybody else
2 parents 660e863 + 7a295d1 commit 52aed95

8 files changed

+200
-13
lines changed

compiler/rustc_ast_passes/src/feature_gate.rs

+7
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,13 @@ impl<'a> PostExpansionVisitor<'a> {
9999
}
100100
visit::walk_ty(self, ty);
101101
}
102+
103+
fn visit_anon_const(&mut self, _: &ast::AnonConst) -> Self::Result {
104+
// We don't walk the anon const because it crosses a conceptual boundary: We're no
105+
// longer "inside" the original type.
106+
// Brittle: We assume that the callers of `check_impl_trait` will later recurse into
107+
// the items found in the AnonConst to look for nested TyAliases.
108+
}
102109
}
103110
ImplTraitVisitor { vis: self, in_associated_ty }.visit_ty(ty);
104111
}

tests/ui/feature-gates/feature-gate-impl_trait_in_assoc_type.rs

+9
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,13 @@ impl Mop {
1717
//~| ERROR: unconstrained opaque type
1818
}
1919

20+
fn funky(_: [(); {
21+
impl Foo for fn() {
22+
type Bar = impl Sized;
23+
//~^ ERROR: `impl Trait` in associated types is unstable
24+
//~| ERROR: unconstrained opaque type
25+
}
26+
0
27+
}]) {}
28+
2029
fn main() {}

tests/ui/feature-gates/feature-gate-impl_trait_in_assoc_type.stderr

+19-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ LL | type Bop = impl std::fmt::Debug;
1818
= help: add `#![feature(impl_trait_in_assoc_type)]` to the crate attributes to enable
1919
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
2020

21+
error[E0658]: `impl Trait` in associated types is unstable
22+
--> $DIR/feature-gate-impl_trait_in_assoc_type.rs:22:20
23+
|
24+
LL | type Bar = impl Sized;
25+
| ^^^^^^^^^^
26+
|
27+
= note: see issue #63063 <https://github.com/rust-lang/rust/issues/63063> for more information
28+
= help: add `#![feature(impl_trait_in_assoc_type)]` to the crate attributes to enable
29+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
30+
2131
error[E0658]: inherent associated types are unstable
2232
--> $DIR/feature-gate-impl_trait_in_assoc_type.rs:14:5
2333
|
@@ -44,6 +54,14 @@ LL | type Bop = impl std::fmt::Debug;
4454
|
4555
= note: `Bop` must be used in combination with a concrete type within the same impl
4656

47-
error: aborting due to 5 previous errors
57+
error: unconstrained opaque type
58+
--> $DIR/feature-gate-impl_trait_in_assoc_type.rs:22:20
59+
|
60+
LL | type Bar = impl Sized;
61+
| ^^^^^^^^^^
62+
|
63+
= note: `Bar` must be used in combination with a concrete type within the same impl
64+
65+
error: aborting due to 7 previous errors
4866

4967
For more information about this error, try `rustc --explain E0658`.
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,42 @@
1-
//@ check-pass
2-
#![feature(type_alias_impl_trait)]
31
use std::fmt::Debug;
42

5-
type Foo = impl Debug;
3+
type Foo = impl Debug; //~ ERROR `impl Trait` in type aliases is unstable
64

75
struct Bar(Foo);
8-
#[define_opaque(Foo)]
6+
#[define_opaque(Foo)] //~ ERROR use of unstable library feature `type_alias_impl_trait`
97
fn define() -> Bar {
108
Bar(42)
119
}
1210

13-
type Foo2 = impl Debug;
11+
type Foo2 = impl Debug; //~ ERROR `impl Trait` in type aliases is unstable
1412

15-
#[define_opaque(Foo2)]
13+
#[define_opaque(Foo2)] //~ ERROR use of unstable library feature `type_alias_impl_trait`
1614
fn define2() {
1715
let x = || -> Foo2 { 42 };
1816
}
1917

20-
type Foo3 = impl Debug;
18+
type Foo3 = impl Debug; //~ ERROR `impl Trait` in type aliases is unstable
2119

22-
#[define_opaque(Foo3)]
20+
#[define_opaque(Foo3)] //~ ERROR use of unstable library feature `type_alias_impl_trait`
2321
fn define3(x: Foo3) {
2422
let y: i32 = x;
2523
}
26-
#[define_opaque(Foo3)]
24+
#[define_opaque(Foo3)] //~ ERROR use of unstable library feature `type_alias_impl_trait`
2725
fn define3_1() {
2826
define3(42)
2927
}
3028

31-
type Foo4 = impl Debug;
29+
type Foo4 = impl Debug; //~ ERROR `impl Trait` in type aliases is unstable
3230

33-
#[define_opaque(Foo4)]
31+
#[define_opaque(Foo4)] //~ ERROR use of unstable library feature `type_alias_impl_trait`
3432
fn define4(_: Foo4) {
3533
let y: Foo4 = 42;
3634
}
3735

36+
type Foo5 = [(); {
37+
type Foo = impl Debug; //~ ERROR `impl Trait` in type aliases is unstable
38+
//~^ ERROR unconstrained opaque type
39+
0
40+
}];
41+
3842
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
error[E0658]: use of unstable library feature `type_alias_impl_trait`: `type_alias_impl_trait` has open design concerns
2+
--> $DIR/feature-gate-type_alias_impl_trait.rs:6:3
3+
|
4+
LL | #[define_opaque(Foo)]
5+
| ^^^^^^^^^^^^^
6+
|
7+
= note: see issue #63063 <https://github.com/rust-lang/rust/issues/63063> for more information
8+
= help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable
9+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
10+
11+
error[E0658]: use of unstable library feature `type_alias_impl_trait`: `type_alias_impl_trait` has open design concerns
12+
--> $DIR/feature-gate-type_alias_impl_trait.rs:13:3
13+
|
14+
LL | #[define_opaque(Foo2)]
15+
| ^^^^^^^^^^^^^
16+
|
17+
= note: see issue #63063 <https://github.com/rust-lang/rust/issues/63063> for more information
18+
= help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable
19+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
20+
21+
error[E0658]: use of unstable library feature `type_alias_impl_trait`: `type_alias_impl_trait` has open design concerns
22+
--> $DIR/feature-gate-type_alias_impl_trait.rs:20:3
23+
|
24+
LL | #[define_opaque(Foo3)]
25+
| ^^^^^^^^^^^^^
26+
|
27+
= note: see issue #63063 <https://github.com/rust-lang/rust/issues/63063> for more information
28+
= help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable
29+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
30+
31+
error[E0658]: use of unstable library feature `type_alias_impl_trait`: `type_alias_impl_trait` has open design concerns
32+
--> $DIR/feature-gate-type_alias_impl_trait.rs:24:3
33+
|
34+
LL | #[define_opaque(Foo3)]
35+
| ^^^^^^^^^^^^^
36+
|
37+
= note: see issue #63063 <https://github.com/rust-lang/rust/issues/63063> for more information
38+
= help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable
39+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
40+
41+
error[E0658]: use of unstable library feature `type_alias_impl_trait`: `type_alias_impl_trait` has open design concerns
42+
--> $DIR/feature-gate-type_alias_impl_trait.rs:31:3
43+
|
44+
LL | #[define_opaque(Foo4)]
45+
| ^^^^^^^^^^^^^
46+
|
47+
= note: see issue #63063 <https://github.com/rust-lang/rust/issues/63063> for more information
48+
= help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable
49+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
50+
51+
error[E0658]: `impl Trait` in type aliases is unstable
52+
--> $DIR/feature-gate-type_alias_impl_trait.rs:3:12
53+
|
54+
LL | type Foo = impl Debug;
55+
| ^^^^^^^^^^
56+
|
57+
= note: see issue #63063 <https://github.com/rust-lang/rust/issues/63063> for more information
58+
= help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable
59+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
60+
61+
error[E0658]: `impl Trait` in type aliases is unstable
62+
--> $DIR/feature-gate-type_alias_impl_trait.rs:11:13
63+
|
64+
LL | type Foo2 = impl Debug;
65+
| ^^^^^^^^^^
66+
|
67+
= note: see issue #63063 <https://github.com/rust-lang/rust/issues/63063> for more information
68+
= help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable
69+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
70+
71+
error[E0658]: `impl Trait` in type aliases is unstable
72+
--> $DIR/feature-gate-type_alias_impl_trait.rs:18:13
73+
|
74+
LL | type Foo3 = impl Debug;
75+
| ^^^^^^^^^^
76+
|
77+
= note: see issue #63063 <https://github.com/rust-lang/rust/issues/63063> for more information
78+
= help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable
79+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
80+
81+
error[E0658]: `impl Trait` in type aliases is unstable
82+
--> $DIR/feature-gate-type_alias_impl_trait.rs:29:13
83+
|
84+
LL | type Foo4 = impl Debug;
85+
| ^^^^^^^^^^
86+
|
87+
= note: see issue #63063 <https://github.com/rust-lang/rust/issues/63063> for more information
88+
= help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable
89+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
90+
91+
error[E0658]: `impl Trait` in type aliases is unstable
92+
--> $DIR/feature-gate-type_alias_impl_trait.rs:37:16
93+
|
94+
LL | type Foo = impl Debug;
95+
| ^^^^^^^^^^
96+
|
97+
= note: see issue #63063 <https://github.com/rust-lang/rust/issues/63063> for more information
98+
= help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable
99+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
100+
101+
error: unconstrained opaque type
102+
--> $DIR/feature-gate-type_alias_impl_trait.rs:37:16
103+
|
104+
LL | type Foo = impl Debug;
105+
| ^^^^^^^^^^
106+
|
107+
= note: `Foo` must be used in combination with a concrete type within the same crate
108+
109+
error: aborting due to 11 previous errors
110+
111+
For more information about this error, try `rustc --explain E0658`.

tests/ui/impl-trait/impl_trait_projections.rs

+5
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,9 @@ fn projection_from_impl_trait_inside_dyn_trait_is_disallowed()
3535
panic!()
3636
}
3737

38+
fn parametrized_value_in_anon_const_is_disallowed() -> [(); None::<impl Sized>] {
39+
//~^ ERROR `impl Trait` is not allowed in paths
40+
loop {}
41+
}
42+
3843
fn main() {}

tests/ui/impl-trait/impl_trait_projections.stderr

+9-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ LL | -> <dyn Iterator<Item = impl Debug> as Iterator>::Item
3030
|
3131
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
3232

33-
error: aborting due to 4 previous errors
33+
error[E0562]: `impl Trait` is not allowed in paths
34+
--> $DIR/impl_trait_projections.rs:38:68
35+
|
36+
LL | fn parametrized_value_in_anon_const_is_disallowed() -> [(); None::<impl Sized>] {
37+
| ^^^^^^^^^^
38+
|
39+
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
40+
41+
error: aborting due to 5 previous errors
3442

3543
For more information about this error, try `rustc --explain E0562`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Ensure we don't misclassify `impl Trait` as TAIT/ATPIT if located inside an anon const in a
2+
// type alias/assoc type.
3+
// issue: <https://github.com/rust-lang/rust/issues/139055>
4+
//@ check-pass
5+
#![forbid(unstable_features)]
6+
7+
struct Girder<const N: usize>;
8+
9+
type Alias = Girder<{
10+
fn pass(input: impl Sized) -> impl Sized { input }
11+
0
12+
}>;
13+
14+
trait Trait {
15+
type Assoc;
16+
}
17+
18+
impl Trait for () {
19+
type Assoc = [(); {
20+
fn pass(input: impl Sized) -> impl Sized { input }
21+
0
22+
}];
23+
}
24+
25+
fn main() {}

0 commit comments

Comments
 (0)