Skip to content

Commit 8b36d9a

Browse files
authored
Rollup merge of rust-lang#49968 - christianpoveda:stabilize_dyn, r=nikomatsakis
Stabilize dyn trait This PR stabilizes RFC 2113. I followed the [stabilization guide](https://forge.rust-lang.org/stabilization-guide.html). Related issue: rust-lang#49218
2 parents a18e7a6 + b5c7cbf commit 8b36d9a

File tree

50 files changed

+155
-214
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+155
-214
lines changed

src/librustc/hir/lowering.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -4107,15 +4107,13 @@ impl<'a> LoweringContext<'a> {
41074107
}
41084108

41094109
fn maybe_lint_bare_trait(&self, span: Span, id: NodeId, is_global: bool) {
4110-
if self.sess.features_untracked().dyn_trait {
4111-
self.sess.buffer_lint_with_diagnostic(
4112-
builtin::BARE_TRAIT_OBJECT,
4113-
id,
4114-
span,
4115-
"trait objects without an explicit `dyn` are deprecated",
4116-
builtin::BuiltinLintDiagnostics::BareTraitObject(span, is_global),
4117-
)
4118-
}
4110+
self.sess.buffer_lint_with_diagnostic(
4111+
builtin::BARE_TRAIT_OBJECT,
4112+
id,
4113+
span,
4114+
"trait objects without an explicit `dyn` are deprecated",
4115+
builtin::BuiltinLintDiagnostics::BareTraitObject(span, is_global),
4116+
)
41194117
}
41204118

41214119
fn wrap_in_try_constructor(

src/librustc/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@
4545
#![feature(const_fn)]
4646
#![feature(core_intrinsics)]
4747
#![feature(drain_filter)]
48-
#![feature(dyn_trait)]
4948
#![feature(entry_or_default)]
49+
#![cfg_attr(stage0, feature(dyn_trait))]
5050
#![feature(from_ref)]
5151
#![feature(fs_read_write)]
5252
#![cfg_attr(windows, feature(libc))]

src/librustc_mir/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Rust MIR: a lowered representation of Rust. Also: an experiment!
2424
#![feature(const_fn)]
2525
#![feature(core_intrinsics)]
2626
#![feature(decl_macro)]
27-
#![feature(dyn_trait)]
27+
#![cfg_attr(stage0, feature(dyn_trait))]
2828
#![feature(fs_read_write)]
2929
#![feature(macro_vis_matcher)]
3030
#![feature(exhaustive_patterns)]

src/librustc_typeck/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ This API is completely unstable and subject to change.
7171

7272
#![allow(non_camel_case_types)]
7373

74+
#![cfg_attr(stage0, feature(dyn_trait))]
75+
7476
#![feature(box_patterns)]
7577
#![feature(box_syntax)]
7678
#![feature(crate_visibility_modifier)]
@@ -81,7 +83,6 @@ This API is completely unstable and subject to change.
8183
#![feature(rustc_diagnostic_macros)]
8284
#![feature(slice_patterns)]
8385
#![feature(slice_sort_by_cached_key)]
84-
#![feature(dyn_trait)]
8586
#![feature(never_type)]
8687

8788
#[macro_use] extern crate log;

src/librustdoc/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
html_root_url = "https://doc.rust-lang.org/nightly/",
1414
html_playground_url = "https://play.rust-lang.org/")]
1515

16+
#![cfg_attr(stage0, feature(dyn_trait))]
17+
1618
#![feature(ascii_ctype)]
1719
#![feature(rustc_private)]
1820
#![feature(box_patterns)]
@@ -23,7 +25,6 @@
2325
#![feature(test)]
2426
#![feature(vec_remove_item)]
2527
#![feature(entry_and_modify)]
26-
#![feature(dyn_trait)]
2728

2829
extern crate arena;
2930
extern crate getopts;

src/libsyntax/feature_gate.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -375,9 +375,6 @@ declare_features! (
375375
// Future-proofing enums/structs with #[non_exhaustive] attribute (RFC 2008)
376376
(active, non_exhaustive, "1.22.0", Some(44109), None),
377377

378-
// Trait object syntax with `dyn` prefix
379-
(active, dyn_trait, "1.22.0", Some(44662), Some(Edition::Edition2018)),
380-
381378
// `crate` as visibility modifier, synonymous to `pub(crate)`
382379
(active, crate_visibility_modifier, "1.23.0", Some(45388), Some(Edition::Edition2018)),
383380

@@ -592,6 +589,8 @@ declare_features! (
592589
(accepted, cfg_target_feature, "1.27.0", Some(29717), None),
593590
// Allows #[target_feature(...)]
594591
(accepted, target_feature, "1.27.0", None, None),
592+
// Trait object syntax with `dyn` prefix
593+
(accepted, dyn_trait, "1.27.0", Some(44662), None),
595594
);
596595

597596
// If you change this, please modify src/doc/unstable-book as well. You must
@@ -1657,10 +1656,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
16571656
gate_feature_post!(&self, never_type, ty.span,
16581657
"The `!` type is experimental");
16591658
}
1660-
ast::TyKind::TraitObject(_, ast::TraitObjectSyntax::Dyn) => {
1661-
gate_feature_post!(&self, dyn_trait, ty.span,
1662-
"`dyn Trait` syntax is unstable");
1663-
}
16641659
_ => {}
16651660
}
16661661
visit::walk_ty(self, ty)

src/test/compile-fail/impl-trait/where-allowed.rs

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
//! A simple test for testing many permutations of allowedness of
1212
//! impl Trait
13-
#![feature(dyn_trait)]
1413
use std::fmt::Debug;
1514

1615
// Allowed

src/test/compile-fail/mir_check_cast_unsize.rs

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
// compile-flags: -Z borrowck=mir
1212

1313
#![allow(dead_code)]
14-
#![feature(dyn_trait)]
1514

1615
use std::fmt::Debug;
1716

src/test/compile-fail/trait-bounds-not-on-struct.rs

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![feature(dyn_trait)]
1211
#![allow(bare_trait_object)]
1312

1413
struct Foo;

src/test/run-fail/rfc-1937-termination-trait/termination-trait-for-box-dyn-error.rs

-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
// compile-pass
1212
// failure-status: 1
1313

14-
#![feature(dyn_trait)]
15-
1614
use std::error::Error;
1715
use std::io;
1816

src/test/run-pass/dyn-trait.rs

-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
// ignore-pretty `dyn ::foo` parses differently in the current edition
1212

13-
#![feature(dyn_trait)]
14-
1513
use std::fmt::Display;
1614

1715
static BYTE: u8 = 33;

src/test/run-pass/rfc-1937-termination-trait/termination-trait-for-box-dyn-error.rs

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![feature(dyn_trait)]
12-
1311
use std::error::Error;
1412

1513
fn main() -> Result<(), Box<dyn Error>> {

src/test/ui/feature-gate-dyn-trait.rs

-14
This file was deleted.

src/test/ui/feature-gate-dyn-trait.stderr

-11
This file was deleted.

src/test/ui/impl_trait_projections.rs

-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
10-
#![feature(dyn_trait)]
11-
1210
use std::fmt::Debug;
1311
use std::option;
1412

src/test/ui/impl_trait_projections.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
error[E0667]: `impl Trait` is not allowed in path parameters
2-
--> $DIR/impl_trait_projections.rs:23:51
2+
--> $DIR/impl_trait_projections.rs:21:51
33
|
44
LL | fn projection_is_disallowed(x: impl Iterator) -> <impl Iterator>::Item {
55
| ^^^^^^^^^^^^^
66

77
error[E0667]: `impl Trait` is not allowed in path parameters
8-
--> $DIR/impl_trait_projections.rs:30:9
8+
--> $DIR/impl_trait_projections.rs:28:9
99
|
1010
LL | -> <impl Iterator as Iterator>::Item
1111
| ^^^^^^^^^^^^^
1212

1313
error[E0667]: `impl Trait` is not allowed in path parameters
14-
--> $DIR/impl_trait_projections.rs:37:27
14+
--> $DIR/impl_trait_projections.rs:35:27
1515
|
1616
LL | -> <::std::ops::Range<impl Debug> as Iterator>::Item
1717
| ^^^^^^^^^^
1818

1919
error[E0667]: `impl Trait` is not allowed in path parameters
20-
--> $DIR/impl_trait_projections.rs:44:29
20+
--> $DIR/impl_trait_projections.rs:42:29
2121
|
2222
LL | -> <dyn Iterator<Item = impl Debug> as Iterator>::Item
2323
| ^^^^^^^^^^
2424

2525
error[E0223]: ambiguous associated type
26-
--> $DIR/impl_trait_projections.rs:23:50
26+
--> $DIR/impl_trait_projections.rs:21:50
2727
|
2828
LL | fn projection_is_disallowed(x: impl Iterator) -> <impl Iterator>::Item {
2929
| ^^^^^^^^^^^^^^^^^^^^^ ambiguous associated type

src/test/ui/in-band-lifetimes/impl/dyn-trait.nll.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
warning: not reporting region error due to nll
2-
--> $DIR/dyn-trait.rs:33:16
2+
--> $DIR/dyn-trait.rs:32:16
33
|
44
LL | static_val(x); //~ ERROR cannot infer
55
| ^
66

77
error: free region `'a` does not outlive free region `'static`
8-
--> $DIR/dyn-trait.rs:33:5
8+
--> $DIR/dyn-trait.rs:32:5
99
|
1010
LL | static_val(x); //~ ERROR cannot infer
1111
| ^^^^^^^^^^^^^

src/test/ui/in-band-lifetimes/impl/dyn-trait.rs

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
#![allow(warnings)]
1515

16-
#![feature(dyn_trait)]
1716
#![feature(in_band_lifetimes)]
1817

1918
use std::fmt::Debug;

src/test/ui/in-band-lifetimes/impl/dyn-trait.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error[E0495]: cannot infer an appropriate lifetime due to conflicting requirements
2-
--> $DIR/dyn-trait.rs:33:16
2+
--> $DIR/dyn-trait.rs:32:16
33
|
44
LL | static_val(x); //~ ERROR cannot infer
55
| ^
66
|
7-
note: first, the lifetime cannot outlive the lifetime 'a as defined on the function body at 32:1...
8-
--> $DIR/dyn-trait.rs:32:1
7+
note: first, the lifetime cannot outlive the lifetime 'a as defined on the function body at 31:1...
8+
--> $DIR/dyn-trait.rs:31:1
99
|
1010
LL | fn with_dyn_debug_static<'a>(x: Box<dyn Debug + 'a>) {
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

src/test/ui/nll/ty-outlives/projection-no-regions-closure.rs

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
// Iterator>::Item`, to be exact).
1616

1717
#![allow(warnings)]
18-
#![feature(dyn_trait)]
1918
#![feature(rustc_attrs)]
2019

2120
trait Anything { }

src/test/ui/nll/ty-outlives/projection-no-regions-closure.stderr

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
warning: not reporting region error due to nll
2-
--> $DIR/projection-no-regions-closure.rs:36:31
2+
--> $DIR/projection-no-regions-closure.rs:35:31
33
|
44
LL | with_signature(x, |mut y| Box::new(y.next()))
55
| ^^^^^^^^^^^^^^^^^^
66

77
warning: not reporting region error due to nll
8-
--> $DIR/projection-no-regions-closure.rs:54:31
8+
--> $DIR/projection-no-regions-closure.rs:53:31
99
|
1010
LL | with_signature(x, |mut y| Box::new(y.next()))
1111
| ^^^^^^^^^^^^^^^^^^
1212

1313
note: External requirements
14-
--> $DIR/projection-no-regions-closure.rs:36:23
14+
--> $DIR/projection-no-regions-closure.rs:35:23
1515
|
1616
LL | with_signature(x, |mut y| Box::new(y.next()))
1717
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -26,15 +26,15 @@ LL | with_signature(x, |mut y| Box::new(y.next()))
2626
= note: where <T as std::iter::Iterator>::Item: '_#2r
2727

2828
error[E0309]: the associated type `<T as std::iter::Iterator>::Item` may not live long enough
29-
--> $DIR/projection-no-regions-closure.rs:36:23
29+
--> $DIR/projection-no-regions-closure.rs:35:23
3030
|
3131
LL | with_signature(x, |mut y| Box::new(y.next()))
3232
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
3333
|
3434
= help: consider adding an explicit lifetime bound `<T as std::iter::Iterator>::Item: ReEarlyBound(0, 'a)`...
3535

3636
note: No external requirements
37-
--> $DIR/projection-no-regions-closure.rs:32:1
37+
--> $DIR/projection-no-regions-closure.rs:31:1
3838
|
3939
LL | / fn no_region<'a, T>(x: Box<T>) -> Box<dyn Anything + 'a>
4040
LL | | where
@@ -51,7 +51,7 @@ LL | | }
5151
]
5252

5353
note: External requirements
54-
--> $DIR/projection-no-regions-closure.rs:46:23
54+
--> $DIR/projection-no-regions-closure.rs:45:23
5555
|
5656
LL | with_signature(x, |mut y| Box::new(y.next()))
5757
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -66,7 +66,7 @@ LL | with_signature(x, |mut y| Box::new(y.next()))
6666
= note: where <T as std::iter::Iterator>::Item: '_#2r
6767

6868
note: No external requirements
69-
--> $DIR/projection-no-regions-closure.rs:42:1
69+
--> $DIR/projection-no-regions-closure.rs:41:1
7070
|
7171
LL | / fn correct_region<'a, T>(x: Box<T>) -> Box<dyn Anything + 'a>
7272
LL | | where
@@ -82,7 +82,7 @@ LL | | }
8282
]
8383

8484
note: External requirements
85-
--> $DIR/projection-no-regions-closure.rs:54:23
85+
--> $DIR/projection-no-regions-closure.rs:53:23
8686
|
8787
LL | with_signature(x, |mut y| Box::new(y.next()))
8888
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -98,15 +98,15 @@ LL | with_signature(x, |mut y| Box::new(y.next()))
9898
= note: where <T as std::iter::Iterator>::Item: '_#3r
9999

100100
error[E0309]: the associated type `<T as std::iter::Iterator>::Item` may not live long enough
101-
--> $DIR/projection-no-regions-closure.rs:54:23
101+
--> $DIR/projection-no-regions-closure.rs:53:23
102102
|
103103
LL | with_signature(x, |mut y| Box::new(y.next()))
104104
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
105105
|
106106
= help: consider adding an explicit lifetime bound `<T as std::iter::Iterator>::Item: ReEarlyBound(0, 'a)`...
107107

108108
note: No external requirements
109-
--> $DIR/projection-no-regions-closure.rs:50:1
109+
--> $DIR/projection-no-regions-closure.rs:49:1
110110
|
111111
LL | / fn wrong_region<'a, 'b, T>(x: Box<T>) -> Box<dyn Anything + 'a>
112112
LL | | where
@@ -124,7 +124,7 @@ LL | | }
124124
]
125125

126126
note: External requirements
127-
--> $DIR/projection-no-regions-closure.rs:65:23
127+
--> $DIR/projection-no-regions-closure.rs:64:23
128128
|
129129
LL | with_signature(x, |mut y| Box::new(y.next()))
130130
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -140,7 +140,7 @@ LL | with_signature(x, |mut y| Box::new(y.next()))
140140
= note: where <T as std::iter::Iterator>::Item: '_#3r
141141

142142
note: No external requirements
143-
--> $DIR/projection-no-regions-closure.rs:60:1
143+
--> $DIR/projection-no-regions-closure.rs:59:1
144144
|
145145
LL | / fn outlives_region<'a, 'b, T>(x: Box<T>) -> Box<dyn Anything + 'a>
146146
LL | | where

src/test/ui/nll/ty-outlives/projection-no-regions-fn.rs

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
// compile-flags:-Zborrowck=mir -Zverbose
1212

1313
#![allow(warnings)]
14-
#![feature(dyn_trait)]
1514

1615
trait Anything { }
1716

0 commit comments

Comments
 (0)