Skip to content

Commit b5a3acf

Browse files
committed
Auto merge of #3273 - rust-lang:rustup-2024-01-23, r=RalfJung
Automatic Rustup
2 parents 3d63f42 + cc08dd1 commit b5a3acf

File tree

706 files changed

+12472
-6270
lines changed

Some content is hidden

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

706 files changed

+12472
-6270
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ If you wish to _contribute_ to the compiler, you should read
1515
<summary>Table of Contents</summary>
1616

1717
- [Quick Start](#quick-start)
18+
- [Installing from Source](#installing-from-source)
1819
- [Getting Help](#getting-help)
1920
- [Contributing](#contributing)
2021
- [License](#license)
@@ -29,9 +30,10 @@ Read ["Installation"] from [The Book].
2930
["Installation"]: https://doc.rust-lang.org/book/ch01-01-installation.html
3031
[The Book]: https://doc.rust-lang.org/book/index.html
3132

32-
## Installing from source
33+
## Installing from Source
3334

34-
If you really want to install from source (though this is not recommended), see [INSTALL.md](INSTALL.md).
35+
If you really want to install from source (though this is not recommended), see
36+
[INSTALL.md](INSTALL.md).
3537

3638
## Getting Help
3739

compiler/rustc_arena/src/lib.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,19 @@ impl DroplessArena {
484484
}
485485
}
486486

487+
/// Used by `Lift` to check whether this slice is allocated
488+
/// in this arena.
489+
#[inline]
490+
pub fn contains_slice<T>(&self, slice: &[T]) -> bool {
491+
for chunk in self.chunks.borrow_mut().iter_mut() {
492+
let ptr = slice.as_ptr().cast::<u8>().cast_mut();
493+
if chunk.start() <= ptr && chunk.end() >= ptr {
494+
return true;
495+
}
496+
}
497+
false
498+
}
499+
487500
/// Allocates a string slice that is copied into the `DroplessArena`, returning a
488501
/// reference to it. Will panic if passed an empty string.
489502
///

compiler/rustc_ast/src/ast.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pub use UnsafeSource::*;
2727
use crate::ptr::P;
2828
use crate::token::{self, CommentKind, Delimiter};
2929
use crate::tokenstream::{DelimSpan, LazyAttrTokenStream, TokenStream};
30+
use rustc_data_structures::packed::Pu128;
3031
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
3132
use rustc_data_structures::stack::ensure_sufficient_stack;
3233
use rustc_data_structures::sync::Lrc;
@@ -1833,7 +1834,7 @@ pub enum LitKind {
18331834
/// A character literal (`'a'`).
18341835
Char(char),
18351836
/// An integer literal (`1`).
1836-
Int(u128, LitIntType),
1837+
Int(Pu128, LitIntType),
18371838
/// A float literal (`1.0`, `1f64` or `1E10f64`). The pre-suffix part is
18381839
/// stored as a symbol rather than `f64` so that `LitKind` can impl `Eq`
18391840
/// and `Hash`.
@@ -3304,13 +3305,9 @@ mod size_asserts {
33043305
static_assert_size!(Impl, 136);
33053306
static_assert_size!(Item, 136);
33063307
static_assert_size!(ItemKind, 64);
3307-
// This can be removed after i128:128 is in the bootstrap compiler's target.
3308-
#[cfg(not(bootstrap))]
3309-
static_assert_size!(LitKind, 32);
3308+
static_assert_size!(LitKind, 24);
33103309
static_assert_size!(Local, 72);
3311-
// This can be removed after i128:128 is in the bootstrap compiler's target.
3312-
#[cfg(not(bootstrap))]
3313-
static_assert_size!(MetaItemLit, 48);
3310+
static_assert_size!(MetaItemLit, 40);
33143311
static_assert_size!(Param, 40);
33153312
static_assert_size!(Pat, 72);
33163313
static_assert_size!(Path, 24);

compiler/rustc_ast/src/util/literal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ fn integer_lit(symbol: Symbol, suffix: Option<Symbol>) -> Result<LitKind, LitErr
366366
};
367367

368368
let s = &s[if base != 10 { 2 } else { 0 }..];
369-
u128::from_str_radix(s, base).map(|i| LitKind::Int(i, ty)).map_err(|_| {
369+
u128::from_str_radix(s, base).map(|i| LitKind::Int(i.into(), ty)).map_err(|_| {
370370
// Small bases are lexed as if they were base 10, e.g, the string
371371
// might be `0b10201`. This will cause the conversion above to fail,
372372
// but these kinds of errors are already reported by the lexer.

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1899,15 +1899,21 @@ impl<'hir> LoweringContext<'_, 'hir> {
18991899
pub(super) fn expr_usize(&mut self, sp: Span, value: usize) -> hir::Expr<'hir> {
19001900
let lit = self.arena.alloc(hir::Lit {
19011901
span: sp,
1902-
node: ast::LitKind::Int(value as u128, ast::LitIntType::Unsigned(ast::UintTy::Usize)),
1902+
node: ast::LitKind::Int(
1903+
(value as u128).into(),
1904+
ast::LitIntType::Unsigned(ast::UintTy::Usize),
1905+
),
19031906
});
19041907
self.expr(sp, hir::ExprKind::Lit(lit))
19051908
}
19061909

19071910
pub(super) fn expr_u32(&mut self, sp: Span, value: u32) -> hir::Expr<'hir> {
19081911
let lit = self.arena.alloc(hir::Lit {
19091912
span: sp,
1910-
node: ast::LitKind::Int(value.into(), ast::LitIntType::Unsigned(ast::UintTy::U32)),
1913+
node: ast::LitKind::Int(
1914+
u128::from(value).into(),
1915+
ast::LitIntType::Unsigned(ast::UintTy::U32),
1916+
),
19111917
});
19121918
self.expr(sp, hir::ExprKind::Lit(lit))
19131919
}

compiler/rustc_ast_passes/src/feature_gate.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,8 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
398398
&self,
399399
exclusive_range_pattern,
400400
pattern.span,
401-
"exclusive range pattern syntax is experimental"
401+
"exclusive range pattern syntax is experimental",
402+
"use an inclusive range pattern, like N..=M"
402403
);
403404
}
404405
_ => {}

compiler/rustc_attr/src/builtin.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,9 +1185,9 @@ fn allow_unstable<'a>(
11851185

11861186
pub fn parse_alignment(node: &ast::LitKind) -> Result<u32, &'static str> {
11871187
if let ast::LitKind::Int(literal, ast::LitIntType::Unsuffixed) = node {
1188-
if literal.is_power_of_two() {
1188+
if literal.get().is_power_of_two() {
11891189
// rustc_middle::ty::layout::Align restricts align to <= 2^29
1190-
if *literal <= 1 << 29 { Ok(*literal as u32) } else { Err("larger than 2^29") }
1190+
if *literal <= 1 << 29 { Ok(literal.get() as u32) } else { Err("larger than 2^29") }
11911191
} else {
11921192
Err("not a power of two")
11931193
}

compiler/rustc_attr/src/session_diagnostics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ impl<'a> IncorrectReprFormatGenericCause<'a> {
296296
pub fn from_lit_kind(span: Span, kind: &ast::LitKind, name: &'a str) -> Option<Self> {
297297
match kind {
298298
ast::LitKind::Int(int, ast::LitIntType::Unsuffixed) => {
299-
Some(Self::Int { span, name, int: *int })
299+
Some(Self::Int { span, name, int: int.get() })
300300
}
301301
ast::LitKind::Str(symbol, _) => Some(Self::Symbol { span, name, symbol: *symbol }),
302302
_ => None,

compiler/rustc_borrowck/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ fn do_mir_borrowck<'tcx>(
415415

416416
let mut_span = tcx.sess.source_map().span_until_non_whitespace(span);
417417

418-
tcx.emit_spanned_lint(UNUSED_MUT, lint_root, span, VarNeedNotMut { span: mut_span })
418+
tcx.emit_node_span_lint(UNUSED_MUT, lint_root, span, VarNeedNotMut { span: mut_span })
419419
}
420420

421421
let tainted_by_errors = mbcx.emit_errors();

compiler/rustc_builtin_macros/src/concat_bytes.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ fn invalid_type_err(
5454
val,
5555
ast::LitIntType::Unsuffixed | ast::LitIntType::Unsigned(ast::UintTy::U8),
5656
)) => {
57-
assert!(val > u8::MAX.into()); // must be an error
57+
assert!(val.get() > u8::MAX.into()); // must be an error
5858
dcx.emit_err(ConcatBytesOob { span });
5959
}
6060
Ok(ast::LitKind::Int(_, _)) => {
@@ -86,7 +86,7 @@ fn handle_array_element(
8686
Ok(ast::LitKind::Int(
8787
val,
8888
ast::LitIntType::Unsuffixed | ast::LitIntType::Unsigned(ast::UintTy::U8),
89-
)) if val <= u8::MAX.into() => Some(val as u8),
89+
)) if val.get() <= u8::MAX.into() => Some(val.get() as u8),
9090

9191
Ok(ast::LitKind::Byte(val)) => Some(val),
9292
Ok(ast::LitKind::ByteStr(..)) => {
@@ -148,7 +148,7 @@ pub fn expand_concat_bytes(
148148
if let Some(elem) =
149149
handle_array_element(cx, &mut has_errors, &mut missing_literals, expr)
150150
{
151-
for _ in 0..count_val {
151+
for _ in 0..count_val.get() {
152152
accumulator.push(elem);
153153
}
154154
}

compiler/rustc_builtin_macros/src/format.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ fn make_format_args(
529529

530530
// Only check for unused named argument names if there are no other errors to avoid causing
531531
// too much noise in output errors, such as when a named argument is entirely unused.
532-
if invalid_refs.is_empty() && ecx.dcx().err_count() == 0 {
532+
if invalid_refs.is_empty() && ecx.dcx().has_errors().is_none() {
533533
for &(index, span, used_as) in &numeric_refences_to_named_arg {
534534
let (position_sp_to_replace, position_sp_for_msg) = match used_as {
535535
Placeholder(pspan) => (span, pspan),

compiler/rustc_codegen_ssa/messages.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ codegen_ssa_unsupported_arch = unsupported arch `{$arch}` for os `{$os}`
325325
326326
codegen_ssa_unsupported_link_self_contained = option `-C link-self-contained` is not supported on this target
327327
328-
codegen_ssa_use_cargo_directive = use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#cargorustc-link-libkindname)
328+
codegen_ssa_use_cargo_directive = use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#rustc-link-lib)
329329
330330
codegen_ssa_version_script_write_failure = failed to write version script: {$error}
331331

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
563563
if codegen_fn_attrs.inline == InlineAttr::Always {
564564
if let (Some(no_sanitize_span), Some(inline_span)) = (no_sanitize_span, inline_span) {
565565
let hir_id = tcx.local_def_id_to_hir_id(did);
566-
tcx.struct_span_lint_hir(
566+
tcx.node_span_lint(
567567
lint::builtin::INLINE_NO_SANITIZE,
568568
hir_id,
569569
no_sanitize_span,
@@ -658,7 +658,7 @@ fn check_link_ordinal(tcx: TyCtxt<'_>, attr: &ast::Attribute) -> Option<u16> {
658658
// if the resulting EXE runs, as I haven't yet built the necessary DLL -- see earlier comment
659659
// about LINK.EXE failing.)
660660
if *ordinal <= u16::MAX as u128 {
661-
Some(*ordinal as u16)
661+
Some(ordinal.get() as u16)
662662
} else {
663663
let msg = format!("ordinal value in `link_ordinal` is too large: `{}`", &ordinal);
664664
tcx.dcx()

compiler/rustc_const_eval/src/const_eval/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ pub(super) fn lint<'tcx, 'mir, L>(
175175
{
176176
let (span, frames) = get_span_and_frames(tcx, machine);
177177

178-
tcx.emit_spanned_lint(
178+
tcx.emit_node_span_lint(
179179
lint,
180180
// We use the root frame for this so the crate that defines the const defines whether the
181181
// lint is emitted.

compiler/rustc_const_eval/src/const_eval/machine.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
611611
.0
612612
.is_error();
613613
let span = ecx.cur_span();
614-
ecx.tcx.emit_spanned_lint(
614+
ecx.tcx.emit_node_span_lint(
615615
rustc_session::lint::builtin::LONG_RUNNING_CONST_EVAL,
616616
hir_id,
617617
span,

compiler/rustc_const_eval/src/transform/validate.rs

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,67 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
796796
};
797797
}
798798
match rvalue {
799-
Rvalue::Use(_) | Rvalue::CopyForDeref(_) | Rvalue::Aggregate(..) => {}
799+
Rvalue::Use(_) | Rvalue::CopyForDeref(_) => {}
800+
Rvalue::Aggregate(kind, fields) => match **kind {
801+
AggregateKind::Tuple => {}
802+
AggregateKind::Array(dest) => {
803+
for src in fields {
804+
if !self.mir_assign_valid_types(src.ty(self.body, self.tcx), dest) {
805+
self.fail(location, "array field has the wrong type");
806+
}
807+
}
808+
}
809+
AggregateKind::Adt(def_id, idx, args, _, Some(field)) => {
810+
let adt_def = self.tcx.adt_def(def_id);
811+
assert!(adt_def.is_union());
812+
assert_eq!(idx, FIRST_VARIANT);
813+
let dest = adt_def.non_enum_variant().fields[field].ty(self.tcx, args);
814+
if fields.len() != 1 {
815+
self.fail(location, "unions should have one initialized field");
816+
}
817+
if !self.mir_assign_valid_types(fields.raw[0].ty(self.body, self.tcx), dest) {
818+
self.fail(location, "union field has the wrong type");
819+
}
820+
}
821+
AggregateKind::Adt(def_id, idx, args, _, None) => {
822+
let adt_def = self.tcx.adt_def(def_id);
823+
assert!(!adt_def.is_union());
824+
let variant = &adt_def.variants()[idx];
825+
if variant.fields.len() != fields.len() {
826+
self.fail(location, "adt has the wrong number of initialized fields");
827+
}
828+
for (src, dest) in std::iter::zip(fields, &variant.fields) {
829+
if !self.mir_assign_valid_types(
830+
src.ty(self.body, self.tcx),
831+
dest.ty(self.tcx, args),
832+
) {
833+
self.fail(location, "adt field has the wrong type");
834+
}
835+
}
836+
}
837+
AggregateKind::Closure(_, args) => {
838+
let upvars = args.as_closure().upvar_tys();
839+
if upvars.len() != fields.len() {
840+
self.fail(location, "closure has the wrong number of initialized fields");
841+
}
842+
for (src, dest) in std::iter::zip(fields, upvars) {
843+
if !self.mir_assign_valid_types(src.ty(self.body, self.tcx), dest) {
844+
self.fail(location, "closure field has the wrong type");
845+
}
846+
}
847+
}
848+
AggregateKind::Coroutine(_, args) => {
849+
let upvars = args.as_coroutine().upvar_tys();
850+
if upvars.len() != fields.len() {
851+
self.fail(location, "coroutine has the wrong number of initialized fields");
852+
}
853+
for (src, dest) in std::iter::zip(fields, upvars) {
854+
if !self.mir_assign_valid_types(src.ty(self.body, self.tcx), dest) {
855+
self.fail(location, "coroutine field has the wrong type");
856+
}
857+
}
858+
}
859+
},
800860
Rvalue::Ref(_, BorrowKind::Fake, _) => {
801861
if self.mir_phase >= MirPhase::Runtime(RuntimePhase::Initial) {
802862
self.fail(

compiler/rustc_data_structures/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ pub mod aligned;
9393
pub mod frozen;
9494
mod hashes;
9595
pub mod owned_slice;
96+
pub mod packed;
9697
pub mod sso;
9798
pub mod steal;
9899
pub mod tagged_ptr;
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
use crate::stable_hasher::{HashStable, StableHasher};
2+
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
3+
use std::cmp::Ordering;
4+
use std::fmt;
5+
6+
#[repr(packed(8))]
7+
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
8+
pub struct Pu128(pub u128);
9+
10+
impl Pu128 {
11+
#[inline]
12+
pub fn get(self) -> u128 {
13+
self.0
14+
}
15+
}
16+
17+
impl From<u128> for Pu128 {
18+
#[inline]
19+
fn from(value: u128) -> Self {
20+
Self(value)
21+
}
22+
}
23+
24+
impl PartialEq<u128> for Pu128 {
25+
#[inline]
26+
fn eq(&self, other: &u128) -> bool {
27+
({ self.0 }) == *other
28+
}
29+
}
30+
31+
impl PartialOrd<u128> for Pu128 {
32+
#[inline]
33+
fn partial_cmp(&self, other: &u128) -> Option<Ordering> {
34+
{ self.0 }.partial_cmp(other)
35+
}
36+
}
37+
38+
impl fmt::Display for Pu128 {
39+
#[inline]
40+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
41+
{ self.0 }.fmt(f)
42+
}
43+
}
44+
45+
impl fmt::UpperHex for Pu128 {
46+
#[inline]
47+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
48+
{ self.0 }.fmt(f)
49+
}
50+
}
51+
52+
impl<CTX> HashStable<CTX> for Pu128 {
53+
#[inline]
54+
fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) {
55+
{ self.0 }.hash_stable(ctx, hasher)
56+
}
57+
}
58+
59+
impl<S: Encoder> Encodable<S> for Pu128 {
60+
#[inline]
61+
fn encode(&self, s: &mut S) {
62+
{ self.0 }.encode(s);
63+
}
64+
}
65+
66+
impl<D: Decoder> Decodable<D> for Pu128 {
67+
#[inline]
68+
fn decode(d: &mut D) -> Self {
69+
Self(u128::decode(d))
70+
}
71+
}

compiler/rustc_errors/src/diagnostic_impls.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,14 @@ impl IntoDiagnosticArg for char {
110110
}
111111
}
112112

113+
impl IntoDiagnosticArg for Vec<char> {
114+
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
115+
DiagnosticArgValue::StrListSepByAnd(
116+
self.into_iter().map(|c| Cow::Owned(format!("{c:?}"))).collect(),
117+
)
118+
}
119+
}
120+
113121
impl IntoDiagnosticArg for Symbol {
114122
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
115123
self.to_ident_string().into_diagnostic_arg()

0 commit comments

Comments
 (0)