- // in order for a libstd function to be considered min_const_fn
- // it needs to be stable and have no `rustc_const_unstable` attribute
- match self.lookup_stability(def_id) {
- // stable functions with unstable const fn aren't `min_const_fn`
- Some(&attr::Stability { const_stability: Some(_), .. }) => false,
- // unstable functions don't need to conform
- Some(&attr::Stability { ref level, .. }) if level.is_unstable() => false,
- // everything else needs to conform, because it would be callable from
- // other `min_const_fn` functions
+ // In order for a libstd function to be considered min_const_fn
+ // it needs to be stable and have no `rustc_const_unstable` attribute.
+ match self.lookup_const_stability(def_id) {
+ // `rustc_const_unstable` functions don't need to conform.
+ Some(&attr::ConstStability { ref level, .. }) if level.is_unstable() => false,
+ None => if let Some(stab) = self.lookup_stability(def_id) {
+ if stab.level.is_stable() {
+ self.sess.span_err(
+ self.def_span(def_id),
+ "stable const functions must have either `rustc_const_stable` or \
+ `rustc_const_unstable` attribute",
+ );
+ // While we errored above, because we don't know if we need to conform, we
+ // err on the "safe" side and require min_const_fn.
+ true
+ } else {
+ // Unstable functions need not conform to min const fn.
+ false
+ }
+ } else {
+ // Unstable functions or internal functions need not conform to min const fn.
+ false
+ },
+ // Everything else needs to conform, because it would be callable from
+ // other `min_const_fn` functions.