Skip to content

Commit

Permalink
Rollup merge of rust-lang#56365 - alexreg:stabilise-self_struct_ctor,…
Browse files Browse the repository at this point in the history
… r=Centril

Stabilize self_struct_ctor feature.

[**Tracking Issue**](rust-lang#51994)
  • Loading branch information
kennytm committed Nov 30, 2018
2 parents 8641b8d + 24717fd commit 440bda4
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 141 deletions.
33 changes: 0 additions & 33 deletions src/doc/unstable-book/src/language-features/self-struct-ctor.md

This file was deleted.

16 changes: 0 additions & 16 deletions src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ use syntax::ast;
use syntax::ast::*;
use syntax::errors;
use syntax::ext::hygiene::{Mark, SyntaxContext};
use syntax::feature_gate::{emit_feature_err, GateIssue};
use syntax::print::pprust;
use syntax::ptr::P;
use syntax::source_map::{self, respan, CompilerDesugaringKind, Spanned};
Expand Down Expand Up @@ -3628,7 +3627,6 @@ impl<'a> LoweringContext<'a> {
ParamMode::Optional,
ImplTraitContext::disallowed(),
);
self.check_self_struct_ctor_feature(&qpath);
hir::PatKind::TupleStruct(
qpath,
pats.iter().map(|x| self.lower_pat(x)).collect(),
Expand All @@ -3643,7 +3641,6 @@ impl<'a> LoweringContext<'a> {
ParamMode::Optional,
ImplTraitContext::disallowed(),
);
self.check_self_struct_ctor_feature(&qpath);
hir::PatKind::Path(qpath)
}
PatKind::Struct(ref path, ref fields, etc) => {
Expand Down Expand Up @@ -4039,7 +4036,6 @@ impl<'a> LoweringContext<'a> {
ParamMode::Optional,
ImplTraitContext::disallowed(),
);
self.check_self_struct_ctor_feature(&qpath);
hir::ExprKind::Path(qpath)
}
ExprKind::Break(opt_label, ref opt_expr) => {
Expand Down Expand Up @@ -5102,18 +5098,6 @@ impl<'a> LoweringContext<'a> {
ThinVec::new()));
P(self.expr_call(e.span, from_err, hir_vec![e]))
}

fn check_self_struct_ctor_feature(&self, qp: &hir::QPath) {
if let hir::QPath::Resolved(_, ref p) = qp {
if p.segments.len() == 1 &&
p.segments[0].ident.name == keywords::SelfType.name() &&
!self.sess.features_untracked().self_struct_ctor {
emit_feature_err(&self.sess.parse_sess, "self_struct_ctor",
p.span, GateIssue::Language,
"`Self` struct constructors are unstable");
}
}
}
}

fn body_ids(bodies: &BTreeMap<hir::BodyId, hir::Body>) -> Vec<hir::BodyId> {
Expand Down
5 changes: 3 additions & 2 deletions src/librustc/middle/reachable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,9 @@ impl<'a, 'tcx> Visitor<'tcx> for ReachableContext<'a, 'tcx> {
self.reachable_symbols.insert(node_id);
}
Some(def) => {
let def_id = def.def_id();
if let Some(node_id) = self.tcx.hir.as_local_node_id(def_id) {
if let Some((node_id, def_id)) = def.opt_def_id().and_then(|def_id| {
self.tcx.hir.as_local_node_id(def_id).map(|node_id| (node_id, def_id))
}) {
if self.def_id_represents_local_inlined_item(def_id) {
self.worklist.push(node_id);
} else {
Expand Down
7 changes: 3 additions & 4 deletions src/libsyntax/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,9 +475,6 @@ declare_features! (
// Non-builtin attributes in inner attribute position
(active, custom_inner_attributes, "1.30.0", Some(54726), None),

// Self struct constructor (RFC 2302)
(active, self_struct_ctor, "1.30.0", Some(51994), None),

// allow mixing of bind-by-move in patterns and references to
// those identifiers in guards, *if* we are using MIR-borrowck
// (aka NLL). Essentially this means you need to be on
Expand Down Expand Up @@ -688,9 +685,11 @@ declare_features! (
(accepted, macro_literal_matcher, "1.31.0", Some(35625), None),
// Use `?` as the Kleene "at most one" operator
(accepted, macro_at_most_once_rep, "1.32.0", Some(48075), None),
// Self struct constructor (RFC 2302)
(accepted, self_struct_ctor, "1.32.0", Some(51994), None),
);

// If you change this, please modify src/doc/unstable-book as well. You must
// If you change this, please modify `src/doc/unstable-book` as well. You must
// move that documentation into the relevant place in the other docs, and
// remove the chapter on the flag.

Expand Down
2 changes: 0 additions & 2 deletions src/test/run-pass/rfcs/rfc-2302-self-struct-ctor.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// run-pass

#![feature(self_struct_ctor)]

#![allow(dead_code)]

use std::fmt::Display;
Expand Down
22 changes: 0 additions & 22 deletions src/test/ui/feature-gates/feature-gate-self-struct-ctor.rs

This file was deleted.

19 changes: 0 additions & 19 deletions src/test/ui/feature-gates/feature-gate-self-struct-ctor.stderr

This file was deleted.

17 changes: 17 additions & 0 deletions src/test/ui/issues/issue-56202.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// compile-pass

trait FooTrait {}

trait BarTrait {
fn foo<T: FooTrait>(_: T) -> Self;
}

struct FooStruct(u32);

impl BarTrait for FooStruct {
fn foo<T: FooTrait>(_: T) -> Self {
Self(u32::default())
}
}

fn main() {}
1 change: 0 additions & 1 deletion src/test/ui/keyword/keyword-self-as-identifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@

fn main() {
let Self = 22; //~ ERROR cannot find unit struct/variant or constant `Self` in this scope
//~^ ERROR `Self` struct constructors are unstable (see issue #51994)
}
13 changes: 2 additions & 11 deletions src/test/ui/keyword/keyword-self-as-identifier.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,6 @@ error[E0531]: cannot find unit struct/variant or constant `Self` in this scope
LL | let Self = 22; //~ ERROR cannot find unit struct/variant or constant `Self` in this scope
| ^^^^ not found in this scope

error[E0658]: `Self` struct constructors are unstable (see issue #51994)
--> $DIR/keyword-self-as-identifier.rs:12:9
|
LL | let Self = 22; //~ ERROR cannot find unit struct/variant or constant `Self` in this scope
| ^^^^
|
= help: add #![feature(self_struct_ctor)] to the crate attributes to enable

error: aborting due to 2 previous errors
error: aborting due to previous error

Some errors occurred: E0531, E0658.
For more information about an error, try `rustc --explain E0531`.
For more information about this error, try `rustc --explain E0531`.
3 changes: 0 additions & 3 deletions src/test/ui/self/self_type_keyword-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,11 @@ use self::Self as Foo; //~ ERROR unresolved import `self::Self`
pub fn main() {
let Self = 5;
//~^ ERROR cannot find unit struct/variant or constant `Self` in this scope
//~^^ ERROR `Self` struct constructors are unstable (see issue #51994)

match 15 {
Self => (),
//~^ ERROR cannot find unit struct/variant or constant `Self` in this scope
//~^^ ERROR `Self` struct constructors are unstable (see issue #51994)
Foo { x: Self } => (),
//~^ ERROR cannot find unit struct/variant or constant `Self` in this scope
//~^^ ERROR `Self` struct constructors are unstable (see issue #51994)
}
}
32 changes: 4 additions & 28 deletions src/test/ui/self/self_type_keyword-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -11,42 +11,18 @@ LL | let Self = 5;
| ^^^^ not found in this scope

error[E0531]: cannot find unit struct/variant or constant `Self` in this scope
--> $DIR/self_type_keyword-2.rs:19:9
--> $DIR/self_type_keyword-2.rs:18:9
|
LL | Self => (),
| ^^^^ not found in this scope

error[E0531]: cannot find unit struct/variant or constant `Self` in this scope
--> $DIR/self_type_keyword-2.rs:22:18
--> $DIR/self_type_keyword-2.rs:20:18
|
LL | Foo { x: Self } => (),
| ^^^^ not found in this scope

error[E0658]: `Self` struct constructors are unstable (see issue #51994)
--> $DIR/self_type_keyword-2.rs:14:9
|
LL | let Self = 5;
| ^^^^
|
= help: add #![feature(self_struct_ctor)] to the crate attributes to enable

error[E0658]: `Self` struct constructors are unstable (see issue #51994)
--> $DIR/self_type_keyword-2.rs:19:9
|
LL | Self => (),
| ^^^^
|
= help: add #![feature(self_struct_ctor)] to the crate attributes to enable

error[E0658]: `Self` struct constructors are unstable (see issue #51994)
--> $DIR/self_type_keyword-2.rs:22:18
|
LL | Foo { x: Self } => (),
| ^^^^
|
= help: add #![feature(self_struct_ctor)] to the crate attributes to enable

error: aborting due to 7 previous errors
error: aborting due to 4 previous errors

Some errors occurred: E0432, E0531, E0658.
Some errors occurred: E0432, E0531.
For more information about an error, try `rustc --explain E0432`.

0 comments on commit 440bda4

Please sign in to comment.