Auto merge of #125593 - workingjubilee:rollup-67qk7di, r=workingjubilee · rust-lang/rust@529bb25

26 files changed

lines changed

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

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 {

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 {

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 => {

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
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()

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

}

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() {

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.

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.