Skip to content

Commit bf96a7b

Browse files
authored
Rollup merge of rust-lang#56366 - alexreg:stabilise-self_in_typedefs, r=Centril
Stabilize self_in_typedefs feature [**Tracking Issue**](rust-lang#49303) r? @Centril
2 parents e9a8055 + d609fdf commit bf96a7b

File tree

11 files changed

+25
-82
lines changed

11 files changed

+25
-82
lines changed

src/doc/unstable-book/src/language-features/self-in-typedefs.md

-24
This file was deleted.

src/librustc_resolve/lib.rs

+4-16
Original file line numberDiff line numberDiff line change
@@ -2373,13 +2373,9 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
23732373
self.with_current_self_item(item, |this| {
23742374
this.with_type_parameter_rib(HasTypeParameters(generics, ItemRibKind), |this| {
23752375
let item_def_id = this.definitions.local_def_id(item.id);
2376-
if this.session.features_untracked().self_in_typedefs {
2377-
this.with_self_rib(Def::SelfTy(None, Some(item_def_id)), |this| {
2378-
visit::walk_item(this, item);
2379-
});
2380-
} else {
2376+
this.with_self_rib(Def::SelfTy(None, Some(item_def_id)), |this| {
23812377
visit::walk_item(this, item);
2382-
}
2378+
});
23832379
});
23842380
});
23852381
}
@@ -3185,16 +3181,8 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
31853181
if is_self_type(path, ns) {
31863182
__diagnostic_used!(E0411);
31873183
err.code(DiagnosticId::Error("E0411".into()));
3188-
let available_in = if this.session.features_untracked().self_in_typedefs {
3189-
"impls, traits, and type definitions"
3190-
} else {
3191-
"traits and impls"
3192-
};
3193-
err.span_label(span, format!("`Self` is only available in {}", available_in));
3194-
if this.current_self_item.is_some() && nightly_options::is_nightly_build() {
3195-
err.help("add #![feature(self_in_typedefs)] to the crate attributes \
3196-
to enable");
3197-
}
3184+
err.span_label(span, format!("`Self` is only available in impls, traits, \
3185+
and type definitions"));
31983186
return (err, Vec::new());
31993187
}
32003188
if is_self_value(path, ns) {

src/libsyntax/feature_gate.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -462,9 +462,6 @@ declare_features! (
462462
// Allows `use x::y;` to resolve through `self::x`, not just `::x`
463463
(active, uniform_paths, "1.30.0", Some(53130), None),
464464

465-
// Allows `Self` in type definitions
466-
(active, self_in_typedefs, "1.30.0", Some(49303), None),
467-
468465
// Allows unsized rvalues at arguments and parameters
469466
(active, unsized_locals, "1.30.0", Some(48055), None),
470467

@@ -675,21 +672,23 @@ declare_features! (
675672
(accepted, extern_prelude, "1.30.0", Some(44660), None),
676673
// Parentheses in patterns
677674
(accepted, pattern_parentheses, "1.31.0", Some(51087), None),
678-
// Allows the definition of `const fn` functions.
675+
// Allows the definition of `const fn` functions
679676
(accepted, min_const_fn, "1.31.0", Some(53555), None),
680677
// Scoped lints
681678
(accepted, tool_lints, "1.31.0", Some(44690), None),
682679
// impl<I:Iterator> Iterator for &mut Iterator
683680
// impl Debug for Foo<'_>
684681
(accepted, impl_header_lifetime_elision, "1.31.0", Some(15872), None),
685-
// `extern crate foo as bar;` puts `bar` into extern prelude.
682+
// `extern crate foo as bar;` puts `bar` into extern prelude
686683
(accepted, extern_crate_item_prelude, "1.31.0", Some(55599), None),
687684
// Allows use of the :literal macro fragment specifier (RFC 1576)
688685
(accepted, macro_literal_matcher, "1.31.0", Some(35625), None),
689686
// Use `?` as the Kleene "at most one" operator
690687
(accepted, macro_at_most_once_rep, "1.32.0", Some(48075), None),
691-
// Self struct constructor (RFC 2302)
688+
// `Self` struct constructor (RFC 2302)
692689
(accepted, self_struct_ctor, "1.32.0", Some(51994), None),
690+
// `Self` in type definitions (RFC 2300)
691+
(accepted, self_in_typedefs, "1.32.0", Some(49303), None),
693692
);
694693

695694
// If you change this, please modify `src/doc/unstable-book` as well. You must

src/test/run-pass/self/self-in-typedefs.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@
99
// except according to those terms.
1010

1111
// run-pass
12-
#![allow(unions_with_drop_fields)]
1312

14-
#![feature(self_in_typedefs)]
1513
#![feature(untagged_unions)]
1614

1715
#![allow(dead_code)]
16+
#![allow(unions_with_drop_fields)]
1817

1918
enum A<'a, T: 'a>
2019
where

src/test/ui/error-codes/E0411.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0411]: cannot find type `Self` in this scope
22
--> $DIR/E0411.rs:12:6
33
|
44
LL | <Self>::foo; //~ ERROR E0411
5-
| ^^^^ `Self` is only available in traits and impls
5+
| ^^^^ `Self` is only available in impls, traits, and type definitions
66

77
error: aborting due to previous error
88

src/test/ui/feature-gates/feature-gate-self_in_typedefs.rs

-18
This file was deleted.

src/test/ui/feature-gates/feature-gate-self_in_typedefs.stderr

-11
This file was deleted.

src/test/ui/issues/issue-36638.rs

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
struct Foo<Self>(Self);
1414
//~^ ERROR expected identifier, found keyword `Self`
15+
//~^^ ERROR E0392
1516

1617
trait Bar<Self> {}
1718
//~^ ERROR expected identifier, found keyword `Self`

src/test/ui/issues/issue-36638.stderr

+11-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,19 @@ LL | struct Foo<Self>(Self);
55
| ^^^^ expected identifier, found keyword
66

77
error: expected identifier, found keyword `Self`
8-
--> $DIR/issue-36638.rs:16:11
8+
--> $DIR/issue-36638.rs:17:11
99
|
1010
LL | trait Bar<Self> {}
1111
| ^^^^ expected identifier, found keyword
1212

13-
error: aborting due to 2 previous errors
13+
error[E0392]: parameter `Self` is never used
14+
--> $DIR/issue-36638.rs:13:12
15+
|
16+
LL | struct Foo<Self>(Self);
17+
| ^^^^ unused type parameter
18+
|
19+
= help: consider removing `Self` or using a marker such as `std::marker::PhantomData`
20+
21+
error: aborting due to 3 previous errors
1422

23+
For more information about this error, try `rustc --explain E0392`.

src/test/ui/resolve/issue-24968.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0411]: cannot find type `Self` in this scope
22
--> $DIR/issue-24968.rs:11:11
33
|
44
LL | fn foo(_: Self) {
5-
| ^^^^ `Self` is only available in traits and impls
5+
| ^^^^ `Self` is only available in impls, traits, and type definitions
66

77
error: aborting due to previous error
88

src/test/ui/resolve/resolve-self-in-impl-2.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0411]: expected trait, found self type `Self`
22
--> $DIR/resolve-self-in-impl-2.rs:14:6
33
|
44
LL | impl Self for S {} //~ ERROR expected trait, found self type `Self`
5-
| ^^^^ `Self` is only available in traits and impls
5+
| ^^^^ `Self` is only available in impls, traits, and type definitions
66

77
error[E0405]: cannot find trait `N` in `Self`
88
--> $DIR/resolve-self-in-impl-2.rs:15:12

0 commit comments

Comments
 (0)