Skip to content

Commit f39cad8

Browse files
authored
Update to nightly-2024-12-01 (#32)
* Update README * Update to nightly-2024-12-01 * Fix various lints * More lints
1 parent 712c214 commit f39cad8

File tree

25 files changed

+232
-297
lines changed

25 files changed

+232
-297
lines changed

.github/workflows/release.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ jobs:
1414
uses: baptiste0928/cargo-install@v2
1515
with:
1616
crate: cargo-workspaces
17+
version: 0.2.44
1718
- name: Run tests
1819
run: cargo test --all-features -- --test-threads=1
1920
- name: Generate documentation

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/cache.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ where
7979
/// # Panics
8080
///
8181
/// If this is a recursive invocation for this key.
82-
pub fn get(&self, key: In, compute: impl FnOnce(In) -> Out) -> &Out {
82+
pub fn get(&self, key: &In, compute: impl FnOnce(In) -> Out) -> &Out {
8383
self
8484
.get_maybe_recursive(key, compute)
8585
.unwrap_or_else(recursion_panic)
@@ -90,10 +90,10 @@ where
9090
/// Returns `None` if this is a recursive invocation of `get` for key `key`.
9191
pub fn get_maybe_recursive<'a>(
9292
&'a self,
93-
key: In,
93+
key: &In,
9494
compute: impl FnOnce(In) -> Out,
9595
) -> Option<&'a Out> {
96-
if !self.0.borrow().contains_key(&key) {
96+
if !self.0.borrow().contains_key(key) {
9797
self.0.borrow_mut().insert(key.clone(), None);
9898
let out = Box::pin(compute(key.clone()));
9999
self.0.borrow_mut().insert(key.clone(), Some(out));
@@ -102,7 +102,7 @@ where
102102
let cache = self.0.borrow();
103103
// Important here to first `unwrap` the `Option` created by `get`, then
104104
// propagate the potential option stored in the map.
105-
let entry = cache.get(&key).expect("invariant broken").as_ref()?;
105+
let entry = cache.get(key).expect("invariant broken").as_ref()?;
106106

107107
// SAFETY: because the entry is pinned, it cannot move and this pointer will
108108
// only be invalidated if Cache is dropped. The returned reference has a lifetime
@@ -139,7 +139,7 @@ where
139139
/// # Panics
140140
///
141141
/// If this is a recursive invocation for this key.
142-
pub fn get(&self, key: In, compute: impl FnOnce(In) -> Out) -> Out {
142+
pub fn get(&self, key: &In, compute: impl FnOnce(In) -> Out) -> Out {
143143
self
144144
.get_maybe_recursive(key, compute)
145145
.unwrap_or_else(recursion_panic)
@@ -151,16 +151,16 @@ where
151151
/// Returns `None` if this is a recursive invocation of `get` for key `key`.
152152
pub fn get_maybe_recursive(
153153
&self,
154-
key: In,
154+
key: &In,
155155
compute: impl FnOnce(In) -> Out,
156156
) -> Option<Out> {
157-
if !self.0.borrow().contains_key(&key) {
157+
if !self.0.borrow().contains_key(key) {
158158
self.0.borrow_mut().insert(key.clone(), None);
159159
let out = compute(key.clone());
160160
self.0.borrow_mut().insert(key.clone(), Some(out));
161161
}
162162

163-
*self.0.borrow_mut().get(&key).expect("invariant broken")
163+
*self.0.borrow_mut().get(key).expect("invariant broken")
164164
}
165165
}
166166

@@ -177,9 +177,9 @@ mod test {
177177
#[test]
178178
fn test_cached() {
179179
let cache: Cache<usize, usize> = Cache::default();
180-
let x = cache.get(0, |_| 0);
181-
let y = cache.get(1, |_| 1);
182-
let z = cache.get(0, |_| 2);
180+
let x = cache.get(&0, |_| 0);
181+
let y = cache.get(&1, |_| 1);
182+
let z = cache.get(&0, |_| 2);
183183
assert_eq!(*x, 0);
184184
assert_eq!(*y, 1);
185185
assert_eq!(*z, 0);
@@ -193,12 +193,12 @@ mod test {
193193
fn get_infinite_recursion(&self, i: i32) -> i32 {
194194
self
195195
.0
196-
.get_maybe_recursive(i, |_| i + self.get_infinite_recursion(i))
196+
.get_maybe_recursive(&i, |_| i + self.get_infinite_recursion(i))
197197
.copied()
198198
.unwrap_or(-18)
199199
}
200200
fn get_safe_recursion(&self, i: i32) -> i32 {
201-
*self.0.get(i, |_| {
201+
*self.0.get(&i, |_| {
202202
if i == 0 {
203203
0
204204
} else {
@@ -208,7 +208,7 @@ mod test {
208208
}
209209
}
210210

211-
let cache = RecursiveUse(Default::default());
211+
let cache = RecursiveUse(Cache::default());
212212

213213
assert_eq!(cache.get_infinite_recursion(60), 42);
214214
assert_eq!(cache.get_safe_recursion(5), 15);

crates/rustc_utils/src/hir/ty.rs

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,74 @@
11
//! Utilities for [`Ty`].
22
3-
use rustc_data_structures::captures::Captures;
43
use rustc_hir::def_id::DefId;
54
use rustc_infer::infer::TyCtxtInferExt;
6-
use rustc_middle::ty::{GenericArgKind, ParamEnv, Region, Ty, TyCtxt};
5+
use rustc_middle::ty::{GenericArgKind, ParamEnv, Region, Ty, TyCtxt, TypingEnv};
76
use rustc_trait_selection::infer::InferCtxtExt;
7+
use rustc_type_ir::TypingMode;
88

99
/// Extension trait for [`Ty`].
1010
pub trait TyExt<'tcx> {
11-
type AllRegionsIter<'a>: Iterator<Item = Region<'tcx>>
12-
where
13-
Self: 'a;
14-
1511
/// Returns an iterator over the regions appearing within a type.
16-
fn inner_regions(&self) -> Self::AllRegionsIter<'_>;
12+
fn inner_regions(self) -> impl Iterator<Item = Region<'tcx>>;
1713

1814
/// Returns true if a type implements a given trait.
1915
fn does_implement_trait(
20-
&self,
16+
self,
2117
tcx: TyCtxt<'tcx>,
2218
param_env: ParamEnv<'tcx>,
2319
trait_def_id: DefId,
2420
) -> bool;
2521

22+
#[allow(clippy::wrong_self_convention)]
2623
/// Returns true if a type implements `Copy`.
27-
fn is_copyable(&self, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>) -> bool;
24+
fn is_copyable(self, tcx: TyCtxt<'tcx>, typing_env: TypingEnv<'tcx>) -> bool;
2825
}
2926

3027
impl<'tcx> TyExt<'tcx> for Ty<'tcx> {
31-
type AllRegionsIter<'a> = impl Iterator<Item = Region<'tcx>> + Captures<'tcx> + 'a
32-
where Self: 'a;
33-
34-
fn inner_regions(&self) -> Self::AllRegionsIter<'_> {
28+
fn inner_regions(self) -> impl Iterator<Item = Region<'tcx>> {
3529
self.walk().filter_map(|part| match part.unpack() {
3630
GenericArgKind::Lifetime(region) => Some(region),
3731
_ => None,
3832
})
3933
}
4034

4135
fn does_implement_trait(
42-
&self,
36+
self,
4337
tcx: TyCtxt<'tcx>,
4438
param_env: ParamEnv<'tcx>,
4539
trait_def_id: DefId,
4640
) -> bool {
4741
use rustc_infer::traits::EvaluationResult;
4842

49-
let infcx = tcx.infer_ctxt().build();
50-
let ty = tcx.erase_regions(*self);
43+
let infcx = tcx.infer_ctxt().build(TypingMode::non_body_analysis());
44+
let ty = tcx.erase_regions(self);
5145
let result = infcx.type_implements_trait(trait_def_id, [ty], param_env);
5246
matches!(
5347
result,
5448
EvaluationResult::EvaluatedToOk | EvaluationResult::EvaluatedToOkModuloRegions
5549
)
5650
}
5751

58-
fn is_copyable(&self, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>) -> bool {
59-
let ty = tcx.erase_regions(*self);
60-
ty.is_copy_modulo_regions(tcx, param_env)
52+
fn is_copyable(self, tcx: TyCtxt<'tcx>, typing_env: TypingEnv<'tcx>) -> bool {
53+
let ty = tcx.erase_regions(self);
54+
ty.is_copy_modulo_regions(tcx, typing_env)
6155
}
6256
}
6357

6458
#[cfg(test)]
6559
mod test {
66-
use rustc_middle::ty::ParamEnv;
60+
use rustc_middle::ty::TypingEnv;
6761

6862
use super::TyExt;
6963
use crate::{test_utils, BodyExt};
7064

7165
#[test]
7266
fn test_ty_ext() {
73-
let input = r#"
67+
let input = r"
7468
fn main() {
7569
let x = &mut 0;
7670
let y = 0;
77-
}"#;
71+
}";
7872

7973
test_utils::compile_body(input, |tcx, _, body| {
8074
let body = &body.body;
@@ -84,8 +78,8 @@ fn main() {
8478
assert_eq!(x.ty.inner_regions().count(), 1);
8579
assert_eq!(y.ty.inner_regions().count(), 0);
8680

87-
assert!(!x.ty.is_copyable(tcx, ParamEnv::empty()));
88-
assert!(y.ty.is_copyable(tcx, ParamEnv::empty()));
81+
assert!(!x.ty.is_copyable(tcx, TypingEnv::fully_monomorphized()));
82+
assert!(y.ty.is_copyable(tcx, TypingEnv::fully_monomorphized()));
8983
});
9084
}
9185
}

0 commit comments

Comments
 (0)