Skip to content

Commit 82d9326

Browse files
committed
Auto merge of rust-lang#3440 - rust-lang:rustup-2024-04-03, r=RalfJung
Automatic Rustup
2 parents 4397b6b + 22382eb commit 82d9326

File tree

584 files changed

+10697
-7718
lines changed

Some content is hidden

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

584 files changed

+10697
-7718
lines changed

Cargo.lock

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2590,6 +2590,15 @@ dependencies = [
25902590
"winapi",
25912591
]
25922592

2593+
[[package]]
2594+
name = "nu-ansi-term"
2595+
version = "0.49.0"
2596+
source = "registry+https://github.com/rust-lang/crates.io-index"
2597+
checksum = "c073d3c1930d0751774acf49e66653acecb416c3a54c6ec095a9b11caddb5a68"
2598+
dependencies = [
2599+
"windows-sys 0.48.0",
2600+
]
2601+
25932602
[[package]]
25942603
name = "num-conv"
25952604
version = "0.1.0"
@@ -3560,6 +3569,7 @@ dependencies = [
35603569
name = "rustc_attr"
35613570
version = "0.0.0"
35623571
dependencies = [
3572+
"rustc_abi",
35633573
"rustc_ast",
35643574
"rustc_ast_pretty",
35653575
"rustc_data_structures",
@@ -4773,6 +4783,8 @@ version = "0.0.0"
47734783
dependencies = [
47744784
"arrayvec",
47754785
"askama",
4786+
"base64",
4787+
"byteorder",
47764788
"expect-test",
47774789
"indexmap",
47784790
"itertools 0.12.1",
@@ -5358,9 +5370,9 @@ dependencies = [
53585370

53595371
[[package]]
53605372
name = "sysinfo"
5361-
version = "0.30.7"
5373+
version = "0.30.8"
53625374
source = "registry+https://github.com/rust-lang/crates.io-index"
5363-
checksum = "0c385888ef380a852a16209afc8cfad22795dd8873d69c9a14d2e2088f118d18"
5375+
checksum = "4b1a378e48fb3ce3a5cf04359c456c9c98ff689bcf1c1bc6e6a31f247686f275"
53645376
dependencies = [
53655377
"cfg-if",
53665378
"core-foundation-sys",
@@ -5778,17 +5790,6 @@ dependencies = [
57785790
"tracing-subscriber",
57795791
]
57805792

5781-
[[package]]
5782-
name = "tracing-log"
5783-
version = "0.1.4"
5784-
source = "registry+https://github.com/rust-lang/crates.io-index"
5785-
checksum = "f751112709b4e791d8ce53e32c4ed2d353565a795ce84da2285393f41557bdf2"
5786-
dependencies = [
5787-
"log",
5788-
"once_cell",
5789-
"tracing-core",
5790-
]
5791-
57925793
[[package]]
57935794
name = "tracing-log"
57945795
version = "0.2.0"
@@ -5807,7 +5808,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
58075808
checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b"
58085809
dependencies = [
58095810
"matchers",
5810-
"nu-ansi-term",
5811+
"nu-ansi-term 0.46.0",
58115812
"once_cell",
58125813
"parking_lot",
58135814
"regex",
@@ -5816,18 +5817,18 @@ dependencies = [
58165817
"thread_local",
58175818
"tracing",
58185819
"tracing-core",
5819-
"tracing-log 0.2.0",
5820+
"tracing-log",
58205821
]
58215822

58225823
[[package]]
58235824
name = "tracing-tree"
5824-
version = "0.2.5"
5825+
version = "0.3.0"
58255826
source = "registry+https://github.com/rust-lang/crates.io-index"
5826-
checksum = "2ec6adcab41b1391b08a308cc6302b79f8095d1673f6947c2dc65ffb028b0b2d"
5827+
checksum = "65139ecd2c3f6484c3b99bc01c77afe21e95473630747c7aca525e78b0666675"
58275828
dependencies = [
5828-
"nu-ansi-term",
5829+
"nu-ansi-term 0.49.0",
58295830
"tracing-core",
5830-
"tracing-log 0.1.4",
5831+
"tracing-log",
58315832
"tracing-subscriber",
58325833
]
58335834

compiler/rustc_abi/src/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,7 @@ impl fmt::Display for AlignFromBytesError {
698698

699699
impl Align {
700700
pub const ONE: Align = Align { pow2: 0 };
701+
pub const EIGHT: Align = Align { pow2: 3 };
701702
// LLVM has a maximal supported alignment of 2^29, we inherit that.
702703
pub const MAX: Align = Align { pow2: 29 };
703704

@@ -707,19 +708,19 @@ impl Align {
707708
}
708709

709710
#[inline]
710-
pub fn from_bytes(align: u64) -> Result<Align, AlignFromBytesError> {
711+
pub const fn from_bytes(align: u64) -> Result<Align, AlignFromBytesError> {
711712
// Treat an alignment of 0 bytes like 1-byte alignment.
712713
if align == 0 {
713714
return Ok(Align::ONE);
714715
}
715716

716717
#[cold]
717-
fn not_power_of_2(align: u64) -> AlignFromBytesError {
718+
const fn not_power_of_2(align: u64) -> AlignFromBytesError {
718719
AlignFromBytesError::NotPowerOfTwo(align)
719720
}
720721

721722
#[cold]
722-
fn too_large(align: u64) -> AlignFromBytesError {
723+
const fn too_large(align: u64) -> AlignFromBytesError {
723724
AlignFromBytesError::TooLarge(align)
724725
}
725726

compiler/rustc_ast/src/ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3341,7 +3341,7 @@ impl TryFrom<ItemKind> for ForeignItemKind {
33413341
pub type ForeignItem = Item<ForeignItemKind>;
33423342

33433343
// 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"))]
3344+
#[cfg(all(any(target_arch = "x86_64", target_arch = "aarch64"), target_pointer_width = "64"))]
33453345
mod size_asserts {
33463346
use super::*;
33473347
use rustc_data_structures::static_assert_size;

compiler/rustc_ast/src/token.rs

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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_attr/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ edition = "2021"
55

66
[dependencies]
77
# tidy-alphabetical-start
8+
rustc_abi = { path = "../rustc_abi" }
89
rustc_ast = { path = "../rustc_ast" }
910
rustc_ast_pretty = { path = "../rustc_ast_pretty" }
1011
rustc_data_structures = { path = "../rustc_data_structures" }

compiler/rustc_attr/src/builtin.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Parsing and validation of builtin attributes
22
3+
use rustc_abi::Align;
34
use rustc_ast::{self as ast, attr};
45
use rustc_ast::{Attribute, LitKind, MetaItem, MetaItemKind, MetaItemLit, NestedMetaItem, NodeId};
56
use rustc_ast_pretty::pprust;
@@ -919,10 +920,10 @@ pub enum ReprAttr {
919920
ReprInt(IntType),
920921
ReprRust,
921922
ReprC,
922-
ReprPacked(u32),
923+
ReprPacked(Align),
923924
ReprSimd,
924925
ReprTransparent,
925-
ReprAlign(u32),
926+
ReprAlign(Align),
926927
}
927928

928929
#[derive(Eq, PartialEq, Debug, Copy, Clone)]
@@ -968,7 +969,7 @@ pub fn parse_repr_attr(sess: &Session, attr: &Attribute) -> Vec<ReprAttr> {
968969
let hint = match item.name_or_empty() {
969970
sym::Rust => Some(ReprRust),
970971
sym::C => Some(ReprC),
971-
sym::packed => Some(ReprPacked(1)),
972+
sym::packed => Some(ReprPacked(Align::ONE)),
972973
sym::simd => Some(ReprSimd),
973974
sym::transparent => Some(ReprTransparent),
974975
sym::align => {
@@ -1209,11 +1210,17 @@ fn allow_unstable<'a>(
12091210
})
12101211
}
12111212

1212-
pub fn parse_alignment(node: &ast::LitKind) -> Result<u32, &'static str> {
1213+
pub fn parse_alignment(node: &ast::LitKind) -> Result<Align, &'static str> {
12131214
if let ast::LitKind::Int(literal, ast::LitIntType::Unsuffixed) = node {
1215+
// `Align::from_bytes` accepts 0 as an input, check is_power_of_two() first
12141216
if literal.get().is_power_of_two() {
1215-
// rustc_middle::ty::layout::Align restricts align to <= 2^29
1216-
if *literal <= 1 << 29 { Ok(literal.get() as u32) } else { Err("larger than 2^29") }
1217+
// Only possible error is larger than 2^29
1218+
literal
1219+
.get()
1220+
.try_into()
1221+
.ok()
1222+
.and_then(|v| Align::from_bytes(v).ok())
1223+
.ok_or("larger than 2^29")
12171224
} else {
12181225
Err("not a power of two")
12191226
}

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -540,19 +540,23 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
540540
}
541541
}
542542

543+
/// Suggest `map[k] = v` => `map.insert(k, v)` and the like.
543544
fn suggest_map_index_mut_alternatives(&self, ty: Ty<'tcx>, err: &mut Diag<'tcx>, span: Span) {
544545
let Some(adt) = ty.ty_adt_def() else { return };
545546
let did = adt.did();
546547
if self.infcx.tcx.is_diagnostic_item(sym::HashMap, did)
547548
|| self.infcx.tcx.is_diagnostic_item(sym::BTreeMap, did)
548549
{
549-
struct V<'a, 'tcx> {
550+
/// Walks through the HIR, looking for the corresponding span for this error.
551+
/// When it finds it, see if it corresponds to assignment operator whose LHS
552+
/// is an index expr.
553+
struct SuggestIndexOperatorAlternativeVisitor<'a, 'tcx> {
550554
assign_span: Span,
551555
err: &'a mut Diag<'tcx>,
552556
ty: Ty<'tcx>,
553557
suggested: bool,
554558
}
555-
impl<'a, 'tcx> Visitor<'tcx> for V<'a, 'tcx> {
559+
impl<'a, 'tcx> Visitor<'tcx> for SuggestIndexOperatorAlternativeVisitor<'a, 'tcx> {
556560
fn visit_stmt(&mut self, stmt: &'tcx hir::Stmt<'tcx>) {
557561
hir::intravisit::walk_stmt(self, stmt);
558562
let expr = match stmt.kind {
@@ -645,7 +649,12 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
645649
let Some(body_id) = hir_map.maybe_body_owned_by(local_def_id) else { return };
646650
let body = self.infcx.tcx.hir().body(body_id);
647651

648-
let mut v = V { assign_span: span, err, ty, suggested: false };
652+
let mut v = SuggestIndexOperatorAlternativeVisitor {
653+
assign_span: span,
654+
err,
655+
ty,
656+
suggested: false,
657+
};
649658
v.visit_body(body);
650659
if !v.suggested {
651660
err.help(format!(

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2279,7 +2279,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
22792279
}
22802280
}
22812281

2282-
CastKind::PointerFromExposedAddress => {
2282+
CastKind::PointerWithExposedProvenance => {
22832283
let ty_from = op.ty(body, tcx);
22842284
let cast_ty_from = CastTy::from_ty(ty_from);
22852285
let cast_ty_to = CastTy::from_ty(*ty);
@@ -2289,7 +2289,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
22892289
span_mirbug!(
22902290
self,
22912291
rvalue,
2292-
"Invalid PointerFromExposedAddress cast {:?} -> {:?}",
2292+
"Invalid PointerWithExposedProvenance cast {:?} -> {:?}",
22932293
ty_from,
22942294
ty
22952295
)

compiler/rustc_builtin_macros/messages.ftl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ builtin_macros_env_not_defined = environment variable `{$var}` not defined at co
114114
.cargo = Cargo sets build script variables at run time. Use `std::env::var({$var_expr})` instead
115115
.custom = use `std::env::var({$var_expr})` to read the variable at run time
116116
117+
builtin_macros_env_not_unicode = environment variable `{$var}` is not a valid Unicode string
118+
117119
builtin_macros_env_takes_args = `env!()` takes 1 or 2 arguments
118120
119121
builtin_macros_expected_one_cfg_pattern = expected 1 cfg-pattern

compiler/rustc_builtin_macros/src/env.rs

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,19 @@ use rustc_expand::base::{DummyResult, ExpandResult, ExtCtxt, MacEager, MacroExpa
1111
use rustc_span::symbol::{kw, sym, Ident, Symbol};
1212
use rustc_span::Span;
1313
use std::env;
14+
use std::env::VarError;
1415
use thin_vec::thin_vec;
1516

1617
use crate::errors;
1718

18-
fn lookup_env<'cx>(cx: &'cx ExtCtxt<'_>, var: Symbol) -> Option<Symbol> {
19+
fn lookup_env<'cx>(cx: &'cx ExtCtxt<'_>, var: Symbol) -> Result<Symbol, VarError> {
1920
let var = var.as_str();
2021
if let Some(value) = cx.sess.opts.logical_env.get(var) {
21-
return Some(Symbol::intern(value));
22+
return Ok(Symbol::intern(value));
2223
}
2324
// If the environment variable was not defined with the `--env-set` option, we try to retrieve it
2425
// from rustc's environment.
25-
env::var(var).ok().as_deref().map(Symbol::intern)
26+
Ok(Symbol::intern(&env::var(var)?))
2627
}
2728

2829
pub fn expand_option_env<'cx>(
@@ -39,7 +40,7 @@ pub fn expand_option_env<'cx>(
3940
};
4041

4142
let sp = cx.with_def_site_ctxt(sp);
42-
let value = lookup_env(cx, var);
43+
let value = lookup_env(cx, var).ok();
4344
cx.sess.psess.env_depinfo.borrow_mut().insert((var, value));
4445
let e = match value {
4546
None => {
@@ -108,35 +109,43 @@ pub fn expand_env<'cx>(
108109

109110
let span = cx.with_def_site_ctxt(sp);
110111
let value = lookup_env(cx, var);
111-
cx.sess.psess.env_depinfo.borrow_mut().insert((var, value));
112+
cx.sess.psess.env_depinfo.borrow_mut().insert((var, value.as_ref().ok().copied()));
112113
let e = match value {
113-
None => {
114+
Err(err) => {
114115
let ExprKind::Lit(token::Lit {
115116
kind: LitKind::Str | LitKind::StrRaw(..), symbol, ..
116117
}) = &var_expr.kind
117118
else {
118119
unreachable!("`expr_to_string` ensures this is a string lit")
119120
};
120121

121-
let guar = if let Some(msg_from_user) = custom_msg {
122-
cx.dcx().emit_err(errors::EnvNotDefinedWithUserMessage { span, msg_from_user })
123-
} else if is_cargo_env_var(var.as_str()) {
124-
cx.dcx().emit_err(errors::EnvNotDefined::CargoEnvVar {
125-
span,
126-
var: *symbol,
127-
var_expr: var_expr.ast_deref(),
128-
})
129-
} else {
130-
cx.dcx().emit_err(errors::EnvNotDefined::CustomEnvVar {
131-
span,
132-
var: *symbol,
133-
var_expr: var_expr.ast_deref(),
134-
})
122+
let guar = match err {
123+
VarError::NotPresent => {
124+
if let Some(msg_from_user) = custom_msg {
125+
cx.dcx()
126+
.emit_err(errors::EnvNotDefinedWithUserMessage { span, msg_from_user })
127+
} else if is_cargo_env_var(var.as_str()) {
128+
cx.dcx().emit_err(errors::EnvNotDefined::CargoEnvVar {
129+
span,
130+
var: *symbol,
131+
var_expr: var_expr.ast_deref(),
132+
})
133+
} else {
134+
cx.dcx().emit_err(errors::EnvNotDefined::CustomEnvVar {
135+
span,
136+
var: *symbol,
137+
var_expr: var_expr.ast_deref(),
138+
})
139+
}
140+
}
141+
VarError::NotUnicode(_) => {
142+
cx.dcx().emit_err(errors::EnvNotUnicode { span, var: *symbol })
143+
}
135144
};
136145

137146
return ExpandResult::Ready(DummyResult::any(sp, guar));
138147
}
139-
Some(value) => cx.expr_str(span, value),
148+
Ok(value) => cx.expr_str(span, value),
140149
};
141150
ExpandResult::Ready(MacEager::expr(e))
142151
}

compiler/rustc_builtin_macros/src/errors.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,14 @@ pub(crate) enum EnvNotDefined<'a> {
458458
},
459459
}
460460

461+
#[derive(Diagnostic)]
462+
#[diag(builtin_macros_env_not_unicode)]
463+
pub(crate) struct EnvNotUnicode {
464+
#[primary_span]
465+
pub(crate) span: Span,
466+
pub(crate) var: Symbol,
467+
}
468+
461469
#[derive(Diagnostic)]
462470
#[diag(builtin_macros_format_requires_string)]
463471
pub(crate) struct FormatRequiresString {

compiler/rustc_codegen_cranelift/src/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ fn codegen_stmt<'tcx>(
650650
| CastKind::FnPtrToPtr
651651
| CastKind::PtrToPtr
652652
| CastKind::PointerExposeAddress
653-
| CastKind::PointerFromExposedAddress,
653+
| CastKind::PointerWithExposedProvenance,
654654
ref operand,
655655
to_ty,
656656
) => {

0 commit comments

Comments
 (0)