Skip to content

Rollup of 10 pull requests #141790

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
5f8954b
Fix the issue of typo of comma in arm parsing
chenyukang May 16, 2025
90ebad3
add exact_div functions
Qelxiros May 19, 2025
457f8ba
mir-opt: Do not transform non-int type in match_branches
dianqk May 24, 2025
e7683f1
core: begin deduplicating pointer docs
lolbinarycat May 26, 2025
51d247c
Add Range parameter to `BTreeMap::extract_if` and `BTreeSet::extract_if`
rs-sac May 8, 2025
1ae96fc
Update tests with Range parameter to `BTreeMap::extract_if` etc.
rs-sac May 8, 2025
38c37eb
Update docs for new Range parameter to `BTreeMap::extract_if` etc.
rs-sac May 8, 2025
8656d9e
Unit test for Range parameter of `BTreeMap::extract_if`
rs-sac May 8, 2025
5b68db1
ci: use arm to calculate job matrix
marcoieni May 30, 2025
78d9874
Increase timeout for new bors try builds
Kobzol May 30, 2025
4a18439
Fix spans for unsafe binders
matthewjasper May 30, 2025
d5802c1
Rollup merge of #140825 - rs-sac:ext, r=workingjubilee
workingjubilee May 30, 2025
c913ca9
Rollup merge of #141077 - chenyukang:yukang-fix-140991-comma, r=wesle…
workingjubilee May 30, 2025
f199b12
Rollup merge of #141237 - Qelxiros:139911-exact-div, r=workingjubilee
workingjubilee May 30, 2025
1c72ac0
Rollup merge of #141494 - dianqk:match-br-non-int, r=wesleywiser
workingjubilee May 30, 2025
909eefd
Rollup merge of #141609 - lolbinarycat:core-dedup-ptr-docs-139190, r=…
workingjubilee May 30, 2025
2edc950
Rollup merge of #141768 - marcoieni:calculate-matrix-arm, r=Kobzol
workingjubilee May 30, 2025
1c77136
Rollup merge of #141771 - Kobzol:bors-increase-timeout, r=marcoieni
workingjubilee May 30, 2025
e51a52a
Rollup merge of #141781 - matthewjasper:unused-unsafe-lifetimes, r=co…
workingjubilee May 30, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
# If you want to modify CI jobs, take a look at src/ci/github-actions/jobs.yml.
calculate_matrix:
name: Calculate job matrix
runs-on: ubuntu-24.04
runs-on: ubuntu-24.04-arm
outputs:
jobs: ${{ steps.jobs.outputs.jobs }}
run_type: ${{ steps.jobs.outputs.run_type }}
Expand Down
6 changes: 4 additions & 2 deletions compiler/rustc_mir_transform/src/match_branches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,12 +284,14 @@ fn can_cast(
let v = match src_layout.ty.kind() {
ty::Uint(_) => from_scalar.to_uint(src_layout.size),
ty::Int(_) => from_scalar.to_int(src_layout.size) as u128,
_ => unreachable!("invalid int"),
// We can also transform the values of other integer representations (such as char),
// although this may not be practical in real-world scenarios.
_ => return false,
};
let size = match *cast_ty.kind() {
ty::Int(t) => Integer::from_int_ty(&tcx, t).size(),
ty::Uint(t) => Integer::from_uint_ty(&tcx, t).size(),
_ => unreachable!("invalid int"),
_ => return false,
};
let v = size.truncate(v);
let cast_scalar = ScalarInt::try_from_uint(v, size).unwrap();
Expand Down
54 changes: 36 additions & 18 deletions compiler/rustc_parse/src/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3311,26 +3311,44 @@ impl<'a> Parser<'a> {
let sm = this.psess.source_map();
if let Ok(expr_lines) = sm.span_to_lines(expr_span)
&& let Ok(arm_start_lines) = sm.span_to_lines(arm_start_span)
&& arm_start_lines.lines[0].end_col == expr_lines.lines[0].end_col
&& expr_lines.lines.len() == 2
{
// We check whether there's any trailing code in the parse span,
// if there isn't, we very likely have the following:
//
// X | &Y => "y"
// | -- - missing comma
// | |
// | arrow_span
// X | &X => "x"
// | - ^^ self.token.span
// | |
// | parsed until here as `"y" & X`
err.span_suggestion_short(
arm_start_span.shrink_to_hi(),
"missing a comma here to end this `match` arm",
",",
Applicability::MachineApplicable,
);
if arm_start_lines.lines[0].end_col == expr_lines.lines[0].end_col {
// We check whether there's any trailing code in the parse span,
// if there isn't, we very likely have the following:
//
// X | &Y => "y"
// | -- - missing comma
// | |
// | arrow_span
// X | &X => "x"
// | - ^^ self.token.span
// | |
// | parsed until here as `"y" & X`
err.span_suggestion_short(
arm_start_span.shrink_to_hi(),
"missing a comma here to end this `match` arm",
",",
Applicability::MachineApplicable,
);
} else if arm_start_lines.lines[0].end_col + rustc_span::CharPos(1)
== expr_lines.lines[0].end_col
{
// similar to the above, but we may typo a `.` or `/` at the end of the line
let comma_span = arm_start_span
.shrink_to_hi()
.with_hi(arm_start_span.hi() + rustc_span::BytePos(1));
if let Ok(res) = sm.span_to_snippet(comma_span)
&& (res == "." || res == "/")
{
err.span_suggestion_short(
comma_span,
"you might have meant to write a `,` to end this `match` arm",
",",
Applicability::MachineApplicable,
);
}
}
}
} else {
err.span_label(
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -934,8 +934,7 @@ impl<'ra: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'_, 'ast, 'r
)
}
TyKind::UnsafeBinder(unsafe_binder) => {
// FIXME(unsafe_binder): Better span
let span = ty.span;
let span = ty.span.shrink_to_lo().to(unsafe_binder.inner_ty.span.shrink_to_lo());
self.with_generic_param_rib(
&unsafe_binder.generic_params,
RibKind::Normal,
Expand Down
62 changes: 48 additions & 14 deletions library/alloc/src/collections/btree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1151,7 +1151,7 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
K: Ord,
F: FnMut(&K, &mut V) -> bool,
{
self.extract_if(|k, v| !f(k, v)).for_each(drop);
self.extract_if(.., |k, v| !f(k, v)).for_each(drop);
}

/// Moves all elements from `other` into `self`, leaving `other` empty.
Expand Down Expand Up @@ -1397,7 +1397,7 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
}
}

/// Creates an iterator that visits all elements (key-value pairs) in
/// Creates an iterator that visits elements (key-value pairs) in the specified range in
/// ascending key order and uses a closure to determine if an element
/// should be removed.
///
Expand All @@ -1423,33 +1423,42 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
/// use std::collections::BTreeMap;
///
/// let mut map: BTreeMap<i32, i32> = (0..8).map(|x| (x, x)).collect();
/// let evens: BTreeMap<_, _> = map.extract_if(|k, _v| k % 2 == 0).collect();
/// let evens: BTreeMap<_, _> = map.extract_if(.., |k, _v| k % 2 == 0).collect();
/// let odds = map;
/// assert_eq!(evens.keys().copied().collect::<Vec<_>>(), [0, 2, 4, 6]);
/// assert_eq!(odds.keys().copied().collect::<Vec<_>>(), [1, 3, 5, 7]);
///
/// let mut map: BTreeMap<i32, i32> = (0..8).map(|x| (x, x)).collect();
/// let low: BTreeMap<_, _> = map.extract_if(0..4, |_k, _v| true).collect();
/// let high = map;
/// assert_eq!(low.keys().copied().collect::<Vec<_>>(), [0, 1, 2, 3]);
/// assert_eq!(high.keys().copied().collect::<Vec<_>>(), [4, 5, 6, 7]);
/// ```
#[unstable(feature = "btree_extract_if", issue = "70530")]
pub fn extract_if<F>(&mut self, pred: F) -> ExtractIf<'_, K, V, F, A>
pub fn extract_if<F, R>(&mut self, range: R, pred: F) -> ExtractIf<'_, K, V, R, F, A>
where
K: Ord,
R: RangeBounds<K>,
F: FnMut(&K, &mut V) -> bool,
{
let (inner, alloc) = self.extract_if_inner();
let (inner, alloc) = self.extract_if_inner(range);
ExtractIf { pred, inner, alloc }
}

pub(super) fn extract_if_inner(&mut self) -> (ExtractIfInner<'_, K, V>, A)
pub(super) fn extract_if_inner<R>(&mut self, range: R) -> (ExtractIfInner<'_, K, V, R>, A)
where
K: Ord,
R: RangeBounds<K>,
{
if let Some(root) = self.root.as_mut() {
let (root, dormant_root) = DormantMutRef::new(root);
let front = root.borrow_mut().first_leaf_edge();
let first = root.borrow_mut().lower_bound(SearchBound::from_range(range.start_bound()));
(
ExtractIfInner {
length: &mut self.length,
dormant_root: Some(dormant_root),
cur_leaf_edge: Some(front),
cur_leaf_edge: Some(first),
range,
},
(*self.alloc).clone(),
)
Expand All @@ -1459,6 +1468,7 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
length: &mut self.length,
dormant_root: None,
cur_leaf_edge: None,
range,
},
(*self.alloc).clone(),
)
Expand Down Expand Up @@ -1917,18 +1927,19 @@ pub struct ExtractIf<
'a,
K,
V,
R,
F,
#[unstable(feature = "allocator_api", issue = "32838")] A: Allocator + Clone = Global,
> {
pred: F,
inner: ExtractIfInner<'a, K, V>,
inner: ExtractIfInner<'a, K, V, R>,
/// The BTreeMap will outlive this IntoIter so we don't care about drop order for `alloc`.
alloc: A,
}

/// Most of the implementation of ExtractIf are generic over the type
/// of the predicate, thus also serving for BTreeSet::ExtractIf.
pub(super) struct ExtractIfInner<'a, K, V> {
pub(super) struct ExtractIfInner<'a, K, V, R> {
/// Reference to the length field in the borrowed map, updated live.
length: &'a mut usize,
/// Buried reference to the root field in the borrowed map.
Expand All @@ -1938,10 +1949,13 @@ pub(super) struct ExtractIfInner<'a, K, V> {
/// Empty if the map has no root, if iteration went beyond the last leaf edge,
/// or if a panic occurred in the predicate.
cur_leaf_edge: Option<Handle<NodeRef<marker::Mut<'a>, K, V, marker::Leaf>, marker::Edge>>,
/// Range over which iteration was requested. We don't need the left side, but we
/// can't extract the right side without requiring K: Clone.
range: R,
}

#[unstable(feature = "btree_extract_if", issue = "70530")]
impl<K, V, F, A> fmt::Debug for ExtractIf<'_, K, V, F, A>
impl<K, V, R, F, A> fmt::Debug for ExtractIf<'_, K, V, R, F, A>
where
K: fmt::Debug,
V: fmt::Debug,
Expand All @@ -1953,8 +1967,10 @@ where
}

#[unstable(feature = "btree_extract_if", issue = "70530")]
impl<K, V, F, A: Allocator + Clone> Iterator for ExtractIf<'_, K, V, F, A>
impl<K, V, R, F, A: Allocator + Clone> Iterator for ExtractIf<'_, K, V, R, F, A>
where
K: PartialOrd,
R: RangeBounds<K>,
F: FnMut(&K, &mut V) -> bool,
{
type Item = (K, V);
Expand All @@ -1968,7 +1984,7 @@ where
}
}

impl<'a, K, V> ExtractIfInner<'a, K, V> {
impl<'a, K, V, R> ExtractIfInner<'a, K, V, R> {
/// Allow Debug implementations to predict the next element.
pub(super) fn peek(&self) -> Option<(&K, &V)> {
let edge = self.cur_leaf_edge.as_ref()?;
Expand All @@ -1978,10 +1994,22 @@ impl<'a, K, V> ExtractIfInner<'a, K, V> {
/// Implementation of a typical `ExtractIf::next` method, given the predicate.
pub(super) fn next<F, A: Allocator + Clone>(&mut self, pred: &mut F, alloc: A) -> Option<(K, V)>
where
K: PartialOrd,
R: RangeBounds<K>,
F: FnMut(&K, &mut V) -> bool,
{
while let Ok(mut kv) = self.cur_leaf_edge.take()?.next_kv() {
let (k, v) = kv.kv_mut();

// On creation, we navigated directly to the left bound, so we need only check the
// right bound here to decide whether to stop.
match self.range.end_bound() {
Bound::Included(ref end) if (*k).le(end) => (),
Bound::Excluded(ref end) if (*k).lt(end) => (),
Bound::Unbounded => (),
_ => return None,
}

if pred(k, v) {
*self.length -= 1;
let (kv, pos) = kv.remove_kv_tracking(
Expand Down Expand Up @@ -2013,7 +2041,13 @@ impl<'a, K, V> ExtractIfInner<'a, K, V> {
}

#[unstable(feature = "btree_extract_if", issue = "70530")]
impl<K, V, F> FusedIterator for ExtractIf<'_, K, V, F> where F: FnMut(&K, &mut V) -> bool {}
impl<K, V, R, F> FusedIterator for ExtractIf<'_, K, V, R, F>
where
K: PartialOrd,
R: RangeBounds<K>,
F: FnMut(&K, &mut V) -> bool,
{
}

#[stable(feature = "btree_range", since = "1.17.0")]
impl<'a, K, V> Iterator for Range<'a, K, V> {
Expand Down
Loading
Loading