Skip to content

Commit a40a100

Browse files
committed
Auto merge of #3294 - rust-lang:rustup-2024-02-11, r=saethlin
Automatic Rustup
2 parents 5a3a2d5 + 48bb2bf commit a40a100

File tree

171 files changed

+2273
-2644
lines changed

Some content is hidden

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

171 files changed

+2273
-2644
lines changed

compiler/rustc_ast/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#![feature(box_patterns)]
1616
#![feature(if_let_guard)]
1717
#![feature(let_chains)]
18-
#![feature(min_specialization)]
18+
#![cfg_attr(bootstrap, feature(min_specialization))]
1919
#![feature(negative_impls)]
2020
#![feature(stmt_expr_attributes)]
2121

compiler/rustc_ast_lowering/messages.ftl

+4-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ ast_lowering_arbitrary_expression_in_pattern =
88
99
ast_lowering_argument = argument
1010
11+
ast_lowering_assoc_ty_binding_in_dyn =
12+
associated type bounds are not allowed in `dyn` types
13+
.suggestion = use `impl Trait` to introduce a type instead
14+
1115
ast_lowering_assoc_ty_parentheses =
1216
parenthesized generic arguments cannot be used in associated type constraints
1317
@@ -100,9 +104,6 @@ ast_lowering_match_arm_with_no_body =
100104
`match` arm with no body
101105
.suggestion = add a body after the pattern
102106
103-
ast_lowering_misplaced_assoc_ty_binding =
104-
associated type bounds are only allowed in where clauses and function signatures, not in {$position}
105-
106107
ast_lowering_misplaced_double_dot =
107108
`..` patterns are not allowed here
108109
.note = only allowed in tuple, tuple struct, and slice patterns

compiler/rustc_ast_lowering/src/errors.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,12 @@ pub struct MisplacedImplTrait<'a> {
9494
}
9595

9696
#[derive(Diagnostic)]
97-
#[diag(ast_lowering_misplaced_assoc_ty_binding)]
98-
pub struct MisplacedAssocTyBinding<'a> {
97+
#[diag(ast_lowering_assoc_ty_binding_in_dyn)]
98+
pub struct MisplacedAssocTyBinding {
9999
#[primary_span]
100100
pub span: Span,
101-
pub position: DiagnosticArgFromDisplay<'a>,
101+
#[suggestion(code = " = impl", applicability = "maybe-incorrect", style = "verbose")]
102+
pub suggestion: Option<Span>,
102103
}
103104

104105
#[derive(Diagnostic, Clone, Copy)]

compiler/rustc_ast_lowering/src/lib.rs

+30-86
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,6 @@ trait ResolverAstLoweringExt {
197197
fn get_label_res(&self, id: NodeId) -> Option<NodeId>;
198198
fn get_lifetime_res(&self, id: NodeId) -> Option<LifetimeRes>;
199199
fn take_extra_lifetime_params(&mut self, id: NodeId) -> Vec<(Ident, NodeId, LifetimeRes)>;
200-
fn remap_extra_lifetime_params(&mut self, from: NodeId, to: NodeId);
201200
}
202201

203202
impl ResolverAstLoweringExt for ResolverAstLowering {
@@ -256,11 +255,6 @@ impl ResolverAstLoweringExt for ResolverAstLowering {
256255
fn take_extra_lifetime_params(&mut self, id: NodeId) -> Vec<(Ident, NodeId, LifetimeRes)> {
257256
self.extra_lifetime_params_map.remove(&id).unwrap_or_default()
258257
}
259-
260-
fn remap_extra_lifetime_params(&mut self, from: NodeId, to: NodeId) {
261-
let lifetimes = self.extra_lifetime_params_map.remove(&from).unwrap_or_default();
262-
self.extra_lifetime_params_map.insert(to, lifetimes);
263-
}
264258
}
265259

266260
/// Context of `impl Trait` in code, which determines whether it is allowed in an HIR subtree,
@@ -1084,88 +1078,38 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
10841078
hir::TypeBindingKind::Equality { term }
10851079
}
10861080
AssocConstraintKind::Bound { bounds } => {
1087-
enum DesugarKind {
1088-
ImplTrait,
1089-
Error(ImplTraitPosition),
1090-
Bound,
1091-
}
1092-
1093-
// Piggy-back on the `impl Trait` context to figure out the correct behavior.
1094-
let desugar_kind = match itctx {
1095-
// in an argument, RPIT, or TAIT, if we are within a dyn type:
1096-
//
1097-
// fn foo(x: dyn Iterator<Item: Debug>)
1098-
//
1099-
// then desugar to:
1100-
//
1101-
// fn foo(x: dyn Iterator<Item = impl Debug>)
1102-
//
1103-
// This is because dyn traits must have all of their associated types specified.
1104-
ImplTraitContext::ReturnPositionOpaqueTy { .. }
1105-
| ImplTraitContext::TypeAliasesOpaqueTy { .. }
1106-
| ImplTraitContext::Universal
1107-
if self.is_in_dyn_type =>
1108-
{
1109-
DesugarKind::ImplTrait
1110-
}
1111-
1112-
ImplTraitContext::Disallowed(position) if self.is_in_dyn_type => {
1113-
DesugarKind::Error(position)
1114-
}
1115-
1116-
// We are in the parameter position, but not within a dyn type:
1117-
//
1118-
// fn foo(x: impl Iterator<Item: Debug>)
1119-
//
1120-
// so we leave it as is and this gets expanded in astconv to a bound like
1121-
// `<T as Iterator>::Item: Debug` where `T` is the type parameter for the
1122-
// `impl Iterator`.
1123-
_ => DesugarKind::Bound,
1124-
};
1125-
1126-
match desugar_kind {
1127-
DesugarKind::ImplTrait => {
1128-
// Desugar `AssocTy: Bounds` into `AssocTy = impl Bounds`. We do this by
1129-
// constructing the HIR for `impl bounds...` and then lowering that.
1130-
1131-
let impl_trait_node_id = self.next_node_id();
1132-
// Shift `impl Trait` lifetime captures from the associated type bound's
1133-
// node id to the opaque node id, so that the opaque can actually use
1134-
// these lifetime bounds.
1135-
self.resolver
1136-
.remap_extra_lifetime_params(constraint.id, impl_trait_node_id);
1137-
1138-
self.with_dyn_type_scope(false, |this| {
1139-
let node_id = this.next_node_id();
1140-
let ty = this.lower_ty(
1141-
&Ty {
1142-
id: node_id,
1143-
kind: TyKind::ImplTrait(impl_trait_node_id, bounds.clone()),
1144-
span: this.lower_span(constraint.span),
1145-
tokens: None,
1146-
},
1147-
itctx,
1148-
);
1081+
// Disallow ATB in dyn types
1082+
if self.is_in_dyn_type {
1083+
let suggestion = match itctx {
1084+
ImplTraitContext::ReturnPositionOpaqueTy { .. }
1085+
| ImplTraitContext::TypeAliasesOpaqueTy { .. }
1086+
| ImplTraitContext::Universal => {
1087+
let bound_end_span = constraint
1088+
.gen_args
1089+
.as_ref()
1090+
.map_or(constraint.ident.span, |args| args.span());
1091+
if bound_end_span.eq_ctxt(constraint.span) {
1092+
Some(self.tcx.sess.source_map().next_point(bound_end_span))
1093+
} else {
1094+
None
1095+
}
1096+
}
1097+
_ => None,
1098+
};
11491099

1150-
hir::TypeBindingKind::Equality { term: ty.into() }
1151-
})
1152-
}
1153-
DesugarKind::Bound => {
1154-
// Desugar `AssocTy: Bounds` into a type binding where the
1155-
// later desugars into a trait predicate.
1156-
let bounds = self.lower_param_bounds(bounds, itctx);
1100+
let guar = self.dcx().emit_err(errors::MisplacedAssocTyBinding {
1101+
span: constraint.span,
1102+
suggestion,
1103+
});
1104+
let err_ty =
1105+
&*self.arena.alloc(self.ty(constraint.span, hir::TyKind::Err(guar)));
1106+
hir::TypeBindingKind::Equality { term: err_ty.into() }
1107+
} else {
1108+
// Desugar `AssocTy: Bounds` into a type binding where the
1109+
// later desugars into a trait predicate.
1110+
let bounds = self.lower_param_bounds(bounds, itctx);
11571111

1158-
hir::TypeBindingKind::Constraint { bounds }
1159-
}
1160-
DesugarKind::Error(position) => {
1161-
let guar = self.dcx().emit_err(errors::MisplacedAssocTyBinding {
1162-
span: constraint.span,
1163-
position: DiagnosticArgFromDisplay(&position),
1164-
});
1165-
let err_ty =
1166-
&*self.arena.alloc(self.ty(constraint.span, hir::TyKind::Err(guar)));
1167-
hir::TypeBindingKind::Equality { term: err_ty.into() }
1168-
}
1112+
hir::TypeBindingKind::Constraint { bounds }
11691113
}
11701114
}
11711115
};

compiler/rustc_codegen_llvm/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#![feature(hash_raw_entry)]
1414
#![feature(iter_intersperse)]
1515
#![feature(let_chains)]
16-
#![feature(min_specialization)]
1716
#![feature(impl_trait_in_assoc_type)]
1817

1918
#[macro_use]

compiler/rustc_codegen_ssa/messages.ftl

+2
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ codegen_ssa_no_module_named =
190190
191191
codegen_ssa_no_natvis_directory = error enumerating natvis directory: {$error}
192192
193+
codegen_ssa_no_saved_object_file = cached cgu {$cgu_name} should have an object file, but doesn't
194+
193195
codegen_ssa_processing_dymutil_failed = processing debug info with `dsymutil` failed: {$status}
194196
.note = {$output}
195197

compiler/rustc_codegen_ssa/src/back/write.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,9 @@ fn execute_copy_from_cache_work_item<B: ExtraBackendMethods>(
913913

914914
let object = load_from_incr_comp_dir(
915915
cgcx.output_filenames.temp_path(OutputType::Object, Some(&module.name)),
916-
module.source.saved_files.get("o").expect("no saved object file in work product"),
916+
module.source.saved_files.get("o").unwrap_or_else(|| {
917+
cgcx.create_dcx().emit_fatal(errors::NoSavedObjectFile { cgu_name: &module.name })
918+
}),
917919
);
918920
let dwarf_object =
919921
module.source.saved_files.get("dwo").as_ref().and_then(|saved_dwarf_object_file| {

compiler/rustc_codegen_ssa/src/errors.rs

+6
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@ pub struct NoNatvisDirectory {
121121
pub error: Error,
122122
}
123123

124+
#[derive(Diagnostic)]
125+
#[diag(codegen_ssa_no_saved_object_file)]
126+
pub struct NoSavedObjectFile<'a> {
127+
pub cgu_name: &'a str,
128+
}
129+
124130
#[derive(Diagnostic)]
125131
#[diag(codegen_ssa_copy_path_buf)]
126132
pub struct CopyPathBuf {

compiler/rustc_const_eval/messages.ftl

+7-7
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ const_eval_closure_non_const =
3030
cannot call non-const closure in {const_eval_const_context}s
3131
const_eval_consider_dereferencing =
3232
consider dereferencing here
33-
const_eval_const_accesses_static = constant accesses static
33+
34+
const_eval_const_accesses_mut_global =
35+
constant accesses mutable global memory
3436
3537
const_eval_const_context = {$kind ->
3638
[const] constant
@@ -319,12 +321,6 @@ const_eval_size_overflow =
319321
const_eval_stack_frame_limit_reached =
320322
reached the configured maximum number of stack frames
321323
322-
const_eval_static_access =
323-
{const_eval_const_context}s cannot refer to statics
324-
.help = consider extracting the value of the `static` to a `const`, and referring to that
325-
.teach_note = `static` and `const` variables can refer to other `const` variables. A `const` variable, however, cannot refer to a `static` variable.
326-
.teach_help = To fix this, the value can be extracted to a `const` and then used.
327-
328324
const_eval_thread_local_access =
329325
thread-local statics cannot be accessed at compile-time
330326
@@ -415,6 +411,10 @@ const_eval_upcast_mismatch =
415411
## (We'd love to sort this differently to make that more clear but tidy won't let us...)
416412
const_eval_validation_box_to_static = {$front_matter}: encountered a box pointing to a static variable in a constant
417413
const_eval_validation_box_to_uninhabited = {$front_matter}: encountered a box pointing to uninhabited type {$ty}
414+
415+
const_eval_validation_const_ref_to_extern = {$front_matter}: encountered reference to `extern` static in `const`
416+
const_eval_validation_const_ref_to_mutable = {$front_matter}: encountered reference to mutable memory in `const`
417+
418418
const_eval_validation_dangling_box_no_provenance = {$front_matter}: encountered a dangling box ({$pointer} has no provenance)
419419
const_eval_validation_dangling_box_out_of_bounds = {$front_matter}: encountered a dangling box (going beyond the bounds of its allocation)
420420
const_eval_validation_dangling_box_use_after_free = {$front_matter}: encountered a dangling box (use-after-free)

compiler/rustc_const_eval/src/const_eval/error.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use crate::interpret::{ErrorHandled, InterpError, InterpErrorInfo, MachineStopTy
1717
/// The CTFE machine has some custom error kinds.
1818
#[derive(Clone, Debug)]
1919
pub enum ConstEvalErrKind {
20-
ConstAccessesStatic,
20+
ConstAccessesMutGlobal,
2121
ModifiedGlobal,
2222
AssertFailure(AssertKind<ConstInt>),
2323
Panic { msg: Symbol, line: u32, col: u32, file: Symbol },
@@ -28,7 +28,7 @@ impl MachineStopType for ConstEvalErrKind {
2828
use crate::fluent_generated::*;
2929
use ConstEvalErrKind::*;
3030
match self {
31-
ConstAccessesStatic => const_eval_const_accesses_static,
31+
ConstAccessesMutGlobal => const_eval_const_accesses_mut_global,
3232
ModifiedGlobal => const_eval_modified_global,
3333
Panic { .. } => const_eval_panic,
3434
AssertFailure(x) => x.diagnostic_message(),
@@ -37,7 +37,7 @@ impl MachineStopType for ConstEvalErrKind {
3737
fn add_args(self: Box<Self>, adder: &mut dyn FnMut(DiagnosticArgName, DiagnosticArgValue)) {
3838
use ConstEvalErrKind::*;
3939
match *self {
40-
ConstAccessesStatic | ModifiedGlobal => {}
40+
ConstAccessesMutGlobal | ModifiedGlobal => {}
4141
AssertFailure(kind) => kind.add_args(adder),
4242
Panic { msg, line, col, file } => {
4343
adder("msg".into(), msg.into_diagnostic_arg());

compiler/rustc_const_eval/src/const_eval/eval_queries.rs

+13-8
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_middle::ty::{self, TyCtxt};
1111
use rustc_span::Span;
1212
use rustc_target::abi::{self, Abi};
1313

14-
use super::{CanAccessStatics, CompileTimeEvalContext, CompileTimeInterpreter};
14+
use super::{CanAccessMutGlobal, CompileTimeEvalContext, CompileTimeInterpreter};
1515
use crate::const_eval::CheckAlignment;
1616
use crate::errors;
1717
use crate::errors::ConstEvalError;
@@ -90,14 +90,14 @@ pub(crate) fn mk_eval_cx<'mir, 'tcx>(
9090
tcx: TyCtxt<'tcx>,
9191
root_span: Span,
9292
param_env: ty::ParamEnv<'tcx>,
93-
can_access_statics: CanAccessStatics,
93+
can_access_mut_global: CanAccessMutGlobal,
9494
) -> CompileTimeEvalContext<'mir, 'tcx> {
9595
debug!("mk_eval_cx: {:?}", param_env);
9696
InterpCx::new(
9797
tcx,
9898
root_span,
9999
param_env,
100-
CompileTimeInterpreter::new(can_access_statics, CheckAlignment::No),
100+
CompileTimeInterpreter::new(can_access_mut_global, CheckAlignment::No),
101101
)
102102
}
103103

@@ -200,7 +200,7 @@ pub(crate) fn turn_into_const_value<'tcx>(
200200
tcx,
201201
tcx.def_span(key.value.instance.def_id()),
202202
key.param_env,
203-
CanAccessStatics::from(is_static),
203+
CanAccessMutGlobal::from(is_static),
204204
);
205205

206206
let mplace = ecx.raw_const_to_mplace(constant).expect(
@@ -277,9 +277,11 @@ pub fn eval_to_allocation_raw_provider<'tcx>(
277277
tcx,
278278
tcx.def_span(def),
279279
key.param_env,
280-
// Statics (and promoteds inside statics) may access other statics, because unlike consts
280+
// Statics (and promoteds inside statics) may access mutable global memory, because unlike consts
281281
// they do not have to behave "as if" they were evaluated at runtime.
282-
CompileTimeInterpreter::new(CanAccessStatics::from(is_static), CheckAlignment::Error),
282+
// For consts however we want to ensure they behave "as if" they were evaluated at runtime,
283+
// so we have to reject reading mutable global memory.
284+
CompileTimeInterpreter::new(CanAccessMutGlobal::from(is_static), CheckAlignment::Error),
283285
);
284286
eval_in_interpreter(ecx, cid, is_static)
285287
}
@@ -358,15 +360,18 @@ pub fn const_validate_mplace<'mir, 'tcx>(
358360
// Promoteds in statics are consts that re allowed to point to statics.
359361
CtfeValidationMode::Const {
360362
allow_immutable_unsafe_cell: false,
361-
allow_static_ptrs: true,
363+
allow_extern_static_ptrs: true,
362364
}
363365
}
364366
Some(mutbl) => CtfeValidationMode::Static { mutbl }, // a `static`
365367
None => {
366368
// In normal `const` (not promoted), the outermost allocation is always only copied,
367369
// so having `UnsafeCell` in there is okay despite them being in immutable memory.
368370
let allow_immutable_unsafe_cell = cid.promoted.is_none() && !inner;
369-
CtfeValidationMode::Const { allow_immutable_unsafe_cell, allow_static_ptrs: false }
371+
CtfeValidationMode::Const {
372+
allow_immutable_unsafe_cell,
373+
allow_extern_static_ptrs: false,
374+
}
370375
}
371376
};
372377
ecx.const_validate_operand(&mplace.into(), path, &mut ref_tracking, mode)?;

0 commit comments

Comments
 (0)