Skip to content

Commit c43bc13

Browse files
committed
Auto merge of rust-lang#105918 - matthiaskrgr:rollup-mmazd62, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#105801 (Realistic `Path::as_mut_os_str` doctest) - rust-lang#105860 (Add long error docs for `E0460` and `E0457`) - rust-lang#105895 (Test that we don't add a new kind of breaking change with TAITs) - rust-lang#105902 (docs: improve pin docs) - rust-lang#105910 (Update books) - rust-lang#105913 (rustdoc: remove width-limiter from source pages, stop overriding CSS) - rust-lang#105915 (Revert "Replace usage of `ResumeTy` in async lowering with `Context`") Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 696563e + 575b2a2 commit c43bc13

36 files changed

+250
-85
lines changed

compiler/rustc_ast_lowering/src/expr.rs

+21-36
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc_hir::def::Res;
1616
use rustc_hir::definitions::DefPathData;
1717
use rustc_session::errors::report_lit_error;
1818
use rustc_span::source_map::{respan, DesugaringKind, Span, Spanned};
19-
use rustc_span::symbol::{kw, sym, Ident};
19+
use rustc_span::symbol::{sym, Ident};
2020
use rustc_span::DUMMY_SP;
2121
use thin_vec::thin_vec;
2222

@@ -596,38 +596,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
596596
) -> hir::ExprKind<'hir> {
597597
let output = ret_ty.unwrap_or_else(|| hir::FnRetTy::DefaultReturn(self.lower_span(span)));
598598

599-
// Resume argument type, which should be `&mut Context<'_>`.
600-
// NOTE: Using the `'static` lifetime here is technically cheating.
601-
// The `Future::poll` argument really is `&'a mut Context<'b>`, but we cannot
602-
// express the fact that we are not storing it across yield-points yet,
603-
// and we would thus run into lifetime errors.
604-
// See <https://github.com/rust-lang/rust/issues/68923>.
605-
// Our lowering makes sure we are not mis-using the `_task_context` input type
606-
// in the sense that we are indeed not using it across yield points. We
607-
// get a fresh `&mut Context` for each resume / call of `Future::poll`.
608-
// This "cheating" was previously done with a `ResumeTy` that contained a raw
609-
// pointer, and a `get_context` accessor that pulled the `Context` lifetimes
610-
// out of thin air.
611-
let context_lifetime_ident = Ident::with_dummy_span(kw::StaticLifetime);
612-
let context_lifetime = self.arena.alloc(hir::Lifetime {
613-
hir_id: self.next_id(),
614-
ident: context_lifetime_ident,
615-
res: hir::LifetimeName::Static,
616-
});
617-
let context_path =
618-
hir::QPath::LangItem(hir::LangItem::Context, self.lower_span(span), None);
619-
let context_ty = hir::MutTy {
620-
ty: self.arena.alloc(hir::Ty {
621-
hir_id: self.next_id(),
622-
kind: hir::TyKind::Path(context_path),
623-
span: self.lower_span(span),
624-
}),
625-
mutbl: hir::Mutability::Mut,
626-
};
599+
// Resume argument type: `ResumeTy`
600+
let unstable_span =
601+
self.mark_span_with_reason(DesugaringKind::Async, span, self.allow_gen_future.clone());
602+
let resume_ty = hir::QPath::LangItem(hir::LangItem::ResumeTy, unstable_span, None);
627603
let input_ty = hir::Ty {
628604
hir_id: self.next_id(),
629-
kind: hir::TyKind::Rptr(context_lifetime, context_ty),
630-
span: self.lower_span(span),
605+
kind: hir::TyKind::Path(resume_ty),
606+
span: unstable_span,
631607
};
632608

633609
// The closure/generator `FnDecl` takes a single (resume) argument of type `input_ty`.
@@ -686,9 +662,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
686662
.map_or(false, |attrs| attrs.into_iter().any(|attr| attr.has_name(sym::track_caller)));
687663

688664
let hir_id = self.lower_node_id(closure_node_id);
689-
let unstable_span =
690-
self.mark_span_with_reason(DesugaringKind::Async, span, self.allow_gen_future.clone());
691665
if track_caller {
666+
let unstable_span = self.mark_span_with_reason(
667+
DesugaringKind::Async,
668+
span,
669+
self.allow_gen_future.clone(),
670+
);
692671
self.lower_attrs(
693672
hir_id,
694673
&[Attribute {
@@ -731,7 +710,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
731710
/// mut __awaitee => loop {
732711
/// match unsafe { ::std::future::Future::poll(
733712
/// <::std::pin::Pin>::new_unchecked(&mut __awaitee),
734-
/// task_context,
713+
/// ::std::future::get_context(task_context),
735714
/// ) } {
736715
/// ::std::task::Poll::Ready(result) => break result,
737716
/// ::std::task::Poll::Pending => {}
@@ -772,7 +751,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
772751
// unsafe {
773752
// ::std::future::Future::poll(
774753
// ::std::pin::Pin::new_unchecked(&mut __awaitee),
775-
// task_context,
754+
// ::std::future::get_context(task_context),
776755
// )
777756
// }
778757
let poll_expr = {
@@ -790,10 +769,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
790769
arena_vec![self; ref_mut_awaitee],
791770
Some(expr_hir_id),
792771
);
772+
let get_context = self.expr_call_lang_item_fn_mut(
773+
gen_future_span,
774+
hir::LangItem::GetContext,
775+
arena_vec![self; task_context],
776+
Some(expr_hir_id),
777+
);
793778
let call = self.expr_call_lang_item_fn(
794779
span,
795780
hir::LangItem::FuturePoll,
796-
arena_vec![self; new_unchecked, task_context],
781+
arena_vec![self; new_unchecked, get_context],
797782
Some(expr_hir_id),
798783
);
799784
self.arena.alloc(self.expr_unsafe(call))

compiler/rustc_error_codes/src/error_codes.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,10 @@ E0452: include_str!("./error_codes/E0452.md"),
239239
E0453: include_str!("./error_codes/E0453.md"),
240240
E0454: include_str!("./error_codes/E0454.md"),
241241
E0455: include_str!("./error_codes/E0455.md"),
242+
E0457: include_str!("./error_codes/E0457.md"),
242243
E0458: include_str!("./error_codes/E0458.md"),
243244
E0459: include_str!("./error_codes/E0459.md"),
245+
E0460: include_str!("./error_codes/E0460.md"),
244246
E0463: include_str!("./error_codes/E0463.md"),
245247
E0464: include_str!("./error_codes/E0464.md"),
246248
E0466: include_str!("./error_codes/E0466.md"),
@@ -592,8 +594,6 @@ E0791: include_str!("./error_codes/E0791.md"),
592594
// E0421, // merged into 531
593595
// E0427, // merged into 530
594596
// E0456, // plugin `..` is not available for triple `..`
595-
E0457, // plugin `..` only found in rlib format, but must be available...
596-
E0460, // found possibly newer version of crate `..`
597597
E0461, // couldn't find crate `..` with expected target triple ..
598598
E0462, // found staticlib `..` instead of rlib or dylib
599599
E0465, // multiple .. candidates for `..` found
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
Plugin `..` only found in rlib format, but must be available in dylib format.
2+
3+
Erroronous code example:
4+
5+
`rlib-plugin.rs`
6+
```ignore (needs-linkage-with-other-tests)
7+
#![crate_type = "rlib"]
8+
#![feature(rustc_private)]
9+
10+
extern crate rustc_middle;
11+
extern crate rustc_driver;
12+
13+
use rustc_driver::plugin::Registry;
14+
15+
#[no_mangle]
16+
fn __rustc_plugin_registrar(_: &mut Registry) {}
17+
```
18+
19+
`main.rs`
20+
```ignore (needs-linkage-with-other-tests)
21+
#![feature(plugin)]
22+
#![plugin(rlib_plugin)] // error: plugin `rlib_plugin` only found in rlib
23+
// format, but must be available in dylib
24+
25+
fn main() {}
26+
```
27+
28+
The compiler exposes a plugin interface to allow altering the compile process
29+
(adding lints, etc). Plugins must be defined in their own crates (similar to
30+
[proc-macro](../reference/procedural-macros.html) isolation) and then compiled
31+
and linked to another crate. Plugin crates *must* be compiled to the
32+
dynamically-linked dylib format, and not the statically-linked rlib format.
33+
Learn more about different output types in
34+
[this section](../reference/linkage.html) of the Rust reference.
35+
36+
This error is easily fixed by recompiling the plugin crate in the dylib format.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
Found possibly newer version of crate `..` which `..` depends on.
2+
3+
Consider these erroneous files:
4+
5+
`a1.rs`
6+
```ignore (needs-linkage-with-other-tests)
7+
#![crate_name = "a"]
8+
9+
pub fn foo<T>() {}
10+
```
11+
12+
`a2.rs`
13+
```ignore (needs-linkage-with-other-tests)
14+
#![crate_name = "a"]
15+
16+
pub fn foo<T>() {
17+
println!("foo<T>()");
18+
}
19+
```
20+
21+
`b.rs`
22+
```ignore (needs-linkage-with-other-tests)
23+
#![crate_name = "b"]
24+
25+
extern crate a; // linked with `a1.rs`
26+
27+
pub fn foo() {
28+
a::foo::<isize>();
29+
}
30+
```
31+
32+
`main.rs`
33+
```ignore (needs-linkage-with-other-tests)
34+
extern crate a; // linked with `a2.rs`
35+
extern crate b; // error: found possibly newer version of crate `a` which `b`
36+
// depends on
37+
38+
fn main() {}
39+
```
40+
41+
The dependency graph of this program can be represented as follows:
42+
```text
43+
crate `main`
44+
|
45+
+-------------+
46+
| |
47+
| v
48+
depends: | crate `b`
49+
`a` v1 | |
50+
| | depends:
51+
| | `a` v2
52+
v |
53+
crate `a` <------+
54+
```
55+
56+
Crate `main` depends on crate `a` (version 1) and crate `b` which in turn
57+
depends on crate `a` (version 2); this discrepancy in versions cannot be
58+
reconciled. This difference in versions typically occurs when one crate is
59+
compiled and linked, then updated and linked to another crate. The crate
60+
"version" is a SVH (Strict Version Hash) of the crate in an
61+
implementation-specific way. Note that this error can *only* occur when
62+
directly compiling and linking with `rustc`; [Cargo] automatically resolves
63+
dependencies, without using the compiler's own dependency management that
64+
causes this issue.
65+
66+
This error can be fixed by:
67+
* Using [Cargo], the Rust package manager, automatically fixing this issue.
68+
* Recompiling crate `a` so that both crate `b` and `main` have a uniform
69+
version to depend on.
70+
71+
[Cargo]: ../cargo/index.html

compiler/rustc_hir/src/lang_items.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,10 @@ language_item_table! {
286286

287287
// FIXME(swatinem): the following lang items are used for async lowering and
288288
// should become obsolete eventually.
289+
ResumeTy, sym::ResumeTy, resume_ty, Target::Struct, GenericRequirement::None;
289290
IdentityFuture, sym::identity_future, identity_future_fn, Target::Fn, GenericRequirement::None;
291+
GetContext, sym::get_context, get_context_fn, Target::Fn, GenericRequirement::None;
290292

291-
Context, sym::Context, context, Target::Struct, GenericRequirement::None;
292293
FuturePoll, sym::poll, future_poll_fn, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None;
293294

294295
FromFrom, sym::from, from_fn, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None;

compiler/rustc_span/src/symbol.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ symbols! {
164164
Capture,
165165
Center,
166166
Clone,
167-
Context,
168167
Continue,
169168
Copy,
170169
Count,
@@ -264,6 +263,7 @@ symbols! {
264263
Relaxed,
265264
Release,
266265
Result,
266+
ResumeTy,
267267
Return,
268268
Right,
269269
Rust,
@@ -753,6 +753,7 @@ symbols! {
753753
generic_associated_types_extended,
754754
generic_const_exprs,
755755
generic_param_attrs,
756+
get_context,
756757
global_allocator,
757758
global_asm,
758759
globs,

library/core/src/future/mod.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub use poll_fn::{poll_fn, PollFn};
4444
/// non-Send/Sync as well, and we don't want that.
4545
///
4646
/// It also simplifies the HIR lowering of `.await`.
47-
// FIXME(swatinem): This type can be removed when bumping the bootstrap compiler
47+
#[cfg_attr(not(bootstrap), lang = "ResumeTy")]
4848
#[doc(hidden)]
4949
#[unstable(feature = "gen_future", issue = "50547")]
5050
#[derive(Debug, Copy, Clone)]
@@ -61,7 +61,6 @@ unsafe impl Sync for ResumeTy {}
6161
/// This function returns a `GenFuture` underneath, but hides it in `impl Trait` to give
6262
/// better error messages (`impl Future` rather than `GenFuture<[closure.....]>`).
6363
// This is `const` to avoid extra errors after we recover from `const async fn`
64-
// FIXME(swatinem): This fn can be removed when bumping the bootstrap compiler
6564
#[cfg_attr(bootstrap, lang = "from_generator")]
6665
#[doc(hidden)]
6766
#[unstable(feature = "gen_future", issue = "50547")]
@@ -103,8 +102,7 @@ where
103102
GenFuture(gen)
104103
}
105104

106-
// FIXME(swatinem): This fn can be removed when bumping the bootstrap compiler
107-
#[cfg_attr(bootstrap, lang = "get_context")]
105+
#[lang = "get_context"]
108106
#[doc(hidden)]
109107
#[unstable(feature = "gen_future", issue = "50547")]
110108
#[must_use]
@@ -115,10 +113,6 @@ pub unsafe fn get_context<'a, 'b>(cx: ResumeTy) -> &'a mut Context<'b> {
115113
unsafe { &mut *cx.0.as_ptr().cast() }
116114
}
117115

118-
// FIXME(swatinem): This fn is currently needed to work around shortcomings
119-
// in type and lifetime inference.
120-
// See the comment at the bottom of `LoweringContext::make_async_expr` and
121-
// <https://github.com/rust-lang/rust/issues/104826>.
122116
#[cfg_attr(not(bootstrap), lang = "identity_future")]
123117
#[doc(hidden)]
124118
#[unstable(feature = "gen_future", issue = "50547")]

library/core/src/pin.rs

+35-1
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,16 @@ impl<P: Deref<Target: Unpin>> Pin<P> {
485485
///
486486
/// Unlike `Pin::new_unchecked`, this method is safe because the pointer
487487
/// `P` dereferences to an [`Unpin`] type, which cancels the pinning guarantees.
488+
///
489+
/// # Examples
490+
///
491+
/// ```
492+
/// use std::pin::Pin;
493+
///
494+
/// let mut val: u8 = 5;
495+
/// // We can pin the value, since it doesn't care about being moved
496+
/// let mut pinned: Pin<&mut u8> = Pin::new(&mut val);
497+
/// ```
488498
#[inline(always)]
489499
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
490500
#[stable(feature = "pin", since = "1.33.0")]
@@ -496,8 +506,20 @@ impl<P: Deref<Target: Unpin>> Pin<P> {
496506

497507
/// Unwraps this `Pin<P>` returning the underlying pointer.
498508
///
499-
/// This requires that the data inside this `Pin` is [`Unpin`] so that we
509+
/// This requires that the data inside this `Pin` implements [`Unpin`] so that we
500510
/// can ignore the pinning invariants when unwrapping it.
511+
///
512+
/// # Examples
513+
///
514+
/// ```
515+
/// use std::pin::Pin;
516+
///
517+
/// let mut val: u8 = 5;
518+
/// let pinned: Pin<&mut u8> = Pin::new(&mut val);
519+
/// // Unwrap the pin to get a reference to the value
520+
/// let r = Pin::into_inner(pinned);
521+
/// assert_eq!(*r, 5);
522+
/// ```
501523
#[inline(always)]
502524
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
503525
#[stable(feature = "pin_into_inner", since = "1.39.0")]
@@ -707,6 +729,18 @@ impl<P: DerefMut> Pin<P> {
707729
///
708730
/// This overwrites pinned data, but that is okay: its destructor gets
709731
/// run before being overwritten, so no pinning guarantee is violated.
732+
///
733+
/// # Example
734+
///
735+
/// ```
736+
/// use std::pin::Pin;
737+
///
738+
/// let mut val: u8 = 5;
739+
/// let mut pinned: Pin<&mut u8> = Pin::new(&mut val);
740+
/// println!("{}", pinned); // 5
741+
/// pinned.as_mut().set(10);
742+
/// println!("{}", pinned); // 10
743+
/// ```
710744
#[stable(feature = "pin", since = "1.33.0")]
711745
#[inline(always)]
712746
pub fn set(&mut self, value: P::Target)

library/core/src/task/wake.rs

-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ impl RawWakerVTable {
174174
/// Currently, `Context` only serves to provide access to a [`&Waker`](Waker)
175175
/// which can be used to wake the current task.
176176
#[stable(feature = "futures_api", since = "1.36.0")]
177-
#[cfg_attr(not(bootstrap), lang = "Context")]
178177
pub struct Context<'a> {
179178
waker: &'a Waker,
180179
// Ensure we future-proof against variance changes by forcing

library/std/src/path.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2039,12 +2039,12 @@ impl Path {
20392039
/// #![feature(path_as_mut_os_str)]
20402040
/// use std::path::{Path, PathBuf};
20412041
///
2042-
/// let mut path = PathBuf::from("/Foo.TXT").into_boxed_path();
2042+
/// let mut path = PathBuf::from("Foo.TXT");
20432043
///
2044-
/// assert_ne!(&*path, Path::new("/foo.txt"));
2044+
/// assert_ne!(path, Path::new("foo.txt"));
20452045
///
20462046
/// path.as_mut_os_str().make_ascii_lowercase();
2047-
/// assert_eq!(&*path, Path::new("/foo.txt"));
2047+
/// assert_eq!(path, Path::new("foo.txt"));
20482048
/// ```
20492049
#[unstable(feature = "path_as_mut_os_str", issue = "105021")]
20502050
#[must_use]

src/doc/nomicon

0 commit comments

Comments
 (0)