Skip to content

Commit 1408715

Browse files
committed
Auto merge of #83866 - jyn514:disambiguator-error, r=camelid
rustdoc: Link to the docs on namespaces when an unknown disambiguator is found cc #83859 `@lopopolo` does this look about like what you expected? r? `@camelid`
2 parents 0bbf473 + 3478f83 commit 1408715

File tree

7 files changed

+46
-14
lines changed

7 files changed

+46
-14
lines changed

src/librustdoc/clean/types.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use rustc_ast::{self as ast, AttrStyle};
1616
use rustc_attr::{ConstStability, Deprecation, Stability, StabilityLevel};
1717
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1818
use rustc_data_structures::thin_vec::ThinVec;
19-
use rustc_feature::UnstableFeatures;
2019
use rustc_hir as hir;
2120
use rustc_hir::def::{CtorKind, Res};
2221
use rustc_hir::def_id::{CrateNum, DefId, DefIndex};
@@ -228,14 +227,9 @@ impl Item {
228227
"../".repeat(depth)
229228
}
230229
Some(&(_, _, ExternalLocation::Remote(ref s))) => s.to_string(),
231-
Some(&(_, _, ExternalLocation::Unknown)) | None => String::from(
232-
// NOTE: intentionally doesn't pass crate name to avoid having
233-
// different primitive links between crates
234-
if UnstableFeatures::from_environment(None).is_nightly_build() {
235-
"https://doc.rust-lang.org/nightly"
236-
} else {
237-
"https://doc.rust-lang.org"
238-
},
230+
Some(&(_, _, ExternalLocation::Unknown)) | None => format!(
231+
"https://doc.rust-lang.org/{}",
232+
crate::doc_rust_lang_org_channel(),
239233
),
240234
};
241235
// This is a primitive so the url is done "by hand".

src/librustdoc/clean/utils.rs

+11
Original file line numberDiff line numberDiff line change
@@ -521,3 +521,14 @@ crate fn has_doc_flag(attrs: ty::Attributes<'_>, flag: Symbol) -> bool {
521521
&& attr.meta_item_list().map_or(false, |l| rustc_attr::list_contains_name(&l, flag))
522522
})
523523
}
524+
525+
/// Return a channel suitable for using in a `doc.rust-lang.org/{channel}` format string.
526+
crate fn doc_rust_lang_org_channel() -> &'static str {
527+
match env!("CFG_RELEASE_CHANNEL") {
528+
"stable" => env!("CFG_RELEASE_NUM"),
529+
"beta" => "beta",
530+
"nightly" | "dev" => "nightly",
531+
// custom build of rustdoc maybe? link to the stable docs just in case
532+
_ => "",
533+
}
534+
}

src/librustdoc/core.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -498,15 +498,18 @@ crate fn run_global_ctxt(
498498
let mut krate = tcx.sess.time("clean_crate", || clean::krate(&mut ctxt));
499499

500500
if krate.module.doc_value().map(|d| d.is_empty()).unwrap_or(true) {
501-
let help = "The following guide may be of use:\n\
502-
https://doc.rust-lang.org/nightly/rustdoc/how-to-write-documentation.html";
501+
let help = format!(
502+
"The following guide may be of use:\n\
503+
https://doc.rust-lang.org/{}/rustdoc/how-to-write-documentation.html",
504+
crate::doc_rust_lang_org_channel(),
505+
);
503506
tcx.struct_lint_node(
504507
crate::lint::MISSING_CRATE_LEVEL_DOCS,
505508
DocContext::as_local_hir_id(tcx, krate.module.def_id).unwrap(),
506509
|lint| {
507510
let mut diag =
508511
lint.build("no documentation found for this crate's top-level module");
509-
diag.help(help);
512+
diag.help(&help);
510513
diag.emit();
511514
},
512515
);

src/librustdoc/lib.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ use rustc_session::config::{make_crate_type_option, ErrorOutputType, RustcOptGro
8282
use rustc_session::getopts;
8383
use rustc_session::{early_error, early_warn};
8484

85+
use crate::clean::utils::doc_rust_lang_org_channel;
86+
8587
/// A macro to create a FxHashMap.
8688
///
8789
/// Example:
@@ -597,7 +599,10 @@ fn usage(argv0: &str) {
597599
}
598600
println!("{}", options.usage(&format!("{} [options] <input>", argv0)));
599601
println!(" @path Read newline separated options from `path`\n");
600-
println!("More information available at https://doc.rust-lang.org/rustdoc/what-is-rustdoc.html")
602+
println!(
603+
"More information available at https://doc.rust-lang.org/{}/rustdoc/what-is-rustdoc.html",
604+
doc_rust_lang_org_channel()
605+
);
601606
}
602607

603608
/// A result type used by several functions under `main()`.

src/librustdoc/passes/collect_intra_doc_links.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -1924,7 +1924,14 @@ fn disambiguator_error(
19241924
msg: &str,
19251925
) {
19261926
diag_info.link_range = disambiguator_range;
1927-
report_diagnostic(cx.tcx, BROKEN_INTRA_DOC_LINKS, msg, &diag_info, |_diag, _sp| {});
1927+
report_diagnostic(cx.tcx, BROKEN_INTRA_DOC_LINKS, msg, &diag_info, |diag, _sp| {
1928+
let msg = format!(
1929+
"see https://doc.rust-lang.org/{}/rustdoc/linking-to-items-by-name.html#namespaces-and-disambiguators \
1930+
for more info about disambiguators",
1931+
crate::doc_rust_lang_org_channel(),
1932+
);
1933+
diag.note(&msg);
1934+
});
19281935
}
19291936

19301937
/// Report an ambiguity error, where there were multiple possible resolutions.

src/test/rustdoc-ui/intra-doc/email-address-localhost.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ note: the lint level is defined here
1010
LL | #![deny(warnings)]
1111
| ^^^^^^^^
1212
= note: `#[deny(rustdoc::broken_intra_doc_links)]` implied by `#[deny(warnings)]`
13+
= note: see https://doc.rust-lang.org/nightly/rustdoc/linking-to-items-by-name.html#namespaces-and-disambiguators for more info about disambiguators
1314

1415
error: aborting due to previous error
1516

src/test/rustdoc-ui/intra-doc/unknown-disambiguator.stderr

+11
Original file line numberDiff line numberDiff line change
@@ -10,36 +10,47 @@ note: the lint level is defined here
1010
LL | #![deny(warnings)]
1111
| ^^^^^^^^
1212
= note: `#[deny(rustdoc::broken_intra_doc_links)]` implied by `#[deny(warnings)]`
13+
= note: see https://doc.rust-lang.org/nightly/rustdoc/linking-to-items-by-name.html#namespaces-and-disambiguators for more info about disambiguators
1314

1415
error: unknown disambiguator `bar`
1516
--> $DIR/unknown-disambiguator.rs:3:35
1617
|
1718
LL | //! Linking to [foo@banana] and [`bar@banana!()`].
1819
| ^^^
20+
|
21+
= note: see https://doc.rust-lang.org/nightly/rustdoc/linking-to-items-by-name.html#namespaces-and-disambiguators for more info about disambiguators
1922

2023
error: unknown disambiguator `foo`
2124
--> $DIR/unknown-disambiguator.rs:9:34
2225
|
2326
LL | //! And with weird backticks: [``foo@hello``] [foo`@`hello].
2427
| ^^^
28+
|
29+
= note: see https://doc.rust-lang.org/nightly/rustdoc/linking-to-items-by-name.html#namespaces-and-disambiguators for more info about disambiguators
2530

2631
error: unknown disambiguator `foo`
2732
--> $DIR/unknown-disambiguator.rs:9:48
2833
|
2934
LL | //! And with weird backticks: [``foo@hello``] [foo`@`hello].
3035
| ^^^
36+
|
37+
= note: see https://doc.rust-lang.org/nightly/rustdoc/linking-to-items-by-name.html#namespaces-and-disambiguators for more info about disambiguators
3138

3239
error: unknown disambiguator ``
3340
--> $DIR/unknown-disambiguator.rs:6:31
3441
|
3542
LL | //! And to [no disambiguator](@nectarine) and [another](@apricot!()).
3643
| ^
44+
|
45+
= note: see https://doc.rust-lang.org/nightly/rustdoc/linking-to-items-by-name.html#namespaces-and-disambiguators for more info about disambiguators
3746

3847
error: unknown disambiguator ``
3948
--> $DIR/unknown-disambiguator.rs:6:57
4049
|
4150
LL | //! And to [no disambiguator](@nectarine) and [another](@apricot!()).
4251
| ^
52+
|
53+
= note: see https://doc.rust-lang.org/nightly/rustdoc/linking-to-items-by-name.html#namespaces-and-disambiguators for more info about disambiguators
4354

4455
error: aborting due to 6 previous errors
4556

0 commit comments

Comments
 (0)