Skip to content

Rollup of 8 pull requests #141908

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

Closed
wants to merge 34 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
44612c5
docs: add documentation for find_all_refs constructor search (#10725)
vremyavnikuda May 25, 2025
1e8eacd
fix: the lines are formatted according to clippy
vremyavnikuda May 25, 2025
693ff34
fix: the lines are formatted according to clippy
vremyavnikuda May 25, 2025
57707c2
fix: formated to clippy
vremyavnikuda May 26, 2025
eb0a3c0
Update SGX maintainers
raoulstrackx May 28, 2025
430f75a
docs:deleting duplicate documentation
vremyavnikuda May 28, 2025
d2bc368
fix: Recognize salsa cycles in `thread_result_to_response`
Veykril May 28, 2025
f06e376
Merge pull request #19888 from Veykril/push-wylsryzpnnop
Veykril May 29, 2025
087cfe3
fix: Fix import insertion not being fully cfg aware
Veykril May 28, 2025
23738b5
Merge pull request #19890 from Veykril/push-kzzntrpllsqx
Veykril May 29, 2025
8d958aa
Merge pull request #19861 from vremyavnikuda/docs/find-all-refs-const…
Veykril May 30, 2025
1b809b7
Add some more `hir_expand::files` conversions
Veykril May 30, 2025
7ad2c36
ci: use free runner for aarch64-gnu-llvm-19-1 PR job
marcoieni May 30, 2025
1383bca
internal: Restructure some semantics APIs for virtual macro files
Veykril May 30, 2025
deeb464
Merge pull request #19896 from Veykril/push-qyutrlxyznum
Veykril May 30, 2025
ed508c7
refactor: Remove unncessary duplication in highlight_related
Veykril May 31, 2025
9c45a45
Merge pull request #19898 from Veykril/push-ykumpuwmuvmu
Veykril May 31, 2025
1b9fb33
Account for `Generate` actions when filtering the allowed ones
SomeoneToIgnore May 31, 2025
cac7468
Merge pull request #19899 from SomeoneToIgnore/generate-actions
Veykril May 31, 2025
2428070
fix: Fix manual not containing diagnostics documentation
Veykril May 31, 2025
01a1908
Merge pull request #19900 from Veykril/push-zurosouxqxzz
Veykril May 31, 2025
861ee47
ci: switch `x86_64-msvc-{1,2}` back to Windows Server 2025 images
jieyouxu Jun 1, 2025
1e169d8
Optionally don't steal the THIR
Nadrieril Jun 1, 2025
9b94cae
allow macro_use as first segment
bvanjoi Jun 2, 2025
aba70e8
Add missing `dyn` keywords to tests that do not test for them
Veykril Jun 2, 2025
7167e7c
Fix false positive lint error from no_implicit_prelude attr
chenyukang Jun 2, 2025
d3639e5
Rollup merge of #141767 - marcoieni:free-pr-job, r=Kobzol
matthiaskrgr Jun 2, 2025
1961b51
Rollup merge of #141861 - jieyouxu:windows-server-2025-20250527, r=Ko…
matthiaskrgr Jun 2, 2025
2eb684c
Rollup merge of #141865 - Nadrieril:dont-steal-thir, r=oli-obk
matthiaskrgr Jun 2, 2025
e35a985
Rollup merge of #141881 - lnicola:sync-from-ra, r=lnicola
matthiaskrgr Jun 2, 2025
cdb674b
Rollup merge of #141884 - bvanjoi:issue-140255, r=petrochenkov
matthiaskrgr Jun 2, 2025
f0b7060
Rollup merge of #141885 - raoulstrackx:raoul/rte-484-update_sgx_maint…
matthiaskrgr Jun 2, 2025
6559a26
Rollup merge of #141889 - ferrocene:lw/missing-dyn-kw, r=petrochenkov
matthiaskrgr Jun 2, 2025
93c8c49
Rollup merge of #141892 - chenyukang:yukang-fix-141785-extern-crate, …
matthiaskrgr Jun 2, 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 compiler/rustc_interface/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,7 @@ fn test_unstable_options_tracking_hash() {
untracked!(no_analysis, true);
untracked!(no_leak_check, true);
untracked!(no_parallel_backend, true);
untracked!(no_steal_thir, true);
untracked!(parse_crate_root_only, true);
// `pre_link_arg` is omitted because it just forwards to `pre_link_args`.
untracked!(pre_link_args, vec![String::from("abc"), String::from("def")]);
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,8 @@ rustc_queries! {
separate_provide_extern
}

/// Fetch the THIR for a given body.
/// Fetch the THIR for a given body. The THIR body gets stolen by unsafety checking unless
/// `-Zno-steal-thir` is on.
query thir_body(key: LocalDefId) -> Result<(&'tcx Steal<thir::Thir<'tcx>>, thir::ExprId), ErrorGuaranteed> {
// Perf tests revealed that hashing THIR is inefficient (see #85729).
no_hash
Expand Down
16 changes: 13 additions & 3 deletions compiler/rustc_mir_build/src/check_unsafety.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,14 @@ impl<'tcx> UnsafetyVisitor<'_, 'tcx> {
/// Handle closures/coroutines/inline-consts, which is unsafecked with their parent body.
fn visit_inner_body(&mut self, def: LocalDefId) {
if let Ok((inner_thir, expr)) = self.tcx.thir_body(def) {
// Runs all other queries that depend on THIR.
// Run all other queries that depend on THIR.
self.tcx.ensure_done().mir_built(def);
let inner_thir = &inner_thir.steal();
let inner_thir = if self.tcx.sess.opts.unstable_opts.no_steal_thir {
&inner_thir.borrow()
} else {
// We don't have other use for the THIR. Steal it to reduce memory usage.
&inner_thir.steal()
};
let hir_context = self.tcx.local_def_id_to_hir_id(def);
let safety_context = mem::replace(&mut self.safety_context, SafetyContext::Safe);
let mut inner_visitor = UnsafetyVisitor {
Expand Down Expand Up @@ -1157,7 +1162,12 @@ pub(crate) fn check_unsafety(tcx: TyCtxt<'_>, def: LocalDefId) {
let Ok((thir, expr)) = tcx.thir_body(def) else { return };
// Runs all other queries that depend on THIR.
tcx.ensure_done().mir_built(def);
let thir = &thir.steal();
let thir = if tcx.sess.opts.unstable_opts.no_steal_thir {
&thir.borrow()
} else {
// We don't have other use for the THIR. Steal it to reduce memory usage.
&thir.steal()
};

let hir_id = tcx.local_def_id_to_hir_id(def);
let safety_context = tcx.hir_fn_sig_by_hir_id(hir_id).map_or(SafetyContext::Safe, |fn_sig| {
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2312,7 +2312,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
}

fn check_macro_use(&self, hir_id: HirId, attr: &Attribute, target: Target) {
let name = attr.name().unwrap();
let Some(name) = attr.name() else {
return;
};
match target {
Target::ExternCrate | Target::Mod => {}
_ => {
Expand Down
10 changes: 10 additions & 0 deletions compiler/rustc_resolve/src/check_unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,16 @@ impl<'a, 'ra, 'tcx> UnusedImportCheckVisitor<'a, 'ra, 'tcx> {
continue;
}

let module = self
.r
.get_nearest_non_block_module(self.r.local_def_id(extern_crate.id).to_def_id());
if module.no_implicit_prelude {
// If the module has `no_implicit_prelude`, then we don't suggest
// replacing the extern crate with a use, as it would not be
// inserted into the prelude. User writes `extern` style deliberately.
continue;
}

let vis_span = extern_crate
.vis_span
.find_ancestor_inside(extern_crate.span)
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_session/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2366,6 +2366,8 @@ options! {
"run LLVM in non-parallel mode (while keeping codegen-units and ThinLTO)"),
no_profiler_runtime: bool = (false, parse_no_value, [TRACKED],
"prevent automatic injection of the profiler_builtins crate"),
no_steal_thir: bool = (false, parse_bool, [UNTRACKED],
"don't steal the THIR when we're done with it; useful for rustc drivers (default: no)"),
no_trait_vptr: bool = (false, parse_no_value, [TRACKED],
"disable generation of trait vptr in vtable for upcasting"),
no_unique_section_names: bool = (false, parse_bool, [TRACKED],
Expand Down
12 changes: 3 additions & 9 deletions src/ci/github-actions/jobs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ runners:
os: windows-2022
<<: *base-job

# FIXME(#141022): Windows Server 2025 20250504.1.0 currently experiences
# insufficient disk space.
- &job-windows-25
os: windows-2025
<<: *base-job
Expand Down Expand Up @@ -127,7 +125,7 @@ pr:
env:
IMAGE: aarch64-gnu-llvm-19
DOCKER_SCRIPT: stage_2_test_set1.sh
<<: *job-aarch64-linux-8c
<<: *job-aarch64-linux
- name: aarch64-gnu-llvm-19-2
env:
IMAGE: aarch64-gnu-llvm-19
Expand Down Expand Up @@ -497,17 +495,13 @@ auto:
env:
RUST_CONFIGURE_ARGS: --build=x86_64-pc-windows-msvc --enable-sanitizers --enable-profiler
SCRIPT: make ci-msvc-py
# FIXME(#141022): Windows Server 2025 20250504.1.0 currently experiences
# insufficient disk space.
<<: *job-windows
<<: *job-windows-25

- name: x86_64-msvc-2
env:
RUST_CONFIGURE_ARGS: --build=x86_64-pc-windows-msvc --enable-sanitizers --enable-profiler
SCRIPT: make ci-msvc-ps1
# FIXME(#141022): Windows Server 2025 20250504.1.0 currently experiences
# insufficient disk space.
<<: *job-windows
<<: *job-windows-25

# i686-msvc is split into two jobs to run tests in parallel.
- name: i686-msvc-1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ based on the ABI defined by Fortanix for the [Enclave Development Platform

[@jethrogb](https://github.com/jethrogb)
[@raoulstrackx](https://github.com/raoulstrackx)
[@mzohreva](https://github.com/mzohreva)
[@aditijannu](https://github.com/aditijannu)

Further contacts:

Expand Down
7 changes: 7 additions & 0 deletions src/doc/unstable-book/src/compiler-flags/no-steal-thir.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# `no-steal-thir`

By default, to save on memory, the THIR body (obtained from the `tcx.thir_body` query) is stolen
once no longer used. This is inconvenient for authors of rustc drivers who want to access the THIR.

This option disables the stealing. This has no observable effect on compiler behavior, only on
memory usage.
52 changes: 49 additions & 3 deletions src/tools/rust-analyzer/crates/hir-expand/src/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,49 @@ impl FilePosition {
FilePositionWrapper { file_id: self.file_id.file_id(db), offset: self.offset }
}
}

impl From<FileRange> for HirFileRange {
fn from(value: FileRange) -> Self {
HirFileRange { file_id: value.file_id.into(), range: value.range }
}
}

impl From<FilePosition> for HirFilePosition {
fn from(value: FilePosition) -> Self {
HirFilePosition { file_id: value.file_id.into(), offset: value.offset }
}
}

impl FilePositionWrapper<span::FileId> {
pub fn with_edition(self, db: &dyn ExpandDatabase, edition: span::Edition) -> FilePosition {
FilePositionWrapper {
file_id: EditionedFileId::new(db, self.file_id, edition),
offset: self.offset,
}
}
}

impl FileRangeWrapper<span::FileId> {
pub fn with_edition(self, db: &dyn ExpandDatabase, edition: span::Edition) -> FileRange {
FileRangeWrapper {
file_id: EditionedFileId::new(db, self.file_id, edition),
range: self.range,
}
}
}

impl<T> InFileWrapper<span::FileId, T> {
pub fn with_edition(self, db: &dyn ExpandDatabase, edition: span::Edition) -> InRealFile<T> {
InRealFile { file_id: EditionedFileId::new(db, self.file_id, edition), value: self.value }
}
}

impl HirFileRange {
pub fn file_range(self) -> Option<FileRange> {
Some(FileRange { file_id: self.file_id.file_id()?, range: self.range })
}
}

#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)]
pub struct FileRangeWrapper<FileKind> {
pub file_id: FileKind,
Expand Down Expand Up @@ -194,6 +237,9 @@ impl<FileId: Copy, N: AstNode> InFileWrapper<FileId, N> {
pub fn syntax(&self) -> InFileWrapper<FileId, &SyntaxNode> {
self.with_value(self.value.syntax())
}
pub fn node_file_range(&self) -> FileRangeWrapper<FileId> {
FileRangeWrapper { file_id: self.file_id, range: self.value.syntax().text_range() }
}
}

impl<FileId: Copy, N: AstNode> InFileWrapper<FileId, &N> {
Expand All @@ -204,9 +250,9 @@ impl<FileId: Copy, N: AstNode> InFileWrapper<FileId, &N> {
}

// region:specific impls
impl<SN: Borrow<SyntaxNode>> InRealFile<SN> {
pub fn file_range(&self) -> FileRange {
FileRange { file_id: self.file_id, range: self.value.borrow().text_range() }
impl<FileId: Copy, SN: Borrow<SyntaxNode>> InFileWrapper<FileId, SN> {
pub fn file_range(&self) -> FileRangeWrapper<FileId> {
FileRangeWrapper { file_id: self.file_id, range: self.value.borrow().text_range() }
}
}

Expand Down
18 changes: 12 additions & 6 deletions src/tools/rust-analyzer/crates/hir-expand/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,10 @@ impl HirFileId {
}
}

pub fn call_node(self, db: &dyn ExpandDatabase) -> Option<InFile<SyntaxNode>> {
Some(db.lookup_intern_macro_call(self.macro_file()?).to_node(db))
}

pub fn as_builtin_derive_attr_node(
&self,
db: &dyn ExpandDatabase,
Expand Down Expand Up @@ -848,7 +852,10 @@ impl ExpansionInfo {
map_node_range_up(db, &self.exp_map, range)
}

/// Maps up the text range out of the expansion into is macro call.
/// Maps up the text range out of the expansion into its macro call.
///
/// Note that this may return multiple ranges as we lose the precise association between input to output
/// and as such we may consider inputs that are unrelated.
pub fn map_range_up_once(
&self,
db: &dyn ExpandDatabase,
Expand All @@ -864,11 +871,10 @@ impl ExpansionInfo {
InFile { file_id, value: smallvec::smallvec![span.range + anchor_offset] }
}
SpanMap::ExpansionSpanMap(arg_map) => {
let arg_range = self
.arg
.value
.as_ref()
.map_or_else(|| TextRange::empty(TextSize::from(0)), |it| it.text_range());
let Some(arg_node) = &self.arg.value else {
return InFile::new(self.arg.file_id, smallvec::smallvec![]);
};
let arg_range = arg_node.text_range();
InFile::new(
self.arg.file_id,
arg_map
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,42 +20,46 @@ pub fn prettify_macro_expansion(
let span_offset = syn.text_range().start();
let target_crate = target_crate_id.data(db);
let mut syntax_ctx_id_to_dollar_crate_replacement = FxHashMap::default();
syntax_bridge::prettify_macro_expansion::prettify_macro_expansion(syn, &mut |dollar_crate| {
let ctx = span_map.span_at(dollar_crate.text_range().start() + span_offset).ctx;
let replacement =
syntax_ctx_id_to_dollar_crate_replacement.entry(ctx).or_insert_with(|| {
let macro_call_id =
ctx.outer_expn(db).expect("`$crate` cannot come from `SyntaxContextId::ROOT`");
let macro_call = db.lookup_intern_macro_call(macro_call_id.into());
let macro_def_crate = macro_call.def.krate;
// First, if this is the same crate as the macro, nothing will work but `crate`.
// If not, if the target trait has the macro's crate as a dependency, using the dependency name
// will work in inserted code and match the user's expectation.
// If not, the crate's display name is what the dependency name is likely to be once such dependency
// is inserted, and also understandable to the user.
// Lastly, if nothing else found, resort to leaving `$crate`.
if target_crate_id == macro_def_crate {
make::tokens::crate_kw()
} else if let Some(dep) =
target_crate.dependencies.iter().find(|dep| dep.crate_id == macro_def_crate)
{
make::tokens::ident(dep.name.as_str())
} else if let Some(crate_name) = &macro_def_crate.extra_data(db).display_name {
make::tokens::ident(crate_name.crate_name().as_str())
} else {
return dollar_crate.clone();
}
});
if replacement.text() == "$crate" {
// The parent may have many children, and looking for the token may yield incorrect results.
return dollar_crate.clone();
}
// We need to `clone_subtree()` but rowan doesn't provide such operation for tokens.
let parent = replacement.parent().unwrap().clone_subtree().clone_for_update();
parent
.children_with_tokens()
.filter_map(NodeOrToken::into_token)
.find(|it| it.kind() == replacement.kind())
.unwrap()
})
syntax_bridge::prettify_macro_expansion::prettify_macro_expansion(
syn,
&mut |dollar_crate| {
let ctx = span_map.span_at(dollar_crate.text_range().start() + span_offset).ctx;
let replacement =
syntax_ctx_id_to_dollar_crate_replacement.entry(ctx).or_insert_with(|| {
let macro_call_id = ctx
.outer_expn(db)
.expect("`$crate` cannot come from `SyntaxContextId::ROOT`");
let macro_call = db.lookup_intern_macro_call(macro_call_id.into());
let macro_def_crate = macro_call.def.krate;
// First, if this is the same crate as the macro, nothing will work but `crate`.
// If not, if the target trait has the macro's crate as a dependency, using the dependency name
// will work in inserted code and match the user's expectation.
// If not, the crate's display name is what the dependency name is likely to be once such dependency
// is inserted, and also understandable to the user.
// Lastly, if nothing else found, resort to leaving `$crate`.
if target_crate_id == macro_def_crate {
make::tokens::crate_kw()
} else if let Some(dep) =
target_crate.dependencies.iter().find(|dep| dep.crate_id == macro_def_crate)
{
make::tokens::ident(dep.name.as_str())
} else if let Some(crate_name) = &macro_def_crate.extra_data(db).display_name {
make::tokens::ident(crate_name.crate_name().as_str())
} else {
return dollar_crate.clone();
}
});
if replacement.text() == "$crate" {
// The parent may have many children, and looking for the token may yield incorrect results.
return None;
}
// We need to `clone_subtree()` but rowan doesn't provide such operation for tokens.
let parent = replacement.parent().unwrap().clone_subtree().clone_for_update();
parent
.children_with_tokens()
.filter_map(NodeOrToken::into_token)
.find(|it| it.kind() == replacement.kind())
},
|_| (),
)
}
Loading
Loading