Skip to content

Commit 8a0a9cc

Browse files
committed
Update to nightly-2024-12-01
1 parent ed7cca3 commit 8a0a9cc

File tree

17 files changed

+109
-133
lines changed

17 files changed

+109
-133
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
The Rust compiler's interface is not stable, so the only sensible way to develop a Rust compiler plugin is by pinning to a specific nightly. Each version of `rustc_plugin` is pinned to one nightly, and you *have* to use the same nightly version that we do. Therefore each release of `rustc_plugin` has a semantic version number (e.g. `0.1.0`) and the nightly version is added as a prerelease label (e.g. `-nightly-2023-08-25`). You can add a dependency to your `Cargo.toml` like this:
1212

1313
```toml
14-
rustc_plugin = "=0.10.0-nightly-2024-05-20"
14+
rustc_plugin = "=0.11.0-nightly-2024-12-01"
1515
```
1616

1717
We will treat a change to the nightly version as a breaking change, so the semantic version will be correspondingly updated as a breaking update.
@@ -55,7 +55,7 @@ Normally, Rust libraries have a [minimum supported Rust version][msrv] because t
5555
[Aquascope]: https://github.com/cognitive-engineering-lab/aquascope
5656
[Clippy]: https://github.com/rust-lang/rust-clippy
5757
[example]: https://github.com/cognitive-engineering-lab/rustc_plugin/tree/main/crates/rustc_plugin/examples/print-all-items
58-
[docs]: https://cognitive-engineering-lab.github.io/rustc_plugin/v0.10.0-nightly-2024-05-20/rustc_plugin/
59-
[docs-utils]: https://cognitive-engineering-lab.github.io/rustc_plugin/v0.10.0-nightly-2024-05-20/rustc_utils/
58+
[docs]: https://cognitive-engineering-lab.github.io/rustc_plugin/v0.11.0-nightly-2024-12-01/rustc_plugin/
59+
[docs-utils]: https://cognitive-engineering-lab.github.io/rustc_plugin/v0.11.0-nightly-2024-12-01/rustc_utils/
6060
[msrv]: https://doc.rust-lang.org/cargo/reference/manifest.html#the-rust-version-field
6161

crates/rustc_plugin/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rustc_plugin"
3-
version = "0.10.0-nightly-2024-05-20"
3+
version = "0.11.0-nightly-2024-12-01"
44
edition = "2021"
55
authors = ["Will Crichton <crichton.will@gmail.com>"]
66
description = "A framework for writing plugins that integrate with the Rust compiler"

crates/rustc_plugin/examples/print-all-items/src/bin/cargo-print-all-items.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![feature(rustc_private)]
2+
13
fn main() {
24
env_logger::init();
35
rustc_plugin::cli_main(print_all_items::PrintAllItemsPlugin);

crates/rustc_plugin/examples/print-all-items/src/bin/print-all-items-driver.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![feature(rustc_private)]
2+
13
fn main() {
24
env_logger::init();
35
rustc_plugin::driver_main(print_all_items::PrintAllItemsPlugin);

crates/rustc_plugin/examples/print-all-items/src/lib.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,10 @@ impl rustc_driver::Callbacks for PrintAllItemsCallbacks {
7878
fn after_analysis<'tcx>(
7979
&mut self,
8080
_compiler: &rustc_interface::interface::Compiler,
81-
queries: &'tcx rustc_interface::Queries<'tcx>,
81+
tcx: TyCtxt<'tcx>,
8282
) -> rustc_driver::Compilation {
83-
// We extract a key data structure, the `TyCtxt`, which is all we need
84-
// for our simple task of printing out item names.
85-
queries
86-
.global_ctxt()
87-
.unwrap()
88-
.enter(|tcx| print_all_items(tcx, &self.args));
83+
// We call our top-level function with access to the type context `tcx` and the CLI arguments.
84+
print_all_items(tcx, &self.args);
8985

9086
// Note that you should generally allow compilation to continue. If
9187
// your plugin is being invoked on a dependency, then you need to ensure

crates/rustc_plugin/src/cli.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ fn only_run_on_file(
209209
CompileKind::ProcMacro => {}
210210
}
211211

212-
cmd.env(SPECIFIC_CRATE, &pkg.name.replace('-', "_"));
212+
cmd.env(SPECIFIC_CRATE, pkg.name.replace('-', "_"));
213213
cmd.env(SPECIFIC_TARGET, kind_str);
214214

215215
log::debug!(

crates/rustc_utils/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rustc_utils"
3-
version = "0.10.0-nightly-2024-05-20"
3+
version = "0.11.0-nightly-2024-12-01"
44
edition = "2021"
55
authors = ["Will Crichton <crichton.will@gmail.com>"]
66
description = "Utilities for working with the Rust compiler"

crates/rustc_utils/src/hir/ty.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
use rustc_data_structures::captures::Captures;
44
use rustc_hir::def_id::DefId;
55
use rustc_infer::infer::TyCtxtInferExt;
6-
use rustc_middle::ty::{GenericArgKind, ParamEnv, Region, Ty, TyCtxt};
6+
use rustc_middle::ty::{GenericArgKind, ParamEnv, Region, Ty, TyCtxt, TypingEnv};
77
use rustc_trait_selection::infer::InferCtxtExt;
8+
use rustc_type_ir::TypingMode;
89

910
/// Extension trait for [`Ty`].
1011
pub trait TyExt<'tcx> {
@@ -24,12 +25,14 @@ pub trait TyExt<'tcx> {
2425
) -> bool;
2526

2627
/// Returns true if a type implements `Copy`.
27-
fn is_copyable(&self, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>) -> bool;
28+
fn is_copyable(&self, tcx: TyCtxt<'tcx>, typing_env: TypingEnv<'tcx>) -> bool;
2829
}
2930

3031
impl<'tcx> TyExt<'tcx> for Ty<'tcx> {
31-
type AllRegionsIter<'a> = impl Iterator<Item = Region<'tcx>> + Captures<'tcx> + 'a
32-
where Self: 'a;
32+
type AllRegionsIter<'a>
33+
= impl Iterator<Item = Region<'tcx>> + Captures<'tcx> + 'a
34+
where
35+
Self: 'a;
3336

3437
fn inner_regions(&self) -> Self::AllRegionsIter<'_> {
3538
self.walk().filter_map(|part| match part.unpack() {
@@ -46,7 +49,7 @@ impl<'tcx> TyExt<'tcx> for Ty<'tcx> {
4649
) -> bool {
4750
use rustc_infer::traits::EvaluationResult;
4851

49-
let infcx = tcx.infer_ctxt().build();
52+
let infcx = tcx.infer_ctxt().build(TypingMode::non_body_analysis());
5053
let ty = tcx.erase_regions(*self);
5154
let result = infcx.type_implements_trait(trait_def_id, [ty], param_env);
5255
matches!(
@@ -55,15 +58,15 @@ impl<'tcx> TyExt<'tcx> for Ty<'tcx> {
5558
)
5659
}
5760

58-
fn is_copyable(&self, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>) -> bool {
61+
fn is_copyable(&self, tcx: TyCtxt<'tcx>, typing_env: TypingEnv<'tcx>) -> bool {
5962
let ty = tcx.erase_regions(*self);
60-
ty.is_copy_modulo_regions(tcx, param_env)
63+
ty.is_copy_modulo_regions(tcx, typing_env)
6164
}
6265
}
6366

6467
#[cfg(test)]
6568
mod test {
66-
use rustc_middle::ty::ParamEnv;
69+
use rustc_middle::ty::TypingEnv;
6770

6871
use super::TyExt;
6972
use crate::{test_utils, BodyExt};
@@ -84,8 +87,8 @@ fn main() {
8487
assert_eq!(x.ty.inner_regions().count(), 1);
8588
assert_eq!(y.ty.inner_regions().count(), 0);
8689

87-
assert!(!x.ty.is_copyable(tcx, ParamEnv::empty()));
88-
assert!(y.ty.is_copyable(tcx, ParamEnv::empty()));
90+
assert!(!x.ty.is_copyable(tcx, TypingEnv::fully_monomorphized()));
91+
assert!(y.ty.is_copyable(tcx, TypingEnv::fully_monomorphized()));
8992
});
9093
}
9194
}

crates/rustc_utils/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
negative_impls, // for !Send
1616
min_specialization, // for rustc_index::newtype_index
1717
type_alias_impl_trait, // for iterators in traits
18-
lazy_cell, // for global constants w/ heap allocation
1918
box_patterns, // for ergonomics
2019
let_chains, // for places_conflict module
2120
exact_size_is_empty, // for graphviz module

crates/rustc_utils/src/mir/body.rs

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use std::{
77
};
88

99
use anyhow::{ensure, Result};
10+
use pretty::PrettyPrintMirOptions;
1011
use rustc_data_structures::{captures::Captures, fx::FxHashMap as HashMap};
1112
use rustc_hir::{def_id::DefId, CoroutineDesugaring, CoroutineKind, HirId};
1213
use rustc_middle::{
@@ -84,7 +85,10 @@ pub trait BodyExt<'tcx> {
8485
}
8586

8687
impl<'tcx> BodyExt<'tcx> for Body<'tcx> {
87-
type AllReturnsIter<'a> = impl Iterator<Item = Location> + Captures<'tcx> + 'a where Self: 'a;
88+
type AllReturnsIter<'a>
89+
= impl Iterator<Item = Location> + Captures<'tcx> + 'a
90+
where
91+
Self: 'a;
8892
fn all_returns(&self) -> Self::AllReturnsIter<'_> {
8993
self
9094
.basic_blocks
@@ -98,7 +102,10 @@ impl<'tcx> BodyExt<'tcx> for Body<'tcx> {
98102
})
99103
}
100104

101-
type AllLocationsIter<'a> = impl Iterator<Item = Location> + Captures<'tcx> + 'a where Self: 'a;
105+
type AllLocationsIter<'a>
106+
= impl Iterator<Item = Location> + Captures<'tcx> + 'a
107+
where
108+
Self: 'a;
102109
fn all_locations(&self) -> Self::AllLocationsIter<'_> {
103110
self
104111
.basic_blocks
@@ -133,7 +140,15 @@ impl<'tcx> BodyExt<'tcx> for Body<'tcx> {
133140

134141
fn to_string(&self, tcx: TyCtxt<'tcx>) -> Result<String> {
135142
let mut buffer = Vec::new();
136-
write_mir_fn(tcx, self, &mut |_, _| Ok(()), &mut buffer)?;
143+
write_mir_fn(
144+
tcx,
145+
self,
146+
&mut |_, _| Ok(()),
147+
&mut buffer,
148+
PrettyPrintMirOptions {
149+
include_extra_comments: false,
150+
},
151+
)?;
137152
Ok(String::from_utf8(buffer)?)
138153
}
139154

@@ -166,13 +181,17 @@ impl<'tcx> BodyExt<'tcx> for Body<'tcx> {
166181
}
167182
}
168183

169-
type ArgRegionsIter<'a> = impl Iterator<Item = Region<'tcx>> + Captures<'tcx> + 'a
170-
where Self: 'a;
184+
type ArgRegionsIter<'a>
185+
= impl Iterator<Item = Region<'tcx>> + Captures<'tcx> + 'a
186+
where
187+
Self: 'a;
171188

172189
type ReturnRegionsIter = impl Iterator<Item = Region<'tcx>>;
173190

174-
type PlacesIter<'a> = impl Iterator<Item = Place<'tcx>> + Captures<'tcx> + 'a
175-
where Self: 'a;
191+
type PlacesIter<'a>
192+
= impl Iterator<Item = Place<'tcx>> + Captures<'tcx> + 'a
193+
where
194+
Self: 'a;
176195

177196
fn regions_in_args(&self) -> Self::ArgRegionsIter<'_> {
178197
self

0 commit comments

Comments
 (0)