Skip to content

Rollup of 7 pull requests #84757

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

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion library/core/src/hint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ pub fn spin_loop() {
#[cfg(target_arch = "aarch64")]
{
// SAFETY: the `cfg` attr ensures that we only execute this on aarch64 targets.
unsafe { crate::arch::aarch64::__yield() };
unsafe { crate::arch::aarch64::__isb(crate::arch::aarch64::SY) };
}
#[cfg(target_arch = "arm")]
{
Expand Down
305 changes: 174 additions & 131 deletions src/doc/rustc/src/platform-support.md

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions src/doc/rustc/src/target-tier-policy.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Target Tier Policy

## Table of Contents

* [General](#general)
* [Tier 3 target policy](#tier-3-target-policy)
* [Tier 2 target policy](#tier-2-target-policy)
* [Tier 2 with host tools](#tier-2-with-host-tools)
* [Tier 1 target policy](#tier-1-target-policy)
* [Tier 1 with host tools](#tier-1-with-host-tools)

## General

Rust provides three tiers of target support:

- Rust provides no guarantees about tier 3 targets; they exist in the codebase,
Expand Down
59 changes: 56 additions & 3 deletions src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::fmt;
use std::hash::{Hash, Hasher};
use std::iter::FromIterator;
use std::lazy::SyncOnceCell as OnceCell;
use std::path::PathBuf;
use std::rc::Rc;
use std::sync::Arc;
use std::{slice, vec};
Expand Down Expand Up @@ -90,6 +91,58 @@ impl ExternalCrate {
tcx.crate_name(self.crate_num)
}

crate fn src_root(&self, tcx: TyCtxt<'_>) -> PathBuf {
match self.src(tcx) {
FileName::Real(ref p) => match p.local_path().parent() {
Some(p) => p.to_path_buf(),
None => PathBuf::new(),
},
_ => PathBuf::new(),
}
}

/// Attempts to find where an external crate is located, given that we're
/// rendering in to the specified source destination.
crate fn location(
&self,
extern_url: Option<&str>,
dst: &std::path::Path,
tcx: TyCtxt<'_>,
) -> ExternalLocation {
use ExternalLocation::*;

fn to_remote(url: impl ToString) -> ExternalLocation {
let mut url = url.to_string();
if !url.ends_with('/') {
url.push('/');
}
Remote(url)
}

// See if there's documentation generated into the local directory
// WARNING: since rustdoc creates these directories as it generates documentation, this check is only accurate before rendering starts.
// Make sure to call `location()` by that time.
let local_location = dst.join(&*self.name(tcx).as_str());
if local_location.is_dir() {
return Local;
}

if let Some(url) = extern_url {
return to_remote(url);
}

// Failing that, see if there's an attribute specifying where to find this
// external crate
let did = DefId { krate: self.crate_num, index: CRATE_DEF_INDEX };
tcx.get_attrs(did)
.lists(sym::doc)
.filter(|a| a.has_name(sym::html_root_url))
.filter_map(|a| a.value_str())
.map(to_remote)
.next()
.unwrap_or(Unknown) // Well, at least we tried.
}

crate fn keywords(&self, tcx: TyCtxt<'_>) -> ThinVec<(DefId, Symbol)> {
let root = self.def_id();

Expand Down Expand Up @@ -381,7 +434,7 @@ impl Item {
let relative_to = &cx.current;
if let Some(ref fragment) = *fragment {
let url = match cx.cache().extern_locations.get(&self.def_id.krate) {
Some(&(_, _, ExternalLocation::Local)) => {
Some(ExternalLocation::Local) => {
if relative_to[0] == "std" {
let depth = relative_to.len() - 1;
"../".repeat(depth)
Expand All @@ -390,10 +443,10 @@ impl Item {
format!("{}std/", "../".repeat(depth))
}
}
Some(&(_, _, ExternalLocation::Remote(ref s))) => {
Some(ExternalLocation::Remote(ref s)) => {
format!("{}/std/", s.trim_end_matches('/'))
}
Some(&(_, _, ExternalLocation::Unknown)) | None => format!(
Some(ExternalLocation::Unknown) | None => format!(
"https://doc.rust-lang.org/{}/std/",
crate::doc_rust_lang_org_channel(),
),
Expand Down
21 changes: 4 additions & 17 deletions src/librustdoc/formats/cache.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
use std::collections::BTreeMap;
use std::mem;
use std::path::{Path, PathBuf};
use std::path::Path;

use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX};
use rustc_middle::middle::privacy::AccessLevels;
use rustc_middle::ty::TyCtxt;
use rustc_span::source_map::FileName;
use rustc_span::symbol::sym;
use rustc_span::Symbol;

use crate::clean::{self, GetDefId};
use crate::fold::DocFolder;
use crate::formats::item_type::ItemType;
use crate::formats::Impl;
use crate::html::markdown::short_markdown_summary;
use crate::html::render::cache::{extern_location, get_index_search_type, ExternalLocation};
use crate::html::render::cache::{get_index_search_type, ExternalLocation};
use crate::html::render::IndexItem;

/// This cache is used to store information about the [`clean::Crate`] being
Expand Down Expand Up @@ -72,7 +70,7 @@ crate struct Cache {
crate implementors: FxHashMap<DefId, Vec<Impl>>,

/// Cache of where external crate documentation can be found.
crate extern_locations: FxHashMap<CrateNum, (Symbol, PathBuf, ExternalLocation)>,
crate extern_locations: FxHashMap<CrateNum, ExternalLocation>,

/// Cache of where documentation for primitives can be found.
crate primitive_locations: FxHashMap<clean::PrimitiveType, DefId>,
Expand Down Expand Up @@ -155,21 +153,10 @@ impl Cache {
// 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
for &(n, ref e) in &krate.externs {
let src_root = match e.src(tcx) {
FileName::Real(ref p) => match p.local_path().parent() {
Some(p) => p.to_path_buf(),
None => PathBuf::new(),
},
_ => PathBuf::new(),
};
let name = e.name(tcx);
let extern_url = extern_html_root_urls.get(&*name.as_str()).map(|u| &**u);
let did = DefId { krate: n, index: CRATE_DEF_INDEX };
self.extern_locations.insert(
n,
(name, src_root, extern_location(e, extern_url, tcx.get_attrs(did), &dst, tcx)),
);

self.extern_locations.insert(n, e.location(extern_url, &dst, tcx));
self.external_paths.insert(did, (vec![name.to_string()], ItemType::Module));
}

Expand Down
20 changes: 11 additions & 9 deletions src/librustdoc/html/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use rustc_middle::ty::TyCtxt;
use rustc_span::def_id::{DefId, CRATE_DEF_INDEX};
use rustc_target::spec::abi::Abi;

use crate::clean::{self, utils::find_nearest_parent_module, PrimitiveType};
use crate::clean::{self, utils::find_nearest_parent_module, ExternalCrate, PrimitiveType};
use crate::formats::item_type::ItemType;
use crate::html::escape::Escape;
use crate::html::render::cache::ExternalLocation;
Expand Down Expand Up @@ -465,14 +465,14 @@ crate fn href(did: DefId, cx: &Context<'_>) -> Option<(String, ItemType, Vec<Str
fqp,
shortty,
match cache.extern_locations[&did.krate] {
(.., ExternalLocation::Remote(ref s)) => {
ExternalLocation::Remote(ref s) => {
let s = s.trim_end_matches('/');
let mut s = vec![&s[..]];
s.extend(module_fqp[..].iter().map(String::as_str));
s
}
(.., ExternalLocation::Local) => href_relative_parts(module_fqp, relative_to),
(.., ExternalLocation::Unknown) => return None,
ExternalLocation::Local => href_relative_parts(module_fqp, relative_to),
ExternalLocation::Unknown => return None,
},
)
}
Expand Down Expand Up @@ -578,20 +578,22 @@ fn primitive_link(
Some(&def_id) => {
let cname_str;
let loc = match m.extern_locations[&def_id.krate] {
(ref cname, _, ExternalLocation::Remote(ref s)) => {
cname_str = cname.as_str();
ExternalLocation::Remote(ref s) => {
cname_str =
ExternalCrate { crate_num: def_id.krate }.name(cx.tcx()).as_str();
Some(vec![s.trim_end_matches('/'), &cname_str[..]])
}
(ref cname, _, ExternalLocation::Local) => {
cname_str = cname.as_str();
ExternalLocation::Local => {
cname_str =
ExternalCrate { crate_num: def_id.krate }.name(cx.tcx()).as_str();
Some(if cx.current.first().map(|x| &x[..]) == Some(&cname_str[..]) {
iter::repeat("..").take(cx.current.len() - 1).collect()
} else {
let cname = iter::once(&cname_str[..]);
iter::repeat("..").take(cx.current.len()).chain(cname).collect()
})
}
(.., ExternalLocation::Unknown) => None,
ExternalLocation::Unknown => None,
};
if let Some(loc) = loc {
write!(
Expand Down
47 changes: 2 additions & 45 deletions src/librustdoc/html/render/cache.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
use std::collections::BTreeMap;
use std::path::Path;

use rustc_ast::ast;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_middle::ty::TyCtxt;
use rustc_span::symbol::{sym, Symbol};
use rustc_span::symbol::Symbol;
use serde::ser::{Serialize, SerializeStruct, Serializer};

use crate::clean;
use crate::clean::types::{
AttributesExt, FnDecl, FnRetTy, GenericBound, Generics, GetDefId, Type, WherePredicate,
FnDecl, FnRetTy, GenericBound, Generics, GetDefId, Type, WherePredicate,
};
use crate::formats::cache::Cache;
use crate::formats::item_type::ItemType;
Expand All @@ -26,47 +24,6 @@ crate enum ExternalLocation {
Unknown,
}

/// Attempts to find where an external crate is located, given that we're
/// rendering in to the specified source destination.
crate fn extern_location(
e: &clean::ExternalCrate,
extern_url: Option<&str>,
ast_attrs: &[ast::Attribute],
dst: &Path,
tcx: TyCtxt<'_>,
) -> ExternalLocation {
use ExternalLocation::*;
// See if there's documentation generated into the local directory
let local_location = dst.join(&*e.name(tcx).as_str());
if local_location.is_dir() {
return Local;
}

if let Some(url) = extern_url {
let mut url = url.to_string();
if !url.ends_with('/') {
url.push('/');
}
return Remote(url);
}

// Failing that, see if there's an attribute specifying where to find this
// external crate
ast_attrs
.lists(sym::doc)
.filter(|a| a.has_name(sym::html_root_url))
.filter_map(|a| a.value_str())
.map(|url| {
let mut url = url.to_string();
if !url.ends_with('/') {
url.push('/')
}
Remote(url)
})
.next()
.unwrap_or(Unknown) // Well, at least we tried.
}

/// Builds the search index from the collected metadata
crate fn build_index<'tcx>(krate: &clean::Crate, cache: &mut Cache, tcx: TyCtxt<'tcx>) -> String {
let mut defid_to_pathid = FxHashMap::default();
Expand Down
14 changes: 9 additions & 5 deletions src/librustdoc/html/render/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use super::print_item::{full_path, item_path, print_item};
use super::write_shared::write_shared;
use super::{print_sidebar, settings, AllTypes, NameDoc, StylePath, BASIC_KEYWORDS};

use crate::clean;
use crate::clean::{self, ExternalCrate};
use crate::config::RenderOptions;
use crate::docfs::{DocFS, PathError};
use crate::error::Error;
Expand Down Expand Up @@ -304,12 +304,16 @@ impl<'tcx> Context<'tcx> {
}
} else {
let (krate, src_root) = match *self.cache.extern_locations.get(&cnum)? {
(name, ref src, ExternalLocation::Local) => (name, src),
(name, ref src, ExternalLocation::Remote(ref s)) => {
ExternalLocation::Local => {
let e = ExternalCrate { crate_num: cnum };
(e.name(self.tcx()), e.src_root(self.tcx()))
}
ExternalLocation::Remote(ref s) => {
root = s.to_string();
(name, src)
let e = ExternalCrate { crate_num: cnum };
(e.name(self.tcx()), e.src_root(self.tcx()))
}
(_, _, ExternalLocation::Unknown) => return None,
ExternalLocation::Unknown => return None,
};

sources::clean_path(&src_root, file, false, |component| {
Expand Down
55 changes: 35 additions & 20 deletions src/librustdoc/html/static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1490,27 +1490,42 @@ function hideThemeButtonState() {
searchState.setup();
}());

function copy_path(but) {
var parent = but.parentElement;
var path = [];
(function () {
var reset_button_timeout = null;

onEach(parent.childNodes, function(child) {
if (child.tagName === 'A') {
path.push(child.textContent);
}
});
window.copy_path = function(but) {
var parent = but.parentElement;
var path = [];

var el = document.createElement('textarea');
el.value = 'use ' + path.join('::') + ';';
el.setAttribute('readonly', '');
// To not make it appear on the screen.
el.style.position = 'absolute';
el.style.left = '-9999px';
onEach(parent.childNodes, function(child) {
if (child.tagName === 'A') {
path.push(child.textContent);
}
});

document.body.appendChild(el);
el.select();
document.execCommand('copy');
document.body.removeChild(el);
var el = document.createElement('textarea');
el.value = 'use ' + path.join('::') + ';';
el.setAttribute('readonly', '');
// To not make it appear on the screen.
el.style.position = 'absolute';
el.style.left = '-9999px';

but.textContent = '✓';
}
document.body.appendChild(el);
el.select();
document.execCommand('copy');
document.body.removeChild(el);

but.textContent = '✓';

if (reset_button_timeout !== null) {
window.clearTimeout(reset_button_timeout);
}

function reset_button() {
but.textContent = '⎘';
reset_button_timeout = null;
}

reset_button_timeout = window.setTimeout(reset_button, 1000);
};
}());
Loading