Skip to content

Commit 978fe3c

Browse files
committed
Cleanup
1 parent d0ab32e commit 978fe3c

File tree

11 files changed

+29
-36
lines changed

11 files changed

+29
-36
lines changed

compiler/rustc_const_eval/src/const_eval/eval_queries.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ pub fn eval_to_const_value_raw_provider<'tcx>(
292292
tcx: TyCtxt<'tcx>,
293293
key: ty::PseudoCanonicalInput<'tcx, GlobalId<'tcx>>,
294294
) -> ::rustc_middle::mir::interpret::EvalToConstValueResult<'tcx> {
295-
if let Some((value, _ty)) = tcx.is_trivial_const(key.value.instance.def_id()) {
295+
if let Some((value, _ty)) = tcx.trivial_const(key.value.instance.def_id()) {
296296
return Ok(value);
297297
}
298298
tcx.eval_to_allocation_raw(key).map(|val| turn_into_const_value(tcx, val, key))
@@ -359,7 +359,6 @@ fn eval_in_interpreter<'tcx, R: InterpretationResult<'tcx>>(
359359
typing_env: ty::TypingEnv<'tcx>,
360360
) -> Result<R, ErrorHandled> {
361361
let def = cid.instance.def.def_id();
362-
363362
let is_static = tcx.is_static(def);
364363

365364
let mut ecx = InterpCx::new(
@@ -373,7 +372,7 @@ fn eval_in_interpreter<'tcx, R: InterpretationResult<'tcx>>(
373372
CompileTimeMachine::new(CanAccessMutGlobal::from(is_static), CheckAlignment::Error),
374373
);
375374

376-
if let Some((value, ty)) = tcx.is_trivial_const(def) {
375+
if let Some((value, ty)) = tcx.trivial_const(def) {
377376
let layout = ecx.layout_of(ty).unwrap();
378377
let opty = ecx.const_val_to_op(value, ty, Some(layout)).unwrap();
379378
let res = ecx.allocate(layout, MemoryKind::Stack).unwrap();

compiler/rustc_interface/src/passes.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,7 +1088,7 @@ fn run_required_analyses(tcx: TyCtxt<'_>) {
10881088

10891089
sess.time("MIR_borrow_checking", || {
10901090
tcx.par_hir_body_owners(|def_id| {
1091-
if tcx.is_trivial_const(def_id).is_some() {
1091+
if tcx.is_trivial_const(def_id) {
10921092
return;
10931093
}
10941094
if !tcx.is_typeck_child(def_id.to_def_id()) {
@@ -1201,7 +1201,7 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) {
12011201
if tcx.sess.opts.unstable_opts.validate_mir {
12021202
sess.time("ensuring_final_MIR_is_computable", || {
12031203
tcx.par_hir_body_owners(|def_id| {
1204-
if tcx.is_trivial_const(def_id).is_none() {
1204+
if !tcx.is_trivial_const(def_id) {
12051205
tcx.instance_mir(ty::InstanceKind::Item(def_id.into()));
12061206
}
12071207
});

compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ provide! { tcx, def_id, other, cdata,
240240
thir_abstract_const => { table }
241241
optimized_mir => { table }
242242
mir_for_ctfe => { table }
243-
is_trivial_const => { table }
243+
trivial_const => { table }
244244
closure_saved_names_of_captured_variables => { table }
245245
mir_coroutine_witnesses => { table }
246246
promoted_mir => { table }

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1793,9 +1793,9 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
17931793
}
17941794
let mut is_trivial = false;
17951795
if encode_const {
1796-
if let Some((val, ty)) = tcx.is_trivial_const(def_id) {
1796+
if let Some((val, ty)) = tcx.trivial_const(def_id) {
17971797
is_trivial = true;
1798-
record!(self.tables.is_trivial_const[def_id.to_def_id()] <- (val, ty));
1798+
record!(self.tables.trivial_const[def_id.to_def_id()] <- (val, ty));
17991799
} else {
18001800
is_trivial = false;
18011801
record!(self.tables.mir_for_ctfe[def_id.to_def_id()] <- tcx.mir_for_ctfe(def_id));
@@ -2243,7 +2243,7 @@ fn prefetch_mir(tcx: TyCtxt<'_>) {
22432243

22442244
let reachable_set = tcx.reachable_set(());
22452245
par_for_each_in(tcx.mir_keys(()), |&&def_id| {
2246-
if tcx.is_trivial_const(def_id).is_some() {
2246+
if tcx.is_trivial_const(def_id) {
22472247
return;
22482248
}
22492249
let (encode_const, encode_opt) = should_encode_mir(tcx, reachable_set, def_id);

compiler/rustc_metadata/src/rmeta/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ define_tables! {
427427
object_lifetime_default: Table<DefIndex, LazyValue<ObjectLifetimeDefault>>,
428428
optimized_mir: Table<DefIndex, LazyValue<mir::Body<'static>>>,
429429
mir_for_ctfe: Table<DefIndex, LazyValue<mir::Body<'static>>>,
430-
is_trivial_const: Table<DefIndex, LazyValue<(ConstValue, Ty<'static>)>>,
430+
trivial_const: Table<DefIndex, LazyValue<(ConstValue, Ty<'static>)>>,
431431
closure_saved_names_of_captured_variables: Table<DefIndex, LazyValue<IndexVec<FieldIdx, Symbol>>>,
432432
mir_coroutine_witnesses: Table<DefIndex, LazyValue<mir::CoroutineLayout<'static>>>,
433433
promoted_mir: Table<DefIndex, LazyValue<IndexVec<mir::Promoted, mir::Body<'static>>>>,

compiler/rustc_middle/src/mir/graphviz.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ where
1616

1717
let mirs = def_ids
1818
.iter()
19-
.filter(|def_id| tcx.is_trivial_const(*def_id).is_none())
19+
.filter(|def_id| !tcx.is_trivial_const(*def_id))
2020
.flat_map(|def_id| {
2121
if tcx.is_const_fn(*def_id) {
2222
vec![tcx.optimized_mir(*def_id), tcx.mir_for_ctfe(*def_id)]

compiler/rustc_middle/src/mir/pretty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ pub fn write_mir_pretty<'tcx>(
353353
// are shared between mir_for_ctfe and optimized_mir
354354
writer.write_mir_fn(tcx.mir_for_ctfe(def_id), w)?;
355355
} else {
356-
if tcx.is_trivial_const(def_id).is_none() {
356+
if !tcx.is_trivial_const(def_id) {
357357
let instance_mir = tcx.instance_mir(ty::InstanceKind::Item(def_id));
358358
render_body(w, instance_mir)?;
359359
}

compiler/rustc_middle/src/query/erase.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,6 @@ impl EraseType for Result<mir::ConstValue, mir::interpret::ErrorHandled> {
160160
type Result = [u8; size_of::<Result<mir::ConstValue, mir::interpret::ErrorHandled>>()];
161161
}
162162

163-
impl EraseType for Option<mir::ConstValue> {
164-
type Result = [u8; size_of::<Option<mir::ConstValue>>()];
165-
}
166-
167163
impl EraseType for Option<(mir::ConstValue, Ty<'_>)> {
168164
type Result = [u8; size_of::<Option<(mir::ConstValue, Ty<'_>)>>()];
169165
}

compiler/rustc_middle/src/query/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2719,7 +2719,7 @@ rustc_queries! {
27192719
separate_provide_extern
27202720
}
27212721

2722-
query is_trivial_const(def_id: DefId) -> Option<(mir::ConstValue, Ty<'tcx>)> {
2722+
query trivial_const(def_id: DefId) -> Option<(mir::ConstValue, Ty<'tcx>)> {
27232723
desc { |tcx| "checking if `{}` is a trivial const", tcx.def_path_str(def_id) }
27242724
cache_on_disk_if { def_id.is_local() }
27252725
separate_provide_extern

compiler/rustc_middle/src/ty/context.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3546,6 +3546,13 @@ impl<'tcx> TyCtxt<'tcx> {
35463546
self.get_diagnostic_attr(def_id, sym::do_not_recommend).is_some()
35473547
}
35483548

3549+
pub fn is_trivial_const<P>(self, def_id: P) -> bool
3550+
where
3551+
P: IntoQueryParam<DefId>,
3552+
{
3553+
self.trivial_const(def_id).is_some()
3554+
}
3555+
35493556
/// Whether this def is one of the special bin crate entrypoint functions that must have a
35503557
/// monomorphization and also not be internalized in the bin crate.
35513558
pub fn is_entrypoint(self, def_id: DefId) -> bool {

0 commit comments

Comments
 (0)