Skip to content

Commit

Permalink
Clean up the logic in is_min_const_fn
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Dec 4, 2018
1 parent ae0b00c commit b75d5f1
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions src/librustc/ty/constness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,24 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {

/// Returns true if this function must conform to `min_const_fn`
pub fn is_min_const_fn(self, def_id: DefId) -> bool {
if self.features().staged_api {
// some intrinsics are waved through if called inside the
// standard library. Users never need to call them directly
if let abi::Abi::RustIntrinsic = self.fn_sig(def_id).abi() {
assert!(!self.is_const_fn(def_id));
match &self.item_name(def_id).as_str()[..] {
| "size_of"
| "min_align_of"
| "needs_drop"
=> return true,
_ => {},
}
// some intrinsics are waved through if called inside the
// standard library. Users never need to call them directly
if let abi::Abi::RustIntrinsic = self.fn_sig(def_id).abi() {
match &self.item_name(def_id).as_str()[..] {
| "size_of"
| "min_align_of"
| "needs_drop"
=> return true,
_ => {},
}
}

// Bail out if the signature doesn't contain `const`
if !self.is_const_fn_raw(def_id) {
return false;
}

if self.features().staged_api {
// in order for a libstd function to be considered min_const_fn
// it needs to be stable and have no `rustc_const_unstable` attribute
self.is_const_fn_raw(def_id) && match self.lookup_stability(def_id) {
Expand All @@ -66,7 +71,7 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
}
} else {
// users enabling the `const_fn` feature gate can do what they want
self.is_const_fn_raw(def_id) && !self.features().const_fn
!self.features().const_fn
}
}
}
Expand Down

0 comments on commit b75d5f1

Please sign in to comment.