Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 19f42cb

Browse files
committed
Auto merge of rust-lang#139054 - matthiaskrgr:rollup-2bk2fb4, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#137889 (update outdated doc with new example) - rust-lang#138104 (Greatly simplify doctest parsing and information extraction) - rust-lang#138678 (rustc_resolve: fix instability in lib.rmeta contents) - rust-lang#138986 (feat(config): Add ChangeId enum for suppressing warnings) - rust-lang#139038 (Update target maintainers for thumb targets to reflect new REWG Arm team name) - rust-lang#139045 (bootstrap: update `test_find` test) - rust-lang#139047 (Remove ScopeDepth) Failed merges: - rust-lang#139044 (bootstrap: Avoid cloning `change-id` list) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 2a06022 + 310bebc commit 19f42cb

File tree

30 files changed

+431
-473
lines changed

30 files changed

+431
-473
lines changed

‎Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4300,6 +4300,7 @@ name = "rustc_resolve"
43004300
version = "0.0.0"
43014301
dependencies = [
43024302
"bitflags",
4303+
"itertools",
43034304
"pulldown-cmark 0.11.3",
43044305
"rustc_arena",
43054306
"rustc_ast",

‎bootstrap.example.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@
2828
# - A new option
2929
# - A change in the default values
3030
#
31-
# If `change-id` does not match the version that is currently running,
32-
# `x.py` will inform you about the changes made on bootstrap.
31+
# If the change-id does not match the version currently in use, x.py will
32+
# display the changes made to the bootstrap.
33+
# To suppress these warnings, you can set change-id = "ignore".
3334
#change-id = <latest change id in src/bootstrap/src/utils/change_tracker.rs>
3435

3536
# =============================================================================

‎compiler/rustc_hir_analysis/src/check/region.rs

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,11 @@ use tracing::debug;
2323

2424
#[derive(Debug, Copy, Clone)]
2525
struct Context {
26-
/// The scope that contains any new variables declared, plus its depth in
27-
/// the scope tree.
26+
/// The scope that contains any new variables declared.
2827
var_parent: Option<Scope>,
2928

30-
/// Region parent of expressions, etc., plus its depth in the scope tree.
31-
parent: Option<(Scope, ScopeDepth)>,
32-
}
33-
34-
impl Context {
35-
fn set_var_parent(&mut self) {
36-
self.var_parent = self.parent.map(|(p, _)| p);
37-
}
29+
/// Region parent of expressions, etc.
30+
parent: Option<Scope>,
3831
}
3932

4033
struct ScopeResolutionVisitor<'tcx> {
@@ -119,7 +112,7 @@ fn resolve_block<'tcx>(visitor: &mut ScopeResolutionVisitor<'tcx>, blk: &'tcx hi
119112
// itself has returned.
120113

121114
visitor.enter_node_scope_with_dtor(blk.hir_id.local_id);
122-
visitor.cx.set_var_parent();
115+
visitor.cx.var_parent = visitor.cx.parent;
123116

124117
{
125118
// This block should be kept approximately in sync with
@@ -138,7 +131,7 @@ fn resolve_block<'tcx>(visitor: &mut ScopeResolutionVisitor<'tcx>, blk: &'tcx hi
138131
local_id: blk.hir_id.local_id,
139132
data: ScopeData::Remainder(FirstStatementIndex::new(i)),
140133
});
141-
visitor.cx.set_var_parent();
134+
visitor.cx.var_parent = visitor.cx.parent;
142135
visitor.visit_stmt(statement);
143136
// We need to back out temporarily to the last enclosing scope
144137
// for the `else` block, so that even the temporaries receiving
@@ -163,7 +156,7 @@ fn resolve_block<'tcx>(visitor: &mut ScopeResolutionVisitor<'tcx>, blk: &'tcx hi
163156
local_id: blk.hir_id.local_id,
164157
data: ScopeData::Remainder(FirstStatementIndex::new(i)),
165158
});
166-
visitor.cx.set_var_parent();
159+
visitor.cx.var_parent = visitor.cx.parent;
167160
visitor.visit_stmt(statement)
168161
}
169162
hir::StmtKind::Item(..) => {
@@ -213,7 +206,7 @@ fn resolve_arm<'tcx>(visitor: &mut ScopeResolutionVisitor<'tcx>, arm: &'tcx hir:
213206
visitor.terminating_scopes.insert(arm.hir_id.local_id);
214207

215208
visitor.enter_node_scope_with_dtor(arm.hir_id.local_id);
216-
visitor.cx.set_var_parent();
209+
visitor.cx.var_parent = visitor.cx.parent;
217210

218211
if let Some(expr) = arm.guard
219212
&& !has_let_expr(expr)
@@ -490,7 +483,7 @@ fn resolve_expr<'tcx>(visitor: &mut ScopeResolutionVisitor<'tcx>, expr: &'tcx hi
490483
ScopeData::IfThen
491484
};
492485
visitor.enter_scope(Scope { local_id: then.hir_id.local_id, data });
493-
visitor.cx.set_var_parent();
486+
visitor.cx.var_parent = visitor.cx.parent;
494487
visitor.visit_expr(cond);
495488
visitor.visit_expr(then);
496489
visitor.cx = expr_cx;
@@ -505,7 +498,7 @@ fn resolve_expr<'tcx>(visitor: &mut ScopeResolutionVisitor<'tcx>, expr: &'tcx hi
505498
ScopeData::IfThen
506499
};
507500
visitor.enter_scope(Scope { local_id: then.hir_id.local_id, data });
508-
visitor.cx.set_var_parent();
501+
visitor.cx.var_parent = visitor.cx.parent;
509502
visitor.visit_expr(cond);
510503
visitor.visit_expr(then);
511504
visitor.cx = expr_cx;
@@ -545,7 +538,7 @@ fn resolve_expr<'tcx>(visitor: &mut ScopeResolutionVisitor<'tcx>, expr: &'tcx hi
545538
// Keep traversing up while we can.
546539
match visitor.scope_tree.parent_map.get(&scope) {
547540
// Don't cross from closure bodies to their parent.
548-
Some(&(superscope, _)) => match superscope.data {
541+
Some(&superscope) => match superscope.data {
549542
ScopeData::CallSite => break,
550543
_ => scope = superscope,
551544
},
@@ -781,20 +774,16 @@ fn resolve_local<'tcx>(
781774

782775
impl<'tcx> ScopeResolutionVisitor<'tcx> {
783776
/// Records the current parent (if any) as the parent of `child_scope`.
784-
/// Returns the depth of `child_scope`.
785-
fn record_child_scope(&mut self, child_scope: Scope) -> ScopeDepth {
777+
fn record_child_scope(&mut self, child_scope: Scope) {
786778
let parent = self.cx.parent;
787779
self.scope_tree.record_scope_parent(child_scope, parent);
788-
// If `child_scope` has no parent, it must be the root node, and so has
789-
// a depth of 1. Otherwise, its depth is one more than its parent's.
790-
parent.map_or(1, |(_p, d)| d + 1)
791780
}
792781

793782
/// Records the current parent (if any) as the parent of `child_scope`,
794783
/// and sets `child_scope` as the new current parent.
795784
fn enter_scope(&mut self, child_scope: Scope) {
796-
let child_depth = self.record_child_scope(child_scope);
797-
self.cx.parent = Some((child_scope, child_depth));
785+
self.record_child_scope(child_scope);
786+
self.cx.parent = Some(child_scope);
798787
}
799788

800789
fn enter_node_scope_with_dtor(&mut self, id: hir::ItemLocalId) {
@@ -855,7 +844,7 @@ impl<'tcx> Visitor<'tcx> for ScopeResolutionVisitor<'tcx> {
855844
self.enter_body(body.value.hir_id, |this| {
856845
if this.tcx.hir_body_owner_kind(owner_id).is_fn_or_closure() {
857846
// The arguments and `self` are parented to the fn.
858-
this.cx.set_var_parent();
847+
this.cx.var_parent = this.cx.parent;
859848
for param in body.params {
860849
this.visit_pat(param.pat);
861850
}

‎compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,10 @@ fn check_well_formed(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(), ErrorGua
188188
/// definition itself. For example, this definition would be illegal:
189189
///
190190
/// ```rust
191-
/// struct Ref<'a, T> { x: &'a T }
191+
/// struct StaticRef<T> { x: &'static T }
192192
/// ```
193193
///
194-
/// because the type did not declare that `T:'a`.
194+
/// because the type did not declare that `T: 'static`.
195195
///
196196
/// We do this check as a pre-pass before checking fn bodies because if these constraints are
197197
/// not included it frequently leads to confusing errors in fn bodies. So it's better to check

‎compiler/rustc_middle/src/middle/region.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,6 @@ impl Scope {
199199
}
200200
}
201201

202-
pub type ScopeDepth = u32;
203-
204202
/// The region scope tree encodes information about region relationships.
205203
#[derive(Default, Debug, HashStable)]
206204
pub struct ScopeTree {
@@ -213,7 +211,7 @@ pub struct ScopeTree {
213211
/// conditional expression or repeating block. (Note that the
214212
/// enclosing scope ID for the block associated with a closure is
215213
/// the closure itself.)
216-
pub parent_map: FxIndexMap<Scope, (Scope,ScopeDepth)>,
214+
pub parent_map: FxIndexMap<Scope, Scope>,
217215

218216
/// Maps from a variable or binding ID to the block in which that
219217
/// variable is declared.
@@ -328,7 +326,7 @@ pub struct YieldData {
328326
}
329327

330328
impl ScopeTree {
331-
pub fn record_scope_parent(&mut self, child: Scope, parent: Option<(Scope,ScopeDepth)>) {
329+
pub fn record_scope_parent(&mut self, child: Scope, parent: Option<Scope>) {
332330
debug!("{:?}.parent = {:?}", child, parent);
333331

334332
if let Some(p) = parent {
@@ -353,7 +351,7 @@ impl ScopeTree {
353351

354352
/// Returns the narrowest scope that encloses `id`, if any.
355353
pub fn opt_encl_scope(&self, id: Scope) -> Option<Scope> {
356-
self.parent_map.get(&id).cloned().map(|(p, _)| p)
354+
self.parent_map.get(&id).cloned()
357355
}
358356

359357
/// Returns the lifetime of the local variable `var_id`, if any.

‎compiler/rustc_middle/src/ty/rvalue_scopes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl RvalueScopes {
3838
let mut id = Scope { local_id: expr_id, data: ScopeData::Node };
3939
let mut backwards_incompatible = None;
4040

41-
while let Some(&(p, _)) = region_scope_tree.parent_map.get(&id) {
41+
while let Some(&p) = region_scope_tree.parent_map.get(&id) {
4242
match p.data {
4343
ScopeData::Destruction => {
4444
debug!("temporary_scope({expr_id:?}) = {id:?} [enclosing]");

‎compiler/rustc_resolve/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ edition = "2024"
66
[dependencies]
77
# tidy-alphabetical-start
88
bitflags = "2.4.1"
9+
itertools = "0.12"
910
pulldown-cmark = { version = "0.11", features = ["html"], default-features = false }
1011
rustc_arena = { path = "../rustc_arena" }
1112
rustc_ast = { path = "../rustc_ast" }

‎compiler/rustc_resolve/src/rustdoc.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
use std::mem;
22
use std::ops::Range;
33

4+
use itertools::Itertools;
45
use pulldown_cmark::{
56
BrokenLink, BrokenLinkCallback, CowStr, Event, LinkType, Options, Parser, Tag,
67
};
78
use rustc_ast as ast;
89
use rustc_ast::attr::AttributeExt;
910
use rustc_ast::util::comments::beautify_doc_string;
10-
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
11+
use rustc_data_structures::fx::FxIndexMap;
12+
use rustc_data_structures::unord::UnordSet;
1113
use rustc_middle::ty::TyCtxt;
1214
use rustc_span::def_id::DefId;
1315
use rustc_span::{DUMMY_SP, InnerSpan, Span, Symbol, kw, sym};
@@ -422,7 +424,7 @@ fn parse_links<'md>(doc: &'md str) -> Vec<Box<str>> {
422424
);
423425
let mut links = Vec::new();
424426

425-
let mut refids = FxHashSet::default();
427+
let mut refids = UnordSet::default();
426428

427429
while let Some(event) = event_iter.next() {
428430
match event {
@@ -454,7 +456,7 @@ fn parse_links<'md>(doc: &'md str) -> Vec<Box<str>> {
454456
}
455457
}
456458

457-
for (label, refdef) in event_iter.reference_definitions().iter() {
459+
for (label, refdef) in event_iter.reference_definitions().iter().sorted_by_key(|x| x.0) {
458460
if !refids.contains(label) {
459461
links.push(preprocess_link(&refdef.dest));
460462
}

‎src/bootstrap/src/bin/main.rs

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ use std::str::FromStr;
1111
use std::{env, process};
1212

1313
use bootstrap::{
14-
Build, CONFIG_CHANGE_HISTORY, Config, Flags, Subcommand, debug, find_recent_config_change_ids,
15-
human_readable_changes, t,
14+
Build, CONFIG_CHANGE_HISTORY, ChangeId,Config, Flags, Subcommand, debug,
15+
find_recent_config_change_ids,human_readable_changes, t,
1616
};
1717
#[cfg(feature = "tracing")]
1818
use tracing::instrument;
@@ -155,50 +155,52 @@ fn check_version(config: &Config) -> Option<String> {
155155
let latest_change_id = CONFIG_CHANGE_HISTORY.last().unwrap().change_id;
156156
let warned_id_path = config.out.join("bootstrap").join(".last-warned-change-id");
157157

158-
if let Some(mut id) = config.change_id {
159-
if id == latest_change_id {
160-
return None;
158+
let mut id = match config.change_id {
159+
Some(ChangeId::Id(id)) if id == latest_change_id => return None,
160+
Some(ChangeId::Ignore) => return None,
161+
Some(ChangeId::Id(id)) => id,
162+
None => {
163+
msg.push_str("WARNING: The `change-id` is missing in the `bootstrap.toml`. This means that you will not be able to track the major changes made to the bootstrap configurations.\n");
164+
msg.push_str("NOTE: to silence this warning, ");
165+
msg.push_str(&format!(
166+
"add `change-id = {latest_change_id}` or change-id = \"ignore\" at the top of `bootstrap.toml`"
167+
));
168+
return Some(msg);
161169
}
170+
};
162171

163-
// Always try to use `change-id` from .last-warned-change-id first. If it doesn't exist,
164-
// then use the one from the bootstrap.toml. This way we never show the same warnings
165-
// more than once.
166-
if let Ok(t) = fs::read_to_string(&warned_id_path) {
167-
let last_warned_id = usize::from_str(&t)
168-
.unwrap_or_else(|_| panic!("{} is corrupted.", warned_id_path.display()));
169-
170-
// We only use the last_warned_id if it exists in `CONFIG_CHANGE_HISTORY`.
171-
// Otherwise, we may retrieve all the changes if it's not the highest value.
172-
// For better understanding, refer to `change_tracker::find_recent_config_change_ids`.
173-
if CONFIG_CHANGE_HISTORY.iter().any(|config| config.change_id == last_warned_id) {
174-
id = last_warned_id;
175-
}
176-
};
172+
// Always try to use `change-id` from .last-warned-change-id first. If it doesn't exist,
173+
// then use the one from the bootstrap.toml. This way we never show the same warnings
174+
// more than once.
175+
if let Ok(t) = fs::read_to_string(&warned_id_path) {
176+
let last_warned_id = usize::from_str(&t)
177+
.unwrap_or_else(|_| panic!("{} is corrupted.", warned_id_path.display()));
178+
179+
// We only use the last_warned_id if it exists in `CONFIG_CHANGE_HISTORY`.
180+
// Otherwise, we may retrieve all the changes if it's not the highest value.
181+
// For better understanding, refer to `change_tracker::find_recent_config_change_ids`.
182+
if CONFIG_CHANGE_HISTORY.iter().any(|config| config.change_id == last_warned_id) {
183+
id = last_warned_id;
184+
}
185+
};
177186

178-
let changes = find_recent_config_change_ids(id);
187+
let changes = find_recent_config_change_ids(id);
179188

180-
if changes.is_empty() {
181-
return None;
182-
}
189+
if changes.is_empty() {
190+
return None;
191+
}
183192

184-
msg.push_str("There have been changes to x.py since you last updated:\n");
185-
msg.push_str(&human_readable_changes(&changes));
193+
msg.push_str("There have been changes to x.py since you last updated:\n");
194+
msg.push_str(&human_readable_changes(&changes));
186195

187-
msg.push_str("NOTE: to silence this warning, ");
188-
msg.push_str(&format!(
189-
"update `bootstrap.toml` to use `change-id = {latest_change_id}` instead"
190-
));
196+
msg.push_str("NOTE: to silence this warning, ");
197+
msg.push_str(&format!(
198+
"update `bootstrap.toml` to use `change-id = {latest_change_id}` or change-id = \"ignore\" instead"
199+
));
191200

192-
if io::stdout().is_terminal() {
193-
t!(fs::write(warned_id_path, latest_change_id.to_string()));
194-
}
195-
} else {
196-
msg.push_str("WARNING: The `change-id` is missing in the `bootstrap.toml`. This means that you will not be able to track the major changes made to the bootstrap configurations.\n");
197-
msg.push_str("NOTE: to silence this warning, ");
198-
msg.push_str(&format!(
199-
"add `change-id = {latest_change_id}` at the top of `bootstrap.toml`"
200-
));
201-
};
201+
if io::stdout().is_terminal() {
202+
t!(fs::write(warned_id_path, latest_change_id.to_string()));
203+
}
202204

203205
Some(msg)
204206
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /