Skip to content

Commit 529bb25

Browse files
committed
Auto merge of #125593 - workingjubilee:rollup-67qk7di, r=workingjubilee
Rollup of 8 pull requests Successful merges: - #124048 (Support C23's Variadics Without a Named Parameter) - #125046 (Only allow immutable statics with #[linkage]) - #125466 (Don't continue probing for method if in suggestion and autoderef hits ambiguity) - #125469 (Don't skip out of inner const when looking for body for suggestion) - #125544 (Also mention my-self for other check-cfg docs changes) - #125559 (Simplify the `unchecked_sh[lr]` ub-checks a bit) - #125566 (Notify T-rustdoc for beta-accepted and stable-accepted too) - #125582 (Avoid a `FieldIdx::from_usize` in InstSimplify) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 0aad3f6 + 4ff7869 commit 529bb25

26 files changed

+185
-139
lines changed

compiler/rustc_ast_passes/messages.ftl

-3
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,6 @@ ast_passes_fn_body_extern = incorrect function inside `extern` block
9292
ast_passes_fn_param_c_var_args_not_last =
9393
`...` must be the last argument of a C-variadic function
9494
95-
ast_passes_fn_param_c_var_args_only =
96-
C-variadic function must be declared with at least one named argument
97-
9895
ast_passes_fn_param_doc_comment =
9996
documentation comments cannot be applied to function parameters
10097
.label = doc comments are not allowed here

compiler/rustc_ast_passes/src/ast_validation.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ impl<'a> AstValidator<'a> {
364364

365365
fn check_fn_decl(&self, fn_decl: &FnDecl, self_semantic: SelfSemantic) {
366366
self.check_decl_num_args(fn_decl);
367-
self.check_decl_cvaradic_pos(fn_decl);
367+
self.check_decl_cvariadic_pos(fn_decl);
368368
self.check_decl_attrs(fn_decl);
369369
self.check_decl_self_param(fn_decl, self_semantic);
370370
}
@@ -379,13 +379,11 @@ impl<'a> AstValidator<'a> {
379379
}
380380
}
381381

382-
fn check_decl_cvaradic_pos(&self, fn_decl: &FnDecl) {
382+
/// Emits an error if a function declaration has a variadic parameter in the
383+
/// beginning or middle of parameter list.
384+
/// Example: `fn foo(..., x: i32)` will emit an error.
385+
fn check_decl_cvariadic_pos(&self, fn_decl: &FnDecl) {
383386
match &*fn_decl.inputs {
384-
[Param { ty, span, .. }] => {
385-
if let TyKind::CVarArgs = ty.kind {
386-
self.dcx().emit_err(errors::FnParamCVarArgsOnly { span: *span });
387-
}
388-
}
389387
[ps @ .., _] => {
390388
for Param { ty, span, .. } in ps {
391389
if let TyKind::CVarArgs = ty.kind {

compiler/rustc_ast_passes/src/errors.rs

-7
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,6 @@ pub struct FnParamTooMany {
9292
pub max_num_args: usize,
9393
}
9494

95-
#[derive(Diagnostic)]
96-
#[diag(ast_passes_fn_param_c_var_args_only)]
97-
pub struct FnParamCVarArgsOnly {
98-
#[primary_span]
99-
pub span: Span,
100-
}
101-
10295
#[derive(Diagnostic)]
10396
#[diag(ast_passes_fn_param_c_var_args_not_last)]
10497
pub struct FnParamCVarArgsNotLast {

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

+12
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,18 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
327327
} else {
328328
codegen_fn_attrs.linkage = linkage;
329329
}
330+
if tcx.is_mutable_static(did.into()) {
331+
let mut diag = tcx.dcx().struct_span_err(
332+
attr.span,
333+
"mutable statics are not allowed with `#[linkage]`",
334+
);
335+
diag.note(
336+
"making the static mutable would allow changing which symbol the \
337+
static references rather than make the target of the symbol \
338+
mutable",
339+
);
340+
diag.emit();
341+
}
330342
}
331343
}
332344
sym::link_section => {

compiler/rustc_hir_typeck/src/coercion.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -1871,11 +1871,8 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
18711871
// If this is due to a block, then maybe we forgot a `return`/`break`.
18721872
if due_to_block
18731873
&& let Some(expr) = expression
1874-
&& let Some((parent_fn_decl, parent_id)) = fcx
1875-
.tcx
1876-
.hir()
1877-
.parent_iter(block_or_return_id)
1878-
.find_map(|(_, node)| Some((node.fn_decl()?, node.associated_body()?.0)))
1874+
&& let Some(parent_fn_decl) =
1875+
fcx.tcx.hir().fn_decl_by_hir_id(fcx.tcx.local_def_id_to_hir_id(fcx.body_id))
18791876
{
18801877
fcx.suggest_missing_break_or_return_expr(
18811878
&mut err,
@@ -1884,7 +1881,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
18841881
expected,
18851882
found,
18861883
block_or_return_id,
1887-
parent_id,
1884+
fcx.body_id,
18881885
);
18891886
}
18901887

compiler/rustc_hir_typeck/src/method/probe.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -395,8 +395,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
395395
// ambiguous.
396396
if let Some(bad_ty) = &steps.opt_bad_ty {
397397
if is_suggestion.0 {
398-
// Ambiguity was encountered during a suggestion. Just keep going.
399-
debug!("ProbeContext: encountered ambiguity in suggestion");
398+
// Ambiguity was encountered during a suggestion. There's really
399+
// not much use in suggesting methods in this case.
400+
return Err(MethodError::NoMatch(NoMatchData {
401+
static_candidates: Vec::new(),
402+
unsatisfied_predicates: Vec::new(),
403+
out_of_scope_traits: Vec::new(),
404+
similar_candidate: None,
405+
mode,
406+
}));
400407
} else if bad_ty.reached_raw_pointer
401408
&& !self.tcx.features().arbitrary_self_types
402409
&& !self.tcx.sess.at_least_rust_2018()

compiler/rustc_mir_transform/src/dataflow_const_prop.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,10 @@ impl<'tcx> ValueAnalysis<'tcx> for ConstAnalysis<'_, 'tcx> {
142142
_ => return,
143143
};
144144
if let Some(variant_target_idx) = variant_target {
145-
for (field_index, operand) in operands.iter().enumerate() {
145+
for (field_index, operand) in operands.iter_enumerated() {
146146
if let Some(field) = self.map().apply(
147147
variant_target_idx,
148-
TrackElem::Field(FieldIdx::from_usize(field_index)),
148+
TrackElem::Field(field_index),
149149
) {
150150
self.assign_operand(state, field, operand);
151151
}

compiler/rustc_mir_transform/src/instsimplify.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use rustc_middle::ty::layout::ValidityRequirement;
99
use rustc_middle::ty::{self, GenericArgsRef, ParamEnv, Ty, TyCtxt};
1010
use rustc_span::sym;
1111
use rustc_span::symbol::Symbol;
12-
use rustc_target::abi::FieldIdx;
1312
use rustc_target::spec::abi::Abi;
1413

1514
pub struct InstSimplify;
@@ -217,11 +216,11 @@ impl<'tcx> InstSimplifyContext<'tcx, '_> {
217216
&& let Some(place) = operand.place()
218217
{
219218
let variant = adt_def.non_enum_variant();
220-
for (i, field) in variant.fields.iter().enumerate() {
219+
for (i, field) in variant.fields.iter_enumerated() {
221220
let field_ty = field.ty(self.tcx, args);
222221
if field_ty == *cast_ty {
223222
let place = place.project_deeper(
224-
&[ProjectionElem::Field(FieldIdx::from_usize(i), *cast_ty)],
223+
&[ProjectionElem::Field(i, *cast_ty)],
225224
self.tcx,
226225
);
227226
let operand = if operand.is_move() {

library/core/src/num/int_macros.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1282,8 +1282,7 @@ macro_rules! int_impl {
12821282
concat!(stringify!($SelfT), "::unchecked_shl cannot overflow"),
12831283
(
12841284
rhs: u32 = rhs,
1285-
bits: u32 = Self::BITS,
1286-
) => rhs < bits,
1285+
) => rhs < <$ActualT>::BITS,
12871286
);
12881287

12891288
// SAFETY: this is guaranteed to be safe by the caller.
@@ -1381,8 +1380,7 @@ macro_rules! int_impl {
13811380
concat!(stringify!($SelfT), "::unchecked_shr cannot overflow"),
13821381
(
13831382
rhs: u32 = rhs,
1384-
bits: u32 = Self::BITS,
1385-
) => rhs < bits,
1383+
) => rhs < <$ActualT>::BITS,
13861384
);
13871385

13881386
// SAFETY: this is guaranteed to be safe by the caller.

library/core/src/num/uint_macros.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1369,8 +1369,7 @@ macro_rules! uint_impl {
13691369
concat!(stringify!($SelfT), "::unchecked_shl cannot overflow"),
13701370
(
13711371
rhs: u32 = rhs,
1372-
bits: u32 = Self::BITS,
1373-
) => rhs < bits,
1372+
) => rhs < <$ActualT>::BITS,
13741373
);
13751374

13761375
// SAFETY: this is guaranteed to be safe by the caller.
@@ -1468,8 +1467,7 @@ macro_rules! uint_impl {
14681467
concat!(stringify!($SelfT), "::unchecked_shr cannot overflow"),
14691468
(
14701469
rhs: u32 = rhs,
1471-
bits: u32 = Self::BITS,
1472-
) => rhs < bits,
1470+
) => rhs < <$ActualT>::BITS,
14731471
);
14741472

14751473
// SAFETY: this is guaranteed to be safe by the caller.

tests/mir-opt/inline/unchecked_shifts.unchecked_shl_unsigned_smaller.Inline.panic-abort.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
}
3030

3131
bb1: {
32-
+ _6 = core::num::<impl u16>::unchecked_shl::precondition_check(_4, const core::num::<impl u16>::BITS) -> [return: bb2, unwind unreachable];
32+
+ _6 = core::num::<impl u16>::unchecked_shl::precondition_check(_4) -> [return: bb2, unwind unreachable];
3333
+ }
3434
+
3535
+ bb2: {

tests/mir-opt/inline/unchecked_shifts.unchecked_shl_unsigned_smaller.Inline.panic-unwind.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
}
3030

3131
bb1: {
32-
+ _6 = core::num::<impl u16>::unchecked_shl::precondition_check(_4, const core::num::<impl u16>::BITS) -> [return: bb2, unwind unreachable];
32+
+ _6 = core::num::<impl u16>::unchecked_shl::precondition_check(_4) -> [return: bb2, unwind unreachable];
3333
+ }
3434
+
3535
+ bb2: {

tests/mir-opt/inline/unchecked_shifts.unchecked_shr_signed_bigger.Inline.panic-abort.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
}
3030

3131
bb1: {
32-
+ _6 = core::num::<impl i64>::unchecked_shr::precondition_check(_4, const core::num::<impl i64>::BITS) -> [return: bb2, unwind unreachable];
32+
+ _6 = core::num::<impl i64>::unchecked_shr::precondition_check(_4) -> [return: bb2, unwind unreachable];
3333
+ }
3434
+
3535
+ bb2: {

tests/mir-opt/inline/unchecked_shifts.unchecked_shr_signed_bigger.Inline.panic-unwind.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
}
3030

3131
bb1: {
32-
+ _6 = core::num::<impl i64>::unchecked_shr::precondition_check(_4, const core::num::<impl i64>::BITS) -> [return: bb2, unwind unreachable];
32+
+ _6 = core::num::<impl i64>::unchecked_shr::precondition_check(_4) -> [return: bb2, unwind unreachable];
3333
+ }
3434
+
3535
+ bb2: {
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
//@ build-pass
2+
3+
// Supported since C23
4+
// https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2975.pdf
15
extern "C" {
26
fn foo(...);
3-
//~^ ERROR C-variadic function must be declared with at least one named argument
47
}
58

69
fn main() {}

tests/ui/c-variadic/variadic-ffi-no-fixed-args.stderr

-8
This file was deleted.

tests/ui/issues/issue-33992.rs

-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55

66
#![feature(linkage)]
77

8-
#[linkage = "common"]
9-
pub static mut TEST1: u32 = 0u32;
10-
118
#[linkage = "external"]
129
pub static TEST2: bool = true;
1310

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//! The symbols are resolved by the linker. It doesn't make sense to change
2+
//! them at runtime, so deny mutable statics with #[linkage].
3+
4+
#![feature(linkage)]
5+
6+
fn main() {
7+
extern "C" {
8+
#[linkage = "weak"] //~ ERROR mutable statics are not allowed with `#[linkage]`
9+
static mut ABC: *const u8;
10+
}
11+
12+
unsafe {
13+
assert_eq!(ABC as usize, 0);
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: mutable statics are not allowed with `#[linkage]`
2+
--> $DIR/linkage-attr-mutable-static.rs:8:9
3+
|
4+
LL | #[linkage = "weak"]
5+
| ^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: making the static mutable would allow changing which symbol the static references rather than make the target of the symbol mutable
8+
9+
error: aborting due to 1 previous error
10+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Fix for <https://github.com/rust-lang/rust/issues/125432>.
2+
3+
fn separate_arms() {
4+
let mut x = None;
5+
match x {
6+
None => {
7+
x = Some(0);
8+
}
9+
Some(right) => {
10+
consume(right);
11+
//~^ ERROR cannot find function `consume` in this scope
12+
}
13+
}
14+
}
15+
16+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0425]: cannot find function `consume` in this scope
2+
--> $DIR/suggest-method-on-call-for-ambig-receiver.rs:10:13
3+
|
4+
LL | consume(right);
5+
| ^^^^^^^ not found in this scope
6+
7+
error: aborting due to 1 previous error
8+
9+
For more information about this error, try `rustc --explain E0425`.

tests/ui/parser/variadic-ffi-semantic-restrictions.rs

-8
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@ fn f1_1(x: isize, ...) {}
88

99
fn f1_2(...) {}
1010
//~^ ERROR only foreign or `unsafe extern "C"` functions may be C-variadic
11-
//~| ERROR C-variadic function must be declared with at least one named argument
1211

1312
extern "C" fn f2_1(x: isize, ...) {}
1413
//~^ ERROR only foreign or `unsafe extern "C"` functions may be C-variadic
1514

1615
extern "C" fn f2_2(...) {}
1716
//~^ ERROR only foreign or `unsafe extern "C"` functions may be C-variadic
18-
//~| ERROR C-variadic function must be declared with at least one named argument
1917

2018
extern "C" fn f2_3(..., x: isize) {}
2119
//~^ ERROR only foreign or `unsafe extern "C"` functions may be C-variadic
@@ -26,7 +24,6 @@ extern "C" fn f3_1(x: isize, ...) {}
2624

2725
extern "C" fn f3_2(...) {}
2826
//~^ ERROR only foreign or `unsafe extern "C"` functions may be C-variadic
29-
//~| ERROR C-variadic function must be declared with at least one named argument
3027

3128
extern "C" fn f3_3(..., x: isize) {}
3229
//~^ ERROR only foreign or `unsafe extern "C"` functions may be C-variadic
@@ -47,8 +44,6 @@ const extern "C" fn f4_3(..., x: isize, ...) {}
4744
//~| ERROR `...` must be the last argument of a C-variadic function
4845

4946
extern "C" {
50-
fn e_f1(...);
51-
//~^ ERROR C-variadic function must be declared with at least one named argument
5247
fn e_f2(..., x: isize);
5348
//~^ ERROR `...` must be the last argument of a C-variadic function
5449
}
@@ -60,7 +55,6 @@ impl X {
6055
//~^ ERROR only foreign or `unsafe extern "C"` functions may be C-variadic
6156
fn i_f2(...) {}
6257
//~^ ERROR only foreign or `unsafe extern "C"` functions may be C-variadic
63-
//~| ERROR C-variadic function must be declared with at least one named argument
6458
fn i_f3(..., x: isize, ...) {}
6559
//~^ ERROR only foreign or `unsafe extern "C"` functions may be C-variadic
6660
//~| ERROR `...` must be the last argument of a C-variadic function
@@ -80,10 +74,8 @@ trait T {
8074
//~^ ERROR only foreign or `unsafe extern "C"` functions may be C-variadic
8175
fn t_f3(...) {}
8276
//~^ ERROR only foreign or `unsafe extern "C"` functions may be C-variadic
83-
//~| ERROR C-variadic function must be declared with at least one named argument
8477
fn t_f4(...);
8578
//~^ ERROR only foreign or `unsafe extern "C"` functions may be C-variadic
86-
//~| ERROR C-variadic function must be declared with at least one named argument
8779
fn t_f5(..., x: isize) {}
8880
//~^ ERROR only foreign or `unsafe extern "C"` functions may be C-variadic
8981
//~| ERROR `...` must be the last argument of a C-variadic function

0 commit comments

Comments
 (0)