Skip to content

Commit f8fd462

Browse files
committed
Auto merge of #68907 - Dylan-DPC:rollup-osm5e8o, r=Dylan-DPC
Rollup of 6 pull requests Successful merges: - #67359 (Rename -Zexternal-macro-backtrace to -Zmacro-backtrace and clean up implementation.) - #68524 (Generator Resume Arguments) - #68791 (implement proper linkchecker hardening) - #68886 (Mark fn map_or() as eagerly evaluated.) - #68888 (error code examples: replace some more ignore with compile_fail) - #68894 (Update E0565 examples) Failed merges: r? @ghost
2 parents 442ae7f + 7ef5b89 commit f8fd462

File tree

389 files changed

+2040
-585
lines changed

Some content is hidden

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

389 files changed

+2040
-585
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -3067,6 +3067,7 @@ name = "rustbook"
30673067
version = "0.1.0"
30683068
dependencies = [
30693069
"clap",
3070+
"codespan",
30703071
"codespan-reporting",
30713072
"failure",
30723073
"mdbook",

src/bootstrap/builder.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,13 @@ impl<'a> Builder<'a> {
847847
rustflags.arg("-Zforce-unstable-if-unmarked");
848848
}
849849

850-
rustflags.arg("-Zexternal-macro-backtrace");
850+
// cfg(bootstrap): the flag was renamed from `-Zexternal-macro-backtrace`
851+
// to `-Zmacro-backtrace`, keep only the latter after beta promotion.
852+
if stage == 0 {
853+
rustflags.arg("-Zexternal-macro-backtrace");
854+
} else {
855+
rustflags.arg("-Zmacro-backtrace");
856+
}
851857

852858
let want_rustdoc = self.doc_tests != DocTests::No;
853859

src/doc/rustc-guide

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

+11-15
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ fn main() {
3737
return "foo"
3838
};
3939

40-
match Pin::new(&mut generator).resume() {
40+
match Pin::new(&mut generator).resume(()) {
4141
GeneratorState::Yielded(1) => {}
4242
_ => panic!("unexpected value from resume"),
4343
}
44-
match Pin::new(&mut generator).resume() {
44+
match Pin::new(&mut generator).resume(()) {
4545
GeneratorState::Complete("foo") => {}
4646
_ => panic!("unexpected value from resume"),
4747
}
@@ -71,9 +71,9 @@ fn main() {
7171
};
7272

7373
println!("1");
74-
Pin::new(&mut generator).resume();
74+
Pin::new(&mut generator).resume(());
7575
println!("3");
76-
Pin::new(&mut generator).resume();
76+
Pin::new(&mut generator).resume(());
7777
println!("5");
7878
}
7979
```
@@ -92,10 +92,10 @@ The `Generator` trait in `std::ops` currently looks like:
9292
# use std::ops::GeneratorState;
9393
# use std::pin::Pin;
9494
95-
pub trait Generator {
95+
pub trait Generator<R = ()> {
9696
type Yield;
9797
type Return;
98-
fn resume(self: Pin<&mut Self>) -> GeneratorState<Self::Yield, Self::Return>;
98+
fn resume(self: Pin<&mut Self>, resume: R) -> GeneratorState<Self::Yield, Self::Return>;
9999
}
100100
```
101101

@@ -152,10 +152,6 @@ closure-like semantics. Namely:
152152
* Whenever a generator is dropped it will drop all captured environment
153153
variables.
154154

155-
Note that unlike closures, generators at this time cannot take any arguments.
156-
That is, generators must always look like `|| { ... }`. This restriction may be
157-
lifted at a future date, the design is ongoing!
158-
159155
### Generators as state machines
160156

161157
In the compiler, generators are currently compiled as state machines. Each
@@ -179,8 +175,8 @@ fn main() {
179175
return ret
180176
};
181177

182-
Pin::new(&mut generator).resume();
183-
Pin::new(&mut generator).resume();
178+
Pin::new(&mut generator).resume(());
179+
Pin::new(&mut generator).resume(());
184180
}
185181
```
186182

@@ -205,7 +201,7 @@ fn main() {
205201
type Yield = i32;
206202
type Return = &'static str;
207203

208-
fn resume(mut self: Pin<&mut Self>) -> GeneratorState<i32, &'static str> {
204+
fn resume(mut self: Pin<&mut Self>, resume: ()) -> GeneratorState<i32, &'static str> {
209205
use std::mem;
210206
match mem::replace(&mut *self, __Generator::Done) {
211207
__Generator::Start(s) => {
@@ -228,8 +224,8 @@ fn main() {
228224
__Generator::Start(ret)
229225
};
230226

231-
Pin::new(&mut generator).resume();
232-
Pin::new(&mut generator).resume();
227+
Pin::new(&mut generator).resume(());
228+
Pin::new(&mut generator).resume(());
233229
}
234230
```
235231

src/liballoc/boxed.rs

+24
Original file line numberDiff line numberDiff line change
@@ -1104,6 +1104,7 @@ impl<T: ?Sized> AsMut<T> for Box<T> {
11041104
#[stable(feature = "pin", since = "1.33.0")]
11051105
impl<T: ?Sized> Unpin for Box<T> {}
11061106

1107+
#[cfg(bootstrap)]
11071108
#[unstable(feature = "generator_trait", issue = "43122")]
11081109
impl<G: ?Sized + Generator + Unpin> Generator for Box<G> {
11091110
type Yield = G::Yield;
@@ -1114,6 +1115,7 @@ impl<G: ?Sized + Generator + Unpin> Generator for Box<G> {
11141115
}
11151116
}
11161117

1118+
#[cfg(bootstrap)]
11171119
#[unstable(feature = "generator_trait", issue = "43122")]
11181120
impl<G: ?Sized + Generator> Generator for Pin<Box<G>> {
11191121
type Yield = G::Yield;
@@ -1124,6 +1126,28 @@ impl<G: ?Sized + Generator> Generator for Pin<Box<G>> {
11241126
}
11251127
}
11261128

1129+
#[cfg(not(bootstrap))]
1130+
#[unstable(feature = "generator_trait", issue = "43122")]
1131+
impl<G: ?Sized + Generator<R> + Unpin, R> Generator<R> for Box<G> {
1132+
type Yield = G::Yield;
1133+
type Return = G::Return;
1134+
1135+
fn resume(mut self: Pin<&mut Self>, arg: R) -> GeneratorState<Self::Yield, Self::Return> {
1136+
G::resume(Pin::new(&mut *self), arg)
1137+
}
1138+
}
1139+
1140+
#[cfg(not(bootstrap))]
1141+
#[unstable(feature = "generator_trait", issue = "43122")]
1142+
impl<G: ?Sized + Generator<R>, R> Generator<R> for Pin<Box<G>> {
1143+
type Yield = G::Yield;
1144+
type Return = G::Return;
1145+
1146+
fn resume(mut self: Pin<&mut Self>, arg: R) -> GeneratorState<Self::Yield, Self::Return> {
1147+
G::resume((*self).as_mut(), arg)
1148+
}
1149+
}
1150+
11271151
#[stable(feature = "futures_api", since = "1.36.0")]
11281152
impl<F: ?Sized + Future + Unpin> Future for Box<F> {
11291153
type Output = F::Output;

src/libcore/ops/generator.rs

+31-4
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ pub enum GeneratorState<Y, R> {
5050
/// return "foo"
5151
/// };
5252
///
53-
/// match Pin::new(&mut generator).resume() {
53+
/// match Pin::new(&mut generator).resume(()) {
5454
/// GeneratorState::Yielded(1) => {}
5555
/// _ => panic!("unexpected return from resume"),
5656
/// }
57-
/// match Pin::new(&mut generator).resume() {
57+
/// match Pin::new(&mut generator).resume(()) {
5858
/// GeneratorState::Complete("foo") => {}
5959
/// _ => panic!("unexpected return from resume"),
6060
/// }
@@ -67,7 +67,7 @@ pub enum GeneratorState<Y, R> {
6767
#[lang = "generator"]
6868
#[unstable(feature = "generator_trait", issue = "43122")]
6969
#[fundamental]
70-
pub trait Generator {
70+
pub trait Generator<#[cfg(not(bootstrap))] R = ()> {
7171
/// The type of value this generator yields.
7272
///
7373
/// This associated type corresponds to the `yield` expression and the
@@ -110,9 +110,13 @@ pub trait Generator {
110110
/// been returned previously. While generator literals in the language are
111111
/// guaranteed to panic on resuming after `Complete`, this is not guaranteed
112112
/// for all implementations of the `Generator` trait.
113-
fn resume(self: Pin<&mut Self>) -> GeneratorState<Self::Yield, Self::Return>;
113+
fn resume(
114+
self: Pin<&mut Self>,
115+
#[cfg(not(bootstrap))] arg: R,
116+
) -> GeneratorState<Self::Yield, Self::Return>;
114117
}
115118

119+
#[cfg(bootstrap)]
116120
#[unstable(feature = "generator_trait", issue = "43122")]
117121
impl<G: ?Sized + Generator> Generator for Pin<&mut G> {
118122
type Yield = G::Yield;
@@ -123,6 +127,7 @@ impl<G: ?Sized + Generator> Generator for Pin<&mut G> {
123127
}
124128
}
125129

130+
#[cfg(bootstrap)]
126131
#[unstable(feature = "generator_trait", issue = "43122")]
127132
impl<G: ?Sized + Generator + Unpin> Generator for &mut G {
128133
type Yield = G::Yield;
@@ -132,3 +137,25 @@ impl<G: ?Sized + Generator + Unpin> Generator for &mut G {
132137
G::resume(Pin::new(&mut *self))
133138
}
134139
}
140+
141+
#[cfg(not(bootstrap))]
142+
#[unstable(feature = "generator_trait", issue = "43122")]
143+
impl<G: ?Sized + Generator<R>, R> Generator<R> for Pin<&mut G> {
144+
type Yield = G::Yield;
145+
type Return = G::Return;
146+
147+
fn resume(mut self: Pin<&mut Self>, arg: R) -> GeneratorState<Self::Yield, Self::Return> {
148+
G::resume((*self).as_mut(), arg)
149+
}
150+
}
151+
152+
#[cfg(not(bootstrap))]
153+
#[unstable(feature = "generator_trait", issue = "43122")]
154+
impl<G: ?Sized + Generator<R> + Unpin, R> Generator<R> for &mut G {
155+
type Yield = G::Yield;
156+
type Return = G::Return;
157+
158+
fn resume(mut self: Pin<&mut Self>, arg: R) -> GeneratorState<Self::Yield, Self::Return> {
159+
G::resume(Pin::new(&mut *self), arg)
160+
}
161+
}

src/libcore/option.rs

+6
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,12 @@ impl<T> Option<T> {
455455
/// Applies a function to the contained value (if any),
456456
/// or returns the provided default (if not).
457457
///
458+
/// Arguments passed to `map_or` are eagerly evaluated; if you are passing
459+
/// the result of a function call, it is recommended to use [`map_or_else`],
460+
/// which is lazily evaluated.
461+
///
462+
/// [`map_or_else`]: #method.map_or_else
463+
///
458464
/// # Examples
459465
///
460466
/// ```

src/libcore/result.rs

+6
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,12 @@ impl<T, E> Result<T, E> {
524524
/// Applies a function to the contained value (if any),
525525
/// or returns the provided default (if not).
526526
///
527+
/// Arguments passed to `map_or` are eagerly evaluated; if you are passing
528+
/// the result of a function call, it is recommended to use [`map_or_else`],
529+
/// which is lazily evaluated.
530+
///
531+
/// [`map_or_else`]: #method.map_or_else
532+
///
527533
/// # Examples
528534
///
529535
/// ```

src/librustc/infer/opaque_types/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,7 @@ where
744744

745745
substs.as_generator().return_ty(def_id, self.tcx).visit_with(self);
746746
substs.as_generator().yield_ty(def_id, self.tcx).visit_with(self);
747+
substs.as_generator().resume_ty(def_id, self.tcx).visit_with(self);
747748
}
748749
_ => {
749750
ty.super_visit_with(self);

src/librustc/mir/mod.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -1120,6 +1120,8 @@ pub enum TerminatorKind<'tcx> {
11201120
value: Operand<'tcx>,
11211121
/// Where to resume to.
11221122
resume: BasicBlock,
1123+
/// The place to store the resume argument in.
1124+
resume_arg: Place<'tcx>,
11231125
/// Cleanup to be done if the generator is dropped at this suspend point.
11241126
drop: Option<BasicBlock>,
11251127
},
@@ -2645,9 +2647,12 @@ impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> {
26452647
target,
26462648
unwind,
26472649
},
2648-
Yield { ref value, resume, drop } => {
2649-
Yield { value: value.fold_with(folder), resume: resume, drop: drop }
2650-
}
2650+
Yield { ref value, resume, ref resume_arg, drop } => Yield {
2651+
value: value.fold_with(folder),
2652+
resume,
2653+
resume_arg: resume_arg.fold_with(folder),
2654+
drop,
2655+
},
26512656
Call { ref func, ref args, ref destination, cleanup, from_hir_call } => {
26522657
let dest =
26532658
destination.as_ref().map(|&(ref loc, dest)| (loc.fold_with(folder), dest));

src/librustc/mir/visit.rs

+6
Original file line numberDiff line numberDiff line change
@@ -516,8 +516,14 @@ macro_rules! make_mir_visitor {
516516
TerminatorKind::Yield {
517517
value,
518518
resume: _,
519+
resume_arg,
519520
drop: _,
520521
} => {
522+
self.visit_place(
523+
resume_arg,
524+
PlaceContext::MutatingUse(MutatingUseContext::Store),
525+
source_location,
526+
);
521527
self.visit_operand(value, source_location);
522528
}
523529

src/librustc/traits/util.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -643,8 +643,10 @@ pub fn generator_trait_ref_and_outputs(
643643
self_ty: Ty<'tcx>,
644644
sig: ty::PolyGenSig<'tcx>,
645645
) -> ty::Binder<(ty::TraitRef<'tcx>, Ty<'tcx>, Ty<'tcx>)> {
646-
let trait_ref =
647-
ty::TraitRef { def_id: fn_trait_def_id, substs: tcx.mk_substs_trait(self_ty, &[]) };
646+
let trait_ref = ty::TraitRef {
647+
def_id: fn_trait_def_id,
648+
substs: tcx.mk_substs_trait(self_ty, &[sig.skip_binder().resume_ty.into()]),
649+
};
648650
ty::Binder::bind((trait_ref, sig.skip_binder().yield_ty, sig.skip_binder().return_ty))
649651
}
650652

src/librustc/ty/layout.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -2350,8 +2350,9 @@ impl<'tcx> ty::Instance<'tcx> {
23502350
]);
23512351
let ret_ty = tcx.mk_adt(state_adt_ref, state_substs);
23522352

2353-
tcx.mk_fn_sig(iter::once(env_ty),
2354-
ret_ty,
2353+
tcx.mk_fn_sig(
2354+
[env_ty, sig.resume_ty].iter(),
2355+
&ret_ty,
23552356
false,
23562357
hir::Unsafety::Normal,
23572358
rustc_target::spec::abi::Abi::Rust

src/librustc/ty/structural_impls.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -598,8 +598,8 @@ impl<'a, 'tcx> Lift<'tcx> for ty::adjustment::AutoBorrow<'a> {
598598
impl<'a, 'tcx> Lift<'tcx> for ty::GenSig<'a> {
599599
type Lifted = ty::GenSig<'tcx>;
600600
fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
601-
tcx.lift(&(self.yield_ty, self.return_ty))
602-
.map(|(yield_ty, return_ty)| ty::GenSig { yield_ty, return_ty })
601+
tcx.lift(&(self.resume_ty, self.yield_ty, self.return_ty))
602+
.map(|(resume_ty, yield_ty, return_ty)| ty::GenSig { resume_ty, yield_ty, return_ty })
603603
}
604604
}
605605

0 commit comments

Comments
 (0)