Skip to content

Commit b69da27

Browse files
committed
Auto merge of #143105 - compiler-errors:rollup-68jh88u, r=compiler-errors
Rollup of 8 pull requests Successful merges: - #139858 (New const traits syntax) - #140809 (Reduce special casing for the panic runtime) - #142963 (Skip unnecessary components in x64 try builds) - #142974 (Update stage0 to 1.89.0-beta.1) - #142987 (rustdoc: show attributes on enum variants) - #143002 (tests: Require `run-fail` ui tests to have an exit code (`SIGABRT` not ok)) - #143092 (const checks for lifetime-extended temporaries: avoid 'top-level scope' terminology) - #143096 (tag_for_variant: properly pass TypingEnv) r? `@ghost` `@rustbot` modify labels: rollup
2 parents fe5f3de + 900341f commit b69da27

File tree

405 files changed

+2640
-2574
lines changed

Some content is hidden

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

405 files changed

+2640
-2574
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ impl ParenthesizedArgs {
323323

324324
pub use crate::node_id::{CRATE_NODE_ID, DUMMY_NODE_ID, NodeId};
325325

326-
/// Modifiers on a trait bound like `~const`, `?` and `!`.
326+
/// Modifiers on a trait bound like `[const]`, `?` and `!`.
327327
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Debug)]
328328
pub struct TraitBoundModifiers {
329329
pub constness: BoundConstness,
@@ -3115,7 +3115,7 @@ pub enum BoundConstness {
31153115
Never,
31163116
/// `Type: const Trait`
31173117
Always(Span),
3118-
/// `Type: ~const Trait`
3118+
/// `Type: [const] Trait`
31193119
Maybe(Span),
31203120
}
31213121

@@ -3124,7 +3124,7 @@ impl BoundConstness {
31243124
match self {
31253125
Self::Never => "",
31263126
Self::Always(_) => "const",
3127-
Self::Maybe(_) => "~const",
3127+
Self::Maybe(_) => "[const]",
31283128
}
31293129
}
31303130
}

compiler/rustc_ast_passes/messages.ftl

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -237,17 +237,17 @@ ast_passes_static_without_body =
237237
free static item without body
238238
.suggestion = provide a definition for the static
239239
240-
ast_passes_tilde_const_disallowed = `~const` is not allowed here
241-
.closure = closures cannot have `~const` trait bounds
242-
.function = this function is not `const`, so it cannot have `~const` trait bounds
243-
.trait = this trait is not a `#[const_trait]`, so it cannot have `~const` trait bounds
244-
.trait_impl = this impl is not `const`, so it cannot have `~const` trait bounds
245-
.impl = inherent impls cannot have `~const` trait bounds
246-
.trait_assoc_ty = associated types in non-`#[const_trait]` traits cannot have `~const` trait bounds
247-
.trait_impl_assoc_ty = associated types in non-const impls cannot have `~const` trait bounds
248-
.inherent_assoc_ty = inherent associated types cannot have `~const` trait bounds
249-
.object = trait objects cannot have `~const` trait bounds
250-
.item = this item cannot have `~const` trait bounds
240+
ast_passes_tilde_const_disallowed = `[const]` is not allowed here
241+
.closure = closures cannot have `[const]` trait bounds
242+
.function = this function is not `const`, so it cannot have `[const]` trait bounds
243+
.trait = this trait is not a `#[const_trait]`, so it cannot have `[const]` trait bounds
244+
.trait_impl = this impl is not `const`, so it cannot have `[const]` trait bounds
245+
.impl = inherent impls cannot have `[const]` trait bounds
246+
.trait_assoc_ty = associated types in non-`#[const_trait]` traits cannot have `[const]` trait bounds
247+
.trait_impl_assoc_ty = associated types in non-const impls cannot have `[const]` trait bounds
248+
.inherent_assoc_ty = inherent associated types cannot have `[const]` trait bounds
249+
.object = trait objects cannot have `[const]` trait bounds
250+
.item = this item cannot have `[const]` trait bounds
251251
252252
ast_passes_trait_fn_const =
253253
functions in {$in_impl ->

compiler/rustc_builtin_macros/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
#![allow(internal_features)]
66
#![allow(rustc::diagnostic_outside_of_impl)]
77
#![allow(rustc::untranslatable_diagnostic)]
8-
#![cfg_attr(not(bootstrap), feature(autodiff))]
98
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
109
#![doc(rust_logo)]
1110
#![feature(assert_matches)]
11+
#![feature(autodiff)]
1212
#![feature(box_patterns)]
1313
#![feature(decl_macro)]
1414
#![feature(if_let_guard)]

compiler/rustc_codegen_ssa/src/back/linker.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1876,12 +1876,28 @@ pub(crate) fn linked_symbols(
18761876
}
18771877
}
18781878

1879+
match tcx.sess.lto() {
1880+
Lto::No | Lto::ThinLocal => {}
1881+
Lto::Thin | Lto::Fat => {
1882+
// We really only need symbols from upstream rlibs to end up in the linked symbols list.
1883+
// The rest are in separate object files which the linker will always link in and
1884+
// doesn't have rules around the order in which they need to appear.
1885+
// When doing LTO, some of the symbols in the linked symbols list happen to be
1886+
// internalized by LTO, which then prevents referencing them from symbols.o. When doing
1887+
// LTO, all object files that get linked in will be local object files rather than
1888+
// pulled in from rlibs, so an empty linked symbols list works fine to avoid referencing
1889+
// all those internalized symbols from symbols.o.
1890+
return Vec::new();
1891+
}
1892+
}
1893+
18791894
let mut symbols = Vec::new();
18801895

18811896
let export_threshold = symbol_export::crates_export_threshold(&[crate_type]);
18821897
for_each_exported_symbols_include_dep(tcx, crate_type, |symbol, info, cnum| {
18831898
if info.level.is_below_threshold(export_threshold) && !tcx.is_compiler_builtins(cnum)
18841899
|| info.used
1900+
|| info.rustc_std_internal_symbol
18851901
{
18861902
symbols.push((
18871903
symbol_export::linking_symbol_name_for_instance_in_crate(

compiler/rustc_codegen_ssa/src/back/symbol_export.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, _: LocalCrate) -> DefIdMap<S
131131
used: codegen_attrs.flags.contains(CodegenFnAttrFlags::USED_COMPILER)
132132
|| codegen_attrs.flags.contains(CodegenFnAttrFlags::USED_LINKER)
133133
|| used,
134+
rustc_std_internal_symbol: codegen_attrs
135+
.flags
136+
.contains(CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL),
134137
};
135138
(def_id.to_def_id(), info)
136139
})
@@ -143,6 +146,7 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, _: LocalCrate) -> DefIdMap<S
143146
level: SymbolExportLevel::C,
144147
kind: SymbolExportKind::Data,
145148
used: false,
149+
rustc_std_internal_symbol: false,
146150
},
147151
);
148152
}
@@ -191,6 +195,7 @@ fn exported_symbols_provider_local<'tcx>(
191195
level: info.level,
192196
kind: SymbolExportKind::Text,
193197
used: info.used,
198+
rustc_std_internal_symbol: info.rustc_std_internal_symbol,
194199
},
195200
)
196201
})
@@ -207,6 +212,7 @@ fn exported_symbols_provider_local<'tcx>(
207212
level: SymbolExportLevel::C,
208213
kind: SymbolExportKind::Text,
209214
used: false,
215+
rustc_std_internal_symbol: false,
210216
},
211217
));
212218
}
@@ -230,6 +236,7 @@ fn exported_symbols_provider_local<'tcx>(
230236
level: SymbolExportLevel::Rust,
231237
kind: SymbolExportKind::Text,
232238
used: false,
239+
rustc_std_internal_symbol: true,
233240
},
234241
));
235242
}
@@ -250,6 +257,7 @@ fn exported_symbols_provider_local<'tcx>(
250257
level: SymbolExportLevel::C,
251258
kind: SymbolExportKind::Data,
252259
used: false,
260+
rustc_std_internal_symbol: false,
253261
},
254262
)
255263
}));
@@ -275,6 +283,7 @@ fn exported_symbols_provider_local<'tcx>(
275283
level: SymbolExportLevel::C,
276284
kind: SymbolExportKind::Data,
277285
used: false,
286+
rustc_std_internal_symbol: false,
278287
},
279288
)
280289
}));
@@ -292,6 +301,7 @@ fn exported_symbols_provider_local<'tcx>(
292301
level: SymbolExportLevel::C,
293302
kind: SymbolExportKind::Data,
294303
used: true,
304+
rustc_std_internal_symbol: false,
295305
},
296306
));
297307
}
@@ -367,6 +377,8 @@ fn exported_symbols_provider_local<'tcx>(
367377
}
368378
}
369379

380+
// Note: These all set rustc_std_internal_symbol to false as generic functions must not
381+
// be marked with this attribute and we are only handling generic functions here.
370382
match *mono_item {
371383
MonoItem::Fn(Instance { def: InstanceKind::Item(def), args }) => {
372384
let has_generics = args.non_erasable_generics().next().is_some();
@@ -382,6 +394,7 @@ fn exported_symbols_provider_local<'tcx>(
382394
level: SymbolExportLevel::Rust,
383395
kind: SymbolExportKind::Text,
384396
used: false,
397+
rustc_std_internal_symbol: false,
385398
},
386399
));
387400
}
@@ -404,6 +417,7 @@ fn exported_symbols_provider_local<'tcx>(
404417
level: SymbolExportLevel::Rust,
405418
kind: SymbolExportKind::Text,
406419
used: false,
420+
rustc_std_internal_symbol: false,
407421
},
408422
));
409423
}
@@ -420,6 +434,7 @@ fn exported_symbols_provider_local<'tcx>(
420434
level: SymbolExportLevel::Rust,
421435
kind: SymbolExportKind::Text,
422436
used: false,
437+
rustc_std_internal_symbol: false,
423438
},
424439
));
425440
}
@@ -430,6 +445,7 @@ fn exported_symbols_provider_local<'tcx>(
430445
level: SymbolExportLevel::Rust,
431446
kind: SymbolExportKind::Text,
432447
used: false,
448+
rustc_std_internal_symbol: false,
433449
},
434450
));
435451
}

compiler/rustc_codegen_ssa/src/base.rs

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::time::{Duration, Instant};
66
use itertools::Itertools;
77
use rustc_abi::FIRST_VARIANT;
88
use rustc_ast as ast;
9-
use rustc_ast::expand::allocator::{ALLOCATOR_METHODS, AllocatorKind, global_fn_name};
9+
use rustc_ast::expand::allocator::AllocatorKind;
1010
use rustc_attr_data_structures::OptimizeAttr;
1111
use rustc_data_structures::fx::{FxHashMap, FxIndexSet};
1212
use rustc_data_structures::profiling::{get_resident_set_size, print_time_passes_entry};
@@ -1056,26 +1056,6 @@ impl CrateInfo {
10561056
.collect::<Vec<_>>();
10571057
symbols.sort_unstable_by(|a, b| a.0.cmp(&b.0));
10581058
linked_symbols.extend(symbols);
1059-
if tcx.allocator_kind(()).is_some() {
1060-
// At least one crate needs a global allocator. This crate may be placed
1061-
// after the crate that defines it in the linker order, in which case some
1062-
// linkers return an error. By adding the global allocator shim methods to
1063-
// the linked_symbols list, linking the generated symbols.o will ensure that
1064-
// circular dependencies involving the global allocator don't lead to linker
1065-
// errors.
1066-
linked_symbols.extend(ALLOCATOR_METHODS.iter().map(|method| {
1067-
(
1068-
add_prefix(
1069-
mangle_internal_symbol(
1070-
tcx,
1071-
global_fn_name(method.name).as_str(),
1072-
),
1073-
SymbolExportKind::Text,
1074-
),
1075-
SymbolExportKind::Text,
1076-
)
1077-
}));
1078-
}
10791059
});
10801060
}
10811061

compiler/rustc_const_eval/messages.ftl

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -125,16 +125,11 @@ const_eval_incompatible_types =
125125
calling a function with argument of type {$callee_ty} passing data of type {$caller_ty}
126126
127127
const_eval_interior_mutable_borrow_escaping =
128-
interior mutable shared borrows of lifetime-extended temporaries in the top-level scope of a {const_eval_const_context} are not allowed
129-
.label = this borrow of an interior mutable value refers to a lifetime-extended temporary
130-
.help = to fix this, the value can be extracted to a separate `static` item and then referenced
131-
.teach_note =
132-
This creates a raw pointer to a temporary that has its lifetime extended to last for the entire program.
133-
Lifetime-extended temporaries in constants and statics must be immutable.
134-
This is to avoid accidentally creating shared mutable state.
135-
136-
137-
If you really want global mutable state, try using an interior mutable `static` or a `static mut`.
128+
interior mutable shared borrows of temporaries that have their lifetime extended until the end of the program are not allowed
129+
.label = this borrow of an interior mutable value refers to such a temporary
130+
.note = Temporaries in constants and statics can have their lifetime extended until the end of the program
131+
.note2 = To avoid accidentally creating global mutable state, such temporaries must be immutable
132+
.help = If you really want global mutable state, try replacing the temporary by an interior mutable `static` or a `static mut`
138133
139134
const_eval_intern_kind = {$kind ->
140135
[static] static
@@ -215,14 +210,11 @@ const_eval_modified_global =
215210
modifying a static's initial value from another static's initializer
216211
217212
const_eval_mutable_borrow_escaping =
218-
mutable borrows of lifetime-extended temporaries in the top-level scope of a {const_eval_const_context} are not allowed
219-
.teach_note =
220-
This creates a reference to a temporary that has its lifetime extended to last for the entire program.
221-
Lifetime-extended temporaries in constants and statics must be immutable.
222-
This is to avoid accidentally creating shared mutable state.
223-
224-
225-
If you really want global mutable state, try using an interior mutable `static` or a `static mut`.
213+
mutable borrows of temporaries that have their lifetime extended until the end of the program are not allowed
214+
.label = this mutable borrow refers to such a temporary
215+
.note = Temporaries in constants and statics can have their lifetime extended until the end of the program
216+
.note2 = To avoid accidentally creating global mutable state, such temporaries must be immutable
217+
.help = If you really want global mutable state, try replacing the temporary by an interior mutable `static` or a `static mut`
226218
227219
const_eval_mutable_ptr_in_final = encountered mutable pointer in final value of {const_eval_intern_kind}
228220

compiler/rustc_const_eval/src/check_consts/check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> {
421421
Some(ConstConditionsHold::Yes)
422422
} else {
423423
tcx.dcx()
424-
.span_delayed_bug(call_span, "this should have reported a ~const error in HIR");
424+
.span_delayed_bug(call_span, "this should have reported a [const] error in HIR");
425425
Some(ConstConditionsHold::No)
426426
}
427427
}

compiler/rustc_const_eval/src/check_consts/ops.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
149149
debug!(?param_ty);
150150
if let Some(generics) = tcx.hir_node_by_def_id(caller).generics() {
151151
let constraint = with_no_trimmed_paths!(format!(
152-
"~const {}",
152+
"[const] {}",
153153
trait_ref.print_trait_sugared(),
154154
));
155155
suggest_constraining_type_param(
@@ -567,12 +567,7 @@ impl<'tcx> NonConstOp<'tcx> for EscapingCellBorrow {
567567
DiagImportance::Secondary
568568
}
569569
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
570-
ccx.dcx().create_err(errors::InteriorMutableBorrowEscaping {
571-
span,
572-
opt_help: matches!(ccx.const_kind(), hir::ConstContext::Static(_)),
573-
kind: ccx.const_kind(),
574-
teach: ccx.tcx.sess.teach(E0492),
575-
})
570+
ccx.dcx().create_err(errors::InteriorMutableBorrowEscaping { span, kind: ccx.const_kind() })
576571
}
577572
}
578573

@@ -594,11 +589,7 @@ impl<'tcx> NonConstOp<'tcx> for EscapingMutBorrow {
594589
}
595590

596591
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
597-
ccx.dcx().create_err(errors::MutableBorrowEscaping {
598-
span,
599-
kind: ccx.const_kind(),
600-
teach: ccx.tcx.sess.teach(E0764),
601-
})
592+
ccx.dcx().create_err(errors::MutableBorrowEscaping { span, kind: ccx.const_kind() })
602593
}
603594
}
604595

compiler/rustc_const_eval/src/check_consts/qualifs.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,14 +170,14 @@ impl Qualif for NeedsNonConstDrop {
170170

171171
#[instrument(level = "trace", skip(cx), ret)]
172172
fn in_any_value_of_ty<'tcx>(cx: &ConstCx<'_, 'tcx>, ty: Ty<'tcx>) -> bool {
173-
// If this doesn't need drop at all, then don't select `~const Destruct`.
173+
// If this doesn't need drop at all, then don't select `[const] Destruct`.
174174
if !ty.needs_drop(cx.tcx, cx.typing_env) {
175175
return false;
176176
}
177177

178-
// We check that the type is `~const Destruct` since that will verify that
179-
// the type is both `~const Drop` (if a drop impl exists for the adt), *and*
180-
// that the components of this type are also `~const Destruct`. This
178+
// We check that the type is `[const] Destruct` since that will verify that
179+
// the type is both `[const] Drop` (if a drop impl exists for the adt), *and*
180+
// that the components of this type are also `[const] Destruct`. This
181181
// amounts to verifying that there are no values in this ADT that may have
182182
// a non-const drop.
183183
let destruct_def_id = cx.tcx.require_lang_item(LangItem::Destruct, cx.body.span);
@@ -203,9 +203,9 @@ impl Qualif for NeedsNonConstDrop {
203203
fn is_structural_in_adt_value<'tcx>(cx: &ConstCx<'_, 'tcx>, adt: AdtDef<'tcx>) -> bool {
204204
// As soon as an ADT has a destructor, then the drop becomes non-structural
205205
// in its value since:
206-
// 1. The destructor may have `~const` bounds which are not present on the type.
206+
// 1. The destructor may have `[const]` bounds which are not present on the type.
207207
// Someone needs to check that those are satisfied.
208-
// While this could be instead satisfied by checking that the `~const Drop`
208+
// While this could be instead satisfied by checking that the `[const] Drop`
209209
// impl holds (i.e. replicating part of the `in_any_value_of_ty` logic above),
210210
// even in this case, we have another problem, which is,
211211
// 2. The destructor may *modify* the operand being dropped, so even if we

compiler/rustc_const_eval/src/const_eval/mod.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,13 @@ pub(crate) fn try_destructure_mir_constant_for_user_output<'tcx>(
6666
#[instrument(skip(tcx), level = "debug")]
6767
pub fn tag_for_variant_provider<'tcx>(
6868
tcx: TyCtxt<'tcx>,
69-
(ty, variant_index): (Ty<'tcx>, VariantIdx),
69+
key: ty::PseudoCanonicalInput<'tcx, (Ty<'tcx>, VariantIdx)>,
7070
) -> Option<ty::ScalarInt> {
71+
let (ty, variant_index) = key.value;
7172
assert!(ty.is_enum());
7273

73-
// FIXME: This uses an empty `TypingEnv` even though
74-
// it may be used by a generic CTFE.
75-
let ecx = InterpCx::new(
76-
tcx,
77-
ty.default_span(tcx),
78-
ty::TypingEnv::fully_monomorphized(),
79-
crate::const_eval::DummyMachine,
80-
);
74+
let ecx =
75+
InterpCx::new(tcx, ty.default_span(tcx), key.typing_env, crate::const_eval::DummyMachine);
8176

8277
let layout = ecx.layout_of(ty).unwrap();
8378
ecx.tag_for_variant(layout, variant_index).unwrap().map(|(tag, _tag_field)| tag)

0 commit comments

Comments
 (0)