Skip to content

Commit 89886e6

Browse files
committed
Auto merge of rust-lang#80314 - GuillaumeGomez:rollup-9rc48vx, r=GuillaumeGomez
Rollup of 17 pull requests Successful merges: - rust-lang#80136 (Add test for issue rust-lang#74824) - rust-lang#80203 (Edit rustc_middle::lint::LintSource docs) - rust-lang#80204 (docs: Edit rustc_middle::ty::query::on_disk_cache) - rust-lang#80219 (Fix labels for 'Library Tracking Issue' template) - rust-lang#80222 (Fix rustc-std-workspace-core documentation) - rust-lang#80223 (docs: Fix outdated crate reference) - rust-lang#80225 (Add module-level docs to rustc_middle::ty) - rust-lang#80241 (Fix typo) - rust-lang#80248 (Remove `I-prioritize` from Zulip topic) - rust-lang#80266 (Remove redundant test) - rust-lang#80272 (rustc_span: Provide a reserved identifier check for a specific edition) - rust-lang#80285 (Update books) - rust-lang#80286 (docs: Edit rustc_middle::middle::privacy) - rust-lang#80297 (Add some intra-doc links to compiler docs) - rust-lang#80298 (Improve the code quality by using matches macro) - rust-lang#80299 (Turn helper method into a closure) - rust-lang#80302 (docs: Update rustc_middle::middle::region::ScopeTree) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 969b42d + 67f8244 commit 89886e6

File tree

25 files changed

+160
-84
lines changed

25 files changed

+160
-84
lines changed

.github/ISSUE_TEMPLATE/library_tracking_issue.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name: Library Tracking Issue
33
about: A tracking issue for an unstable library feature.
44
title: Tracking Issue for XXX
5-
labels: C-tracking-issue T-libs
5+
labels: C-tracking-issue, T-libs
66
---
77
<!--
88
Thank you for creating a tracking issue!

compiler/rustc_builtin_macros/src/deriving/generic/mod.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,10 @@ pub struct Substructure<'a> {
257257
pub type_ident: Ident,
258258
/// ident of the method
259259
pub method_ident: Ident,
260-
/// dereferenced access to any `Self_` or `Ptr(Self_, _)` arguments
260+
/// dereferenced access to any [`Self_`] or [`Ptr(Self_, _)][ptr]` arguments
261+
///
262+
/// [`Self_`]: ty::Ty::Self_
263+
/// [ptr]: ty::Ty::Ptr
261264
pub self_args: &'a [P<Expr>],
262265
/// verbatim access to any other arguments
263266
pub nonself_args: &'a [P<Expr>],

compiler/rustc_interface/src/interface.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ use std::sync::{Arc, Mutex};
2525
pub type Result<T> = result::Result<T, ErrorReported>;
2626

2727
/// Represents a compiler session.
28+
///
2829
/// Can be used to run `rustc_interface` queries.
29-
/// Created by passing `Config` to `run_compiler`.
30+
/// Created by passing [`Config`] to [`run_compiler`].
3031
pub struct Compiler {
3132
pub(crate) sess: Lrc<Session>,
3233
codegen_backend: Lrc<Box<dyn CodegenBackend>>,

compiler/rustc_interface/src/passes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ declare_box_region_type!(
9595
/// harness if one is to be provided, injection of a dependency on the
9696
/// standard library and prelude, and name resolution.
9797
///
98-
/// Returns `None` if we're aborting after handling -W help.
98+
/// Returns [`None`] if we're aborting after handling -W help.
9999
pub fn configure_and_expand(
100100
sess: Lrc<Session>,
101101
lint_store: Lrc<LintStore>,

compiler/rustc_interface/src/queries.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ use std::cell::{Ref, RefCell, RefMut};
2323
use std::rc::Rc;
2424

2525
/// Represent the result of a query.
26-
/// This result can be stolen with the `take` method and generated with the `compute` method.
26+
///
27+
/// This result can be stolen with the [`take`] method and generated with the [`compute`] method.
28+
///
29+
/// [`take`]: Self::take
30+
/// [`compute`]: Self::compute
2731
pub struct Query<T> {
2832
result: RefCell<Option<Result<T>>>,
2933
}

compiler/rustc_middle/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
//! - **MIR.** The "mid-level (M) intermediate representation (IR)" is
99
//! defined in the `mir` module. This module contains only the
1010
//! *definition* of the MIR; the passes that transform and operate
11-
//! on MIR are found in `librustc_mir` crate.
11+
//! on MIR are found in `rustc_mir` crate.
1212
//! - **Types.** The internal representation of types used in rustc is
1313
//! defined in the `ty` module. This includes the **type context**
1414
//! (or `tcx`), which is the central context during most of

compiler/rustc_middle/src/lint.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ pub enum LintSource {
2222
Node(Symbol, Span, Option<Symbol> /* RFC 2383 reason */),
2323

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

compiler/rustc_middle/src/middle/privacy.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ use rustc_macros::HashStable;
88
use std::fmt;
99
use std::hash::Hash;
1010

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

27-
// Accessibility levels for reachable HIR nodes
29+
/// Holds a map of accessibility levels for reachable HIR nodes.
2830
#[derive(Clone)]
2931
pub struct AccessLevels<Id = HirId> {
3032
pub map: FxHashMap<Id, AccessLevel>,

compiler/rustc_middle/src/middle/region.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ pub struct ScopeTree {
332332
pub struct YieldData {
333333
/// The `Span` of the yield.
334334
pub span: Span,
335-
/// The number of expressions and patterns appearing before the `yield` in the body plus one.
335+
/// The number of expressions and patterns appearing before the `yield` in the body, plus one.
336336
pub expr_and_pat_count: usize,
337337
pub source: hir::YieldSource,
338338
}
@@ -449,9 +449,7 @@ impl ScopeTree {
449449
}
450450

451451
/// Checks whether the given scope contains a `yield`. If so,
452-
/// returns `Some((span, expr_count))` with the span of a yield we found and
453-
/// the number of expressions and patterns appearing before the `yield` in the body + 1.
454-
/// If there a are multiple yields in a scope, the one with the highest number is returned.
452+
/// returns `Some(YieldData)`. If not, returns `None`.
455453
pub fn yield_in_scope(&self, scope: Scope) -> Option<YieldData> {
456454
self.yield_in_scope.get(&scope).cloned()
457455
}

compiler/rustc_middle/src/ty/inhabitedness/def_id_forest.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub struct DefIdForest {
1717
/// If A and B are DefIds in the `DefIdForest`, and A is a descendant
1818
/// of B, then only B will be in `root_ids`.
1919
/// We use a `SmallVec` here because (for its use for caching inhabitedness)
20-
/// its rare that this will contain even two IDs.
20+
/// it's rare that this will contain even two IDs.
2121
root_ids: SmallVec<[DefId; 1]>,
2222
}
2323

compiler/rustc_middle/src/ty/mod.rs

+11
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
//! Defines how the compiler represents types internally.
2+
//!
3+
//! Two important entities in this module are:
4+
//!
5+
//! - [`rustc_middle::ty::Ty`], used to represent the semantics of a type.
6+
//! - [`rustc_middle::ty::TyCtxt`], the central data structure in the compiler.
7+
//!
8+
//! For more information, see ["The `ty` module: representing types"] in the ructc-dev-guide.
9+
//!
10+
//! ["The `ty` module: representing types"]: https://rustc-dev-guide.rust-lang.org/ty.html
11+
112
// ignore-tidy-filelength
213
pub use self::fold::{TypeFoldable, TypeFolder, TypeVisitor};
314
pub use self::AssocItemContainer::*;

compiler/rustc_middle/src/ty/query/on_disk_cache.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ impl<'sess> OnDiskCache<'sess> {
666666

667667
//- DECODING -------------------------------------------------------------------
668668

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

955955
//- ENCODING -------------------------------------------------------------------
956956

957-
/// An encoder that can write the incr. comp. cache.
957+
/// An encoder that can write to the incremental compilation cache.
958958
struct CacheEncoder<'a, 'tcx, E: OpaqueEncoder> {
959959
tcx: TyCtxt<'tcx>,
960960
encoder: &'a mut E,

compiler/rustc_middle/src/ty/sty.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -1572,17 +1572,11 @@ impl RegionKind {
15721572
}
15731573

15741574
pub fn is_late_bound(&self) -> bool {
1575-
match *self {
1576-
ty::ReLateBound(..) => true,
1577-
_ => false,
1578-
}
1575+
matches!(*self, ty::ReLateBound(..))
15791576
}
15801577

15811578
pub fn is_placeholder(&self) -> bool {
1582-
match *self {
1583-
ty::RePlaceholder(..) => true,
1584-
_ => false,
1585-
}
1579+
matches!(*self, ty::RePlaceholder(..))
15861580
}
15871581

15881582
pub fn bound_at_or_above_binder(&self, index: ty::DebruijnIndex) -> bool {

compiler/rustc_span/src/symbol.rs

+33-12
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use std::fmt;
1313
use std::hash::{Hash, Hasher};
1414
use std::str;
1515

16-
use crate::{Span, DUMMY_SP, SESSION_GLOBALS};
16+
use crate::{Edition, Span, DUMMY_SP, SESSION_GLOBALS};
1717

1818
#[cfg(test)]
1919
mod tests;
@@ -1609,12 +1609,32 @@ pub mod sym {
16091609
}
16101610

16111611
impl Symbol {
1612-
fn is_used_keyword_2018(self) -> bool {
1613-
self >= kw::Async && self <= kw::Dyn
1612+
fn is_special(self) -> bool {
1613+
self <= kw::Underscore
16141614
}
16151615

1616-
fn is_unused_keyword_2018(self) -> bool {
1617-
self == kw::Try
1616+
fn is_used_keyword_always(self) -> bool {
1617+
self >= kw::As && self <= kw::While
1618+
}
1619+
1620+
fn is_used_keyword_conditional(self, edition: impl FnOnce() -> Edition) -> bool {
1621+
(self >= kw::Async && self <= kw::Dyn) && edition() >= Edition::Edition2018
1622+
}
1623+
1624+
fn is_unused_keyword_always(self) -> bool {
1625+
self >= kw::Abstract && self <= kw::Yield
1626+
}
1627+
1628+
fn is_unused_keyword_conditional(self, edition: impl FnOnce() -> Edition) -> bool {
1629+
self == kw::Try && edition() >= Edition::Edition2018
1630+
}
1631+
1632+
pub fn is_reserved(self, edition: impl Copy + FnOnce() -> Edition) -> bool {
1633+
self.is_special()
1634+
|| self.is_used_keyword_always()
1635+
|| self.is_unused_keyword_always()
1636+
|| self.is_used_keyword_conditional(edition)
1637+
|| self.is_unused_keyword_conditional(edition)
16181638
}
16191639

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

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

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

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

16671688
/// 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 {
16811702
SESSION_GLOBALS.with(|session_globals| f(&mut *session_globals.symbol_interner.lock()))
16821703
}
16831704

1684-
/// An alternative to `Symbol`, useful when the chars within the symbol need to
1705+
/// An alternative to [`Symbol`], useful when the chars within the symbol need to
16851706
/// be accessed. It deliberately has limited functionality and should only be
16861707
/// used for temporary values.
16871708
///

compiler/rustc_typeck/src/check/demand.rs

+22-18
Original file line numberDiff line numberDiff line change
@@ -360,10 +360,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
360360
false
361361
}
362362

363-
fn replace_prefix(&self, s: &str, old: &str, new: &str) -> Option<String> {
364-
s.strip_prefix(old).map(|stripped| new.to_string() + stripped)
365-
}
366-
367363
/// This function is used to determine potential "simple" improvements or users' errors and
368364
/// provide them useful help. For example:
369365
///
@@ -394,6 +390,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
394390
return None;
395391
}
396392

393+
let replace_prefix = |s: &str, old: &str, new: &str| {
394+
s.strip_prefix(old).map(|stripped| new.to_string() + stripped)
395+
};
396+
397397
let is_struct_pat_shorthand_field =
398398
self.is_hir_id_from_struct_pattern_shorthand_field(expr.hir_id, sp);
399399

@@ -409,7 +409,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
409409
(&ty::Str, &ty::Array(arr, _) | &ty::Slice(arr)) if arr == self.tcx.types.u8 => {
410410
if let hir::ExprKind::Lit(_) = expr.kind {
411411
if let Ok(src) = sm.span_to_snippet(sp) {
412-
if let Some(src) = self.replace_prefix(&src, "b\"", "\"") {
412+
if let Some(src) = replace_prefix(&src, "b\"", "\"") {
413413
return Some((
414414
sp,
415415
"consider removing the leading `b`",
@@ -423,7 +423,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
423423
(&ty::Array(arr, _) | &ty::Slice(arr), &ty::Str) if arr == self.tcx.types.u8 => {
424424
if let hir::ExprKind::Lit(_) = expr.kind {
425425
if let Ok(src) = sm.span_to_snippet(sp) {
426-
if let Some(src) = self.replace_prefix(&src, "\"", "b\"") {
426+
if let Some(src) = replace_prefix(&src, "\"", "b\"") {
427427
return Some((
428428
sp,
429429
"consider adding a leading `b`",
@@ -583,23 +583,27 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
583583
hir::Mutability::Mut => {
584584
let new_prefix = "&mut ".to_owned() + derefs;
585585
match mutbl_a {
586-
hir::Mutability::Mut => self
587-
.replace_prefix(&src, "&mut ", &new_prefix)
588-
.map(|s| (s, Applicability::MachineApplicable)),
589-
hir::Mutability::Not => self
590-
.replace_prefix(&src, "&", &new_prefix)
591-
.map(|s| (s, Applicability::Unspecified)),
586+
hir::Mutability::Mut => {
587+
replace_prefix(&src, "&mut ", &new_prefix)
588+
.map(|s| (s, Applicability::MachineApplicable))
589+
}
590+
hir::Mutability::Not => {
591+
replace_prefix(&src, "&", &new_prefix)
592+
.map(|s| (s, Applicability::Unspecified))
593+
}
592594
}
593595
}
594596
hir::Mutability::Not => {
595597
let new_prefix = "&".to_owned() + derefs;
596598
match mutbl_a {
597-
hir::Mutability::Mut => self
598-
.replace_prefix(&src, "&mut ", &new_prefix)
599-
.map(|s| (s, Applicability::MachineApplicable)),
600-
hir::Mutability::Not => self
601-
.replace_prefix(&src, "&", &new_prefix)
602-
.map(|s| (s, Applicability::MachineApplicable)),
599+
hir::Mutability::Mut => {
600+
replace_prefix(&src, "&mut ", &new_prefix)
601+
.map(|s| (s, Applicability::MachineApplicable))
602+
}
603+
hir::Mutability::Not => {
604+
replace_prefix(&src, "&", &new_prefix)
605+
.map(|s| (s, Applicability::MachineApplicable))
606+
}
603607
}
604608
}
605609
} {

library/rustc-std-workspace-core/README.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ This crate is a shim and empty crate which simply depends on `libcore` and
44
reexports all of its contents. The crate is the crux of empowering the standard
55
library to depend on crates from crates.io
66

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

1414
Note that crates on crates.io need to depend on this crate with the name `core`
1515
for everything to work correctly. To do that they can use:

src/doc/book

Submodule book updated 217 files

src/test/rustdoc-ui/reference-link-has-one-warning.rs

-6
This file was deleted.

0 commit comments

Comments
 (0)