Skip to content

Commit b75d5f1

Browse files
committed
Clean up the logic in is_min_const_fn
1 parent ae0b00c commit b75d5f1

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

src/librustc/ty/constness.rs

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,24 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
4040

4141
/// Returns true if this function must conform to `min_const_fn`
4242
pub fn is_min_const_fn(self, def_id: DefId) -> bool {
43-
if self.features().staged_api {
44-
// some intrinsics are waved through if called inside the
45-
// standard library. Users never need to call them directly
46-
if let abi::Abi::RustIntrinsic = self.fn_sig(def_id).abi() {
47-
assert!(!self.is_const_fn(def_id));
48-
match &self.item_name(def_id).as_str()[..] {
49-
| "size_of"
50-
| "min_align_of"
51-
| "needs_drop"
52-
=> return true,
53-
_ => {},
54-
}
43+
// some intrinsics are waved through if called inside the
44+
// standard library. Users never need to call them directly
45+
if let abi::Abi::RustIntrinsic = self.fn_sig(def_id).abi() {
46+
match &self.item_name(def_id).as_str()[..] {
47+
| "size_of"
48+
| "min_align_of"
49+
| "needs_drop"
50+
=> return true,
51+
_ => {},
5552
}
53+
}
54+
55+
// Bail out if the signature doesn't contain `const`
56+
if !self.is_const_fn_raw(def_id) {
57+
return false;
58+
}
59+
60+
if self.features().staged_api {
5661
// in order for a libstd function to be considered min_const_fn
5762
// it needs to be stable and have no `rustc_const_unstable` attribute
5863
self.is_const_fn_raw(def_id) && match self.lookup_stability(def_id) {
@@ -66,7 +71,7 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
6671
}
6772
} else {
6873
// users enabling the `const_fn` feature gate can do what they want
69-
self.is_const_fn_raw(def_id) && !self.features().const_fn
74+
!self.features().const_fn
7075
}
7176
}
7277
}

0 commit comments

Comments
 (0)