Skip to content

Commit bbab2cf

Browse files
authored
Merge branch 'master' into version
2 parents 61b07b7 + ea40fa2 commit bbab2cf

File tree

857 files changed

+11782
-4211
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

857 files changed

+11782
-4211
lines changed

Cargo.lock

-14
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,6 @@ dependencies = [
593593
"syn 2.0.55",
594594
"tempfile",
595595
"termize",
596-
"tester",
597596
"tokio",
598597
"toml 0.7.8",
599598
"ui_test 0.22.2",
@@ -5508,19 +5507,6 @@ dependencies = [
55085507
"std",
55095508
]
55105509

5511-
[[package]]
5512-
name = "tester"
5513-
version = "0.9.1"
5514-
source = "registry+https://github.com/rust-lang/crates.io-index"
5515-
checksum = "89e8bf7e0eb2dd7b4228cc1b6821fc5114cd6841ae59f652a85488c016091e5f"
5516-
dependencies = [
5517-
"cfg-if",
5518-
"getopts",
5519-
"libc",
5520-
"num_cpus",
5521-
"term",
5522-
]
5523-
55245510
[[package]]
55255511
name = "thin-vec"
55265512
version = "0.2.13"

README.md

+24-15
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,36 @@
1-
# The Rust Programming Language
2-
3-
[![Rust Community](https://img.shields.io/badge/Rust_Community%20-Join_us-brightgreen?style=plastic&logo=rust)](https://www.rust-lang.org/community)
1+
<div align="center">
2+
<picture>
3+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/rust-lang/www.rust-lang.org/master/static/images/rust-social-wide-dark.svg">
4+
<source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/rust-lang/www.rust-lang.org/master/static/images/rust-social-wide-light.svg">
5+
<img alt="The Rust Programming Language: A language empowering everyone to build reliable and efficient software"
6+
src="https://raw.githubusercontent.com/rust-lang/www.rust-lang.org/master/static/images/rust-social-wide-light.svg"
7+
width="50%">
8+
</picture>
9+
10+
[Website][Rust] | [Getting started] | [Learn] | [Documentation] | [Contributing]
11+
</div>
412

513
This is the main source code repository for [Rust]. It contains the compiler,
614
standard library, and documentation.
715

816
[Rust]: https://www.rust-lang.org/
17+
[Getting Started]: https://www.rust-lang.org/learn/get-started
18+
[Learn]: https://www.rust-lang.org/learn
19+
[Documentation]: https://www.rust-lang.org/learn#learn-use
20+
[Contributing]: CONTRIBUTING.md
21+
22+
## Why Rust?
923

10-
**Note: this README is for _users_ rather than _contributors_.**
11-
If you wish to _contribute_ to the compiler, you should read
12-
[CONTRIBUTING.md](CONTRIBUTING.md) instead.
24+
- **Performance:** Fast and memory-efficient, suitable for critical services, embedded devices, and easily integrate with other languages.
1325

14-
<details>
15-
<summary>Table of Contents</summary>
26+
- **Reliability:** Our rich type system and ownership model ensure memory and thread safety, reducing bugs at compile-time.
1627

17-
- [Quick Start](#quick-start)
18-
- [Installing from Source](#installing-from-source)
19-
- [Getting Help](#getting-help)
20-
- [Contributing](#contributing)
21-
- [License](#license)
22-
- [Trademark](#trademark)
28+
- **Productivity:** Comprehensive documentation, a compiler committed to providing great diagnostics, and advanced tooling including package manager and build tool ([Cargo]), auto-formatter ([rustfmt]), linter ([Clippy]) and editor support ([rust-analyzer]).
2329

24-
</details>
30+
[Cargo]: https://github.com/rust-lang/cargo
31+
[rustfmt]: https://github.com/rust-lang/rustfmt
32+
[Clippy]: https://github.com/rust-lang/rust-clippy
33+
[rust-analyzer]: https://github.com/rust-lang/rust-analyzer
2534

2635
## Quick Start
2736

compiler/rustc_ast/src/ast.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -1276,7 +1276,8 @@ impl Expr {
12761276
ExprKind::While(..) => ExprPrecedence::While,
12771277
ExprKind::ForLoop { .. } => ExprPrecedence::ForLoop,
12781278
ExprKind::Loop(..) => ExprPrecedence::Loop,
1279-
ExprKind::Match(..) => ExprPrecedence::Match,
1279+
ExprKind::Match(_, _, MatchKind::Prefix) => ExprPrecedence::Match,
1280+
ExprKind::Match(_, _, MatchKind::Postfix) => ExprPrecedence::PostfixMatch,
12801281
ExprKind::Closure(..) => ExprPrecedence::Closure,
12811282
ExprKind::Block(..) => ExprPrecedence::Block,
12821283
ExprKind::TryBlock(..) => ExprPrecedence::TryBlock,
@@ -2483,6 +2484,14 @@ pub enum CoroutineKind {
24832484
}
24842485

24852486
impl CoroutineKind {
2487+
pub fn span(self) -> Span {
2488+
match self {
2489+
CoroutineKind::Async { span, .. } => span,
2490+
CoroutineKind::Gen { span, .. } => span,
2491+
CoroutineKind::AsyncGen { span, .. } => span,
2492+
}
2493+
}
2494+
24862495
pub fn is_async(self) -> bool {
24872496
matches!(self, CoroutineKind::Async { .. })
24882497
}
@@ -3341,7 +3350,7 @@ impl TryFrom<ItemKind> for ForeignItemKind {
33413350
pub type ForeignItem = Item<ForeignItemKind>;
33423351

33433352
// Some nodes are used a lot. Make sure they don't unintentionally get bigger.
3344-
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
3353+
#[cfg(all(any(target_arch = "x86_64", target_arch = "aarch64"), target_pointer_width = "64"))]
33453354
mod size_asserts {
33463355
use super::*;
33473356
use rustc_data_structures::static_assert_size;

compiler/rustc_ast/src/ptr.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,21 @@
11
//! The AST pointer.
22
//!
3-
//! Provides `P<T>`, a frozen owned smart pointer.
3+
//! Provides [`P<T>`][struct@P], an owned smart pointer.
44
//!
55
//! # Motivations and benefits
66
//!
77
//! * **Identity**: sharing AST nodes is problematic for the various analysis
88
//! passes (e.g., one may be able to bypass the borrow checker with a shared
99
//! `ExprKind::AddrOf` node taking a mutable borrow).
1010
//!
11-
//! * **Immutability**: `P<T>` disallows mutating its inner `T`, unlike `Box<T>`
12-
//! (unless it contains an `Unsafe` interior, but that may be denied later).
13-
//! This mainly prevents mistakes, but also enforces a kind of "purity".
14-
//!
1511
//! * **Efficiency**: folding can reuse allocation space for `P<T>` and `Vec<T>`,
1612
//! the latter even when the input and output types differ (as it would be the
1713
//! case with arenas or a GADT AST using type parameters to toggle features).
1814
//!
19-
//! * **Maintainability**: `P<T>` provides a fixed interface - `Deref`,
20-
//! `and_then` and `map` - which can remain fully functional even if the
21-
//! implementation changes (using a special thread-local heap, for example).
22-
//! Moreover, a switch to, e.g., `P<'a, T>` would be easy and mostly automated.
15+
//! * **Maintainability**: `P<T>` provides an interface, which can remain fully
16+
//! functional even if the implementation changes (using a special thread-local
17+
//! heap, for example). Moreover, a switch to, e.g., `P<'a, T>` would be easy
18+
//! and mostly automated.
2319
2420
use std::fmt::{self, Debug, Display};
2521
use std::ops::{Deref, DerefMut};
@@ -29,6 +25,8 @@ use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
2925

3026
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
3127
/// An owned smart pointer.
28+
///
29+
/// See the [module level documentation][crate::ptr] for details.
3230
pub struct P<T: ?Sized> {
3331
ptr: Box<T>,
3432
}

compiler/rustc_ast/src/token.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1021,7 +1021,7 @@ where
10211021
}
10221022

10231023
// Some types are used a lot. Make sure they don't unintentionally get bigger.
1024-
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
1024+
#[cfg(all(any(target_arch = "x86_64", target_arch = "aarch64"), target_pointer_width = "64"))]
10251025
mod size_asserts {
10261026
use super::*;
10271027
use rustc_data_structures::static_assert_size;

compiler/rustc_ast/src/tokenstream.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ impl DelimSpacing {
768768
}
769769

770770
// Some types are used a lot. Make sure they don't unintentionally get bigger.
771-
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
771+
#[cfg(all(any(target_arch = "x86_64", target_arch = "aarch64"), target_pointer_width = "64"))]
772772
mod size_asserts {
773773
use super::*;
774774
use rustc_data_structures::static_assert_size;

compiler/rustc_ast/src/util/parser.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ pub enum ExprPrecedence {
281281
ForLoop,
282282
Loop,
283283
Match,
284+
PostfixMatch,
284285
ConstBlock,
285286
Block,
286287
TryBlock,
@@ -334,7 +335,8 @@ impl ExprPrecedence {
334335
| ExprPrecedence::InlineAsm
335336
| ExprPrecedence::Mac
336337
| ExprPrecedence::FormatArgs
337-
| ExprPrecedence::OffsetOf => PREC_POSTFIX,
338+
| ExprPrecedence::OffsetOf
339+
| ExprPrecedence::PostfixMatch => PREC_POSTFIX,
338340

339341
// Never need parens
340342
ExprPrecedence::Array
@@ -390,7 +392,8 @@ pub fn contains_exterior_struct_lit(value: &ast::Expr) -> bool {
390392
| ast::ExprKind::Cast(x, _)
391393
| ast::ExprKind::Type(x, _)
392394
| ast::ExprKind::Field(x, _)
393-
| ast::ExprKind::Index(x, _, _) => {
395+
| ast::ExprKind::Index(x, _, _)
396+
| ast::ExprKind::Match(x, _, ast::MatchKind::Postfix) => {
394397
// &X { y: 1 }, X { y: 1 }.y
395398
contains_exterior_struct_lit(x)
396399
}

compiler/rustc_ast_lowering/src/index.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use rustc_hir as hir;
33
use rustc_hir::def_id::{LocalDefId, LocalDefIdMap};
44
use rustc_hir::intravisit::Visitor;
55
use rustc_hir::*;
6-
use rustc_index::{Idx, IndexVec};
6+
use rustc_index::IndexVec;
77
use rustc_middle::span_bug;
88
use rustc_middle::ty::TyCtxt;
99
use rustc_span::{Span, DUMMY_SP};
@@ -19,7 +19,7 @@ struct NodeCollector<'a, 'hir> {
1919
parenting: LocalDefIdMap<ItemLocalId>,
2020

2121
/// The parent of this node
22-
parent_node: hir::ItemLocalId,
22+
parent_node: ItemLocalId,
2323

2424
owner: OwnerId,
2525
}
@@ -31,17 +31,16 @@ pub(super) fn index_hir<'hir>(
3131
bodies: &SortedMap<ItemLocalId, &'hir Body<'hir>>,
3232
num_nodes: usize,
3333
) -> (IndexVec<ItemLocalId, ParentedNode<'hir>>, LocalDefIdMap<ItemLocalId>) {
34-
let zero_id = ItemLocalId::new(0);
35-
let err_node = ParentedNode { parent: zero_id, node: Node::Err(item.span()) };
34+
let err_node = ParentedNode { parent: ItemLocalId::ZERO, node: Node::Err(item.span()) };
3635
let mut nodes = IndexVec::from_elem_n(err_node, num_nodes);
3736
// This node's parent should never be accessed: the owner's parent is computed by the
3837
// hir_owner_parent query. Make it invalid (= ItemLocalId::MAX) to force an ICE whenever it is
3938
// used.
40-
nodes[zero_id] = ParentedNode { parent: ItemLocalId::INVALID, node: item.into() };
39+
nodes[ItemLocalId::ZERO] = ParentedNode { parent: ItemLocalId::INVALID, node: item.into() };
4140
let mut collector = NodeCollector {
4241
tcx,
4342
owner: item.def_id(),
44-
parent_node: zero_id,
43+
parent_node: ItemLocalId::ZERO,
4544
nodes,
4645
bodies,
4746
parenting: Default::default(),
@@ -112,7 +111,9 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
112111
}
113112

114113
fn insert_nested(&mut self, item: LocalDefId) {
115-
self.parenting.insert(item, self.parent_node);
114+
if self.parent_node != ItemLocalId::ZERO {
115+
self.parenting.insert(item, self.parent_node);
116+
}
116117
}
117118
}
118119

compiler/rustc_ast_lowering/src/item.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_hir as hir;
1111
use rustc_hir::def::{DefKind, Res};
1212
use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID};
1313
use rustc_hir::PredicateOrigin;
14-
use rustc_index::{Idx, IndexSlice, IndexVec};
14+
use rustc_index::{IndexSlice, IndexVec};
1515
use rustc_middle::span_bug;
1616
use rustc_middle::ty::{ResolverAstLowering, TyCtxt};
1717
use rustc_span::edit_distance::find_best_match_for_name;
@@ -563,7 +563,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
563563
let kind =
564564
this.lower_use_tree(use_tree, &prefix, id, vis_span, &mut ident, attrs);
565565
if let Some(attrs) = attrs {
566-
this.attrs.insert(hir::ItemLocalId::new(0), attrs);
566+
this.attrs.insert(hir::ItemLocalId::ZERO, attrs);
567567
}
568568

569569
let item = hir::Item {

compiler/rustc_ast_lowering/src/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
157157
attrs: SortedMap::default(),
158158
children: Vec::default(),
159159
current_hir_id_owner: hir::CRATE_OWNER_ID,
160-
item_local_id_counter: hir::ItemLocalId::new(0),
160+
item_local_id_counter: hir::ItemLocalId::ZERO,
161161
node_id_to_local_id: Default::default(),
162162
trait_map: Default::default(),
163163

@@ -583,7 +583,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
583583
// and the caller to refer to some of the subdefinitions' nodes' `LocalDefId`s.
584584

585585
// Always allocate the first `HirId` for the owner itself.
586-
let _old = self.node_id_to_local_id.insert(owner, hir::ItemLocalId::new(0));
586+
let _old = self.node_id_to_local_id.insert(owner, hir::ItemLocalId::ZERO);
587587
debug_assert_eq!(_old, None);
588588

589589
let item = f(self);
@@ -677,7 +677,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
677677
v.insert(local_id);
678678
self.item_local_id_counter.increment_by(1);
679679

680-
assert_ne!(local_id, hir::ItemLocalId::new(0));
680+
assert_ne!(local_id, hir::ItemLocalId::ZERO);
681681
if let Some(def_id) = self.opt_local_def_id(ast_node_id) {
682682
self.children.push((def_id, hir::MaybeOwner::NonOwner(hir_id)));
683683
}
@@ -696,7 +696,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
696696
fn next_id(&mut self) -> hir::HirId {
697697
let owner = self.current_hir_id_owner;
698698
let local_id = self.item_local_id_counter;
699-
assert_ne!(local_id, hir::ItemLocalId::new(0));
699+
assert_ne!(local_id, hir::ItemLocalId::ZERO);
700700
self.item_local_id_counter.increment_by(1);
701701
hir::HirId { owner, local_id }
702702
}

compiler/rustc_ast_passes/messages.ftl

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ ast_passes_extern_block_suggestion = if you meant to declare an externally defin
6868
6969
ast_passes_extern_fn_qualifiers = functions in `extern` blocks cannot have qualifiers
7070
.label = in this `extern` block
71-
.suggestion = remove the qualifiers
71+
.suggestion = remove this qualifier
7272
7373
ast_passes_extern_item_ascii = items in `extern` blocks cannot use non-ascii identifiers
7474
.label = in this `extern` block

compiler/rustc_ast_passes/src/ast_validation.rs

+24-5
Original file line numberDiff line numberDiff line change
@@ -514,13 +514,32 @@ impl<'a> AstValidator<'a> {
514514
}
515515

516516
/// An `fn` in `extern { ... }` cannot have qualifiers, e.g. `async fn`.
517-
fn check_foreign_fn_headerless(&self, ident: Ident, span: Span, header: FnHeader) {
518-
if header.has_qualifiers() {
517+
fn check_foreign_fn_headerless(
518+
&self,
519+
// Deconstruct to ensure exhaustiveness
520+
FnHeader { unsafety, coroutine_kind, constness, ext }: FnHeader,
521+
) {
522+
let report_err = |span| {
519523
self.dcx().emit_err(errors::FnQualifierInExtern {
520-
span: ident.span,
524+
span: span,
521525
block: self.current_extern_span(),
522-
sugg_span: span.until(ident.span.shrink_to_lo()),
523526
});
527+
};
528+
match unsafety {
529+
Unsafe::Yes(span) => report_err(span),
530+
Unsafe::No => (),
531+
}
532+
match coroutine_kind {
533+
Some(knd) => report_err(knd.span()),
534+
None => (),
535+
}
536+
match constness {
537+
Const::Yes(span) => report_err(span),
538+
Const::No => (),
539+
}
540+
match ext {
541+
Extern::None => (),
542+
Extern::Implicit(span) | Extern::Explicit(_, span) => report_err(span),
524543
}
525544
}
526545

@@ -1145,7 +1164,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
11451164
ForeignItemKind::Fn(box Fn { defaultness, sig, body, .. }) => {
11461165
self.check_defaultness(fi.span, *defaultness);
11471166
self.check_foreign_fn_bodyless(fi.ident, body.as_deref());
1148-
self.check_foreign_fn_headerless(fi.ident, fi.span, sig.header);
1167+
self.check_foreign_fn_headerless(sig.header);
11491168
self.check_foreign_item_ascii_only(fi.ident);
11501169
}
11511170
ForeignItemKind::TyAlias(box TyAlias {

compiler/rustc_ast_passes/src/errors.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -270,11 +270,10 @@ pub struct FnBodyInExtern {
270270
#[diag(ast_passes_extern_fn_qualifiers)]
271271
pub struct FnQualifierInExtern {
272272
#[primary_span]
273+
#[suggestion(code = "", applicability = "maybe-incorrect")]
273274
pub span: Span,
274275
#[label]
275276
pub block: Span,
276-
#[suggestion(code = "fn ", applicability = "maybe-incorrect", style = "verbose")]
277-
pub sugg_span: Span,
278277
}
279278

280279
#[derive(Diagnostic)]

compiler/rustc_borrowck/src/borrow_set.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ impl<'tcx> BorrowSet<'tcx> {
159159
}
160160

161161
pub(crate) fn indices(&self) -> impl Iterator<Item = BorrowIndex> {
162-
BorrowIndex::from_usize(0)..BorrowIndex::from_usize(self.len())
162+
BorrowIndex::ZERO..BorrowIndex::from_usize(self.len())
163163
}
164164

165165
pub(crate) fn iter_enumerated(&self) -> impl Iterator<Item = (BorrowIndex, &BorrowData<'tcx>)> {

compiler/rustc_borrowck/src/type_check/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2261,7 +2261,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
22612261
}
22622262
}
22632263

2264-
CastKind::PointerExposeAddress => {
2264+
CastKind::PointerExposeProvenance => {
22652265
let ty_from = op.ty(body, tcx);
22662266
let cast_ty_from = CastTy::from_ty(ty_from);
22672267
let cast_ty_to = CastTy::from_ty(*ty);
@@ -2271,7 +2271,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
22712271
span_mirbug!(
22722272
self,
22732273
rvalue,
2274-
"Invalid PointerExposeAddress cast {:?} -> {:?}",
2274+
"Invalid PointerExposeProvenance cast {:?} -> {:?}",
22752275
ty_from,
22762276
ty
22772277
)

0 commit comments

Comments
 (0)