Rollup merge of #86142 - m-ou-se:proc-macro-subspan-bound-cloned-cleanup, r=petrochenkov

Simplify proc_macro code using Bound::cloned().
This commit is contained in:
Yuki Okushi 2021-06-09 12:04:08 +09:00 committed by GitHub
commit 3a9609b936
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -31,6 +31,7 @@
#![feature(restricted_std)]
#![feature(rustc_attrs)]
#![feature(min_specialization)]
#![feature(bound_cloned)]
#![recursion_limit = "256"]
#[unstable(feature = "proc_macro_internals", issue = "27812")]
@ -43,7 +44,7 @@ mod diagnostic;
pub use diagnostic::{Diagnostic, Level, MultiSpan};
use std::cmp::Ordering;
use std::ops::{Bound, RangeBounds};
use std::ops::RangeBounds;
use std::path::PathBuf;
use std::str::FromStr;
use std::{error, fmt, iter, mem};
@ -1162,16 +1163,7 @@ impl Literal {
// was 'c' or whether it was '\u{63}'.
#[unstable(feature = "proc_macro_span", issue = "54725")]
pub fn subspan<R: RangeBounds<usize>>(&self, range: R) -> Option<Span> {
// HACK(eddyb) something akin to `Option::cloned`, but for `Bound<&T>`.
fn cloned_bound<T: Clone>(bound: Bound<&T>) -> Bound<T> {
match bound {
Bound::Included(x) => Bound::Included(x.clone()),
Bound::Excluded(x) => Bound::Excluded(x.clone()),
Bound::Unbounded => Bound::Unbounded,
}
}
self.0.subspan(cloned_bound(range.start_bound()), cloned_bound(range.end_bound())).map(Span)
self.0.subspan(range.start_bound().cloned(), range.end_bound().cloned()).map(Span)
}
}