Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 2913ad6

Browse files
committed
Auto merge of rust-lang#111585 - matthiaskrgr:rollup-468pykj, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - rust-lang#102673 (Update doc for `PhantomData` to match code example) - rust-lang#111531 (Fix ice caused by shorthand fields in NoFieldsForFnCall) - rust-lang#111547 (Start node has no immediate dominator) - rust-lang#111548 (add util function to TokenStream to eliminate some clones) - rust-lang#111560 (Simplify find_width_of_character_at_span.) - rust-lang#111569 (Appease lints) - rust-lang#111581 (Fix some misleading and copy-pasted `Pattern` examples) - rust-lang#111582 ((docs) Change "wanting" to "want") Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 8006510 + 75186c0 commit 2913ad6

File tree

15 files changed

+84
-67
lines changed

15 files changed

+84
-67
lines changed

compiler/rustc_ast/src/tokenstream.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,10 @@ impl TokenStream {
551551
vec_mut.extend(stream_iter);
552552
}
553553
}
554+
555+
pub fn chunks(&self, chunk_size: usize) -> core::slice::Chunks<'_, TokenTree> {
556+
self.0.chunks(chunk_size)
557+
}
554558
}
555559

556560
/// By-reference iterator over a [`TokenStream`], that produces `&TokenTree`

compiler/rustc_const_eval/src/transform/validate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
164164
if let Some(root) = post_contract_node.get(&bb) {
165165
break *root;
166166
}
167-
let parent = doms.immediate_dominator(bb);
167+
let parent = doms.immediate_dominator(bb).unwrap();
168168
dom_path.push(bb);
169169
if !self.body.basic_blocks[parent].is_cleanup {
170170
break bb;

compiler/rustc_data_structures/src/graph/dominators/mod.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,9 @@ pub fn dominators<G: ControlFlowGraph>(graph: G) -> Dominators<G::Node> {
242242
immediate_dominators[*node] = Some(pre_order_to_real[idom[idx]]);
243243
}
244244

245-
Dominators { post_order_rank, immediate_dominators }
245+
let start_node = graph.start_node();
246+
immediate_dominators[start_node] = None;
247+
Dominators { start_node, post_order_rank, immediate_dominators }
246248
}
247249

248250
/// Evaluate the link-eval virtual forest, providing the currently minimum semi
@@ -308,6 +310,7 @@ fn compress(
308310
/// Tracks the list of dominators for each node.
309311
#[derive(Clone, Debug)]
310312
pub struct Dominators<N: Idx> {
313+
start_node: N,
311314
post_order_rank: IndexVec<N, usize>,
312315
// Even though we track only the immediate dominator of each node, it's
313316
// possible to get its full list of dominators by looking up the dominator
@@ -316,14 +319,14 @@ pub struct Dominators<N: Idx> {
316319
}
317320

318321
impl<Node: Idx> Dominators<Node> {
319-
/// Whether the given Node has an immediate dominator.
322+
/// Returns true if node is reachable from the start node.
320323
pub fn is_reachable(&self, node: Node) -> bool {
321-
self.immediate_dominators[node].is_some()
324+
node == self.start_node || self.immediate_dominators[node].is_some()
322325
}
323326

324-
pub fn immediate_dominator(&self, node: Node) -> Node {
325-
assert!(self.is_reachable(node), "node {node:?} is not reachable");
326-
self.immediate_dominators[node].unwrap()
327+
/// Returns the immediate dominator of node, if any.
328+
pub fn immediate_dominator(&self, node: Node) -> Option<Node> {
329+
self.immediate_dominators[node]
327330
}
328331

329332
/// Provides an iterator over each dominator up the CFG, for the given Node.
@@ -357,12 +360,7 @@ impl<'dom, Node: Idx> Iterator for Iter<'dom, Node> {
357360

358361
fn next(&mut self) -> Option<Self::Item> {
359362
if let Some(node) = self.node {
360-
let dom = self.dominators.immediate_dominator(node);
361-
if dom == node {
362-
self.node = None; // reached the root
363-
} else {
364-
self.node = Some(dom);
365-
}
363+
self.node = self.dominators.immediate_dominator(node);
366364
Some(node)
367365
} else {
368366
None

compiler/rustc_data_structures/src/graph/dominators/tests.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ fn diamond() {
88

99
let dominators = dominators(&graph);
1010
let immediate_dominators = &dominators.immediate_dominators;
11-
assert_eq!(immediate_dominators[0], Some(0));
11+
assert_eq!(immediate_dominators[0], None);
1212
assert_eq!(immediate_dominators[1], Some(0));
1313
assert_eq!(immediate_dominators[2], Some(0));
1414
assert_eq!(immediate_dominators[3], Some(0));
@@ -30,7 +30,7 @@ fn paper() {
3030
assert_eq!(immediate_dominators[3], Some(6));
3131
assert_eq!(immediate_dominators[4], Some(6));
3232
assert_eq!(immediate_dominators[5], Some(6));
33-
assert_eq!(immediate_dominators[6], Some(6));
33+
assert_eq!(immediate_dominators[6], None);
3434
}
3535

3636
#[test]
@@ -43,3 +43,13 @@ fn paper_slt() {
4343

4444
dominators(&graph);
4545
}
46+
47+
#[test]
48+
fn immediate_dominator() {
49+
let graph = TestGraph::new(1, &[(1, 2), (2, 3)]);
50+
let dominators = dominators(&graph);
51+
assert_eq!(dominators.immediate_dominator(0), None);
52+
assert_eq!(dominators.immediate_dominator(1), None);
53+
assert_eq!(dominators.immediate_dominator(2), Some(1));
54+
assert_eq!(dominators.immediate_dominator(3), Some(2));
55+
}

compiler/rustc_parse/src/parser/expr.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,6 +1180,10 @@ impl<'a> Parser<'a> {
11801180
self.restore_snapshot(snapshot);
11811181
let close_paren = self.prev_token.span;
11821182
let span = lo.to(close_paren);
1183+
// filter shorthand fields
1184+
let fields: Vec<_> =
1185+
fields.into_iter().filter(|field| !field.is_shorthand).collect();
1186+
11831187
if !fields.is_empty() &&
11841188
// `token.kind` should not be compared here.
11851189
// This is because the `snapshot.token.kind` is treated as the same as

compiler/rustc_span/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#![feature(min_specialization)]
2121
#![feature(rustc_attrs)]
2222
#![feature(let_chains)]
23+
#![feature(round_char_boundary)]
2324
#![deny(rustc::untranslatable_diagnostic)]
2425
#![deny(rustc::diagnostic_outside_of_impl)]
2526

compiler/rustc_span/src/source_map.rs

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,36 +1019,19 @@ impl SourceMap {
10191019

10201020
let src = local_begin.sf.external_src.borrow();
10211021

1022-
// We need to extend the snippet to the end of the src rather than to end_index so when
1023-
// searching forwards for boundaries we've got somewhere to search.
1024-
let snippet = if let Some(ref src) = local_begin.sf.src {
1025-
&src[start_index..]
1022+
let snippet = if let Some(src) = &local_begin.sf.src {
1023+
src
10261024
} else if let Some(src) = src.get_source() {
1027-
&src[start_index..]
1025+
src
10281026
} else {
10291027
return 1;
10301028
};
1031-
debug!("snippet=`{:?}`", snippet);
10321029

1033-
let mut target = if forwards { end_index + 1 } else { end_index - 1 };
1034-
debug!("initial target=`{:?}`", target);
1035-
1036-
while !snippet.is_char_boundary(target - start_index) && target < source_len {
1037-
target = if forwards {
1038-
target + 1
1039-
} else {
1040-
match target.checked_sub(1) {
1041-
Some(target) => target,
1042-
None => {
1043-
break;
1044-
}
1045-
}
1046-
};
1047-
debug!("target=`{:?}`", target);
1030+
if forwards {
1031+
(snippet.ceil_char_boundary(end_index + 1) - end_index) as u32
1032+
} else {
1033+
(end_index - snippet.floor_char_boundary(end_index - 1)) as u32
10481034
}
1049-
debug!("final target=`{:?}`", target);
1050-
1051-
if forwards { (target - end_index) as u32 } else { (end_index - target) as u32 }
10521035
}
10531036

10541037
pub fn get_source_file(&self, filename: &FileName) -> Option<Lrc<SourceFile>> {

library/core/src/marker.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ impl<T: ?Sized> !Sync for *mut T {}
695695
/// }
696696
/// ```
697697
///
698-
/// This also in turn requires the annotation `T: 'a`, indicating
698+
/// This also in turn infers the lifetime bound `T: 'a`, indicating
699699
/// that any references in `T` are valid over the lifetime `'a`.
700700
///
701701
/// When initializing a `Slice` you simply provide the value

library/core/src/str/pattern.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -791,8 +791,8 @@ pub struct CharArrayRefSearcher<'a, 'b, const N: usize>(
791791
/// # Examples
792792
///
793793
/// ```
794-
/// assert_eq!("Hello world".find(['l', 'l']), Some(2));
795-
/// assert_eq!("Hello world".find(['l', 'l']), Some(2));
794+
/// assert_eq!("Hello world".find(['o', 'l']), Some(2));
795+
/// assert_eq!("Hello world".find(['h', 'w']), Some(6));
796796
/// ```
797797
impl<'a, const N: usize> Pattern<'a> for [char; N] {
798798
pattern_methods!(CharArraySearcher<'a, N>, MultiCharEqPattern, CharArraySearcher);
@@ -811,8 +811,8 @@ unsafe impl<'a, const N: usize> ReverseSearcher<'a> for CharArraySearcher<'a, N>
811811
/// # Examples
812812
///
813813
/// ```
814-
/// assert_eq!("Hello world".find(&['l', 'l']), Some(2));
815-
/// assert_eq!("Hello world".find(&['l', 'l']), Some(2));
814+
/// assert_eq!("Hello world".find(&['o', 'l']), Some(2));
815+
/// assert_eq!("Hello world".find(&['h', 'w']), Some(6));
816816
/// ```
817817
impl<'a, 'b, const N: usize> Pattern<'a> for &'b [char; N] {
818818
pattern_methods!(CharArrayRefSearcher<'a, 'b, N>, MultiCharEqPattern, CharArrayRefSearcher);

library/std/src/fs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1946,7 +1946,7 @@ pub fn rename<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> io::Result<()>
19461946
/// On success, the total number of bytes copied is returned and it is equal to
19471947
/// the length of the `to` file as reported by `metadata`.
19481948
///
1949-
/// If you’re wanting to copy the contents of one file to another and you’re
1949+
/// If you want to copy the contents of one file to another and you’re
19501950
/// working with [`File`]s, see the [`io::copy()`] function.
19511951
///
19521952
/// # Platform-specific behavior

0 commit comments

Comments
 (0)