Skip to content

Commit 3a9609b

Browse files
authored
Rollup merge of #86142 - m-ou-se:proc-macro-subspan-bound-cloned-cleanup, r=petrochenkov
Simplify proc_macro code using Bound::cloned().
2 parents e163e3c + 58e0889 commit 3a9609b

File tree

1 file changed

+3
-11
lines changed

1 file changed

+3
-11
lines changed

library/proc_macro/src/lib.rs

+3-11
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#![feature(restricted_std)]
3232
#![feature(rustc_attrs)]
3333
#![feature(min_specialization)]
34+
#![feature(bound_cloned)]
3435
#![recursion_limit = "256"]
3536

3637
#[unstable(feature = "proc_macro_internals", issue = "27812")]
@@ -43,7 +44,7 @@ mod diagnostic;
4344
pub use diagnostic::{Diagnostic, Level, MultiSpan};
4445

4546
use std::cmp::Ordering;
46-
use std::ops::{Bound, RangeBounds};
47+
use std::ops::RangeBounds;
4748
use std::path::PathBuf;
4849
use std::str::FromStr;
4950
use std::{error, fmt, iter, mem};
@@ -1162,16 +1163,7 @@ impl Literal {
11621163
// was 'c' or whether it was '\u{63}'.
11631164
#[unstable(feature = "proc_macro_span", issue = "54725")]
11641165
pub fn subspan<R: RangeBounds<usize>>(&self, range: R) -> Option<Span> {
1165-
// HACK(eddyb) something akin to `Option::cloned`, but for `Bound<&T>`.
1166-
fn cloned_bound<T: Clone>(bound: Bound<&T>) -> Bound<T> {
1167-
match bound {
1168-
Bound::Included(x) => Bound::Included(x.clone()),
1169-
Bound::Excluded(x) => Bound::Excluded(x.clone()),
1170-
Bound::Unbounded => Bound::Unbounded,
1171-
}
1172-
}
1173-
1174-
self.0.subspan(cloned_bound(range.start_bound()), cloned_bound(range.end_bound())).map(Span)
1166+
self.0.subspan(range.start_bound().cloned(), range.end_bound().cloned()).map(Span)
11751167
}
11761168
}
11771169

0 commit comments

Comments
 (0)