Auto merge of #111585 - matthiaskrgr:rollup-468pykj, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #102673 (Update doc for `PhantomData` to match code example) - #111531 (Fix ice caused by shorthand fields in NoFieldsForFnCall) - #111547 (Start node has no immediate dominator) - #111548 (add util function to TokenStream to eliminate some clones) - #111560 (Simplify find_width_of_character_at_span.) - #111569 (Appease lints) - #111581 (Fix some misleading and copy-pasted `Pattern` examples) - #111582 ((docs) Change "wanting" to "want") Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
This commit is contained in:
commit
2913ad6db0
15 changed files with 84 additions and 67 deletions
|
@ -551,6 +551,10 @@ impl TokenStream {
|
|||
vec_mut.extend(stream_iter);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chunks(&self, chunk_size: usize) -> core::slice::Chunks<'_, TokenTree> {
|
||||
self.0.chunks(chunk_size)
|
||||
}
|
||||
}
|
||||
|
||||
/// By-reference iterator over a [`TokenStream`], that produces `&TokenTree`
|
||||
|
|
|
@ -164,7 +164,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||
if let Some(root) = post_contract_node.get(&bb) {
|
||||
break *root;
|
||||
}
|
||||
let parent = doms.immediate_dominator(bb);
|
||||
let parent = doms.immediate_dominator(bb).unwrap();
|
||||
dom_path.push(bb);
|
||||
if !self.body.basic_blocks[parent].is_cleanup {
|
||||
break bb;
|
||||
|
|
|
@ -242,7 +242,9 @@ pub fn dominators<G: ControlFlowGraph>(graph: G) -> Dominators<G::Node> {
|
|||
immediate_dominators[*node] = Some(pre_order_to_real[idom[idx]]);
|
||||
}
|
||||
|
||||
Dominators { post_order_rank, immediate_dominators }
|
||||
let start_node = graph.start_node();
|
||||
immediate_dominators[start_node] = None;
|
||||
Dominators { start_node, post_order_rank, immediate_dominators }
|
||||
}
|
||||
|
||||
/// Evaluate the link-eval virtual forest, providing the currently minimum semi
|
||||
|
@ -308,6 +310,7 @@ fn compress(
|
|||
/// Tracks the list of dominators for each node.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Dominators<N: Idx> {
|
||||
start_node: N,
|
||||
post_order_rank: IndexVec<N, usize>,
|
||||
// Even though we track only the immediate dominator of each node, it's
|
||||
// possible to get its full list of dominators by looking up the dominator
|
||||
|
@ -316,14 +319,14 @@ pub struct Dominators<N: Idx> {
|
|||
}
|
||||
|
||||
impl<Node: Idx> Dominators<Node> {
|
||||
/// Whether the given Node has an immediate dominator.
|
||||
/// Returns true if node is reachable from the start node.
|
||||
pub fn is_reachable(&self, node: Node) -> bool {
|
||||
self.immediate_dominators[node].is_some()
|
||||
node == self.start_node || self.immediate_dominators[node].is_some()
|
||||
}
|
||||
|
||||
pub fn immediate_dominator(&self, node: Node) -> Node {
|
||||
assert!(self.is_reachable(node), "node {node:?} is not reachable");
|
||||
self.immediate_dominators[node].unwrap()
|
||||
/// Returns the immediate dominator of node, if any.
|
||||
pub fn immediate_dominator(&self, node: Node) -> Option<Node> {
|
||||
self.immediate_dominators[node]
|
||||
}
|
||||
|
||||
/// 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> {
|
|||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
if let Some(node) = self.node {
|
||||
let dom = self.dominators.immediate_dominator(node);
|
||||
if dom == node {
|
||||
self.node = None; // reached the root
|
||||
} else {
|
||||
self.node = Some(dom);
|
||||
}
|
||||
self.node = self.dominators.immediate_dominator(node);
|
||||
Some(node)
|
||||
} else {
|
||||
None
|
||||
|
|
|
@ -8,7 +8,7 @@ fn diamond() {
|
|||
|
||||
let dominators = dominators(&graph);
|
||||
let immediate_dominators = &dominators.immediate_dominators;
|
||||
assert_eq!(immediate_dominators[0], Some(0));
|
||||
assert_eq!(immediate_dominators[0], None);
|
||||
assert_eq!(immediate_dominators[1], Some(0));
|
||||
assert_eq!(immediate_dominators[2], Some(0));
|
||||
assert_eq!(immediate_dominators[3], Some(0));
|
||||
|
@ -30,7 +30,7 @@ fn paper() {
|
|||
assert_eq!(immediate_dominators[3], Some(6));
|
||||
assert_eq!(immediate_dominators[4], Some(6));
|
||||
assert_eq!(immediate_dominators[5], Some(6));
|
||||
assert_eq!(immediate_dominators[6], Some(6));
|
||||
assert_eq!(immediate_dominators[6], None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -43,3 +43,13 @@ fn paper_slt() {
|
|||
|
||||
dominators(&graph);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn immediate_dominator() {
|
||||
let graph = TestGraph::new(1, &[(1, 2), (2, 3)]);
|
||||
let dominators = dominators(&graph);
|
||||
assert_eq!(dominators.immediate_dominator(0), None);
|
||||
assert_eq!(dominators.immediate_dominator(1), None);
|
||||
assert_eq!(dominators.immediate_dominator(2), Some(1));
|
||||
assert_eq!(dominators.immediate_dominator(3), Some(2));
|
||||
}
|
||||
|
|
|
@ -1180,6 +1180,10 @@ impl<'a> Parser<'a> {
|
|||
self.restore_snapshot(snapshot);
|
||||
let close_paren = self.prev_token.span;
|
||||
let span = lo.to(close_paren);
|
||||
// filter shorthand fields
|
||||
let fields: Vec<_> =
|
||||
fields.into_iter().filter(|field| !field.is_shorthand).collect();
|
||||
|
||||
if !fields.is_empty() &&
|
||||
// `token.kind` should not be compared here.
|
||||
// This is because the `snapshot.token.kind` is treated as the same as
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#![feature(min_specialization)]
|
||||
#![feature(rustc_attrs)]
|
||||
#![feature(let_chains)]
|
||||
#![feature(round_char_boundary)]
|
||||
#![deny(rustc::untranslatable_diagnostic)]
|
||||
#![deny(rustc::diagnostic_outside_of_impl)]
|
||||
|
||||
|
|
|
@ -1019,36 +1019,19 @@ impl SourceMap {
|
|||
|
||||
let src = local_begin.sf.external_src.borrow();
|
||||
|
||||
// We need to extend the snippet to the end of the src rather than to end_index so when
|
||||
// searching forwards for boundaries we've got somewhere to search.
|
||||
let snippet = if let Some(ref src) = local_begin.sf.src {
|
||||
&src[start_index..]
|
||||
let snippet = if let Some(src) = &local_begin.sf.src {
|
||||
src
|
||||
} else if let Some(src) = src.get_source() {
|
||||
&src[start_index..]
|
||||
src
|
||||
} else {
|
||||
return 1;
|
||||
};
|
||||
debug!("snippet=`{:?}`", snippet);
|
||||
|
||||
let mut target = if forwards { end_index + 1 } else { end_index - 1 };
|
||||
debug!("initial target=`{:?}`", target);
|
||||
|
||||
while !snippet.is_char_boundary(target - start_index) && target < source_len {
|
||||
target = if forwards {
|
||||
target + 1
|
||||
} else {
|
||||
match target.checked_sub(1) {
|
||||
Some(target) => target,
|
||||
None => {
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
debug!("target=`{:?}`", target);
|
||||
if forwards {
|
||||
(snippet.ceil_char_boundary(end_index + 1) - end_index) as u32
|
||||
} else {
|
||||
(end_index - snippet.floor_char_boundary(end_index - 1)) as u32
|
||||
}
|
||||
debug!("final target=`{:?}`", target);
|
||||
|
||||
if forwards { (target - end_index) as u32 } else { (end_index - target) as u32 }
|
||||
}
|
||||
|
||||
pub fn get_source_file(&self, filename: &FileName) -> Option<Lrc<SourceFile>> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue