-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Support multiple crate versions in --extern-html-root-url #143465
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -395,6 +395,11 @@ flags to control that behavior. When the `--extern-html-root-url` flag is given | |
one of your dependencies, rustdoc use that URL for those docs. Keep in mind that if those docs exist | ||
in the output directory, those local docs will still override this flag. | ||
|
||
Crate names in this flag refer to the names in the [extern prelude], and support crates renamed | ||
via the `--extern` `rustc` flag. | ||
Comment on lines
+398
to
+399
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think there's a few improvements that could be made here:
I think this should be split into at least two sentences, one tersely and precisely describing the behavior (extern prelude with fallback), and another describing the consequence of this behavior (e.g. support for various methods of renaming, backwards compatibility) |
||
|
||
[extern prelude]: https://doc.rust-lang.org/reference/names/preludes.html#extern-prelude | ||
|
||
## `-Z force-unstable-if-unmarked` | ||
|
||
Using this flag looks like this: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ use std::mem; | |
use rustc_attr_data_structures::StabilityLevel; | ||
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet}; | ||
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, DefIdSet}; | ||
use rustc_metadata::creader::CStore; | ||
use rustc_middle::ty::{self, TyCtxt}; | ||
use rustc_span::Symbol; | ||
use tracing::debug; | ||
|
@@ -158,18 +159,31 @@ impl Cache { | |
assert!(cx.external_traits.is_empty()); | ||
cx.cache.traits = mem::take(&mut krate.external_traits); | ||
|
||
let render_options = &cx.render_options; | ||
let extern_url_takes_precedence = render_options.extern_html_root_takes_precedence; | ||
let dst = &render_options.output; | ||
|
||
// Make `--extern-html-root-url` support the same names as `--extern` whenever possible | ||
let cstore = CStore::from_tcx(tcx); | ||
for (name, extern_url) in &render_options.extern_html_root_urls { | ||
if let Some(crate_num) = cstore.resolved_extern_crate(Symbol::intern(name)) { | ||
let e = ExternalCrate { crate_num }; | ||
let location = e.location(Some(extern_url), extern_url_takes_precedence, dst, tcx); | ||
cx.cache.extern_locations.insert(e.crate_num, location); | ||
} | ||
} | ||
|
||
// Cache where all our extern crates are located | ||
// FIXME: this part is specific to HTML so it'd be nice to remove it from the common code | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if the doc url is emitted in the json, doesn't that make this fixme comment wrong? if so, i would replace it with a note saying that this needs to be common because it is actually emitted by both backends. |
||
for &crate_num in tcx.crates(()) { | ||
let e = ExternalCrate { crate_num }; | ||
|
||
let name = e.name(tcx); | ||
let render_options = &cx.render_options; | ||
let extern_url = render_options.extern_html_root_urls.get(name.as_str()).map(|u| &**u); | ||
let extern_url_takes_precedence = render_options.extern_html_root_takes_precedence; | ||
let dst = &render_options.output; | ||
let location = e.location(extern_url, extern_url_takes_precedence, dst, tcx); | ||
cx.cache.extern_locations.insert(e.crate_num, location); | ||
cx.cache.extern_locations.entry(e.crate_num).or_insert_with(|| { | ||
let extern_url = | ||
render_options.extern_html_root_urls.get(name.as_str()).map(|u| &**u); | ||
e.location(extern_url, extern_url_takes_precedence, dst, tcx) | ||
}); | ||
cx.cache.external_paths.insert(e.def_id(), (vec![name], ItemType::Module)); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
//@ compile-flags:-Z unstable-options --extern-html-root-url extern_prelude_name=https://renamed.example.com --extern-html-root-url empty=https://bad.invalid | ||
//@ aux-crate:extern_prelude_name=empty.rs | ||
|
||
extern crate extern_prelude_name as internal_ident_name; | ||
|
||
//@ has extern_html_alias/index.html | ||
//@ has - '//a/@href' 'https://renamed.example.com/empty/index.html' | ||
pub use internal_ident_name as yet_different_name; | ||
Comment on lines
+2
to
+8
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Doing all this would probably require at least a second There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I've renamed things to avoid referring to the extern prelude. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added it to the assert's message