Skip to content
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

Rollup of 8 pull requests #83905

Merged
merged 22 commits into from
Apr 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
b5782ba
Catch a bad placeholder type error for statics in `extern`s
JohnTitor Apr 1, 2021
98ad0af
Properly suggest deref in else block
mibac138 Dec 6, 2020
e603f99
Address review comments
mibac138 Dec 17, 2020
0887944
Add additional test
LeSeulArtichaut Mar 25, 2021
fb7cf09
Don't suggest dereferencing an `else if` expression
LeSeulArtichaut Apr 1, 2021
cd22425
expand: Do not ICE when a legacy AST-based macro attribute produces a…
petrochenkov Apr 3, 2021
5f92951
rustdoc: sort search index items for compression
notriddle Apr 4, 2021
2370e3b
Get rid of unneeded `aliases` field
notriddle Apr 4, 2021
6ce9a02
:arrow_up: rust-analyzer
lnicola Apr 5, 2021
d63b3f9
Remove duplicate unwrap_or_else
jyn514 Apr 4, 2021
ac04dbd
Reduce indentation in `resolve_associated_item`
jyn514 Apr 4, 2021
3b7e654
Use more appropriate return type for `resolve_associated_item`
jyn514 Apr 4, 2021
0a351ab
Document compiler/ with -Aprivate-intra-doc-links
jyn514 Apr 5, 2021
f8653c9
Add config file for tools enabling stage1 downloads by default
jyn514 Dec 4, 2020
e5edded
Rollup merge of #83370 - jyn514:setup-tools, r=Mark-Simulacrum
JohnTitor Apr 5, 2021
d9f123a
Rollup merge of #83489 - LeSeulArtichaut:deref-else, r=davidtwco
JohnTitor Apr 5, 2021
76be7e2
Rollup merge of #83734 - JohnTitor:issue-83621, r=davidtwco
JohnTitor Apr 5, 2021
67ffbed
Rollup merge of #83814 - petrochenkov:emptyexpr, r=davidtwco
JohnTitor Apr 5, 2021
12d007d
Rollup merge of #83835 - notriddle:sort-index, r=ollie27
JohnTitor Apr 5, 2021
f93412f
Rollup merge of #83849 - jyn514:intra-doc-cleanup, r=bugadani
JohnTitor Apr 5, 2021
fb6eb4a
Rollup merge of #83881 - lnicola:rust-analyzer-2021-04-05, r=jonas-sc…
JohnTitor Apr 5, 2021
d8c04b1
Rollup merge of #83885 - jyn514:private-links, r=Mark-Simulacrum
JohnTitor Apr 5, 2021
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
9 changes: 0 additions & 9 deletions compiler/rustc_errors/src/diagnostic_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ macro_rules! forward {
pub fn $n:ident(&self, $($name:ident: $ty:ty),* $(,)?) -> &Self
) => {
$(#[$attrs])*
// we always document with --document-private-items
#[cfg_attr(not(bootstrap), allow(rustdoc::private_intra_doc_links))]
#[cfg_attr(bootstrap, allow(private_intra_doc_links))]
#[doc = concat!("See [`Diagnostic::", stringify!($n), "()`].")]
pub fn $n(&self, $($name: $ty),*) -> &Self {
self.diagnostic.$n($($name),*);
Expand All @@ -62,9 +59,6 @@ macro_rules! forward {
) => {
$(#[$attrs])*
#[doc = concat!("See [`Diagnostic::", stringify!($n), "()`].")]
// we always document with --document-private-items
#[cfg_attr(not(bootstrap), allow(rustdoc::private_intra_doc_links))]
#[cfg_attr(bootstrap, allow(private_intra_doc_links))]
pub fn $n(&mut self, $($name: $ty),*) -> &mut Self {
self.0.diagnostic.$n($($name),*);
self
Expand All @@ -82,9 +76,6 @@ macro_rules! forward {
) => {
$(#[$attrs])*
#[doc = concat!("See [`Diagnostic::", stringify!($n), "()`].")]
// we always document with --document-private-items
#[cfg_attr(not(bootstrap), allow(rustdoc::private_intra_doc_links))]
#[cfg_attr(bootstrap, allow(private_intra_doc_links))]
pub fn $n<$($generic: $bound),*>(&mut self, $($name: $ty),*) -> &mut Self {
self.0.diagnostic.$n($($name),*);
self
Expand Down
9 changes: 8 additions & 1 deletion compiler/rustc_expand/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,14 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
});
}
};
fragment_kind.expect_from_annotatables(items)
if fragment_kind == AstFragmentKind::Expr && items.is_empty() {
let msg =
"removing an expression is not supported in this position";
self.cx.span_err(span, msg);
fragment_kind.dummy(span)
} else {
fragment_kind.expect_from_annotatables(items)
}
}
Err(mut err) => {
err.emit();
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_resolve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#![feature(nll)]
#![cfg_attr(bootstrap, feature(or_patterns))]
#![recursion_limit = "256"]
#![allow(rustdoc::private_intra_doc_links)]

pub use rustc_hir::def::{Namespace, PerNS};

Expand Down
28 changes: 28 additions & 0 deletions compiler/rustc_typeck/src/check/demand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,29 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
false
}

/// If the given `HirId` corresponds to a block with a trailing expression, return that expression
crate fn maybe_get_block_expr(&self, hir_id: hir::HirId) -> Option<&'tcx hir::Expr<'tcx>> {
match self.tcx.hir().find(hir_id)? {
Node::Expr(hir::Expr { kind: hir::ExprKind::Block(block, ..), .. }) => block.expr,
_ => None,
}
}

/// Returns whether the given expression is an `else if`.
crate fn is_else_if_block(&self, expr: &hir::Expr<'_>) -> bool {
if let hir::ExprKind::If(..) = expr.kind {
let parent_id = self.tcx.hir().get_parent_node(expr.hir_id);
if let Some(Node::Expr(hir::Expr {
kind: hir::ExprKind::If(_, _, Some(else_expr)),
..
})) = self.tcx.hir().find(parent_id)
{
return else_expr.hir_id == expr.hir_id;
}
}
false
}

/// This function is used to determine potential "simple" improvements or users' errors and
/// provide them useful help. For example:
///
Expand Down Expand Up @@ -652,6 +675,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
};
let suggestion = if is_struct_pat_shorthand_field {
format!("{}: *{}", code, code)
} else if self.is_else_if_block(expr) {
// Don't suggest nonsense like `else *if`
return None;
} else if let Some(expr) = self.maybe_get_block_expr(expr.hir_id) {
format!("*{}", sm.span_to_snippet(expr.span).unwrap_or(code))
} else {
format!("*{}", code)
};
Expand Down
10 changes: 8 additions & 2 deletions compiler/rustc_typeck/src/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -734,8 +734,14 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
tcx.ensure().generics_of(item.def_id);
tcx.ensure().type_of(item.def_id);
tcx.ensure().predicates_of(item.def_id);
if let hir::ForeignItemKind::Fn(..) = item.kind {
tcx.ensure().fn_sig(item.def_id);
match item.kind {
hir::ForeignItemKind::Fn(..) => tcx.ensure().fn_sig(item.def_id),
hir::ForeignItemKind::Static(..) => {
let mut visitor = PlaceholderHirTyCollector::default();
visitor.visit_foreign_item(item);
placeholder_type_error(tcx, None, &[], visitor.0, false, None);
}
_ => (),
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/bootstrap/defaults/config.compiler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ debug-logging = true
incremental = true

[llvm]
# Will download LLVM from CI if available on your platform (Linux only for now)
# https://github.com/rust-lang/rust/issues/77084 tracks support for more platforms
# Will download LLVM from CI if available on your platform.
download-ci-llvm = "if-available"
16 changes: 16 additions & 0 deletions src/bootstrap/defaults/config.tools.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# These defaults are meant for contributors to tools which build on the
# compiler, but do not modify it directly.
[rust]
# This enables `RUSTC_LOG=debug`, avoiding confusing situations
# where adding `debug!()` appears to do nothing.
# However, it makes running the compiler slightly slower.
debug-logging = true
# This greatly increases the speed of rebuilds, especially when there are only minor changes. However, it makes the initial build slightly slower.
incremental = true
# Download rustc from CI instead of building it from source.
# This cuts compile times by almost 60x, but means you can't modify the compiler.
download-rustc = "if-unchanged"

[llvm]
# Will download LLVM from CI if available on your platform.
download-ci-llvm = "if-available"
2 changes: 2 additions & 0 deletions src/bootstrap/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,8 @@ impl Step for Rustc {
// Build cargo command.
let mut cargo = builder.cargo(compiler, Mode::Rustc, SourceType::InTree, target, "doc");
cargo.rustdocflag("--document-private-items");
// Since we always pass --document-private-items, there's no need to warn about linking to private items.
cargo.rustdocflag("-Arustdoc::private-intra-doc-links");
cargo.rustdocflag("--enable-index-page");
cargo.rustdocflag("-Zunstable-options");
cargo.rustdocflag("-Znormalize-docs");
Expand Down
20 changes: 17 additions & 3 deletions src/bootstrap/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub enum Profile {
Compiler,
Codegen,
Library,
Tools,
User,
}

Expand All @@ -24,15 +25,16 @@ impl Profile {
pub fn all() -> impl Iterator<Item = Self> {
use Profile::*;
// N.B. these are ordered by how they are displayed, not alphabetically
[Library, Compiler, Codegen, User].iter().copied()
[Library, Compiler, Codegen, Tools, User].iter().copied()
}

pub fn purpose(&self) -> String {
use Profile::*;
match self {
Library => "Contribute to the standard library",
Compiler => "Contribute to the compiler or rustdoc",
Compiler => "Contribute to the compiler itself",
Codegen => "Contribute to the compiler, and also modify LLVM or codegen",
Tools => "Contribute to tools which depend on the compiler, but do not modify it directly (e.g. rustdoc, clippy, miri)",
User => "Install Rust from source",
}
.to_string()
Expand All @@ -53,9 +55,12 @@ impl FromStr for Profile {
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"lib" | "library" => Ok(Profile::Library),
"compiler" | "rustdoc" => Ok(Profile::Compiler),
"compiler" => Ok(Profile::Compiler),
"llvm" | "codegen" => Ok(Profile::Codegen),
"maintainer" | "user" => Ok(Profile::User),
"tools" | "tool" | "rustdoc" | "clippy" | "miri" | "rustfmt" | "rls" => {
Ok(Profile::Tools)
}
_ => Err(format!("unknown profile: '{}'", s)),
}
}
Expand All @@ -68,6 +73,7 @@ impl fmt::Display for Profile {
Profile::Codegen => write!(f, "codegen"),
Profile::Library => write!(f, "library"),
Profile::User => write!(f, "user"),
Profile::Tools => write!(f, "tools"),
}
}
}
Expand Down Expand Up @@ -103,6 +109,14 @@ pub fn setup(src_path: &Path, profile: Profile) {

let suggestions = match profile {
Profile::Codegen | Profile::Compiler => &["check", "build", "test"][..],
Profile::Tools => &[
"check",
"build",
"test src/test/rustdoc*",
"test src/tools/clippy",
"test src/tools/miri",
"test src/tools/rustfmt",
],
Profile::Library => &["check", "build", "test library/std", "doc"],
Profile::User => &["dist", "build"],
};
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,7 @@ impl Attributes {
.collect()
}

crate fn get_doc_aliases(&self) -> FxHashSet<String> {
crate fn get_doc_aliases(&self) -> Box<[String]> {
let mut aliases = FxHashSet::default();

for attr in self.other_attrs.lists(sym::doc).filter(|a| a.has_name(sym::alias)) {
Expand All @@ -931,7 +931,7 @@ impl Attributes {
aliases.insert(attr.value_str().map(|s| s.to_string()).unwrap());
}
}
aliases
aliases.into_iter().collect::<Vec<String>>().into()
}
}

Expand Down
13 changes: 1 addition & 12 deletions src/librustdoc/formats/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,6 @@ crate struct Cache {
// when gathering trait documentation on a type, hold impls here while
// folding and add them to the cache later on if we find the trait.
orphan_trait_impls: Vec<(DefId, FxHashSet<DefId>, Impl)>,

/// Aliases added through `#[doc(alias = "...")]`. Since a few items can have the same alias,
/// we need the alias element to have an array of items.
crate aliases: BTreeMap<String, Vec<usize>>,
}

/// This struct is used to wrap the `cache` and `tcx` in order to run `DocFolder`.
Expand Down Expand Up @@ -309,15 +305,8 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
parent,
parent_idx: None,
search_type: get_index_search_type(&item, &self.empty_cache, self.tcx),
aliases: item.attrs.get_doc_aliases(),
});

for alias in item.attrs.get_doc_aliases() {
self.cache
.aliases
.entry(alias.to_lowercase())
.or_insert(Vec::new())
.push(self.cache.search_index.len() - 1);
}
}
}
(Some(parent), None) if is_inherent_impl_item => {
Expand Down
31 changes: 22 additions & 9 deletions src/librustdoc/html/render/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,31 @@ crate fn build_index<'tcx>(krate: &clean::Crate, cache: &mut Cache, tcx: TyCtxt<
parent: Some(did),
parent_idx: None,
search_type: get_index_search_type(&item, cache, tcx),
aliases: item.attrs.get_doc_aliases(),
});
for alias in item.attrs.get_doc_aliases() {
cache
.aliases
.entry(alias.to_lowercase())
.or_insert(Vec::new())
.push(cache.search_index.len() - 1);
}
}
}

let Cache { ref mut search_index, ref paths, ref mut aliases, .. } = *cache;
let Cache { ref mut search_index, ref paths, .. } = *cache;

// Aliases added through `#[doc(alias = "...")]`. Since a few items can have the same alias,
// we need the alias element to have an array of items.
let mut aliases: BTreeMap<String, Vec<usize>> = BTreeMap::new();

// Sort search index items. This improves the compressibility of the search index.
search_index.sort_unstable_by(|k1, k2| {
// `sort_unstable_by_key` produces lifetime errors
let k1 = (&k1.path, &k1.name, &k1.ty, &k1.parent);
let k2 = (&k2.path, &k2.name, &k2.ty, &k2.parent);
std::cmp::Ord::cmp(&k1, &k2)
});

// Set up alias indexes.
for (i, item) in search_index.iter().enumerate() {
for alias in &item.aliases[..] {
aliases.entry(alias.to_lowercase()).or_insert(Vec::new()).push(i);
}
}

// Reduce `DefId` in paths into smaller sequential numbers,
// and prune the paths that do not appear in the index.
Expand Down Expand Up @@ -201,7 +214,7 @@ crate fn build_index<'tcx>(krate: &clean::Crate, cache: &mut Cache, tcx: TyCtxt<
doc: crate_doc,
items: crate_items,
paths: crate_paths,
aliases,
aliases: &aliases,
})
.expect("failed serde conversion")
// All these `replace` calls are because we have to go through JS string for JSON content.
Expand Down
1 change: 1 addition & 0 deletions src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ crate struct IndexItem {
crate parent: Option<DefId>,
crate parent_idx: Option<usize>,
crate search_type: Option<IndexItemFunctionType>,
crate aliases: Box<[String]>,
}

/// A type used for the search index.
Expand Down
Loading