Skip to content

Commit

Permalink
Rollup merge of rust-lang#86142 - m-ou-se:proc-macro-subspan-bound-cl…
Browse files Browse the repository at this point in the history
…oned-cleanup, r=petrochenkov

Simplify proc_macro code using Bound::cloned().
  • Loading branch information
JohnTitor committed Jun 9, 2021
2 parents e163e3c + 58e0889 commit 3a9609b
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions library/proc_macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand All @@ -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};
Expand Down Expand Up @@ -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)
}
}

Expand Down

0 comments on commit 3a9609b

Please sign in to comment.