Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on May 28, 2025. It is now read-only.

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

‎.gitignore‎

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

‎compiler/rustc_codegen_cranelift/src/base.rs‎

Lines changed: 4 additions & 11 deletions
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

‎compiler/rustc_codegen_ssa/src/glue.rs‎

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

‎compiler/rustc_codegen_ssa/src/mir/block.rs‎

Lines changed: 2 additions & 9 deletions
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.

‎compiler/rustc_const_eval/src/interpret/machine.rs‎

Lines changed: 2 additions & 2 deletions
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

‎compiler/rustc_const_eval/src/interpret/terminator.rs‎

Lines changed: 2 additions & 6 deletions
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);

‎compiler/rustc_error_codes/src/error_codes.rs‎

Lines changed: 1 addition & 0 deletions
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.
Lines changed: 64 additions & 0 deletions
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`).

‎compiler/rustc_hir_analysis/src/astconv/generics.rs‎

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

‎compiler/rustc_hir_analysis/src/check/compare_impl_item.rs‎

Lines changed: 11 additions & 0 deletions
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),

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /