Skip to content

Rollup of 17 pull requests #80314

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

Merged
merged 34 commits into from
Dec 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
b11b705
Add test for issue #74824
aDotInTheVoid Dec 17, 2020
52b717f
Edit rustc_middle::lint::LintSource docs
pierwill Dec 19, 2020
4fffa74
docs: Edit rustc_middle::ty::query::on_disk_cache
pierwill Dec 19, 2020
c127530
Fix labels for 'Library Tracking Issue' template
camelid Dec 20, 2020
e614a72
Fix rustc-std-workspace-core documentation
GreenRecycleBin Dec 20, 2020
51d1806
docs: Fix outdated crate reference
pierwill Dec 20, 2020
9f8c8e4
Add module-level docs to rustc_middle::ty
pierwill Dec 20, 2020
32baf23
Fix typo
pierwill Dec 20, 2020
dc58fc4
Remove `I-prioritize` from Zulip topic
camelid Dec 20, 2020
dffa1e2
Remove redundant test
bugadani Dec 21, 2020
00ff7fe
rustc_span: Provide a reserved identifier check for a specific edition
petrochenkov Dec 21, 2020
1339c81
Update books
ehuss Dec 22, 2020
80aa551
docs: Edit rustc_middle::middle::privacy
pierwill Dec 22, 2020
9cd992f
Add some intra-doc links to compiler docs
jyn514 Dec 22, 2020
ef75761
Turn helper method into a closure
LingMan Dec 22, 2020
57b5f8c
Improve the code quality by using matches macro
Polkaverse Dec 22, 2020
f078f7c
docs: Update rustc_middle::middle::region::ScopeTree
pierwill Dec 22, 2020
26f2d8e
Rollup merge of #80136 - aDotInTheVoid:74824-test, r=Mark-Simulacrum
GuillaumeGomez Dec 22, 2020
f84ec97
Rollup merge of #80203 - pierwill:pierwill-rustcmiddle-lint, r=oli-obk
GuillaumeGomez Dec 22, 2020
8a35d3a
Rollup merge of #80204 - pierwill:pierwill-rustcmiddle-ondisk, r=varkor
GuillaumeGomez Dec 22, 2020
536754f
Rollup merge of #80219 - camelid:library_tracking_issue-labels, r=m-o…
GuillaumeGomez Dec 22, 2020
9446d43
Rollup merge of #80222 - GreenRecycleBin:daniel/fix-rustc-std-workspa…
GuillaumeGomez Dec 22, 2020
f9f8446
Rollup merge of #80223 - pierwill:patch-10, r=lcnr
GuillaumeGomez Dec 22, 2020
e116732
Rollup merge of #80225 - pierwill:patch-11, r=lcnr
GuillaumeGomez Dec 22, 2020
5589261
Rollup merge of #80241 - pierwill:patch-12, r=lcnr
GuillaumeGomez Dec 22, 2020
805c8ac
Rollup merge of #80248 - camelid:prioritize-zulip-topic, r=Mark-Simul…
GuillaumeGomez Dec 22, 2020
93690dc
Rollup merge of #80266 - bugadani:dup-test, r=jyn514
GuillaumeGomez Dec 22, 2020
aa7cb4f
Rollup merge of #80272 - petrochenkov:kwed, r=oli-obk
GuillaumeGomez Dec 22, 2020
4addcbc
Rollup merge of #80285 - ehuss:update-books, r=ehuss
GuillaumeGomez Dec 22, 2020
174a9fa
Rollup merge of #80286 - pierwill:rustc-middle-privacy, r=petrochenkov
GuillaumeGomez Dec 22, 2020
125156c
Rollup merge of #80297 - jyn514:more-docs, r=bjorn3
GuillaumeGomez Dec 22, 2020
5af144e
Rollup merge of #80298 - PankajChaudhary5:PankajChaudhary, r=Guillaum…
GuillaumeGomez Dec 22, 2020
f711f3f
Rollup merge of #80299 - LingMan:helper, r=lcnr
GuillaumeGomez Dec 22, 2020
67f8244
Rollup merge of #80302 - pierwill:fix-80287, r=lcnr
GuillaumeGomez Dec 22, 2020
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 .github/ISSUE_TEMPLATE/library_tracking_issue.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name: Library Tracking Issue
about: A tracking issue for an unstable library feature.
title: Tracking Issue for XXX
labels: C-tracking-issue T-libs
labels: C-tracking-issue, T-libs
---
<!--
Thank you for creating a tracking issue!
Expand Down
5 changes: 4 additions & 1 deletion compiler/rustc_builtin_macros/src/deriving/generic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,10 @@ pub struct Substructure<'a> {
pub type_ident: Ident,
/// ident of the method
pub method_ident: Ident,
/// dereferenced access to any `Self_` or `Ptr(Self_, _)` arguments
/// dereferenced access to any [`Self_`] or [`Ptr(Self_, _)][ptr]` arguments
///
/// [`Self_`]: ty::Ty::Self_
/// [ptr]: ty::Ty::Ptr
pub self_args: &'a [P<Expr>],
/// verbatim access to any other arguments
pub nonself_args: &'a [P<Expr>],
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_interface/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ use std::sync::{Arc, Mutex};
pub type Result<T> = result::Result<T, ErrorReported>;

/// Represents a compiler session.
///
/// Can be used to run `rustc_interface` queries.
/// Created by passing `Config` to `run_compiler`.
/// Created by passing [`Config`] to [`run_compiler`].
pub struct Compiler {
pub(crate) sess: Lrc<Session>,
codegen_backend: Lrc<Box<dyn CodegenBackend>>,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ declare_box_region_type!(
/// harness if one is to be provided, injection of a dependency on the
/// standard library and prelude, and name resolution.
///
/// Returns `None` if we're aborting after handling -W help.
/// Returns [`None`] if we're aborting after handling -W help.
pub fn configure_and_expand(
sess: Lrc<Session>,
lint_store: Lrc<LintStore>,
Expand Down
6 changes: 5 additions & 1 deletion compiler/rustc_interface/src/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ use std::cell::{Ref, RefCell, RefMut};
use std::rc::Rc;

/// Represent the result of a query.
/// This result can be stolen with the `take` method and generated with the `compute` method.
///
/// This result can be stolen with the [`take`] method and generated with the [`compute`] method.
///
/// [`take`]: Self::take
/// [`compute`]: Self::compute
pub struct Query<T> {
result: RefCell<Option<Result<T>>>,
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
//! - **MIR.** The "mid-level (M) intermediate representation (IR)" is
//! defined in the `mir` module. This module contains only the
//! *definition* of the MIR; the passes that transform and operate
//! on MIR are found in `librustc_mir` crate.
//! on MIR are found in `rustc_mir` crate.
//! - **Types.** The internal representation of types used in rustc is
//! defined in the `ty` module. This includes the **type context**
//! (or `tcx`), which is the central context during most of
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ pub enum LintSource {
Node(Symbol, Span, Option<Symbol> /* RFC 2383 reason */),

/// Lint level was set by a command-line flag.
/// The provided `Level` is the level specified on the command line -
/// the actual level may be lower due to `--cap-lints`
/// The provided `Level` is the level specified on the command line.
/// (The actual level may be lower due to `--cap-lints`.)
CommandLine(Symbol, Level),
}

Expand Down
10 changes: 6 additions & 4 deletions compiler/rustc_middle/src/middle/privacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ use rustc_macros::HashStable;
use std::fmt;
use std::hash::Hash;

// Accessibility levels, sorted in ascending order
/// Represents the levels of accessibility an item can have.
///
/// The variants are sorted in ascending order of accessibility.
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, HashStable)]
pub enum AccessLevel {
/// Superset of `AccessLevel::Reachable` used to mark impl Trait items.
Expand All @@ -18,13 +20,13 @@ pub enum AccessLevel {
/// public, then type `T` is reachable. Its values can be obtained by other crates
/// even if the type itself is not nameable.
Reachable,
/// Public items + items accessible to other crates with help of `pub use` re-exports
/// Public items + items accessible to other crates with the help of `pub use` re-exports.
Exported,
/// Items accessible to other crates directly, without help of re-exports
/// Items accessible to other crates directly, without the help of re-exports.
Public,
}

// Accessibility levels for reachable HIR nodes
/// Holds a map of accessibility levels for reachable HIR nodes.
#[derive(Clone)]
pub struct AccessLevels<Id = HirId> {
pub map: FxHashMap<Id, AccessLevel>,
Expand Down
6 changes: 2 additions & 4 deletions compiler/rustc_middle/src/middle/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ pub struct ScopeTree {
pub struct YieldData {
/// The `Span` of the yield.
pub span: Span,
/// The number of expressions and patterns appearing before the `yield` in the body plus one.
/// The number of expressions and patterns appearing before the `yield` in the body, plus one.
pub expr_and_pat_count: usize,
pub source: hir::YieldSource,
}
Expand Down Expand Up @@ -449,9 +449,7 @@ impl ScopeTree {
}

/// Checks whether the given scope contains a `yield`. If so,
/// returns `Some((span, expr_count))` with the span of a yield we found and
/// the number of expressions and patterns appearing before the `yield` in the body + 1.
/// If there a are multiple yields in a scope, the one with the highest number is returned.
/// returns `Some(YieldData)`. If not, returns `None`.
pub fn yield_in_scope(&self, scope: Scope) -> Option<YieldData> {
self.yield_in_scope.get(&scope).cloned()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub struct DefIdForest {
/// If A and B are DefIds in the `DefIdForest`, and A is a descendant
/// of B, then only B will be in `root_ids`.
/// We use a `SmallVec` here because (for its use for caching inhabitedness)
/// its rare that this will contain even two IDs.
/// it's rare that this will contain even two IDs.
root_ids: SmallVec<[DefId; 1]>,
}

Expand Down
11 changes: 11 additions & 0 deletions compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
//! Defines how the compiler represents types internally.
//!
//! Two important entities in this module are:
//!
//! - [`rustc_middle::ty::Ty`], used to represent the semantics of a type.
//! - [`rustc_middle::ty::TyCtxt`], the central data structure in the compiler.
//!
//! For more information, see ["The `ty` module: representing types"] in the ructc-dev-guide.
//!
//! ["The `ty` module: representing types"]: https://rustc-dev-guide.rust-lang.org/ty.html

// ignore-tidy-filelength
pub use self::fold::{TypeFoldable, TypeFolder, TypeVisitor};
pub use self::AssocItemContainer::*;
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/ty/query/on_disk_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ impl<'sess> OnDiskCache<'sess> {

//- DECODING -------------------------------------------------------------------

/// A decoder that can read from the incr. comp. cache. It is similar to the one
/// A decoder that can read from the incremental compilation cache. It is similar to the one
/// we use for crate metadata decoding in that it can rebase spans and eventually
/// will also handle things that contain `Ty` instances.
crate struct CacheDecoder<'a, 'tcx> {
Expand Down Expand Up @@ -954,7 +954,7 @@ impl<'a, 'tcx> Decodable<CacheDecoder<'a, 'tcx>> for &'tcx [Span] {

//- ENCODING -------------------------------------------------------------------

/// An encoder that can write the incr. comp. cache.
/// An encoder that can write to the incremental compilation cache.
struct CacheEncoder<'a, 'tcx, E: OpaqueEncoder> {
tcx: TyCtxt<'tcx>,
encoder: &'a mut E,
Expand Down
10 changes: 2 additions & 8 deletions compiler/rustc_middle/src/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1572,17 +1572,11 @@ impl RegionKind {
}

pub fn is_late_bound(&self) -> bool {
match *self {
ty::ReLateBound(..) => true,
_ => false,
}
matches!(*self, ty::ReLateBound(..))
}

pub fn is_placeholder(&self) -> bool {
match *self {
ty::RePlaceholder(..) => true,
_ => false,
}
matches!(*self, ty::RePlaceholder(..))
}

pub fn bound_at_or_above_binder(&self, index: ty::DebruijnIndex) -> bool {
Expand Down
45 changes: 33 additions & 12 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use std::fmt;
use std::hash::{Hash, Hasher};
use std::str;

use crate::{Span, DUMMY_SP, SESSION_GLOBALS};
use crate::{Edition, Span, DUMMY_SP, SESSION_GLOBALS};

#[cfg(test)]
mod tests;
Expand Down Expand Up @@ -1609,12 +1609,32 @@ pub mod sym {
}

impl Symbol {
fn is_used_keyword_2018(self) -> bool {
self >= kw::Async && self <= kw::Dyn
fn is_special(self) -> bool {
self <= kw::Underscore
}

fn is_unused_keyword_2018(self) -> bool {
self == kw::Try
fn is_used_keyword_always(self) -> bool {
self >= kw::As && self <= kw::While
}

fn is_used_keyword_conditional(self, edition: impl FnOnce() -> Edition) -> bool {
(self >= kw::Async && self <= kw::Dyn) && edition() >= Edition::Edition2018
}

fn is_unused_keyword_always(self) -> bool {
self >= kw::Abstract && self <= kw::Yield
}

fn is_unused_keyword_conditional(self, edition: impl FnOnce() -> Edition) -> bool {
self == kw::Try && edition() >= Edition::Edition2018
}

pub fn is_reserved(self, edition: impl Copy + FnOnce() -> Edition) -> bool {
self.is_special()
|| self.is_used_keyword_always()
|| self.is_unused_keyword_always()
|| self.is_used_keyword_conditional(edition)
|| self.is_unused_keyword_conditional(edition)
}

/// A keyword or reserved identifier that can be used as a path segment.
Expand Down Expand Up @@ -1642,26 +1662,27 @@ impl Ident {
// Returns `true` for reserved identifiers used internally for elided lifetimes,
// unnamed method parameters, crate root module, error recovery etc.
pub fn is_special(self) -> bool {
self.name <= kw::Underscore
self.name.is_special()
}

/// Returns `true` if the token is a keyword used in the language.
pub fn is_used_keyword(self) -> bool {
// Note: `span.edition()` is relatively expensive, don't call it unless necessary.
self.name >= kw::As && self.name <= kw::While
|| self.name.is_used_keyword_2018() && self.span.rust_2018()
self.name.is_used_keyword_always()
|| self.name.is_used_keyword_conditional(|| self.span.edition())
}

/// Returns `true` if the token is a keyword reserved for possible future use.
pub fn is_unused_keyword(self) -> bool {
// Note: `span.edition()` is relatively expensive, don't call it unless necessary.
self.name >= kw::Abstract && self.name <= kw::Yield
|| self.name.is_unused_keyword_2018() && self.span.rust_2018()
self.name.is_unused_keyword_always()
|| self.name.is_unused_keyword_conditional(|| self.span.edition())
}

/// Returns `true` if the token is either a special identifier or a keyword.
pub fn is_reserved(self) -> bool {
self.is_special() || self.is_used_keyword() || self.is_unused_keyword()
// Note: `span.edition()` is relatively expensive, don't call it unless necessary.
self.name.is_reserved(|| self.span.edition())
}

/// A keyword or reserved identifier that can be used as a path segment.
Expand All @@ -1681,7 +1702,7 @@ fn with_interner<T, F: FnOnce(&mut Interner) -> T>(f: F) -> T {
SESSION_GLOBALS.with(|session_globals| f(&mut *session_globals.symbol_interner.lock()))
}

/// An alternative to `Symbol`, useful when the chars within the symbol need to
/// An alternative to [`Symbol`], useful when the chars within the symbol need to
/// be accessed. It deliberately has limited functionality and should only be
/// used for temporary values.
///
Expand Down
40 changes: 22 additions & 18 deletions compiler/rustc_typeck/src/check/demand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,10 +360,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
false
}

fn replace_prefix(&self, s: &str, old: &str, new: &str) -> Option<String> {
s.strip_prefix(old).map(|stripped| new.to_string() + stripped)
}

/// This function is used to determine potential "simple" improvements or users' errors and
/// provide them useful help. For example:
///
Expand Down Expand Up @@ -394,6 +390,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
return None;
}

let replace_prefix = |s: &str, old: &str, new: &str| {
s.strip_prefix(old).map(|stripped| new.to_string() + stripped)
};

let is_struct_pat_shorthand_field =
self.is_hir_id_from_struct_pattern_shorthand_field(expr.hir_id, sp);

Expand All @@ -409,7 +409,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
(&ty::Str, &ty::Array(arr, _) | &ty::Slice(arr)) if arr == self.tcx.types.u8 => {
if let hir::ExprKind::Lit(_) = expr.kind {
if let Ok(src) = sm.span_to_snippet(sp) {
if let Some(src) = self.replace_prefix(&src, "b\"", "\"") {
if let Some(src) = replace_prefix(&src, "b\"", "\"") {
return Some((
sp,
"consider removing the leading `b`",
Expand All @@ -423,7 +423,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
(&ty::Array(arr, _) | &ty::Slice(arr), &ty::Str) if arr == self.tcx.types.u8 => {
if let hir::ExprKind::Lit(_) = expr.kind {
if let Ok(src) = sm.span_to_snippet(sp) {
if let Some(src) = self.replace_prefix(&src, "\"", "b\"") {
if let Some(src) = replace_prefix(&src, "\"", "b\"") {
return Some((
sp,
"consider adding a leading `b`",
Expand Down Expand Up @@ -583,23 +583,27 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
hir::Mutability::Mut => {
let new_prefix = "&mut ".to_owned() + derefs;
match mutbl_a {
hir::Mutability::Mut => self
.replace_prefix(&src, "&mut ", &new_prefix)
.map(|s| (s, Applicability::MachineApplicable)),
hir::Mutability::Not => self
.replace_prefix(&src, "&", &new_prefix)
.map(|s| (s, Applicability::Unspecified)),
hir::Mutability::Mut => {
replace_prefix(&src, "&mut ", &new_prefix)
.map(|s| (s, Applicability::MachineApplicable))
}
hir::Mutability::Not => {
replace_prefix(&src, "&", &new_prefix)
.map(|s| (s, Applicability::Unspecified))
}
}
}
hir::Mutability::Not => {
let new_prefix = "&".to_owned() + derefs;
match mutbl_a {
hir::Mutability::Mut => self
.replace_prefix(&src, "&mut ", &new_prefix)
.map(|s| (s, Applicability::MachineApplicable)),
hir::Mutability::Not => self
.replace_prefix(&src, "&", &new_prefix)
.map(|s| (s, Applicability::MachineApplicable)),
hir::Mutability::Mut => {
replace_prefix(&src, "&mut ", &new_prefix)
.map(|s| (s, Applicability::MachineApplicable))
}
hir::Mutability::Not => {
replace_prefix(&src, "&", &new_prefix)
.map(|s| (s, Applicability::MachineApplicable))
}
}
}
} {
Expand Down
12 changes: 6 additions & 6 deletions library/rustc-std-workspace-core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ This crate is a shim and empty crate which simply depends on `libcore` and
reexports all of its contents. The crate is the crux of empowering the standard
library to depend on crates from crates.io

Crates on crates.io that the standard library depend on the
`rustc-std-workspace-core` crate from crates.io. On crates.io, however, this
crate is empty. We use `[patch]` to override it to this crate in this
repository. As a result, crates on crates.io will draw a dependency edge to
`libcore`, the version defined in this repository. That should draw all the
dependency edges to ensure Cargo builds crates successfully!
Crates on crates.io that the standard library depend on need to depend on the
`rustc-std-workspace-core` crate from crates.io, which is empty. We use
`[patch]` to override it to this crate in this repository. As a result, crates
on crates.io will draw a dependency edge to `libcore`, the version defined in
this repository. That should draw all the dependency edges to ensure Cargo
builds crates successfully!

Note that crates on crates.io need to depend on this crate with the name `core`
for everything to work correctly. To do that they can use:
Expand Down
2 changes: 1 addition & 1 deletion src/doc/book
Submodule book updated 217 files
2 changes: 1 addition & 1 deletion src/doc/nomicon
2 changes: 1 addition & 1 deletion src/doc/reference
6 changes: 0 additions & 6 deletions src/test/rustdoc-ui/reference-link-has-one-warning.rs

This file was deleted.

Loading