Auto merge of #80314 - GuillaumeGomez:rollup-9rc48vx, r=GuillaumeGomez

Rollup of 17 pull requests

Successful merges:

 - #80136 (Add test for issue #74824)
 - #80203 (Edit rustc_middle::lint::LintSource docs)
 - #80204 (docs: Edit rustc_middle::ty::query::on_disk_cache)
 - #80219 (Fix labels for 'Library Tracking Issue' template)
 - #80222 (Fix rustc-std-workspace-core documentation)
 - #80223 (docs: Fix outdated crate reference)
 - #80225 (Add module-level docs to rustc_middle::ty)
 - #80241 (Fix typo)
 - #80248 (Remove `I-prioritize` from Zulip topic)
 - #80266 (Remove redundant test)
 - #80272 (rustc_span: Provide a reserved identifier check for a specific edition)
 - #80285 (Update books)
 - #80286 (docs: Edit rustc_middle::middle::privacy)
 - #80297 (Add some intra-doc links to compiler docs)
 - #80298 (Improve the code quality by using matches macro)
 - #80299 (Turn helper method into a closure)
 - #80302 (docs: Update rustc_middle::middle::region::ScopeTree)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
This commit is contained in:
bors 2020-12-23 00:41:46 +00:00
commit 89886e6936
25 changed files with 160 additions and 84 deletions

View File

@ -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!

View File

@ -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>],

View File

@ -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>>,

View File

@ -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>,

View File

@ -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>>>,
}

View File

@ -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

View File

@ -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),
}

View File

@ -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.
@ -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>,

View File

@ -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,
}
@ -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()
}

View File

@ -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]>,
}

View File

@ -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::*;

View File

@ -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> {
@ -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,

View File

@ -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 {

View File

@ -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;
@ -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.
@ -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.
@ -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.
///

View File

@ -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:
///
@ -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);
@ -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`",
@ -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`",
@ -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))
}
}
}
} {

View File

@ -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:

@ -1 +1 @@
Subproject commit a190438d77d28041f24da4f6592e287fab073a61
Subproject commit 5bb44f8b5b0aa105c8b22602e9b18800484afa21

@ -1 +1 @@
Subproject commit d8383b65f7948c2ca19191b3b4bd709b403aaf45
Subproject commit a5a48441d411f61556b57d762b03d6874afe575d

@ -1 +1 @@
Subproject commit a8afdca5d0715b2257b6f8b9a032fd4dd7dae855
Subproject commit b278478b766178491a8b6f67afa4bcd6b64d977a

@ -1 +1 @@
Subproject commit 236c734a2cb323541b3394f98682cb981b9ec086
Subproject commit 1cce0737d6a7d3ceafb139b4a206861fb1dcb2ab

View File

@ -1,6 +0,0 @@
// ignore-test
// check-pass
/// docs [label][with#anchor#error]
//~^ WARNING has an issue with the link anchor
pub struct S;

View File

@ -1,10 +0,0 @@
warning: `[with#anchor#error]` has an issue with the link anchor.
--> $DIR/reference-link-has-one-warning.rs:3:18
|
LL | /// docs [label][with#anchor#error]
| ^^^^^^^^^^^^^^^^^ only one `#` is allowed in a link
|
= note: `#[warn(broken_intra_doc_links)]` on by default
warning: 1 warning emitted

View File

@ -0,0 +1,27 @@
#![feature(generic_associated_types)]
#![feature(associated_type_defaults)]
#![allow(incomplete_features)]
use std::ops::Deref;
trait UnsafeCopy {
type Copy<T>: Copy = Box<T>;
//~^ ERROR the trait bound `Box<T>: Copy` is not satisfied
//~^^ ERROR the trait bound `T: Clone` is not satisfied
fn copy<T>(x: &Self::Copy<T>) -> Self::Copy<T> {
*x
}
}
impl<T> UnsafeCopy for T {}
fn main() {
let b = Box::new(42usize);
let copy = <()>::copy(&b);
let raw_b = Box::deref(&b) as *const _;
let raw_copy = Box::deref(&copy) as *const _;
// assert the addresses.
assert_eq!(raw_b, raw_copy);
}

View File

@ -0,0 +1,27 @@
error[E0277]: the trait bound `Box<T>: Copy` is not satisfied
--> $DIR/issue-74824.rs:8:5
|
LL | type Copy<T>: Copy = Box<T>;
| ^^^^^^^^^^^^^^----^^^^^^^^^^
| | |
| | required by this bound in `UnsafeCopy::Copy`
| the trait `Copy` is not implemented for `Box<T>`
error[E0277]: the trait bound `T: Clone` is not satisfied
--> $DIR/issue-74824.rs:8:5
|
LL | type Copy<T>: Copy = Box<T>;
| ^^^^^^^^^^^^^^----^^^^^^^^^^
| | |
| | required by this bound in `UnsafeCopy::Copy`
| the trait `Clone` is not implemented for `T`
|
= note: required because of the requirements on the impl of `Clone` for `Box<T>`
help: consider restricting type parameter `T`
|
LL | type Copy<T: Clone>: Copy = Box<T>;
| ^^^^^^^
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0277`.

View File

@ -90,7 +90,7 @@ exclude_labels = [
[notify-zulip."I-prioritize"]
zulip_stream = 245100 # #t-compiler/wg-prioritization/alerts
topic = "I-prioritize #{number} {title}"
topic = "#{number} {title}"
message_on_add = """\
@*WG-prioritization/alerts* issue #{number} has been requested for prioritization.