Skip to content

Commit a3bc38c

Browse files
committed
Auto merge of #153490 - JonathanBrouwer:rollup-2qfRVzJ, r=JonathanBrouwer
Rollup of 9 pull requests Successful merges: - #153466 (`rust-analyzer` subtree update) - #151280 (Fix incorrect trailing comma suggested in no_accessible_fields) - #152593 (Box in `ValTreeKind::Branch(Box<[I::Const]>)` changed to `List`) - #153174 (std: add wasm64 to sync::Once and thread_parking atomics cfg guards) - #153189 (refactor: move `check_align` to `parse_alignment`) - #153230 (Roll rustfmt reviewers for in-tree rustfmt) - #153445 (Consider try blocks as block-like for overflowed expr) - #153476 (bootstrap.py: fix typo "parallle") - #153483 (Preserve parentheses around `Fn` trait bounds in pretty printer)
2 parents ff08635 + 1dcf802 commit a3bc38c

70 files changed

Lines changed: 1055 additions & 339 deletions

File tree

Some content is hidden

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

compiler/rustc_ast_pretty/src/pprust/state.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1415,6 +1415,9 @@ impl<'a> State<'a> {
14151415
}
14161416

14171417
fn print_poly_trait_ref(&mut self, t: &ast::PolyTraitRef) {
1418+
if let ast::Parens::Yes = t.parens {
1419+
self.popen();
1420+
}
14181421
self.print_formal_generic_params(&t.bound_generic_params);
14191422

14201423
let ast::TraitBoundModifiers { constness, asyncness, polarity } = t.modifiers;
@@ -1437,7 +1440,10 @@ impl<'a> State<'a> {
14371440
}
14381441
}
14391442

1440-
self.print_trait_ref(&t.trait_ref)
1443+
self.print_trait_ref(&t.trait_ref);
1444+
if let ast::Parens::Yes = t.parens {
1445+
self.pclose();
1446+
}
14411447
}
14421448

14431449
fn print_stmt(&mut self, st: &ast::Stmt) {

compiler/rustc_attr_parsing/src/attributes/repr.rs

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use rustc_abi::Align;
1+
use rustc_abi::{Align, Size};
22
use rustc_ast::{IntTy, LitIntType, LitKind, UintTy};
33
use rustc_hir::attrs::{IntType, ReprAttr};
44

@@ -229,7 +229,7 @@ fn parse_repr_align<S: Stage>(
229229
return None;
230230
};
231231

232-
match parse_alignment(&lit.kind) {
232+
match parse_alignment(&lit.kind, cx) {
233233
Ok(literal) => Some(match align_kind {
234234
AlignKind::Packed => ReprAttr::ReprPacked(literal),
235235
AlignKind::Align => ReprAttr::ReprAlign(literal),
@@ -248,23 +248,35 @@ fn parse_repr_align<S: Stage>(
248248
}
249249
}
250250

251-
fn parse_alignment(node: &LitKind) -> Result<Align, &'static str> {
252-
if let LitKind::Int(literal, LitIntType::Unsuffixed) = node {
253-
// `Align::from_bytes` accepts 0 as an input, check is_power_of_two() first
254-
if literal.get().is_power_of_two() {
255-
// Only possible error is larger than 2^29
256-
literal
257-
.get()
258-
.try_into()
259-
.ok()
260-
.and_then(|v| Align::from_bytes(v).ok())
261-
.ok_or("larger than 2^29")
262-
} else {
263-
Err("not a power of two")
264-
}
265-
} else {
266-
Err("not an unsuffixed integer")
251+
fn parse_alignment<S: Stage>(
252+
node: &LitKind,
253+
cx: &AcceptContext<'_, '_, S>,
254+
) -> Result<Align, String> {
255+
let LitKind::Int(literal, LitIntType::Unsuffixed) = node else {
256+
return Err("not an unsuffixed integer".to_string());
257+
};
258+
259+
// `Align::from_bytes` accepts 0 as a valid input,
260+
// so we check if its a power of two first
261+
if !literal.get().is_power_of_two() {
262+
return Err("not a power of two".to_string());
263+
}
264+
// lit must be < 2^29
265+
let align = literal
266+
.get()
267+
.try_into()
268+
.ok()
269+
.and_then(|a| Align::from_bytes(a).ok())
270+
.ok_or("larger than 2^29".to_string())?;
271+
272+
// alignment must not be larger than the pointer width (`isize::MAX`)
273+
let max = Size::from_bits(cx.sess.target.pointer_width).signed_int_max() as u64;
274+
if align.bytes() > max {
275+
return Err(format!(
276+
"alignment larger than `isize::MAX` bytes ({max} for the current target)"
277+
));
267278
}
279+
Ok(align)
268280
}
269281

270282
/// Parse #[align(N)].
@@ -294,7 +306,7 @@ impl RustcAlignParser {
294306
return;
295307
};
296308

297-
match parse_alignment(&lit.kind) {
309+
match parse_alignment(&lit.kind, cx) {
298310
Ok(literal) => self.0 = Ord::max(self.0, Some((literal, cx.attr_span))),
299311
Err(message) => {
300312
cx.emit_err(session_diagnostics::InvalidAlignmentValue {

compiler/rustc_attr_parsing/src/session_diagnostics.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,12 +227,12 @@ pub(crate) struct InvalidReprAlignNeedArg {
227227

228228
#[derive(Diagnostic)]
229229
#[diag("invalid `repr({$repr_arg})` attribute: {$error_part}", code = E0589)]
230-
pub(crate) struct InvalidReprGeneric<'a> {
230+
pub(crate) struct InvalidReprGeneric {
231231
#[primary_span]
232232
pub span: Span,
233233

234234
pub repr_arg: String,
235-
pub error_part: &'a str,
235+
pub error_part: String,
236236
}
237237

238238
#[derive(Diagnostic)]
@@ -479,7 +479,7 @@ pub(crate) struct InvalidTarget {
479479
pub(crate) struct InvalidAlignmentValue {
480480
#[primary_span]
481481
pub span: Span,
482-
pub error_part: &'static str,
482+
pub error_part: String,
483483
}
484484

485485
#[derive(Diagnostic)]

compiler/rustc_const_eval/src/const_eval/valtrees.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ fn valtree_into_mplace<'tcx>(
413413
Some(variant_idx),
414414
)
415415
}
416-
_ => (place.clone(), branches, None),
416+
_ => (place.clone(), branches.as_slice(), None),
417417
};
418418
debug!(?place_adjusted, ?branches);
419419

compiler/rustc_hir_typeck/src/pat.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2436,10 +2436,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
24362436
.struct_span_err(pat.span, "pattern requires `..` due to inaccessible fields");
24372437

24382438
if let Some(field) = fields.last() {
2439+
let tail_span = field.span.shrink_to_hi().to(pat.span.shrink_to_hi());
2440+
let comma_hi_offset =
2441+
self.tcx.sess.source_map().span_to_snippet(tail_span).ok().and_then(|snippet| {
2442+
let trimmed = snippet.trim_start();
2443+
trimmed.starts_with(',').then(|| (snippet.len() - trimmed.len() + 1) as u32)
2444+
});
24392445
err.span_suggestion_verbose(
2440-
field.span.shrink_to_hi(),
2446+
if let Some(comma_hi_offset) = comma_hi_offset {
2447+
tail_span.with_hi(tail_span.lo() + BytePos(comma_hi_offset)).shrink_to_hi()
2448+
} else {
2449+
field.span.shrink_to_hi()
2450+
},
24412451
"ignore the inaccessible and unused fields",
2442-
", ..",
2452+
if comma_hi_offset.is_some() { " .." } else { ", .." },
24432453
Applicability::MachineApplicable,
24442454
);
24452455
} else {

compiler/rustc_middle/src/arena.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ macro_rules! arena_types {
9292
[] name_set: rustc_data_structures::unord::UnordSet<rustc_span::Symbol>,
9393
[] autodiff_item: rustc_hir::attrs::AutoDiffItem,
9494
[] ordered_name_set: rustc_data_structures::fx::FxIndexSet<rustc_span::Symbol>,
95-
[] valtree: rustc_middle::ty::ValTreeKind<rustc_middle::ty::TyCtxt<'tcx>>,
9695
[] stable_order_of_exportable_impls:
9796
rustc_data_structures::fx::FxIndexMap<rustc_hir::def_id::DefId, usize>,
9897

compiler/rustc_middle/src/ty/codec.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use std::marker::{DiscriminantKind, PointeeSized};
1313
use rustc_abi::FieldIdx;
1414
use rustc_data_structures::fx::FxHashMap;
1515
use rustc_hir::def_id::LocalDefId;
16+
use rustc_middle::ty::Const;
1617
use rustc_serialize::{Decodable, Encodable};
1718
use rustc_span::source_map::Spanned;
1819
use rustc_span::{Span, SpanDecoder, SpanEncoder};
@@ -497,6 +498,7 @@ impl_decodable_via_ref! {
497498
&'tcx ty::List<ty::BoundVariableKind<'tcx>>,
498499
&'tcx ty::List<ty::Pattern<'tcx>>,
499500
&'tcx ty::ListWithCachedTypeInfo<ty::Clause<'tcx>>,
501+
&'tcx ty::List<Const<'tcx>>,
500502
}
501503

502504
#[macro_export]

compiler/rustc_middle/src/ty/consts/valtree.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,14 @@ impl<'tcx> ty::ValTreeKind<TyCtxt<'tcx>> {
3131
// recurses through
3232
pub struct ValTree<'tcx>(pub(crate) Interned<'tcx, ty::ValTreeKind<TyCtxt<'tcx>>>);
3333

34-
impl<'tcx> rustc_type_ir::inherent::ValTree<TyCtxt<'tcx>> for ValTree<'tcx> {
35-
fn kind(&self) -> &ty::ValTreeKind<TyCtxt<'tcx>> {
36-
&self
37-
}
38-
}
39-
4034
impl<'tcx> ValTree<'tcx> {
4135
/// Returns the zero-sized valtree: `Branch([])`.
4236
pub fn zst(tcx: TyCtxt<'tcx>) -> Self {
4337
tcx.consts.valtree_zst
4438
}
4539

4640
pub fn is_zst(self) -> bool {
47-
matches!(*self, ty::ValTreeKind::Branch(box []))
41+
matches!(*self, ty::ValTreeKind::Branch(consts) if consts.is_empty())
4842
}
4943

5044
pub fn from_raw_bytes(tcx: TyCtxt<'tcx>, bytes: &[u8]) -> Self {
@@ -58,7 +52,9 @@ impl<'tcx> ValTree<'tcx> {
5852
tcx: TyCtxt<'tcx>,
5953
branches: impl IntoIterator<Item = ty::Const<'tcx>>,
6054
) -> Self {
61-
tcx.intern_valtree(ty::ValTreeKind::Branch(branches.into_iter().collect()))
55+
tcx.intern_valtree(ty::ValTreeKind::Branch(
56+
tcx.mk_const_list_from_iter(branches.into_iter()),
57+
))
6258
}
6359

6460
pub fn from_scalar_int(tcx: TyCtxt<'tcx>, i: ScalarInt) -> Self {
@@ -81,6 +77,14 @@ impl fmt::Debug for ValTree<'_> {
8177
}
8278
}
8379

80+
impl<'tcx> rustc_type_ir::inherent::IntoKind for ty::ValTree<'tcx> {
81+
type Kind = ty::ValTreeKind<TyCtxt<'tcx>>;
82+
83+
fn kind(self) -> Self::Kind {
84+
*self.0
85+
}
86+
}
87+
8488
/// `Ok(Err(ty))` indicates the constant was fine, but the valtree couldn't be constructed
8589
/// because the value contains something of type `ty` that is not valtree-compatible.
8690
/// The caller can then show an appropriate error; the query does not have the

compiler/rustc_middle/src/ty/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ impl<'tcx> CommonConsts<'tcx> {
564564
))
565565
};
566566

567-
let valtree_zst = mk_valtree(ty::ValTreeKind::Branch(Box::default()));
567+
let valtree_zst = mk_valtree(ty::ValTreeKind::Branch(List::empty()));
568568
let valtree_true = mk_valtree(ty::ValTreeKind::Leaf(ty::ScalarInt::TRUE));
569569
let valtree_false = mk_valtree(ty::ValTreeKind::Leaf(ty::ScalarInt::FALSE));
570570

compiler/rustc_middle/src/ty/context/impl_interner.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
9595
type Safety = hir::Safety;
9696
type Abi = ExternAbi;
9797
type Const = ty::Const<'tcx>;
98+
type Consts = &'tcx List<Self::Const>;
9899

99100
type ParamConst = ty::ParamConst;
100101
type ValueConst = ty::Value<'tcx>;

0 commit comments

Comments
 (0)