Skip to content

Commit 09a5d31

Browse files
alexcrichtonZoxc
authored andcommitted
Remove support for gen arg
1 parent 9317204 commit 09a5d31

Some content is hidden

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

68 files changed

+106
-508
lines changed

src/doc/unstable-book/src/language-features/generators.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ fn main() {
3636
return "foo"
3737
};
3838

39-
match generator.resume(()) {
39+
match generator.resume() {
4040
State::Yielded(1) => {}
4141
_ => panic!("unexpected value from resume"),
4242
}
43-
match generator.resume(()) {
43+
match generator.resume() {
4444
State::Complete("foo") => {}
4545
_ => panic!("unexpected value from resume"),
4646
}
@@ -69,9 +69,9 @@ fn main() {
6969
};
7070

7171
println!("1");
72-
generator.resume(());
72+
generator.resume();
7373
println!("3");
74-
generator.resume(());
74+
generator.resume();
7575
println!("5");
7676
}
7777
```
@@ -175,8 +175,8 @@ fn main() {
175175
return ret
176176
};
177177

178-
generator.resume(());
179-
generator.resume(());
178+
generator.resume();
179+
generator.resume();
180180
}
181181
```
182182

@@ -200,7 +200,7 @@ fn main() {
200200
type Yield = i32;
201201
type Return = &'static str;
202202

203-
fn resume(&mut self, arg: ()) -> State<i32, &'static str> {
203+
fn resume(&mut self) -> State<i32, &'static str> {
204204
use std::mem;
205205
match mem::replace(self, __Generator::Done) {
206206
__Generator::Start(s) => {
@@ -223,8 +223,8 @@ fn main() {
223223
__Generator::Start(ret)
224224
};
225225

226-
generator.resume(());
227-
generator.resume(());
226+
generator.resume();
227+
generator.resume();
228228
}
229229
```
230230

src/liballoc/boxed.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -786,12 +786,12 @@ impl<T: ?Sized> AsMut<T> for Box<T> {
786786
}
787787

788788
#[unstable(feature = "generator_trait", issue = "43122")]
789-
impl<T, U> Generator<U> for Box<T>
790-
where T: Generator<U> + ?Sized
789+
impl<T> Generator for Box<T>
790+
where T: Generator + ?Sized
791791
{
792792
type Yield = T::Yield;
793793
type Return = T::Return;
794-
fn resume(&mut self, arg: U) -> State<Self::Yield, Self::Return> {
795-
(**self).resume(arg)
794+
fn resume(&mut self) -> State<Self::Yield, Self::Return> {
795+
(**self).resume()
796796
}
797797
}

src/libcore/ops/generator.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ pub enum State<Y, R> {
5656
/// return "foo"
5757
/// };
5858
///
59-
/// match generator.resume(()) {
59+
/// match generator.resume() {
6060
/// State::Yielded(1) => {}
6161
/// _ => panic!("unexpected return from resume"),
6262
/// }
63-
/// match generator.resume(()) {
63+
/// match generator.resume() {
6464
/// State::Complete("foo") => {}
6565
/// _ => panic!("unexpected return from resume"),
6666
/// }
@@ -73,7 +73,7 @@ pub enum State<Y, R> {
7373
#[cfg_attr(not(stage0), lang = "generator")]
7474
#[unstable(feature = "generator_trait", issue = "43122")]
7575
#[fundamental]
76-
pub trait Generator<Arg = ()> {
76+
pub trait Generator {
7777
/// The type of value this generator yields.
7878
///
7979
/// This associated type corresponds to the `yield` expression and the
@@ -116,16 +116,16 @@ pub trait Generator<Arg = ()> {
116116
/// been returned previously. While generator literals in the language are
117117
/// guaranteed to panic on resuming after `Complete`, this is not guaranteed
118118
/// for all implementations of the `Generator` trait.
119-
fn resume(&mut self, arg: Arg) -> State<Self::Yield, Self::Return>;
119+
fn resume(&mut self) -> State<Self::Yield, Self::Return>;
120120
}
121121

122122
#[unstable(feature = "generator_trait", issue = "43122")]
123-
impl<'a, T, U> Generator<U> for &'a mut T
124-
where T: Generator<U> + ?Sized
123+
impl<'a, T> Generator for &'a mut T
124+
where T: Generator + ?Sized
125125
{
126126
type Yield = T::Yield;
127127
type Return = T::Return;
128-
fn resume(&mut self, arg: U) -> State<Self::Yield, Self::Return> {
129-
(**self).resume(arg)
128+
fn resume(&mut self) -> State<Self::Yield, Self::Return> {
129+
(**self).resume()
130130
}
131131
}

src/librustc/cfg/construct.rs

-1
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,6 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
402402

403403
hir::ExprClosure(..) |
404404
hir::ExprLit(..) |
405-
hir::ExprImplArg(_) |
406405
hir::ExprPath(_) => {
407406
self.straightline(expr, pred, None::<hir::Expr>.iter())
408407
}

src/librustc/hir/intravisit.rs

-6
Original file line numberDiff line numberDiff line change
@@ -399,9 +399,6 @@ pub fn walk_body<'v, V: Visitor<'v>>(visitor: &mut V, body: &'v Body) {
399399
visitor.visit_id(argument.id);
400400
visitor.visit_pat(&argument.pat);
401401
}
402-
if let Some(ref impl_arg) = body.impl_arg {
403-
visitor.visit_id(impl_arg.id);
404-
}
405402
visitor.visit_expr(&body.value);
406403
}
407404

@@ -1048,9 +1045,6 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) {
10481045
ExprYield(ref subexpression) => {
10491046
visitor.visit_expr(subexpression);
10501047
}
1051-
ExprImplArg(id) => {
1052-
visitor.visit_id(id);
1053-
},
10541048
}
10551049
}
10561050

src/librustc/hir/lowering.rs

+10-26
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ pub struct LoweringContext<'a> {
9292
trait_impls: BTreeMap<DefId, Vec<NodeId>>,
9393
trait_default_impl: BTreeMap<DefId, NodeId>,
9494

95-
impl_arg: Option<NodeId>,
95+
is_generator: hir::IsGenerator,
9696

9797
catch_scopes: Vec<NodeId>,
9898
loop_scopes: Vec<NodeId>,
@@ -139,14 +139,14 @@ pub fn lower_crate(sess: &Session,
139139
trait_impls: BTreeMap::new(),
140140
trait_default_impl: BTreeMap::new(),
141141
exported_macros: Vec::new(),
142-
impl_arg: None,
143142
catch_scopes: Vec::new(),
144143
loop_scopes: Vec::new(),
145144
is_in_loop_condition: false,
146145
type_def_lifetime_params: DefIdMap(),
147146
current_hir_id_owner: vec![(CRATE_DEF_INDEX, 0)],
148147
item_local_id_counters: NodeMap(),
149148
node_id_to_hir_id: IndexVec::new(),
149+
is_generator: hir::IsGenerator::No,
150150
}.lower_crate(krate)
151151
}
152152

@@ -365,24 +365,13 @@ impl<'a> LoweringContext<'a> {
365365
})
366366
}
367367

368-
fn impl_arg_id(&mut self) -> NodeId {
369-
if self.impl_arg.is_none() {
370-
self.impl_arg = Some(self.next_id());
371-
}
372-
self.impl_arg.unwrap()
373-
}
374-
375368
fn record_body(&mut self, value: hir::Expr, decl: Option<&FnDecl>)
376369
-> hir::BodyId {
377-
let span = value.span;
378370
let body = hir::Body {
379371
arguments: decl.map_or(hir_vec![], |decl| {
380372
decl.inputs.iter().map(|x| self.lower_arg(x)).collect()
381373
}),
382-
impl_arg: self.impl_arg.map(|id| hir::ImplArg {
383-
id,
384-
span,
385-
}),
374+
is_generator: self.is_generator == hir::IsGenerator::Yes,
386375
value,
387376
};
388377
let id = body.id();
@@ -443,12 +432,11 @@ impl<'a> LoweringContext<'a> {
443432
fn lower_body<F>(&mut self, decl: Option<&FnDecl>, f: F) -> hir::BodyId
444433
where F: FnOnce(&mut LoweringContext) -> hir::Expr
445434
{
446-
let old_impl_arg = self.impl_arg;
447-
self.impl_arg = None;
435+
let prev = mem::replace(&mut self.is_generator, hir::IsGenerator::No);
448436
let result = f(self);
449437
let r = self.record_body(result, decl);
450-
self.impl_arg = old_impl_arg;
451-
r
438+
self.is_generator = prev;
439+
return r
452440
}
453441

454442
fn with_loop_scope<T, F>(&mut self, loop_id: NodeId, f: F) -> T
@@ -1952,13 +1940,13 @@ impl<'a> LoweringContext<'a> {
19521940
ExprKind::Closure(capture_clause, ref decl, ref body, fn_decl_span) => {
19531941
self.with_new_scopes(|this| {
19541942
this.with_parent_def(e.id, |this| {
1955-
let mut gen = None;
1943+
let mut gen = hir::IsGenerator::No;
19561944
let body_id = this.lower_body(Some(decl), |this| {
19571945
let e = this.lower_expr(body);
1958-
gen = this.impl_arg.map(|_| hir::GeneratorClause::Movable);
1946+
gen = this.is_generator;
19591947
e
19601948
});
1961-
if gen.is_some() && !decl.inputs.is_empty() {
1949+
if gen == hir::IsGenerator::Yes && !decl.inputs.is_empty() {
19621950
this.sess.span_fatal(
19631951
fn_decl_span,
19641952
&format!("generators cannot have explicit arguments"));
@@ -2104,17 +2092,13 @@ impl<'a> LoweringContext<'a> {
21042092
}
21052093

21062094
ExprKind::Yield(ref opt_expr) => {
2107-
self.impl_arg_id();
2095+
self.is_generator = hir::IsGenerator::Yes;
21082096
let expr = opt_expr.as_ref().map(|x| self.lower_expr(x)).unwrap_or_else(|| {
21092097
self.expr(e.span, hir::ExprTup(hir_vec![]), ThinVec::new())
21102098
});
21112099
hir::ExprYield(P(expr))
21122100
}
21132101

2114-
ExprKind::ImplArg => {
2115-
hir::ExprImplArg(self.impl_arg_id())
2116-
}
2117-
21182102
// Desugar ExprIfLet
21192103
// From: `if let <pat> = <sub_expr> <body> [<else_opt>]`
21202104
ExprKind::IfLet(ref pat, ref sub_expr, ref body, ref else_opt) => {

src/librustc/hir/map/collector.rs

-7
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,6 @@ impl<'hir> Visitor<'hir> for NodeCollector<'hir> {
182182
});
183183
}
184184

185-
fn visit_body(&mut self, b: &'hir Body) {
186-
if let Some(ref impl_arg) = b.impl_arg {
187-
self.insert(impl_arg.id, NodeImplArg(impl_arg));
188-
}
189-
intravisit::walk_body(self, b);
190-
}
191-
192185
fn visit_fn(&mut self, fk: intravisit::FnKind<'hir>, fd: &'hir FnDecl,
193186
b: BodyId, s: Span, id: NodeId) {
194187
assert_eq!(self.parent_node, id);

src/librustc/hir/map/mod.rs

-11
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ pub enum Node<'hir> {
5555
NodeTraitRef(&'hir TraitRef),
5656
NodeLocal(&'hir Pat),
5757
NodePat(&'hir Pat),
58-
NodeImplArg(&'hir ImplArg),
5958
NodeBlock(&'hir Block),
6059

6160
/// NodeStructCtor represents a tuple struct.
@@ -85,7 +84,6 @@ enum MapEntry<'hir> {
8584
EntryTy(NodeId, &'hir Ty),
8685
EntryTraitRef(NodeId, &'hir TraitRef),
8786
EntryLocal(NodeId, &'hir Pat),
88-
EntryImplArg(NodeId, &'hir ImplArg),
8987
EntryPat(NodeId, &'hir Pat),
9088
EntryBlock(NodeId, &'hir Block),
9189
EntryStructCtor(NodeId, &'hir VariantData),
@@ -117,7 +115,6 @@ impl<'hir> MapEntry<'hir> {
117115
NodeTy(n) => EntryTy(p, n),
118116
NodeTraitRef(n) => EntryTraitRef(p, n),
119117
NodeLocal(n) => EntryLocal(p, n),
120-
NodeImplArg(n) => EntryImplArg(p, n),
121118
NodePat(n) => EntryPat(p, n),
122119
NodeBlock(n) => EntryBlock(p, n),
123120
NodeStructCtor(n) => EntryStructCtor(p, n),
@@ -139,7 +136,6 @@ impl<'hir> MapEntry<'hir> {
139136
EntryStmt(id, _) => id,
140137
EntryTy(id, _) => id,
141138
EntryTraitRef(id, _) => id,
142-
EntryImplArg(id, _) => id,
143139
EntryLocal(id, _) => id,
144140
EntryPat(id, _) => id,
145141
EntryBlock(id, _) => id,
@@ -166,7 +162,6 @@ impl<'hir> MapEntry<'hir> {
166162
EntryTy(_, n) => NodeTy(n),
167163
EntryTraitRef(_, n) => NodeTraitRef(n),
168164
EntryLocal(_, n) => NodeLocal(n),
169-
EntryImplArg(_, n) => NodeImplArg(n),
170165
EntryPat(_, n) => NodePat(n),
171166
EntryBlock(_, n) => NodeBlock(n),
172167
EntryStructCtor(_, n) => NodeStructCtor(n),
@@ -327,7 +322,6 @@ impl<'hir> Map<'hir> {
327322
EntryTy(p, _) |
328323
EntryTraitRef(p, _) |
329324
EntryLocal(p, _) |
330-
EntryImplArg(p, _) |
331325
EntryPat(p, _) |
332326
EntryBlock(p, _) |
333327
EntryStructCtor(p, _) |
@@ -903,7 +897,6 @@ impl<'hir> Map<'hir> {
903897
Some(EntryTy(_, ty)) => ty.span,
904898
Some(EntryTraitRef(_, tr)) => tr.path.span,
905899
Some(EntryLocal(_, pat)) => pat.span,
906-
Some(EntryImplArg(_, impl_arg)) => impl_arg.span,
907900
Some(EntryPat(_, pat)) => pat.span,
908901
Some(EntryBlock(_, block)) => block.span,
909902
Some(EntryStructCtor(_, _)) => self.expect_item(self.get_parent(id)).span,
@@ -1113,7 +1106,6 @@ impl<'a> print::State<'a> {
11131106
}
11141107
NodeLifetime(a) => self.print_lifetime(&a),
11151108
NodeVisibility(a) => self.print_visibility(&a),
1116-
NodeImplArg(_) => bug!("cannot print ImplArg"),
11171109
NodeTyParam(_) => bug!("cannot print TyParam"),
11181110
NodeField(_) => bug!("cannot print StructField"),
11191111
// these cases do not carry enough information in the
@@ -1215,9 +1207,6 @@ fn node_id_to_string(map: &Map, id: NodeId, include_id: bool) -> String {
12151207
Some(NodeLocal(_)) => {
12161208
format!("local {}{}", map.node_to_pretty_string(id), id_str)
12171209
}
1218-
Some(NodeImplArg(_)) => {
1219-
format!("impl_arg {}{}", map.node_to_pretty_string(id), id_str)
1220-
}
12211210
Some(NodePat(_)) => {
12221211
format!("pat {}{}", map.node_to_pretty_string(id), id_str)
12231212
}

0 commit comments

Comments
 (0)