Skip to content

Commit 6292b2a

Browse files
committed
Auto merge of #127244 - matthiaskrgr:rollup-px1vahe, r=matthiaskrgr
Rollup of 10 pull requests Successful merges: - #126883 (Parenthesize break values containing leading label) - #127136 (Fix `FnMut::call_mut`/`Fn::call` shim for async closures that capture references) - #127146 (Uplift fast rejection to new solver) - #127152 (Bootstrap: Try renaming the file if removing fails) - #127168 (Use the aligned size for alloca at args/ret when the pass mode is cast) - #127203 (Fix import suggestion error when path segment failed not from starting) - #127212 (Update books) - #127224 (Make `FloatTy` checks exhaustive in pretty print) - #127230 (chore: remove duplicate words) - #127243 (Add test for adt_const_params) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 49ff390 + 6407580 commit 6292b2a

File tree

79 files changed

+1301
-546
lines changed

Some content is hidden

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

79 files changed

+1301
-546
lines changed

compiler/rustc_ast/src/util/classify.rs

+78-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
//! Routines the parser and pretty-printer use to classify AST nodes.
22
33
use crate::ast::ExprKind::*;
4-
use crate::{ast, token::Delimiter};
4+
use crate::ast::{self, MatchKind};
5+
use crate::token::Delimiter;
56

67
/// This classification determines whether various syntactic positions break out
78
/// of parsing the current expression (true) or continue parsing more of the
@@ -81,6 +82,82 @@ pub fn expr_requires_semi_to_be_stmt(e: &ast::Expr) -> bool {
8182
}
8283
}
8384

85+
/// Returns whether the leftmost token of the given expression is the label of a
86+
/// labeled loop or block, such as in `'inner: loop { break 'inner 1 } + 1`.
87+
///
88+
/// Such expressions are not allowed as the value of an unlabeled break.
89+
///
90+
/// ```ignore (illustrative)
91+
/// 'outer: {
92+
/// break 'inner: loop { break 'inner 1 } + 1; // invalid syntax
93+
///
94+
/// break 'outer 'inner: loop { break 'inner 1 } + 1; // okay
95+
///
96+
/// break ('inner: loop { break 'inner 1 } + 1); // okay
97+
///
98+
/// break ('inner: loop { break 'inner 1 }) + 1; // okay
99+
/// }
100+
/// ```
101+
pub fn leading_labeled_expr(mut expr: &ast::Expr) -> bool {
102+
loop {
103+
match &expr.kind {
104+
Block(_, label) | ForLoop { label, .. } | Loop(_, label, _) | While(_, _, label) => {
105+
return label.is_some();
106+
}
107+
108+
Assign(e, _, _)
109+
| AssignOp(_, e, _)
110+
| Await(e, _)
111+
| Binary(_, e, _)
112+
| Call(e, _)
113+
| Cast(e, _)
114+
| Field(e, _)
115+
| Index(e, _, _)
116+
| Match(e, _, MatchKind::Postfix)
117+
| Range(Some(e), _, _)
118+
| Try(e) => {
119+
expr = e;
120+
}
121+
MethodCall(method_call) => {
122+
expr = &method_call.receiver;
123+
}
124+
125+
AddrOf(..)
126+
| Array(..)
127+
| Become(..)
128+
| Break(..)
129+
| Closure(..)
130+
| ConstBlock(..)
131+
| Continue(..)
132+
| FormatArgs(..)
133+
| Gen(..)
134+
| If(..)
135+
| IncludedBytes(..)
136+
| InlineAsm(..)
137+
| Let(..)
138+
| Lit(..)
139+
| MacCall(..)
140+
| Match(_, _, MatchKind::Prefix)
141+
| OffsetOf(..)
142+
| Paren(..)
143+
| Path(..)
144+
| Range(None, _, _)
145+
| Repeat(..)
146+
| Ret(..)
147+
| Struct(..)
148+
| TryBlock(..)
149+
| Tup(..)
150+
| Type(..)
151+
| Unary(..)
152+
| Underscore
153+
| Yeet(..)
154+
| Yield(..)
155+
| Err(..)
156+
| Dummy => return false,
157+
}
158+
}
159+
}
160+
84161
pub enum TrailingBrace<'a> {
85162
/// Trailing brace in a macro call, like the one in `x as *const brace! {}`.
86163
/// We will suggest changing the macro call to a different delimiter.

compiler/rustc_ast_pretty/src/pprust/state/expr.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use ast::{ForLoopKind, MatchKind};
55
use itertools::{Itertools, Position};
66
use rustc_ast::ptr::P;
77
use rustc_ast::token;
8+
use rustc_ast::util::classify;
89
use rustc_ast::util::literal::escape_byte_str_symbol;
910
use rustc_ast::util::parser::{self, AssocOp, Fixity};
1011
use rustc_ast::{self as ast, BlockCheckMode};
@@ -610,9 +611,12 @@ impl<'a> State<'a> {
610611
}
611612
if let Some(expr) = opt_expr {
612613
self.space();
613-
self.print_expr_maybe_paren(
614+
self.print_expr_cond_paren(
614615
expr,
615-
parser::PREC_JUMP,
616+
// Parenthesize if required by precedence, or in the
617+
// case of `break 'inner: loop { break 'inner 1 } + 1`
618+
expr.precedence().order() < parser::PREC_JUMP
619+
|| (opt_label.is_none() && classify::leading_labeled_expr(expr)),
616620
fixup.subsequent_subexpression(),
617621
);
618622
}

compiler/rustc_codegen_llvm/src/abi.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,8 @@ impl<'ll, 'tcx> ArgAbiExt<'ll, 'tcx> for ArgAbi<'tcx, Ty<'tcx>> {
226226
// when passed by value, making it smaller.
227227
// - On some ABIs, the Rust layout { u16, u16, u16 } may be padded up to 8 bytes
228228
// when passed by value, making it larger.
229-
let copy_bytes = cmp::min(scratch_size.bytes(), self.layout.size.bytes());
229+
let copy_bytes =
230+
cmp::min(cast.unaligned_size(bx).bytes(), self.layout.size.bytes());
230231
// Allocate some scratch space...
231232
let llscratch = bx.alloca(scratch_size, scratch_align);
232233
bx.lifetime_start(llscratch, scratch_size);

compiler/rustc_codegen_ssa/src/mir/block.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
403403
//
404404
// Why only in unoptimized builds?
405405
// - In unoptimized builds LLVM uses FastISel which does not support switches, so it
406-
// must fall back to the to the slower SelectionDAG isel. Therefore, using `br` gives
406+
// must fall back to the slower SelectionDAG isel. Therefore, using `br` gives
407407
// significant compile time speedups for unoptimized builds.
408408
// - In optimized builds the above doesn't hold, and using `br` sometimes results in
409409
// worse generated code because LLVM can no longer tell that the value being switched
@@ -1521,7 +1521,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
15211521
// when passed by value, making it smaller.
15221522
// - On some ABIs, the Rust layout { u16, u16, u16 } may be padded up to 8 bytes
15231523
// when passed by value, making it larger.
1524-
let copy_bytes = cmp::min(scratch_size.bytes(), arg.layout.size.bytes());
1524+
let copy_bytes = cmp::min(cast.unaligned_size(bx).bytes(), arg.layout.size.bytes());
15251525
// Allocate some scratch space...
15261526
let llscratch = bx.alloca(scratch_size, scratch_align);
15271527
bx.lifetime_start(llscratch, scratch_size);

compiler/rustc_codegen_ssa/src/mir/locals.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
4747
let expected_ty = self.monomorphize(self.mir.local_decls[local].ty);
4848
if expected_ty != op.layout.ty {
4949
warn!(
50-
"Unexpected initial operand type: expected {expected_ty:?}, found {:?}.\
50+
"Unexpected initial operand type:\nexpected {expected_ty:?},\nfound {:?}.\n\
5151
See <https://github.com/rust-lang/rust/issues/114858>.",
5252
op.layout.ty
5353
);

compiler/rustc_codegen_ssa/src/mir/mod.rs

+14-4
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,20 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
230230
let layout = start_bx.layout_of(fx.monomorphize(decl.ty));
231231
assert!(!layout.ty.has_erasable_regions());
232232

233-
if local == mir::RETURN_PLACE && fx.fn_abi.ret.is_indirect() {
234-
debug!("alloc: {:?} (return place) -> place", local);
235-
let llretptr = start_bx.get_param(0);
236-
return LocalRef::Place(PlaceRef::new_sized(llretptr, layout));
233+
if local == mir::RETURN_PLACE {
234+
match fx.fn_abi.ret.mode {
235+
PassMode::Indirect { .. } => {
236+
debug!("alloc: {:?} (return place) -> place", local);
237+
let llretptr = start_bx.get_param(0);
238+
return LocalRef::Place(PlaceRef::new_sized(llretptr, layout));
239+
}
240+
PassMode::Cast { ref cast, .. } => {
241+
debug!("alloc: {:?} (return place) -> place", local);
242+
let size = cast.size(&start_bx);
243+
return LocalRef::Place(PlaceRef::alloca_size(&mut start_bx, size, layout));
244+
}
245+
_ => {}
246+
};
237247
}
238248

239249
if memory_locals.contains(local) {

compiler/rustc_codegen_ssa/src/mir/place.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,17 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> {
108108
pub fn alloca<Bx: BuilderMethods<'a, 'tcx, Value = V>>(
109109
bx: &mut Bx,
110110
layout: TyAndLayout<'tcx>,
111+
) -> Self {
112+
Self::alloca_size(bx, layout.size, layout)
113+
}
114+
115+
pub fn alloca_size<Bx: BuilderMethods<'a, 'tcx, Value = V>>(
116+
bx: &mut Bx,
117+
size: Size,
118+
layout: TyAndLayout<'tcx>,
111119
) -> Self {
112120
assert!(layout.is_sized(), "tried to statically allocate unsized place");
113-
PlaceValue::alloca(bx, layout.size, layout.align.abi).with_type(layout)
121+
PlaceValue::alloca(bx, size, layout.align.abi).with_type(layout)
114122
}
115123

116124
/// Returns a place for an indirect reference to an unsized place.

compiler/rustc_const_eval/src/interpret/discriminant.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
245245
// The tag of a `Single` enum is like the tag of the niched
246246
// variant: there's no tag as the discriminant is encoded
247247
// entirely implicitly. If `write_discriminant` ever hits this
248-
// case, we do a "validation read" to ensure the the right
248+
// case, we do a "validation read" to ensure the right
249249
// discriminant is encoded implicitly, so any attempt to write
250250
// the wrong discriminant for a `Single` enum will reliably
251251
// result in UB.

compiler/rustc_hir_typeck/src/method/suggest.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
499499
}
500500
}
501501

502-
// If the shadowed binding has an an itializer expression,
502+
// If the shadowed binding has an itializer expression,
503503
// use the initializer expression'ty to try to find the method again.
504504
// For example like: `let mut x = Vec::new();`,
505505
// `Vec::new()` is the itializer expression.
@@ -968,7 +968,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
968968
}
969969

970970
// Make sure that, if any traits other than the found ones were involved,
971-
// we don't don't report an unimplemented trait.
971+
// we don't report an unimplemented trait.
972972
// We don't want to say that `iter::Cloned` is not an iterator, just
973973
// because of some non-Clone item being iterated over.
974974
for (predicate, _parent_pred, _cause) in unsatisfied_predicates {
@@ -2129,7 +2129,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
21292129
let target_ty = self
21302130
.autoderef(sugg_span, rcvr_ty)
21312131
.find(|(rcvr_ty, _)| {
2132-
DeepRejectCtxt { treat_obligation_params: TreatParams::AsCandidateKey }
2132+
DeepRejectCtxt::new(self.tcx, TreatParams::ForLookup)
21332133
.types_may_unify(*rcvr_ty, impl_ty)
21342134
})
21352135
.map_or(impl_ty, |(ty, _)| ty)

compiler/rustc_middle/src/ty/closure.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ impl<'tcx> TyCtxt<'tcx> {
237237
/// Eg: 1. `foo.x` which is represented using `projections=[Field(x)]` is an ancestor of
238238
/// `foo.x.y` which is represented using `projections=[Field(x), Field(y)]`.
239239
/// Note both `foo.x` and `foo.x.y` start off of the same root variable `foo`.
240-
/// 2. Since we only look at the projections here function will return `bar.x` as an a valid
240+
/// 2. Since we only look at the projections here function will return `bar.x` as a valid
241241
/// ancestor of `foo.x.y`. It's the caller's responsibility to ensure that both projections
242242
/// list are being applied to the same root variable.
243243
pub fn is_ancestor_or_same_capture(

compiler/rustc_middle/src/ty/context.rs

-11
Original file line numberDiff line numberDiff line change
@@ -373,17 +373,6 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
373373
.map(|assoc_item| assoc_item.def_id)
374374
}
375375

376-
fn args_may_unify_deep(
377-
self,
378-
obligation_args: ty::GenericArgsRef<'tcx>,
379-
impl_args: ty::GenericArgsRef<'tcx>,
380-
) -> bool {
381-
ty::fast_reject::DeepRejectCtxt {
382-
treat_obligation_params: ty::fast_reject::TreatParams::ForLookup,
383-
}
384-
.args_may_unify(obligation_args, impl_args)
385-
}
386-
387376
// This implementation is a bit different from `TyCtxt::for_each_relevant_impl`,
388377
// since we want to skip over blanket impls for non-rigid aliases, and also we
389378
// only want to consider types that *actually* unify with float/int vars.

0 commit comments

Comments
 (0)