Skip to content

Commit 79c30b6

Browse files
committed
Auto merge of #3635 - RalfJung:rustup, r=RalfJung
Rustup
2 parents da6c08e + 84f70ab commit 79c30b6

File tree

499 files changed

+5934
-6221
lines changed

Some content is hidden

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

499 files changed

+5934
-6221
lines changed

compiler/rustc_ast_passes/messages.ftl

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

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

Lines changed: 0 additions & 7 deletions
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_borrowck/src/diagnostics/bound_region_errors.rs

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use rustc_errors::Diag;
2+
use rustc_hir::def_id::LocalDefId;
23
use rustc_infer::infer::canonical::Canonical;
34
use rustc_infer::infer::error_reporting::nice_region_error::NiceRegionError;
45
use rustc_infer::infer::region_constraints::Constraint;
@@ -241,7 +242,7 @@ impl<'tcx> TypeOpInfo<'tcx> for PredicateQuery<'tcx> {
241242
mbcx.infcx.tcx.infer_ctxt().build_with_canonical(cause.span, &self.canonical_query);
242243
let ocx = ObligationCtxt::new(&infcx);
243244
type_op_prove_predicate_with_cause(&ocx, key, cause);
244-
try_extract_error_from_fulfill_cx(&ocx, placeholder_region, error_region)
245+
try_extract_error_from_fulfill_cx(&ocx, mbcx.mir_def_id(), placeholder_region, error_region)
245246
}
246247
}
247248

@@ -287,7 +288,7 @@ where
287288
let (param_env, value) = key.into_parts();
288289
let _ = ocx.normalize(&cause, param_env, value.value);
289290

290-
try_extract_error_from_fulfill_cx(&ocx, placeholder_region, error_region)
291+
try_extract_error_from_fulfill_cx(&ocx, mbcx.mir_def_id(), placeholder_region, error_region)
291292
}
292293
}
293294

@@ -318,7 +319,7 @@ impl<'tcx> TypeOpInfo<'tcx> for AscribeUserTypeQuery<'tcx> {
318319
mbcx.infcx.tcx.infer_ctxt().build_with_canonical(cause.span, &self.canonical_query);
319320
let ocx = ObligationCtxt::new(&infcx);
320321
type_op_ascribe_user_type_with_span(&ocx, key, Some(cause.span)).ok()?;
321-
try_extract_error_from_fulfill_cx(&ocx, placeholder_region, error_region)
322+
try_extract_error_from_fulfill_cx(&ocx, mbcx.mir_def_id(), placeholder_region, error_region)
322323
}
323324
}
324325

@@ -342,6 +343,7 @@ impl<'tcx> TypeOpInfo<'tcx> for crate::type_check::InstantiateOpaqueType<'tcx> {
342343
) -> Option<Diag<'tcx>> {
343344
try_extract_error_from_region_constraints(
344345
mbcx.infcx,
346+
mbcx.mir_def_id(),
345347
placeholder_region,
346348
error_region,
347349
self.region_constraints.as_ref().unwrap(),
@@ -358,6 +360,7 @@ impl<'tcx> TypeOpInfo<'tcx> for crate::type_check::InstantiateOpaqueType<'tcx> {
358360
#[instrument(skip(ocx), level = "debug")]
359361
fn try_extract_error_from_fulfill_cx<'tcx>(
360362
ocx: &ObligationCtxt<'_, 'tcx>,
363+
generic_param_scope: LocalDefId,
361364
placeholder_region: ty::Region<'tcx>,
362365
error_region: Option<ty::Region<'tcx>>,
363366
) -> Option<Diag<'tcx>> {
@@ -368,6 +371,7 @@ fn try_extract_error_from_fulfill_cx<'tcx>(
368371
let region_constraints = ocx.infcx.with_region_constraints(|r| r.clone());
369372
try_extract_error_from_region_constraints(
370373
ocx.infcx,
374+
generic_param_scope,
371375
placeholder_region,
372376
error_region,
373377
&region_constraints,
@@ -379,6 +383,7 @@ fn try_extract_error_from_fulfill_cx<'tcx>(
379383
#[instrument(level = "debug", skip(infcx, region_var_origin, universe_of_region))]
380384
fn try_extract_error_from_region_constraints<'tcx>(
381385
infcx: &InferCtxt<'tcx>,
386+
generic_param_scope: LocalDefId,
382387
placeholder_region: ty::Region<'tcx>,
383388
error_region: Option<ty::Region<'tcx>>,
384389
region_constraints: &RegionConstraintData<'tcx>,
@@ -452,15 +457,18 @@ fn try_extract_error_from_region_constraints<'tcx>(
452457
RegionResolutionError::ConcreteFailure(cause.clone(), sub_region, placeholder_region)
453458
}
454459
};
455-
NiceRegionError::new(&infcx.err_ctxt(), error).try_report_from_nll().or_else(|| {
456-
if let SubregionOrigin::Subtype(trace) = cause {
457-
Some(
458-
infcx
459-
.err_ctxt()
460-
.report_and_explain_type_error(*trace, TypeError::RegionsPlaceholderMismatch),
461-
)
462-
} else {
463-
None
464-
}
465-
})
460+
NiceRegionError::new(&infcx.err_ctxt(), generic_param_scope, error)
461+
.try_report_from_nll()
462+
.or_else(|| {
463+
if let SubregionOrigin::Subtype(trace) = cause {
464+
Some(
465+
infcx.err_ctxt().report_and_explain_type_error(
466+
*trace,
467+
TypeError::RegionsPlaceholderMismatch,
468+
),
469+
)
470+
} else {
471+
None
472+
}
473+
})
466474
}

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
361361
let named_region = self.regioncx.name_regions(self.infcx.tcx, member_region);
362362
let diag = unexpected_hidden_region_diagnostic(
363363
self.infcx.tcx,
364+
self.mir_def_id(),
364365
span,
365366
named_ty,
366367
named_region,
@@ -453,7 +454,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
453454
// Check if we can use one of the "nice region errors".
454455
if let (Some(f), Some(o)) = (self.to_error_region(fr), self.to_error_region(outlived_fr)) {
455456
let infer_err = self.infcx.err_ctxt();
456-
let nice = NiceRegionError::new_from_span(&infer_err, cause.span, o, f);
457+
let nice =
458+
NiceRegionError::new_from_span(&infer_err, self.mir_def_id(), cause.span, o, f);
457459
if let Some(diag) = nice.try_report_from_nll() {
458460
self.buffer_error(diag);
459461
return;
@@ -843,14 +845,16 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
843845
if *outlived_f != ty::ReStatic {
844846
return;
845847
}
846-
let suitable_region = self.infcx.tcx.is_suitable_region(f);
848+
let suitable_region = self.infcx.tcx.is_suitable_region(self.mir_def_id(), f);
847849
let Some(suitable_region) = suitable_region else {
848850
return;
849851
};
850852

851853
let fn_returns = self.infcx.tcx.return_type_impl_or_dyn_traits(suitable_region.def_id);
852854

853-
let param = if let Some(param) = find_param_with_region(self.infcx.tcx, f, outlived_f) {
855+
let param = if let Some(param) =
856+
find_param_with_region(self.infcx.tcx, self.mir_def_id(), f, outlived_f)
857+
{
854858
param
855859
} else {
856860
return;
@@ -959,7 +963,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
959963
return;
960964
};
961965

962-
let param = match find_param_with_region(tcx, f, o) {
966+
let param = match find_param_with_region(tcx, self.mir_def_id(), f, o) {
963967
Some(param) => param,
964968
None => return,
965969
};
@@ -1022,25 +1026,30 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
10221026
return;
10231027
};
10241028

1025-
let Some((ty_sub, _)) = self
1026-
.infcx
1027-
.tcx
1028-
.is_suitable_region(sub)
1029-
.and_then(|anon_reg| find_anon_type(self.infcx.tcx, sub, &anon_reg.bound_region))
1029+
let Some((ty_sub, _)) =
1030+
self.infcx.tcx.is_suitable_region(self.mir_def_id(), sub).and_then(|anon_reg| {
1031+
find_anon_type(self.infcx.tcx, self.mir_def_id(), sub, &anon_reg.bound_region)
1032+
})
10301033
else {
10311034
return;
10321035
};
10331036

1034-
let Some((ty_sup, _)) = self
1035-
.infcx
1036-
.tcx
1037-
.is_suitable_region(sup)
1038-
.and_then(|anon_reg| find_anon_type(self.infcx.tcx, sup, &anon_reg.bound_region))
1037+
let Some((ty_sup, _)) =
1038+
self.infcx.tcx.is_suitable_region(self.mir_def_id(), sup).and_then(|anon_reg| {
1039+
find_anon_type(self.infcx.tcx, self.mir_def_id(), sup, &anon_reg.bound_region)
1040+
})
10391041
else {
10401042
return;
10411043
};
10421044

1043-
suggest_adding_lifetime_params(self.infcx.tcx, sub, ty_sup, ty_sub, diag);
1045+
suggest_adding_lifetime_params(
1046+
self.infcx.tcx,
1047+
diag,
1048+
self.mir_def_id(),
1049+
sub,
1050+
ty_sup,
1051+
ty_sub,
1052+
);
10441053
}
10451054

10461055
#[allow(rustc::diagnostic_outside_of_impl)]

compiler/rustc_borrowck/src/diagnostics/region_name.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,8 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
289289
debug!("give_region_a_name: error_region = {:?}", error_region);
290290
match *error_region {
291291
ty::ReEarlyParam(ebr) => ebr.has_name().then(|| {
292-
let span = tcx.hir().span_if_local(ebr.def_id).unwrap_or(DUMMY_SP);
292+
let def_id = tcx.generics_of(self.mir_def_id()).region_param(ebr, tcx).def_id;
293+
let span = tcx.hir().span_if_local(def_id).unwrap_or(DUMMY_SP);
293294
RegionName { name: ebr.name, source: RegionNameSource::NamedEarlyParamRegion(span) }
294295
}),
295296

@@ -912,7 +913,8 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
912913
};
913914

914915
let tcx = self.infcx.tcx;
915-
let region_parent = tcx.parent(region.def_id);
916+
let region_def = tcx.generics_of(self.mir_def_id()).region_param(region, tcx).def_id;
917+
let region_parent = tcx.parent(region_def);
916918
let DefKind::Impl { .. } = tcx.def_kind(region_parent) else {
917919
return None;
918920
};
@@ -925,7 +927,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
925927
Some(RegionName {
926928
name: self.synthesize_region_name(),
927929
source: RegionNameSource::AnonRegionFromImplSignature(
928-
tcx.def_span(region.def_id),
930+
tcx.def_span(region_def),
929931
// FIXME(compiler-errors): Does this ever actually show up
930932
// anywhere other than the self type? I couldn't create an
931933
// example of a `'_` in the impl's trait being referenceable.

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

Lines changed: 13 additions & 1 deletion
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 => {
@@ -564,8 +576,8 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
564576
lint::builtin::INLINE_NO_SANITIZE,
565577
hir_id,
566578
no_sanitize_span,
567-
"`no_sanitize` will have no effect after inlining",
568579
|lint| {
580+
lint.primary_message("`no_sanitize` will have no effect after inlining");
569581
lint.span_note(inline_span, "inlining requested here");
570582
},
571583
)

compiler/rustc_const_eval/src/check_consts/ops.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
309309
}
310310

311311
if let ConstContext::Static(_) = ccx.const_kind() {
312-
err.note("consider wrapping this expression in `Lazy::new(|| ...)` from the `once_cell` crate: https://crates.io/crates/once_cell");
312+
err.note("consider wrapping this expression in `std::sync::LazyLock::new(|| ...)`");
313313
}
314314

315315
err

0 commit comments

Comments
 (0)