Skip to content

Commit 75b0a68

Browse files
committed
Auto merge of rust-lang#72478 - Dylan-DPC:rollup-vval8du, r=Dylan-DPC
Rollup of 7 pull requests Successful merges: - rust-lang#71289 (Allow using `Self::` in doc) - rust-lang#72375 (Improve E0599 explanation) - rust-lang#72385 (Add some teams to prioritization exclude_labels) - rust-lang#72395 (Allow rust-highfive to label issues it creates.) - rust-lang#72453 (Add flag to open docs: x.py doc --open) - rust-lang#72459 (Add core::future::IntoFuture) - rust-lang#72461 (Clean up E0600 explanation) Failed merges: r? @ghost
2 parents 7f940ef + bf1b998 commit 75b0a68

File tree

15 files changed

+296
-11
lines changed

15 files changed

+296
-11
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ dependencies = [
213213
"lazy_static 1.4.0",
214214
"libc",
215215
"num_cpus",
216+
"opener",
216217
"pretty_assertions",
217218
"serde",
218219
"serde_json",

src/bootstrap/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ toml = "0.5"
4848
lazy_static = "1.3.0"
4949
time = "0.1"
5050
ignore = "0.4.10"
51+
opener = "0.4"
5152

5253
[target.'cfg(windows)'.dependencies.winapi]
5354
version = "0.3"

src/bootstrap/builder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ impl<'a> Builder<'a> {
503503
Subcommand::Check { ref paths } => (Kind::Check, &paths[..]),
504504
Subcommand::Clippy { ref paths } => (Kind::Clippy, &paths[..]),
505505
Subcommand::Fix { ref paths } => (Kind::Fix, &paths[..]),
506-
Subcommand::Doc { ref paths } => (Kind::Doc, &paths[..]),
506+
Subcommand::Doc { ref paths, .. } => (Kind::Doc, &paths[..]),
507507
Subcommand::Test { ref paths, .. } => (Kind::Test, &paths[..]),
508508
Subcommand::Bench { ref paths, .. } => (Kind::Bench, &paths[..]),
509509
Subcommand::Dist { ref paths } => (Kind::Dist, &paths[..]),

src/bootstrap/doc.rs

+58-1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,35 @@ book!(
7070
RustdocBook, "src/doc/rustdoc", "rustdoc";
7171
);
7272

73+
fn open(builder: &Builder<'_>, path: impl AsRef<Path>) {
74+
if builder.config.dry_run || !builder.config.cmd.open() {
75+
return;
76+
}
77+
78+
let path = path.as_ref();
79+
builder.info(&format!("Opening doc {}", path.display()));
80+
if let Err(err) = opener::open(path) {
81+
builder.info(&format!("{}\n", err));
82+
}
83+
}
84+
85+
// "src/libstd" -> ["src", "libstd"]
86+
//
87+
// Used for deciding whether a particular step is one requested by the user on
88+
// the `x.py doc` command line, which determines whether `--open` will open that
89+
// page.
90+
fn components_simplified(path: &PathBuf) -> Vec<&str> {
91+
path.iter().map(|component| component.to_str().unwrap_or("???")).collect()
92+
}
93+
94+
fn is_explicit_request(builder: &Builder<'_>, path: &str) -> bool {
95+
builder
96+
.paths
97+
.iter()
98+
.map(components_simplified)
99+
.any(|requested| requested.iter().copied().eq(path.split("/")))
100+
}
101+
73102
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
74103
pub struct UnstableBook {
75104
target: Interned<String>,
@@ -200,6 +229,12 @@ impl Step for TheBook {
200229

201230
invoke_rustdoc(builder, compiler, target, path);
202231
}
232+
233+
if is_explicit_request(builder, "src/doc/book") {
234+
let out = builder.doc_out(target);
235+
let index = out.join("book").join("index.html");
236+
open(builder, &index);
237+
}
203238
}
204239
}
205240

@@ -338,6 +373,13 @@ impl Step for Standalone {
338373
}
339374
builder.run(&mut cmd);
340375
}
376+
377+
// We open doc/index.html as the default if invoked as `x.py doc --open`
378+
// with no particular explicit doc requested (e.g. src/libcore).
379+
if builder.paths.is_empty() || is_explicit_request(builder, "src/doc") {
380+
let index = out.join("index.html");
381+
open(builder, &index);
382+
}
341383
}
342384
}
343385

@@ -418,10 +460,25 @@ impl Step for Std {
418460

419461
builder.run(&mut cargo.into());
420462
};
421-
for krate in &["alloc", "core", "std", "proc_macro", "test"] {
463+
let krates = ["alloc", "core", "std", "proc_macro", "test"];
464+
for krate in &krates {
422465
run_cargo_rustdoc_for(krate);
423466
}
424467
builder.cp_r(&my_out, &out);
468+
469+
// Look for src/libstd, src/libcore etc in the `x.py doc` arguments and
470+
// open the corresponding rendered docs.
471+
for path in builder.paths.iter().map(components_simplified) {
472+
if path.get(0) == Some(&"src")
473+
&& path.get(1).map_or(false, |dir| dir.starts_with("lib"))
474+
{
475+
let requested_crate = &path[1][3..];
476+
if krates.contains(&requested_crate) {
477+
let index = out.join(requested_crate).join("index.html");
478+
open(builder, &index);
479+
}
480+
}
481+
}
425482
}
426483
}
427484

src/bootstrap/flags.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ pub enum Subcommand {
6161
},
6262
Doc {
6363
paths: Vec<PathBuf>,
64+
open: bool,
6465
},
6566
Test {
6667
paths: Vec<PathBuf>,
@@ -248,6 +249,9 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`",
248249
"bench" => {
249250
opts.optmulti("", "test-args", "extra arguments", "ARGS");
250251
}
252+
"doc" => {
253+
opts.optflag("", "open", "open the docs in a browser");
254+
}
251255
"clean" => {
252256
opts.optflag("", "all", "clean all build artifacts");
253257
}
@@ -404,6 +408,7 @@ Arguments:
404408
./x.py doc src/doc/book
405409
./x.py doc src/doc/nomicon
406410
./x.py doc src/doc/book src/libstd
411+
./x.py doc src/libstd --open
407412
408413
If no arguments are passed then everything is documented:
409414
@@ -479,7 +484,7 @@ Arguments:
479484
},
480485
},
481486
"bench" => Subcommand::Bench { paths, test_args: matches.opt_strs("test-args") },
482-
"doc" => Subcommand::Doc { paths },
487+
"doc" => Subcommand::Doc { paths, open: matches.opt_present("open") },
483488
"clean" => {
484489
if !paths.is_empty() {
485490
println!("\nclean does not take a path argument\n");
@@ -613,6 +618,13 @@ impl Subcommand {
613618
_ => None,
614619
}
615620
}
621+
622+
pub fn open(&self) -> bool {
623+
match *self {
624+
Subcommand::Doc { open, .. } => open,
625+
_ => false,
626+
}
627+
}
616628
}
617629

618630
fn split(s: &[String]) -> Vec<String> {

src/libcore/future/into_future.rs

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
use crate::future::Future;
2+
3+
/// Conversion into a `Future`.
4+
#[unstable(feature = "into_future", issue = "67644")]
5+
pub trait IntoFuture {
6+
/// The output that the future will produce on completion.
7+
#[unstable(feature = "into_future", issue = "67644")]
8+
type Output;
9+
10+
/// Which kind of future are we turning this into?
11+
#[unstable(feature = "into_future", issue = "67644")]
12+
type Future: Future<Output = Self::Output>;
13+
14+
/// Creates a future from a value.
15+
#[unstable(feature = "into_future", issue = "67644")]
16+
fn into_future(self) -> Self::Future;
17+
}
18+
19+
#[unstable(feature = "into_future", issue = "67644")]
20+
impl<F: Future> IntoFuture for F {
21+
type Output = F::Output;
22+
type Future = F;
23+
24+
fn into_future(self) -> Self::Future {
25+
self
26+
}
27+
}

src/libcore/future/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,16 @@ use crate::{
1010
};
1111

1212
mod future;
13+
mod into_future;
1314
mod pending;
1415
mod ready;
1516

1617
#[stable(feature = "futures_api", since = "1.36.0")]
1718
pub use self::future::Future;
1819

20+
#[unstable(feature = "into_future", issue = "67644")]
21+
pub use into_future::IntoFuture;
22+
1923
#[unstable(feature = "future_readiness_fns", issue = "70921")]
2024
pub use pending::{pending, Pending};
2125
#[unstable(feature = "future_readiness_fns", issue = "70921")]

src/librustc_error_codes/error_codes/E0599.md

+15
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,18 @@ let x = Mouth;
99
x.chocolate(); // error: no method named `chocolate` found for type `Mouth`
1010
// in the current scope
1111
```
12+
13+
In this case, you need to implement the `chocolate` method to fix the error:
14+
15+
```
16+
struct Mouth;
17+
18+
impl Mouth {
19+
fn chocolate(&self) { // We implement the `chocolate` method here.
20+
println!("Hmmm! I love chocolate!");
21+
}
22+
}
23+
24+
let x = Mouth;
25+
x.chocolate(); // ok!
26+
```

src/librustc_error_codes/error_codes/E0600.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
An unary operator was used on a type which doesn't implement it.
22

3-
Example of erroneous code:
3+
Erroneous code example:
44

55
```compile_fail,E0600
66
enum Question {

src/librustdoc/passes/collect_intra_doc_links.rs

+50-4
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,43 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
431431

432432
look_for_tests(&cx, &dox, &item, true);
433433

434+
// find item's parent to resolve `Self` in item's docs below
435+
let parent_name = self.cx.as_local_hir_id(item.def_id).and_then(|item_hir| {
436+
let parent_hir = self.cx.tcx.hir().get_parent_item(item_hir);
437+
let item_parent = self.cx.tcx.hir().find(parent_hir);
438+
match item_parent {
439+
Some(hir::Node::Item(hir::Item {
440+
kind:
441+
hir::ItemKind::Impl {
442+
self_ty:
443+
hir::Ty {
444+
kind:
445+
hir::TyKind::Path(hir::QPath::Resolved(
446+
_,
447+
hir::Path { segments, .. },
448+
)),
449+
..
450+
},
451+
..
452+
},
453+
..
454+
})) => segments.first().and_then(|seg| Some(seg.ident.to_string())),
455+
Some(hir::Node::Item(hir::Item {
456+
ident, kind: hir::ItemKind::Enum(..), ..
457+
}))
458+
| Some(hir::Node::Item(hir::Item {
459+
ident, kind: hir::ItemKind::Struct(..), ..
460+
}))
461+
| Some(hir::Node::Item(hir::Item {
462+
ident, kind: hir::ItemKind::Union(..), ..
463+
}))
464+
| Some(hir::Node::Item(hir::Item {
465+
ident, kind: hir::ItemKind::Trait(..), ..
466+
})) => Some(ident.to_string()),
467+
_ => None,
468+
}
469+
});
470+
434471
for (ori_link, link_range) in markdown_links(&dox) {
435472
// Bail early for real links.
436473
if ori_link.contains('/') {
@@ -467,7 +504,7 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
467504
};
468505
let (res, fragment) = {
469506
let mut kind = None;
470-
let path_str = if let Some(prefix) =
507+
let mut path_str = if let Some(prefix) =
471508
["struct@", "enum@", "type@", "trait@", "union@"]
472509
.iter()
473510
.find(|p| link.starts_with(**p))
@@ -521,6 +558,15 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
521558
let base_node =
522559
if item.is_mod() && item.attrs.inner_docs { None } else { parent_node };
523560

561+
let resolved_self;
562+
// replace `Self` with suitable item's parent name
563+
if path_str.starts_with("Self::") {
564+
if let Some(ref name) = parent_name {
565+
resolved_self = format!("{}::{}", name, &path_str[6..]);
566+
path_str = &resolved_self;
567+
}
568+
}
569+
524570
match kind {
525571
Some(ns @ ValueNS) => {
526572
match self.resolve(
@@ -529,7 +575,7 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
529575
&current_item,
530576
base_node,
531577
&extra_fragment,
532-
None,
578+
Some(&item),
533579
) {
534580
Ok(res) => res,
535581
Err(ErrorKind::ResolutionFailure) => {
@@ -552,7 +598,7 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
552598
&current_item,
553599
base_node,
554600
&extra_fragment,
555-
None,
601+
Some(&item),
556602
) {
557603
Ok(res) => res,
558604
Err(ErrorKind::ResolutionFailure) => {
@@ -577,7 +623,7 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
577623
&current_item,
578624
base_node,
579625
&extra_fragment,
580-
None,
626+
Some(&item),
581627
) {
582628
Err(ErrorKind::AnchorFailure(msg)) => {
583629
anchor_failure(cx, &item, &ori_link, &dox, link_range, msg);

src/libstd/future.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,16 @@
22
33
#[doc(inline)]
44
#[stable(feature = "futures_api", since = "1.36.0")]
5-
pub use core::future::*;
5+
pub use core::future::Future;
6+
7+
#[doc(inline)]
8+
#[unstable(feature = "gen_future", issue = "50547")]
9+
pub use core::future::{from_generator, get_context, ResumeTy};
10+
11+
#[doc(inline)]
12+
#[unstable(feature = "future_readiness_fns", issue = "70921")]
13+
pub use core::future::{pending, ready, Pending, Ready};
14+
15+
#[doc(inline)]
16+
#[unstable(feature = "into_future", issue = "67644")]
17+
pub use core::future::IntoFuture;

src/libstd/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -266,12 +266,15 @@
266266
#![feature(external_doc)]
267267
#![feature(fn_traits)]
268268
#![feature(format_args_nl)]
269+
#![feature(future_readiness_fns)]
270+
#![feature(gen_future)]
269271
#![feature(generator_trait)]
270272
#![feature(global_asm)]
271273
#![feature(hash_raw_entry)]
272274
#![feature(hashmap_internals)]
273275
#![feature(int_error_internals)]
274276
#![feature(int_error_matching)]
277+
#![feature(into_future)]
275278
#![feature(integer_atomics)]
276279
#![feature(lang_items)]
277280
#![feature(libc)]

0 commit comments

Comments
 (0)