Skip to content
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

Rollup of 7 pull requests #139054

Merged
merged 30 commits into from
Mar 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
4508f5f
update outdated doc with new example
mu001999 Mar 2, 2025
795a666
rustc_resolve: fix instability in lib.rmeta contents
durin42 Mar 18, 2025
1f1c630
Greatly simplify doctest parsing and information extraction
GuillaumeGomez Mar 5, 2025
01fb7c3
Update rustdoc-ui tests
GuillaumeGomez Mar 6, 2025
6f7e8d4
Correctly handle `fn main` in macro
GuillaumeGomez Mar 7, 2025
123ea25
Correctly handle line comments in attributes and generate extern crates
GuillaumeGomez Mar 7, 2025
be13105
Improve comment and test for generated doctest with code comments
GuillaumeGomez Mar 27, 2025
f333ad8
Improve code comment
GuillaumeGomez Mar 27, 2025
8327bb6
Add `expect` to the list of non-crate attributes for doctest generation
GuillaumeGomez Mar 27, 2025
2004dac
Improve code
GuillaumeGomez Mar 27, 2025
1494da4
Add new regression test for doctest
GuillaumeGomez Mar 27, 2025
49f1e9c
Remove recursion in `check_item`
GuillaumeGomez Mar 27, 2025
77eb97d
librustdoc: also stabilize iteration order here
durin42 Mar 27, 2025
eaa0613
feat(config): Add ChangeId enum for suppressing warnings
Shourya742 Mar 26, 2025
0244432
add changeInfo to change tracker
Shourya742 Mar 26, 2025
1437dec
rustc_resolve: prevent iteration of refids for completeness
durin42 Mar 27, 2025
5d27440
Only take outer attributes into account when generating content betwe…
GuillaumeGomez Mar 27, 2025
3b7d59a
Update target maintainers for thumb targets to reflect new REWG Arm t…
adamgreig Mar 28, 2025
b24083b
Add new change-id option in bootstrap.example.toml and update the cha…
Shourya742 Mar 27, 2025
d5f7e71
bootstrap: update `test_find` test
onur-ozkan Mar 28, 2025
3a9a577
Remove ScopeDepth entirely.
m-ou-se Mar 28, 2025
deeac1c
Remove outdated comment.
m-ou-se Mar 28, 2025
87d524b
Update `coverage-run-rustdoc` output
GuillaumeGomez Mar 28, 2025
9597bf7
Rollup merge of #137889 - mu001999-contrib:update-doc, r=wesleywiser
matthiaskrgr Mar 28, 2025
ad87732
Rollup merge of #138104 - GuillaumeGomez:simplify-doctest-parsing, r=…
matthiaskrgr Mar 28, 2025
bdc5adf
Rollup merge of #138678 - durin42:rmeta-stability, r=fmease
matthiaskrgr Mar 28, 2025
60833b1
Rollup merge of #138986 - Shourya742:2025-03-25-add-ignore-to-change-…
matthiaskrgr Mar 28, 2025
5261a0a
Rollup merge of #139038 - adamgreig:thumb-target-maintainers, r=Norat…
matthiaskrgr Mar 28, 2025
ea56904
Rollup merge of #139045 - onur-ozkan:less-verbose-bootstrap-test, r=K…
matthiaskrgr Mar 28, 2025
310bebc
Rollup merge of #139047 - m-ou-se:remove-scope-depth, r=oli-obk
matthiaskrgr Mar 28, 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
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4300,6 +4300,7 @@ name = "rustc_resolve"
version = "0.0.0"
dependencies = [
"bitflags",
"itertools",
"pulldown-cmark 0.11.3",
"rustc_arena",
"rustc_ast",
Expand Down
5 changes: 3 additions & 2 deletions bootstrap.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@
# - A new option
# - A change in the default values
#
# If `change-id` does not match the version that is currently running,
# `x.py` will inform you about the changes made on bootstrap.
# If the change-id does not match the version currently in use, x.py will
# display the changes made to the bootstrap.
# To suppress these warnings, you can set change-id = "ignore".
#change-id = <latest change id in src/bootstrap/src/utils/change_tracker.rs>

# =============================================================================
Expand Down
39 changes: 14 additions & 25 deletions compiler/rustc_hir_analysis/src/check/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,11 @@ use tracing::debug;

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

/// Region parent of expressions, etc., plus its depth in the scope tree.
parent: Option<(Scope, ScopeDepth)>,
}

impl Context {
fn set_var_parent(&mut self) {
self.var_parent = self.parent.map(|(p, _)| p);
}
/// Region parent of expressions, etc.
parent: Option<Scope>,
}

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

visitor.enter_node_scope_with_dtor(blk.hir_id.local_id);
visitor.cx.set_var_parent();
visitor.cx.var_parent = visitor.cx.parent;

{
// This block should be kept approximately in sync with
Expand All @@ -138,7 +131,7 @@ fn resolve_block<'tcx>(visitor: &mut ScopeResolutionVisitor<'tcx>, blk: &'tcx hi
local_id: blk.hir_id.local_id,
data: ScopeData::Remainder(FirstStatementIndex::new(i)),
});
visitor.cx.set_var_parent();
visitor.cx.var_parent = visitor.cx.parent;
visitor.visit_stmt(statement);
// We need to back out temporarily to the last enclosing scope
// for the `else` block, so that even the temporaries receiving
Expand All @@ -163,7 +156,7 @@ fn resolve_block<'tcx>(visitor: &mut ScopeResolutionVisitor<'tcx>, blk: &'tcx hi
local_id: blk.hir_id.local_id,
data: ScopeData::Remainder(FirstStatementIndex::new(i)),
});
visitor.cx.set_var_parent();
visitor.cx.var_parent = visitor.cx.parent;
visitor.visit_stmt(statement)
}
hir::StmtKind::Item(..) => {
Expand Down Expand Up @@ -213,7 +206,7 @@ fn resolve_arm<'tcx>(visitor: &mut ScopeResolutionVisitor<'tcx>, arm: &'tcx hir:
visitor.terminating_scopes.insert(arm.hir_id.local_id);

visitor.enter_node_scope_with_dtor(arm.hir_id.local_id);
visitor.cx.set_var_parent();
visitor.cx.var_parent = visitor.cx.parent;

if let Some(expr) = arm.guard
&& !has_let_expr(expr)
Expand Down Expand Up @@ -490,7 +483,7 @@ fn resolve_expr<'tcx>(visitor: &mut ScopeResolutionVisitor<'tcx>, expr: &'tcx hi
ScopeData::IfThen
};
visitor.enter_scope(Scope { local_id: then.hir_id.local_id, data });
visitor.cx.set_var_parent();
visitor.cx.var_parent = visitor.cx.parent;
visitor.visit_expr(cond);
visitor.visit_expr(then);
visitor.cx = expr_cx;
Expand All @@ -505,7 +498,7 @@ fn resolve_expr<'tcx>(visitor: &mut ScopeResolutionVisitor<'tcx>, expr: &'tcx hi
ScopeData::IfThen
};
visitor.enter_scope(Scope { local_id: then.hir_id.local_id, data });
visitor.cx.set_var_parent();
visitor.cx.var_parent = visitor.cx.parent;
visitor.visit_expr(cond);
visitor.visit_expr(then);
visitor.cx = expr_cx;
Expand Down Expand Up @@ -545,7 +538,7 @@ fn resolve_expr<'tcx>(visitor: &mut ScopeResolutionVisitor<'tcx>, expr: &'tcx hi
// Keep traversing up while we can.
match visitor.scope_tree.parent_map.get(&scope) {
// Don't cross from closure bodies to their parent.
Some(&(superscope, _)) => match superscope.data {
Some(&superscope) => match superscope.data {
ScopeData::CallSite => break,
_ => scope = superscope,
},
Expand Down Expand Up @@ -781,20 +774,16 @@ fn resolve_local<'tcx>(

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

/// Records the current parent (if any) as the parent of `child_scope`,
/// and sets `child_scope` as the new current parent.
fn enter_scope(&mut self, child_scope: Scope) {
let child_depth = self.record_child_scope(child_scope);
self.cx.parent = Some((child_scope, child_depth));
self.record_child_scope(child_scope);
self.cx.parent = Some(child_scope);
}

fn enter_node_scope_with_dtor(&mut self, id: hir::ItemLocalId) {
Expand Down Expand Up @@ -855,7 +844,7 @@ impl<'tcx> Visitor<'tcx> for ScopeResolutionVisitor<'tcx> {
self.enter_body(body.value.hir_id, |this| {
if this.tcx.hir_body_owner_kind(owner_id).is_fn_or_closure() {
// The arguments and `self` are parented to the fn.
this.cx.set_var_parent();
this.cx.var_parent = this.cx.parent;
for param in body.params {
this.visit_pat(param.pat);
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_analysis/src/check/wfcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,10 @@ fn check_well_formed(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(), ErrorGua
/// definition itself. For example, this definition would be illegal:
///
/// ```rust
/// struct Ref<'a, T> { x: &'a T }
/// struct StaticRef<T> { x: &'static T }
/// ```
///
/// because the type did not declare that `T:'a`.
/// because the type did not declare that `T: 'static`.
///
/// We do this check as a pre-pass before checking fn bodies because if these constraints are
/// not included it frequently leads to confusing errors in fn bodies. So it's better to check
Expand Down
8 changes: 3 additions & 5 deletions compiler/rustc_middle/src/middle/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,6 @@ impl Scope {
}
}

pub type ScopeDepth = u32;

/// The region scope tree encodes information about region relationships.
#[derive(Default, Debug, HashStable)]
pub struct ScopeTree {
Expand All @@ -213,7 +211,7 @@ pub struct ScopeTree {
/// conditional expression or repeating block. (Note that the
/// enclosing scope ID for the block associated with a closure is
/// the closure itself.)
pub parent_map: FxIndexMap<Scope, (Scope, ScopeDepth)>,
pub parent_map: FxIndexMap<Scope, Scope>,

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

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

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

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

/// Returns the lifetime of the local variable `var_id`, if any.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/rvalue_scopes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl RvalueScopes {
let mut id = Scope { local_id: expr_id, data: ScopeData::Node };
let mut backwards_incompatible = None;

while let Some(&(p, _)) = region_scope_tree.parent_map.get(&id) {
while let Some(&p) = region_scope_tree.parent_map.get(&id) {
match p.data {
ScopeData::Destruction => {
debug!("temporary_scope({expr_id:?}) = {id:?} [enclosing]");
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_resolve/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ edition = "2024"
[dependencies]
# tidy-alphabetical-start
bitflags = "2.4.1"
itertools = "0.12"
pulldown-cmark = { version = "0.11", features = ["html"], default-features = false }
rustc_arena = { path = "../rustc_arena" }
rustc_ast = { path = "../rustc_ast" }
Expand Down
8 changes: 5 additions & 3 deletions compiler/rustc_resolve/src/rustdoc.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
use std::mem;
use std::ops::Range;

use itertools::Itertools;
use pulldown_cmark::{
BrokenLink, BrokenLinkCallback, CowStr, Event, LinkType, Options, Parser, Tag,
};
use rustc_ast as ast;
use rustc_ast::attr::AttributeExt;
use rustc_ast::util::comments::beautify_doc_string;
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
use rustc_data_structures::fx::FxIndexMap;
use rustc_data_structures::unord::UnordSet;
use rustc_middle::ty::TyCtxt;
use rustc_span::def_id::DefId;
use rustc_span::{DUMMY_SP, InnerSpan, Span, Symbol, kw, sym};
Expand Down Expand Up @@ -422,7 +424,7 @@ fn parse_links<'md>(doc: &'md str) -> Vec<Box<str>> {
);
let mut links = Vec::new();

let mut refids = FxHashSet::default();
let mut refids = UnordSet::default();

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

for (label, refdef) in event_iter.reference_definitions().iter() {
for (label, refdef) in event_iter.reference_definitions().iter().sorted_by_key(|x| x.0) {
if !refids.contains(label) {
links.push(preprocess_link(&refdef.dest));
}
Expand Down
80 changes: 41 additions & 39 deletions src/bootstrap/src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use std::str::FromStr;
use std::{env, process};

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

if let Some(mut id) = config.change_id {
if id == latest_change_id {
return None;
let mut id = match config.change_id {
Some(ChangeId::Id(id)) if id == latest_change_id => return None,
Some(ChangeId::Ignore) => return None,
Some(ChangeId::Id(id)) => id,
None => {
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");
msg.push_str("NOTE: to silence this warning, ");
msg.push_str(&format!(
"add `change-id = {latest_change_id}` or change-id = \"ignore\" at the top of `bootstrap.toml`"
));
return Some(msg);
}
};

// Always try to use `change-id` from .last-warned-change-id first. If it doesn't exist,
// then use the one from the bootstrap.toml. This way we never show the same warnings
// more than once.
if let Ok(t) = fs::read_to_string(&warned_id_path) {
let last_warned_id = usize::from_str(&t)
.unwrap_or_else(|_| panic!("{} is corrupted.", warned_id_path.display()));

// We only use the last_warned_id if it exists in `CONFIG_CHANGE_HISTORY`.
// Otherwise, we may retrieve all the changes if it's not the highest value.
// For better understanding, refer to `change_tracker::find_recent_config_change_ids`.
if CONFIG_CHANGE_HISTORY.iter().any(|config| config.change_id == last_warned_id) {
id = last_warned_id;
}
};
// Always try to use `change-id` from .last-warned-change-id first. If it doesn't exist,
// then use the one from the bootstrap.toml. This way we never show the same warnings
// more than once.
if let Ok(t) = fs::read_to_string(&warned_id_path) {
let last_warned_id = usize::from_str(&t)
.unwrap_or_else(|_| panic!("{} is corrupted.", warned_id_path.display()));

// We only use the last_warned_id if it exists in `CONFIG_CHANGE_HISTORY`.
// Otherwise, we may retrieve all the changes if it's not the highest value.
// For better understanding, refer to `change_tracker::find_recent_config_change_ids`.
if CONFIG_CHANGE_HISTORY.iter().any(|config| config.change_id == last_warned_id) {
id = last_warned_id;
}
};

let changes = find_recent_config_change_ids(id);
let changes = find_recent_config_change_ids(id);

if changes.is_empty() {
return None;
}
if changes.is_empty() {
return None;
}

msg.push_str("There have been changes to x.py since you last updated:\n");
msg.push_str(&human_readable_changes(&changes));
msg.push_str("There have been changes to x.py since you last updated:\n");
msg.push_str(&human_readable_changes(&changes));

msg.push_str("NOTE: to silence this warning, ");
msg.push_str(&format!(
"update `bootstrap.toml` to use `change-id = {latest_change_id}` instead"
));
msg.push_str("NOTE: to silence this warning, ");
msg.push_str(&format!(
"update `bootstrap.toml` to use `change-id = {latest_change_id}` or change-id = \"ignore\" instead"
));

if io::stdout().is_terminal() {
t!(fs::write(warned_id_path, latest_change_id.to_string()));
}
} else {
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");
msg.push_str("NOTE: to silence this warning, ");
msg.push_str(&format!(
"add `change-id = {latest_change_id}` at the top of `bootstrap.toml`"
));
};
if io::stdout().is_terminal() {
t!(fs::write(warned_id_path, latest_change_id.to_string()));
}

Some(msg)
}
Expand Down
Loading
Loading