Skip to content

Commit 2913ad6

Browse files
committed
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
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

+4
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

+1-1
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

+10-12
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

+12-2
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

+4
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

+1
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

+7-24
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

+1-1
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

+4-4
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

+1-1
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

library/std/src/io/copy.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::mem::MaybeUninit;
1010
/// On success, the total number of bytes that were copied from
1111
/// `reader` to `writer` is returned.
1212
///
13-
/// If you’re wanting to copy the contents of one file to another and you’re
13+
/// If you want to copy the contents of one file to another and you’re
1414
/// working with filesystem paths, see the [`fs::copy`] function.
1515
///
1616
/// [`fs::copy`]: crate::fs::copy

src/librustdoc/clean/utils.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -594,9 +594,8 @@ pub(super) fn display_macro_source(
594594
def_id: DefId,
595595
vis: ty::Visibility<DefId>,
596596
) -> String {
597-
let tts: Vec<_> = def.body.tokens.clone().into_trees().collect();
598597
// Extract the spans of all matchers. They represent the "interface" of the macro.
599-
let matchers = tts.chunks(4).map(|arm| &arm[0]);
598+
let matchers = def.body.tokens.chunks(4).map(|arm| &arm[0]);
600599

601600
if def.macro_rules {
602601
format!("macro_rules! {} {{\n{}}}", name, render_macro_arms(cx.tcx, matchers, ";"))

src/tools/linkchecker/main.rs

+16-19
Original file line numberDiff line numberDiff line change
@@ -139,18 +139,18 @@ enum FileEntry {
139139
type Cache = HashMap<String, FileEntry>;
140140

141141
fn small_url_encode(s: &str) -> String {
142-
s.replace("<", "%3C")
143-
.replace(">", "%3E")
144-
.replace(" ", "%20")
145-
.replace("?", "%3F")
146-
.replace("'", "%27")
147-
.replace("&", "%26")
148-
.replace(",", "%2C")
149-
.replace(":", "%3A")
150-
.replace(";", "%3B")
151-
.replace("[", "%5B")
152-
.replace("]", "%5D")
153-
.replace("\"", "%22")
142+
s.replace('<', "%3C")
143+
.replace('>', "%3E")
144+
.replace(' ', "%20")
145+
.replace('?', "%3F")
146+
.replace('\'', "%27")
147+
.replace('&', "%26")
148+
.replace(',', "%2C")
149+
.replace(':', "%3A")
150+
.replace(';', "%3B")
151+
.replace('[', "%5B")
152+
.replace(']', "%5D")
153+
.replace('\"', "%22")
154154
}
155155

156156
impl Checker {
@@ -267,7 +267,6 @@ impl Checker {
267267
FileEntry::OtherFile => return,
268268
FileEntry::Redirect { target } => {
269269
let t = target.clone();
270-
drop(target);
271270
let (target, redir_entry) = self.load_file(&t, report);
272271
match redir_entry {
273272
FileEntry::Missing => {
@@ -391,7 +390,7 @@ impl Checker {
391390
const ERROR_INVALID_NAME: i32 = 123;
392391

393392
let pretty_path =
394-
file.strip_prefix(&self.root).unwrap_or(&file).to_str().unwrap().to_string();
393+
file.strip_prefix(&self.root).unwrap_or(file).to_str().unwrap().to_string();
395394

396395
let entry =
397396
self.cache.entry(pretty_path.clone()).or_insert_with(|| match fs::metadata(file) {
@@ -470,10 +469,8 @@ fn is_exception(file: &Path, link: &str) -> bool {
470469
// NOTE: This cannot be added to `LINKCHECK_EXCEPTIONS` because the resolved path
471470
// calculated in `check` function is outside `build/<triple>/doc` dir.
472471
// So the `strip_prefix` method just returns the old absolute broken path.
473-
if file.ends_with("std/primitive.slice.html") {
474-
if link.ends_with("primitive.slice.html") {
475-
return true;
476-
}
472+
if file.ends_with("std/primitive.slice.html") && link.ends_with("primitive.slice.html") {
473+
return true;
477474
}
478475
false
479476
}
@@ -545,7 +542,7 @@ fn with_attrs_in_source<F: FnMut(&str, usize, &str)>(source: &str, attr: &str, m
545542
fn parse_ids(ids: &mut HashSet<String>, file: &str, source: &str, report: &mut Report) {
546543
if ids.is_empty() {
547544
with_attrs_in_source(source, " id", |fragment, i, _| {
548-
let frag = fragment.trim_start_matches("#").to_owned();
545+
let frag = fragment.trim_start_matches('#').to_owned();
549546
let encoded = small_url_encode(&frag);
550547
if !ids.insert(frag) {
551548
report.errors += 1;
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
let my = monad_bind(mx, T: Try); //~ ERROR invalid `struct` delimiters or `fn` call arguments
3+
}
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error: invalid `struct` delimiters or `fn` call arguments
2+
--> $DIR/issue-111416.rs:2:14
3+
|
4+
LL | let my = monad_bind(mx, T: Try);
5+
| ^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
help: if `monad_bind` is a struct, use braces as delimiters
8+
|
9+
LL | let my = monad_bind { mx, T: Try };
10+
| ~ ~
11+
help: if `monad_bind` is a function, use the arguments directly
12+
|
13+
LL - let my = monad_bind(mx, T: Try);
14+
LL + let my = monad_bind(mx, Try);
15+
|
16+
17+
error: aborting due to previous error
18+

0 commit comments

Comments
 (0)