Skip to content

Commit 80282b1

Browse files
committed
Auto merge of #153507 - JonathanBrouwer:rollup-ki59UTE, r=JonathanBrouwer
Rollup of 14 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) - #153485 (libcore float tests: replace macro shadowing by const-compatible macro) - #153495 (Fix ICE in `offset_of!` error recovery) - #152040 (Do not emit ConstEvaluatable goals if type-const) - #152741 (Suppress invalid suggestions in destructuring assignment) - #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) - #153452 (Cleanup unused diagnostic emission methods) - #153476 (bootstrap.py: fix typo "parallle") - #153483 (Preserve parentheses around `Fn` trait bounds in pretty printer)
2 parents a3ac2f2 + 03a8ae8 commit 80282b1

File tree

126 files changed

+2472
-1294
lines changed

Some content is hidden

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

126 files changed

+2472
-1294
lines changed

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_borrowck/src/diagnostics/move_errors.rs

Lines changed: 53 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_middle::mir::*;
88
use rustc_middle::ty::{self, Ty, TyCtxt};
99
use rustc_mir_dataflow::move_paths::{LookupResult, MovePathIndex};
1010
use rustc_span::def_id::DefId;
11-
use rustc_span::{BytePos, ExpnKind, MacroKind, Span};
11+
use rustc_span::{BytePos, ExpnKind, MacroKind, Span, sym};
1212
use rustc_trait_selection::error_reporting::traits::FindExprBySpan;
1313
use rustc_trait_selection::infer::InferCtxtExt;
1414
use tracing::debug;
@@ -700,14 +700,14 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
700700
binds_to.sort();
701701
binds_to.dedup();
702702

703-
self.add_move_error_details(err, &binds_to);
703+
self.add_move_error_details(err, &binds_to, &[]);
704704
}
705705
}
706706
GroupedMoveError::MovesFromValue { mut binds_to, .. } => {
707707
binds_to.sort();
708708
binds_to.dedup();
709-
self.add_move_error_suggestions(err, &binds_to);
710-
self.add_move_error_details(err, &binds_to);
709+
let desugar_spans = self.add_move_error_suggestions(err, &binds_to);
710+
self.add_move_error_details(err, &binds_to, &desugar_spans);
711711
}
712712
// No binding. Nothing to suggest.
713713
GroupedMoveError::OtherIllegalMove { ref original_path, use_spans, .. } => {
@@ -823,7 +823,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
823823
}
824824
}
825825

826-
fn add_move_error_suggestions(&self, err: &mut Diag<'_>, binds_to: &[Local]) {
826+
fn add_move_error_suggestions(&self, err: &mut Diag<'_>, binds_to: &[Local]) -> Vec<Span> {
827827
/// A HIR visitor to associate each binding with a `&` or `&mut` that could be removed to
828828
/// make it bind by reference instead (if possible)
829829
struct BindingFinder<'tcx> {
@@ -843,6 +843,8 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
843843
ref_pat_for_binding: Vec<(Span, Option<&'tcx hir::Pat<'tcx>>)>,
844844
/// Output: ref patterns that can't be removed straightforwardly
845845
cannot_remove: FxHashSet<HirId>,
846+
/// Output: binding spans from destructuring assignment desugaring
847+
desugar_binding_spans: Vec<Span>,
846848
}
847849
impl<'tcx> Visitor<'tcx> for BindingFinder<'tcx> {
848850
type NestedFilter = rustc_middle::hir::nested_filter::OnlyBodies;
@@ -883,16 +885,38 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
883885
}
884886

885887
if let hir::PatKind::Binding(_, _, ident, _) = p.kind {
886-
// the spans in `binding_spans` encompass both the ident and binding mode
887-
if let Some(&bind_sp) =
888-
self.binding_spans.iter().find(|bind_sp| bind_sp.contains(ident.span))
889-
{
890-
self.ref_pat_for_binding.push((bind_sp, self.ref_pat));
888+
// Skip synthetic bindings from destructuring assignment desugaring
889+
// These have name `lhs` and their parent is a `LetStmt` with
890+
// `LocalSource::AssignDesugar`
891+
let dominated_by_desugar_assign = ident.name == sym::lhs
892+
&& self.tcx.hir_parent_iter(p.hir_id).any(|(_, node)| {
893+
matches!(
894+
node,
895+
hir::Node::LetStmt(&hir::LetStmt {
896+
source: hir::LocalSource::AssignDesugar,
897+
..
898+
})
899+
)
900+
});
901+
902+
if dominated_by_desugar_assign {
903+
if let Some(&bind_sp) =
904+
self.binding_spans.iter().find(|bind_sp| bind_sp.contains(ident.span))
905+
{
906+
self.desugar_binding_spans.push(bind_sp);
907+
}
891908
} else {
892-
// we've encountered a binding that we're not reporting a move error for.
893-
// we don't want to change its type, so don't remove the surrounding `&`.
894-
if let Some(ref_pat) = self.ref_pat {
895-
self.cannot_remove.insert(ref_pat.hir_id);
909+
// the spans in `binding_spans` encompass both the ident and binding mode
910+
if let Some(&bind_sp) =
911+
self.binding_spans.iter().find(|bind_sp| bind_sp.contains(ident.span))
912+
{
913+
self.ref_pat_for_binding.push((bind_sp, self.ref_pat));
914+
} else {
915+
// we've encountered a binding that we're not reporting a move error for.
916+
// we don't want to change its type, so don't remove the surrounding `&`.
917+
if let Some(ref_pat) = self.ref_pat {
918+
self.cannot_remove.insert(ref_pat.hir_id);
919+
}
896920
}
897921
}
898922
}
@@ -913,10 +937,10 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
913937
binding_spans.push(bind_to.source_info.span);
914938
}
915939
}
916-
let Some(pat_span) = pat_span else { return };
940+
let Some(pat_span) = pat_span else { return Vec::new() };
917941

918942
let tcx = self.infcx.tcx;
919-
let Some(body) = tcx.hir_maybe_body_owned_by(self.mir_def_id()) else { return };
943+
let Some(body) = tcx.hir_maybe_body_owned_by(self.mir_def_id()) else { return Vec::new() };
920944
let typeck_results = self.infcx.tcx.typeck(self.mir_def_id());
921945
let mut finder = BindingFinder {
922946
typeck_results,
@@ -928,6 +952,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
928952
has_adjustments: false,
929953
ref_pat_for_binding: Vec::new(),
930954
cannot_remove: FxHashSet::default(),
955+
desugar_binding_spans: Vec::new(),
931956
};
932957
finder.visit_body(body);
933958

@@ -952,9 +977,15 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
952977
for (span, msg, suggestion) in suggestions {
953978
err.span_suggestion_verbose(span, msg, suggestion, Applicability::MachineApplicable);
954979
}
980+
finder.desugar_binding_spans
955981
}
956982

957-
fn add_move_error_details(&self, err: &mut Diag<'_>, binds_to: &[Local]) {
983+
fn add_move_error_details(
984+
&self,
985+
err: &mut Diag<'_>,
986+
binds_to: &[Local],
987+
desugar_spans: &[Span],
988+
) {
958989
for (j, local) in binds_to.iter().enumerate() {
959990
let bind_to = &self.body.local_decls[*local];
960991
let binding_span = bind_to.source_info.span;
@@ -968,7 +999,11 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
968999
if binds_to.len() == 1 {
9691000
let place_desc = self.local_name(*local).map(|sym| format!("`{sym}`"));
9701001

971-
if let Some(expr) = self.find_expr(binding_span) {
1002+
if !desugar_spans.contains(&binding_span)
1003+
&& let Some(expr) = self.find_expr(binding_span)
1004+
{
1005+
// The binding_span doesn't correspond to a let binding desugaring
1006+
// and is an expression where calling `.clone()` would be valid.
9721007
let local_place: PlaceRef<'tcx> = (*local).into();
9731008
self.suggest_cloning(err, local_place, bind_to.ty, expr, None);
9741009
}

compiler/rustc_codegen_cranelift/patches/0029-sysroot_tests-disable-f16-math.patch

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ index c61961f8584..d7b4fa20322 100644
1919
+ f16: #[cfg(false)], // FIXME(rust-lang/rustc_codegen_cranelift#1622)
2020
f128: #[cfg(all(not(miri), target_has_reliable_f128_math))],
2121
},
22-
test<Float> {
22+
test {
2323
@@ -1557,7 +1557,7 @@ fn s_nan() -> Float {
2424
name: exp,
2525
attrs: {
@@ -28,7 +28,7 @@ index c61961f8584..d7b4fa20322 100644
2828
+ f16: #[cfg(false)], // FIXME(rust-lang/rustc_codegen_cranelift#1622)
2929
f128: #[cfg(all(not(miri), target_has_reliable_f128_math))],
3030
},
31-
test<Float> {
31+
test {
3232
@@ -1578,7 +1578,7 @@ fn s_nan() -> Float {
3333
name: exp2,
3434
attrs: {
@@ -37,7 +37,7 @@ index c61961f8584..d7b4fa20322 100644
3737
+ f16: #[cfg(false)], // FIXME(rust-lang/rustc_codegen_cranelift#1622)
3838
f128: #[cfg(all(not(miri), target_has_reliable_f128_math))],
3939
},
40-
test<Float> {
40+
test {
4141
@@ -1598,7 +1598,7 @@ fn s_nan() -> Float {
4242
name: ln,
4343
attrs: {
@@ -46,7 +46,7 @@ index c61961f8584..d7b4fa20322 100644
4646
+ f16: #[cfg(false)], // FIXME(rust-lang/rustc_codegen_cranelift#1622)
4747
f128: #[cfg(all(not(miri), target_has_reliable_f128_math))],
4848
},
49-
test<Float> {
49+
test {
5050
@@ -1620,7 +1620,7 @@ fn s_nan() -> Float {
5151
name: log,
5252
attrs: {
@@ -55,7 +55,7 @@ index c61961f8584..d7b4fa20322 100644
5555
+ f16: #[cfg(false)], // FIXME(rust-lang/rustc_codegen_cranelift#1622)
5656
f128: #[cfg(all(not(miri), target_has_reliable_f128_math))],
5757
},
58-
test<Float> {
58+
test {
5959
@@ -1645,7 +1645,7 @@ fn s_nan() -> Float {
6060
name: log2,
6161
attrs: {
@@ -64,7 +64,7 @@ index c61961f8584..d7b4fa20322 100644
6464
+ f16: #[cfg(false)], // FIXME(rust-lang/rustc_codegen_cranelift#1622)
6565
f128: #[cfg(all(not(miri), target_has_reliable_f128_math))],
6666
},
67-
test<Float> {
67+
test {
6868
@@ -1668,7 +1668,7 @@ fn s_nan() -> Float {
6969
name: log10,
7070
attrs: {
@@ -73,7 +73,7 @@ index c61961f8584..d7b4fa20322 100644
7373
+ f16: #[cfg(false)], // FIXME(rust-lang/rustc_codegen_cranelift#1622)
7474
f128: #[cfg(all(not(miri), target_has_reliable_f128_math))],
7575
},
76-
test<Float> {
76+
test {
7777
@@ -1692,7 +1692,7 @@ fn s_nan() -> Float {
7878
name: asinh,
7979
attrs: {
@@ -82,7 +82,7 @@ index c61961f8584..d7b4fa20322 100644
8282
+ f16: #[cfg(false)], // FIXME(rust-lang/rustc_codegen_cranelift#1622)
8383
f128: #[cfg(all(not(miri), target_has_reliable_f128_math))],
8484
},
85-
test<Float> {
85+
test {
8686
@@ -1725,7 +1725,7 @@ fn s_nan() -> Float {
8787
name: acosh,
8888
attrs: {
@@ -91,7 +91,7 @@ index c61961f8584..d7b4fa20322 100644
9191
+ f16: #[cfg(false)], // FIXME(rust-lang/rustc_codegen_cranelift#1622)
9292
f128: #[cfg(all(not(miri), target_has_reliable_f128_math))],
9393
},
94-
test<Float> {
94+
test {
9595
@@ -1753,7 +1753,7 @@ fn s_nan() -> Float {
9696
name: atanh,
9797
attrs: {
@@ -100,7 +100,7 @@ index c61961f8584..d7b4fa20322 100644
100100
+ f16: #[cfg(false)], // FIXME(rust-lang/rustc_codegen_cranelift#1622)
101101
f128: #[cfg(all(not(miri), target_has_reliable_f128_math))],
102102
},
103-
test<Float> {
103+
test {
104104
@@ -1779,7 +1779,7 @@ fn s_nan() -> Float {
105105
name: gamma,
106106
attrs: {
@@ -109,7 +109,7 @@ index c61961f8584..d7b4fa20322 100644
109109
+ f16: #[cfg(false)], // FIXME(rust-lang/rustc_codegen_cranelift#1622)
110110
f128: #[cfg(all(not(miri), target_has_reliable_f128_math))],
111111
},
112-
test<Float> {
112+
test {
113113
@@ -1814,7 +1814,7 @@ fn s_nan() -> Float {
114114
name: ln_gamma,
115115
attrs: {
@@ -118,7 +118,7 @@ index c61961f8584..d7b4fa20322 100644
118118
+ f16: #[cfg(false)], // FIXME(rust-lang/rustc_codegen_cranelift#1622)
119119
f128: #[cfg(all(not(miri), target_has_reliable_f128_math))],
120120
},
121-
test<Float> {
121+
test {
122122
@@ -2027,7 +2027,7 @@ fn s_nan() -> Float {
123123
attrs: {
124124
// FIXME(f16_f128): add math tests when available
@@ -127,7 +127,7 @@ index c61961f8584..d7b4fa20322 100644
127127
+ f16: #[cfg(false)], // FIXME(rust-lang/rustc_codegen_cranelift#1622)
128128
f128: #[cfg(all(not(miri), target_has_reliable_f128_math))],
129129
},
130-
test<Float> {
130+
test {
131131
--
132132
2.50.1
133133

0 commit comments

Comments
 (0)