Skip to content

Commit f177b7c

Browse files
committed
Auto merge of rust-lang#109303 - matthiaskrgr:rollup-usj4ef5, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - rust-lang#107416 (Error code E0794 for late-bound lifetime parameter error.) - rust-lang#108772 (Speed up tidy quite a lot) - rust-lang#109193 (Add revisions for -Zlower-impl-trait-in-trait-to-assoc-ty fixed tests) - rust-lang#109234 (Tweak implementation of overflow checking assertions) - rust-lang#109238 (Fix generics mismatch errors for RPITITs on -Zlower-impl-trait-in-trait-to-assoc-ty) - rust-lang#109283 (rustdoc: reduce allocations in `visibility_to_src_with_space`) - rust-lang#109287 (Use `size_of_val` instead of manual calculation) - rust-lang#109288 (Stabilise `unix_socket_abstract`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents df61fca + 49a1528 commit f177b7c

File tree

64 files changed

+760
-313
lines changed

Some content is hidden

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

64 files changed

+760
-313
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ no_llvm_build
4242
/llvm/
4343
/mingw-build/
4444
build/
45+
!/compiler/rustc_mir_build/src/build/
4546
/build-rust-analyzer/
4647
/dist/
4748
/unicode-downloads

Diff for: compiler/rustc_codegen_cranelift/src/base.rs

+4-11
Original file line numberDiff line numberDiff line change
@@ -346,17 +346,10 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
346346
crate::abi::codegen_return(fx);
347347
}
348348
TerminatorKind::Assert { cond, expected, msg, target, cleanup: _ } => {
349-
if !fx.tcx.sess.overflow_checks() {
350-
let overflow_not_to_check = match msg {
351-
AssertKind::OverflowNeg(..) => true,
352-
AssertKind::Overflow(op, ..) => op.is_checkable(),
353-
_ => false,
354-
};
355-
if overflow_not_to_check {
356-
let target = fx.get_block(*target);
357-
fx.bcx.ins().jump(target, &[]);
358-
continue;
359-
}
349+
if !fx.tcx.sess.overflow_checks() && msg.is_optional_overflow_check() {
350+
let target = fx.get_block(*target);
351+
fx.bcx.ins().jump(target, &[]);
352+
continue;
360353
}
361354
let cond = codegen_operand(fx, cond).load_scalar(fx);
362355

Diff for: compiler/rustc_codegen_ssa/src/glue.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub fn size_and_align_of_dst<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
4646
// NOTE: ideally, we want the effects of both `unchecked_smul` and `unchecked_umul`
4747
// (resulting in `mul nsw nuw` in LLVM IR), since we know that the multiplication
4848
// cannot signed wrap, and that both operands are non-negative. But at the time of writing,
49-
// `BuilderMethods` can't do this, and it doesn't seem to enable any further optimizations.
49+
// the `LLVM-C` binding can't do this, and it doesn't seem to enable any further optimizations.
5050
bx.unchecked_smul(info.unwrap(), bx.const_usize(unit.size.bytes())),
5151
bx.const_usize(unit.align.abi.bytes()),
5252
)

Diff for: compiler/rustc_codegen_ssa/src/mir/block.rs

+2-9
Original file line numberDiff line numberDiff line change
@@ -563,15 +563,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
563563
// with #[rustc_inherit_overflow_checks] and inlined from
564564
// another crate (mostly core::num generic/#[inline] fns),
565565
// while the current crate doesn't use overflow checks.
566-
if !bx.cx().check_overflow() {
567-
let overflow_not_to_check = match msg {
568-
AssertKind::OverflowNeg(..) => true,
569-
AssertKind::Overflow(op, ..) => op.is_checkable(),
570-
_ => false,
571-
};
572-
if overflow_not_to_check {
573-
const_cond = Some(expected);
574-
}
566+
if !bx.cx().check_overflow() && msg.is_optional_overflow_check() {
567+
const_cond = Some(expected);
575568
}
576569

577570
// Don't codegen the panic block if success if known.

Diff for: compiler/rustc_const_eval/src/interpret/machine.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ pub trait Machine<'mir, 'tcx>: Sized {
155155

156156
/// Whether Assert(OverflowNeg) and Assert(Overflow) MIR terminators should actually
157157
/// check for overflow.
158-
fn ignore_checkable_overflow_assertions(_ecx: &InterpCx<'mir, 'tcx, Self>) -> bool;
158+
fn ignore_optional_overflow_checks(_ecx: &InterpCx<'mir, 'tcx, Self>) -> bool;
159159

160160
/// Entry point for obtaining the MIR of anything that should get evaluated.
161161
/// So not just functions and shims, but also const/static initializers, anonymous
@@ -474,7 +474,7 @@ pub macro compile_time_machine(<$mir: lifetime, $tcx: lifetime>) {
474474
}
475475

476476
#[inline(always)]
477-
fn ignore_checkable_overflow_assertions(_ecx: &InterpCx<$mir, $tcx, Self>) -> bool {
477+
fn ignore_optional_overflow_checks(_ecx: &InterpCx<$mir, $tcx, Self>) -> bool {
478478
false
479479
}
480480

Diff for: compiler/rustc_const_eval/src/interpret/terminator.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
138138
}
139139

140140
Assert { ref cond, expected, ref msg, target, cleanup } => {
141-
let ignored = M::ignore_checkable_overflow_assertions(self)
142-
&& match msg {
143-
mir::AssertKind::OverflowNeg(..) => true,
144-
mir::AssertKind::Overflow(op, ..) => op.is_checkable(),
145-
_ => false,
146-
};
141+
let ignored =
142+
M::ignore_optional_overflow_checks(self) && msg.is_optional_overflow_check();
147143
let cond_val = self.read_scalar(&self.eval_operand(cond, None)?)?.to_bool()?;
148144
if ignored || expected == cond_val {
149145
self.go_to_block(target);

Diff for: compiler/rustc_error_codes/src/error_codes.rs

+1
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,7 @@ E0790: include_str!("./error_codes/E0790.md"),
513513
E0791: include_str!("./error_codes/E0791.md"),
514514
E0792: include_str!("./error_codes/E0792.md"),
515515
E0793: include_str!("./error_codes/E0793.md"),
516+
E0794: include_str!("./error_codes/E0794.md"),
516517
}
517518

518519
// Undocumented removed error codes. Note that many removed error codes are documented.

Diff for: compiler/rustc_error_codes/src/error_codes/E0794.md

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
A lifetime parameter of a function definition is called *late-bound* if it both:
2+
3+
1. appears in an argument type
4+
2. does not appear in a generic type constraint
5+
6+
You cannot specify lifetime arguments for late-bound lifetime parameters.
7+
8+
Erroneous code example:
9+
10+
```compile_fail,E0794
11+
fn foo<'a>(x: &'a str) -> &'a str { x }
12+
let _ = foo::<'static>;
13+
```
14+
15+
The type of a concrete instance of a generic function is universally quantified
16+
over late-bound lifetime parameters. This is because we want the function to
17+
work for any lifetime substituted for the late-bound lifetime parameter, no
18+
matter where the function is called. Consequently, it doesn't make sense to
19+
specify arguments for late-bound lifetime parameters, since they are not
20+
resolved until the function's call site(s).
21+
22+
To fix the issue, remove the specified lifetime:
23+
24+
```
25+
fn foo<'a>(x: &'a str) -> &'a str { x }
26+
let _ = foo;
27+
```
28+
29+
### Additional information
30+
31+
Lifetime parameters that are not late-bound are called *early-bound*.
32+
Confusion may arise from the fact that late-bound and early-bound
33+
lifetime parameters are declared the same way in function definitions.
34+
When referring to a function pointer type, universal quantification over
35+
late-bound lifetime parameters can be made explicit:
36+
37+
```
38+
trait BarTrait<'a> {}
39+
40+
struct Bar<'a> {
41+
s: &'a str
42+
}
43+
44+
impl<'a> BarTrait<'a> for Bar<'a> {}
45+
46+
fn bar<'a, 'b, T>(x: &'a str, _t: T) -> &'a str
47+
where T: BarTrait<'b>
48+
{
49+
x
50+
}
51+
52+
let bar_fn: for<'a> fn(&'a str, Bar<'static>) -> &'a str = bar; // OK
53+
let bar_fn2 = bar::<'static, Bar>; // Not allowed
54+
let bar_fn3 = bar::<Bar>; // OK
55+
```
56+
57+
In the definition of `bar`, the lifetime parameter `'a` is late-bound, while
58+
`'b` is early-bound. This is reflected in the type annotation for `bar_fn`,
59+
where `'a` is universally quantified and `'b` is substituted by a specific
60+
lifetime. It is not allowed to explicitly specify early-bound lifetime
61+
arguments when late-bound lifetime parameters are present (as for `bar_fn2`,
62+
see issue #42868: https://github.com/rust-lang/rust/issues/42868), although the
63+
types that are constrained by early-bound parameters can be specified (as for
64+
`bar_fn3`).

Diff for: compiler/rustc_hir_analysis/src/astconv/generics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ pub(crate) fn prohibit_explicit_late_bound_lifetimes(
612612
if position == GenericArgPosition::Value
613613
&& args.num_lifetime_params() != param_counts.lifetimes
614614
{
615-
let mut err = tcx.sess.struct_span_err(span, msg);
615+
let mut err = struct_span_err!(tcx.sess, span, E0794, "{}", msg);
616616
err.span_note(span_late, note);
617617
err.emit();
618618
} else {

Diff for: compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

+11
Original file line numberDiff line numberDiff line change
@@ -1205,6 +1205,17 @@ fn compare_number_of_generics<'tcx>(
12051205
return Ok(());
12061206
}
12071207

1208+
// We never need to emit a separate error for RPITITs, since if an RPITIT
1209+
// has mismatched type or const generic arguments, then the method that it's
1210+
// inheriting the generics from will also have mismatched arguments, and
1211+
// we'll report an error for that instead. Delay a bug for safety, though.
1212+
if tcx.opt_rpitit_info(trait_.def_id).is_some() {
1213+
return Err(tcx.sess.delay_span_bug(
1214+
rustc_span::DUMMY_SP,
1215+
"errors comparing numbers of generics of trait/impl functions were not emitted",
1216+
));
1217+
}
1218+
12081219
let matchings = [
12091220
("type", trait_own_counts.types, impl_own_counts.types),
12101221
("const", trait_own_counts.consts, impl_own_counts.consts),

Diff for: compiler/rustc_middle/src/mir/mod.rs

+7-10
Original file line numberDiff line numberDiff line change
@@ -1268,6 +1268,13 @@ impl<'tcx> BasicBlockData<'tcx> {
12681268
}
12691269

12701270
impl<O> AssertKind<O> {
1271+
/// Returns true if this an overflow checking assertion controlled by -C overflow-checks.
1272+
pub fn is_optional_overflow_check(&self) -> bool {
1273+
use AssertKind::*;
1274+
use BinOp::*;
1275+
matches!(self, OverflowNeg(..) | Overflow(Add | Sub | Mul | Shl | Shr, ..))
1276+
}
1277+
12711278
/// Getting a description does not require `O` to be printable, and does not
12721279
/// require allocation.
12731280
/// The caller is expected to handle `BoundsCheck` separately.
@@ -1992,16 +1999,6 @@ impl BorrowKind {
19921999
}
19932000
}
19942001

1995-
impl BinOp {
1996-
/// The checkable operators are those whose overflow checking behavior is controlled by
1997-
/// -Coverflow-checks option. The remaining operators have either no overflow conditions (e.g.,
1998-
/// BitAnd, BitOr, BitXor) or are always checked for overflow (e.g., Div, Rem).
1999-
pub fn is_checkable(self) -> bool {
2000-
use self::BinOp::*;
2001-
matches!(self, Add | Sub | Mul | Shl | Shr)
2002-
}
2003-
}
2004-
20052002
impl<'tcx> Debug for Rvalue<'tcx> {
20062003
fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result {
20072004
use self::Rvalue::*;

Diff for: compiler/rustc_middle/src/mir/syntax.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -646,8 +646,7 @@ pub enum TerminatorKind<'tcx> {
646646
/// When overflow checking is disabled and this is run-time MIR (as opposed to compile-time MIR
647647
/// that is used for CTFE), the following variants of this terminator behave as `goto target`:
648648
/// - `OverflowNeg(..)`,
649-
/// - `Overflow(op, ..)` if op is a "checkable" operation (add, sub, mul, shl, shr, but NOT
650-
/// div or rem).
649+
/// - `Overflow(op, ..)` if op is add, sub, mul, shl, shr, but NOT div or rem.
651650
Assert {
652651
cond: Operand<'tcx>,
653652
expected: bool,

Diff for: compiler/rustc_mir_build/src/build/expr/as_rvalue.rs

+35-12
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,34 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
7373
}
7474
ExprKind::Binary { op, lhs, rhs } => {
7575
let lhs = unpack!(
76-
block =
77-
this.as_operand(block, scope, &this.thir[lhs], LocalInfo::Boring, NeedsTemporary::Maybe)
76+
block = this.as_operand(
77+
block,
78+
scope,
79+
&this.thir[lhs],
80+
LocalInfo::Boring,
81+
NeedsTemporary::Maybe
82+
)
7883
);
7984
let rhs = unpack!(
80-
block =
81-
this.as_operand(block, scope, &this.thir[rhs], LocalInfo::Boring, NeedsTemporary::No)
85+
block = this.as_operand(
86+
block,
87+
scope,
88+
&this.thir[rhs],
89+
LocalInfo::Boring,
90+
NeedsTemporary::No
91+
)
8292
);
8393
this.build_binary_op(block, op, expr_span, expr.ty, lhs, rhs)
8494
}
8595
ExprKind::Unary { op, arg } => {
8696
let arg = unpack!(
87-
block =
88-
this.as_operand(block, scope, &this.thir[arg], LocalInfo::Boring, NeedsTemporary::No)
97+
block = this.as_operand(
98+
block,
99+
scope,
100+
&this.thir[arg],
101+
LocalInfo::Boring,
102+
NeedsTemporary::No
103+
)
89104
);
90105
// Check for -MIN on signed integers
91106
if this.check_overflow && op == UnOp::Neg && expr.ty.is_signed() {
@@ -272,8 +287,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
272287
}
273288
ExprKind::Pointer { cast, source } => {
274289
let source = unpack!(
275-
block =
276-
this.as_operand(block, scope, &this.thir[source], LocalInfo::Boring, NeedsTemporary::No)
290+
block = this.as_operand(
291+
block,
292+
scope,
293+
&this.thir[source],
294+
LocalInfo::Boring,
295+
NeedsTemporary::No
296+
)
277297
);
278298
block.and(Rvalue::Cast(CastKind::Pointer(cast), source, expr.ty))
279299
}
@@ -502,8 +522,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
502522
Category::of(&expr.kind),
503523
Some(Category::Rvalue(RvalueFunc::AsRvalue) | Category::Constant)
504524
));
505-
let operand =
506-
unpack!(block = this.as_operand(block, scope, expr, LocalInfo::Boring, NeedsTemporary::No));
525+
let operand = unpack!(
526+
block =
527+
this.as_operand(block, scope, expr, LocalInfo::Boring, NeedsTemporary::No)
528+
);
507529
block.and(Rvalue::Use(operand))
508530
}
509531
}
@@ -662,8 +684,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
662684
// Repeating a const does nothing
663685
} else {
664686
// For a non-const, we may need to generate an appropriate `Drop`
665-
let value_operand =
666-
unpack!(block = this.as_operand(block, scope, value, LocalInfo::Boring, NeedsTemporary::No));
687+
let value_operand = unpack!(
688+
block = this.as_operand(block, scope, value, LocalInfo::Boring, NeedsTemporary::No)
689+
);
667690
if let Operand::Move(to_drop) = value_operand {
668691
let success = this.cfg.start_new_block();
669692
this.cfg.terminate(

Diff for: compiler/rustc_mir_build/src/build/matches/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -2252,7 +2252,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
22522252
user_ty: None,
22532253
source_info,
22542254
internal: false,
2255-
local_info: ClearCrossCrate::Set(Box::new(LocalInfo::User(BindingForm::RefForGuard))),
2255+
local_info: ClearCrossCrate::Set(Box::new(LocalInfo::User(
2256+
BindingForm::RefForGuard,
2257+
))),
22562258
});
22572259
self.var_debug_info.push(VarDebugInfo {
22582260
name,

Diff for: compiler/rustc_mir_build/src/build/mod.rs

+8-11
Original file line numberDiff line numberDiff line change
@@ -876,21 +876,18 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
876876
} => {
877877
self.local_decls[local].mutability = mutability;
878878
self.local_decls[local].source_info.scope = self.source_scope;
879-
**self.local_decls[local].local_info.as_mut().assert_crate_local() = if let Some(kind) = param.self_kind {
880-
LocalInfo::User(
881-
BindingForm::ImplicitSelf(kind),
882-
)
883-
} else {
884-
let binding_mode = ty::BindingMode::BindByValue(mutability);
885-
LocalInfo::User(BindingForm::Var(
886-
VarBindingForm {
879+
**self.local_decls[local].local_info.as_mut().assert_crate_local() =
880+
if let Some(kind) = param.self_kind {
881+
LocalInfo::User(BindingForm::ImplicitSelf(kind))
882+
} else {
883+
let binding_mode = ty::BindingMode::BindByValue(mutability);
884+
LocalInfo::User(BindingForm::Var(VarBindingForm {
887885
binding_mode,
888886
opt_ty_info: param.ty_span,
889887
opt_match_place: Some((None, span)),
890888
pat_span: span,
891-
},
892-
))
893-
};
889+
}))
890+
};
894891
self.var_indices.insert(var, LocalsForNode::One(local));
895892
}
896893
_ => {

Diff for: library/core/src/hash/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,7 @@ mod impls {
834834

835835
#[inline]
836836
fn hash_slice<H: ~const Hasher>(data: &[$ty], state: &mut H) {
837-
let newlen = data.len() * mem::size_of::<$ty>();
837+
let newlen = mem::size_of_val(data);
838838
let ptr = data.as_ptr() as *const u8;
839839
// SAFETY: `ptr` is valid and aligned, as this macro is only used
840840
// for numeric primitives which have no padding. The new slice only

Diff for: library/std/src/os/android/net.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//! Android-specific networking functionality.
22
3-
#![unstable(feature = "tcp_quickack", issue = "96256")]
3+
#![stable(feature = "unix_socket_abstract", since = "CURRENT_RUSTC_VERSION")]
44

5-
#[unstable(feature = "unix_socket_abstract", issue = "85410")]
5+
#[stable(feature = "unix_socket_abstract", since = "CURRENT_RUSTC_VERSION")]
66
pub use crate::os::net::linux_ext::addr::SocketAddrExt;
77

88
#[unstable(feature = "tcp_quickack", issue = "96256")]

Diff for: library/std/src/os/linux/net.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//! Linux-specific networking functionality.
22
3-
#![unstable(feature = "tcp_quickack", issue = "96256")]
3+
#![stable(feature = "unix_socket_abstract", since = "CURRENT_RUSTC_VERSION")]
44

5-
#[unstable(feature = "unix_socket_abstract", issue = "85410")]
5+
#[stable(feature = "unix_socket_abstract", since = "CURRENT_RUSTC_VERSION")]
66
pub use crate::os::net::linux_ext::addr::SocketAddrExt;
77

88
#[unstable(feature = "tcp_quickack", issue = "96256")]

0 commit comments

Comments
 (0)