Skip to content

Commit 8e22049

Browse files
committed
Auto merge of #147874 - matthiaskrgr:rollup-d1x4uyz, r=matthiaskrgr
Rollup of 2 pull requests Successful merges: - #147864 (Parse `const unsafe trait` properly) - #147868 (MirPatch: Simplify new_local.) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 33cab8c + 122ab32 commit 8e22049

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

compiler/rustc_mir_transform/src/patch.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ pub(crate) struct MirPatch<'tcx> {
2424
// Cached block for UnwindTerminate (with reason)
2525
terminate_block: Option<(BasicBlock, UnwindTerminateReason)>,
2626
body_span: Span,
27+
/// The number of locals at the start of the transformation. New locals
28+
/// get appended at the end.
2729
next_local: usize,
2830
/// The number of blocks at the start of the transformation. New blocks
2931
/// get appended at the end.
@@ -176,8 +178,7 @@ impl<'tcx> MirPatch<'tcx> {
176178
span: Span,
177179
local_info: LocalInfo<'tcx>,
178180
) -> Local {
179-
let index = self.next_local;
180-
self.next_local += 1;
181+
let index = self.next_local + self.new_locals.len();
181182
let mut new_decl = LocalDecl::new(ty, span);
182183
**new_decl.local_info.as_mut().unwrap_crate_local() = local_info;
183184
self.new_locals.push(new_decl);
@@ -186,17 +187,16 @@ impl<'tcx> MirPatch<'tcx> {
186187

187188
/// Queues the addition of a new temporary.
188189
pub(crate) fn new_temp(&mut self, ty: Ty<'tcx>, span: Span) -> Local {
189-
let index = self.next_local;
190-
self.next_local += 1;
190+
let index = self.next_local + self.new_locals.len();
191191
self.new_locals.push(LocalDecl::new(ty, span));
192192
Local::new(index)
193193
}
194194

195195
/// Returns the type of a local that's newly-added in the patch.
196196
pub(crate) fn local_ty(&self, local: Local) -> Ty<'tcx> {
197197
let local = local.as_usize();
198-
assert!(local < self.next_local);
199-
let new_local_idx = self.new_locals.len() - (self.next_local - local);
198+
assert!(local < self.next_local + self.new_locals.len());
199+
let new_local_idx = local - self.next_local;
200200
self.new_locals[new_local_idx].ty
201201
}
202202

compiler/rustc_parse/src/parser/item.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2664,7 +2664,10 @@ impl<'a> Parser<'a> {
26642664
// Rule out `unsafe extern {`.
26652665
&& !self.is_unsafe_foreign_mod()
26662666
// Rule out `async gen {` and `async gen move {`
2667-
&& !self.is_async_gen_block())
2667+
&& !self.is_async_gen_block()
2668+
// Rule out `const unsafe auto` and `const unsafe trait`.
2669+
&& !self.is_keyword_ahead(2, &[kw::Auto, kw::Trait])
2670+
)
26682671
})
26692672
// `extern ABI fn`
26702673
|| self.check_keyword_case(exp!(Extern), case)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Test that `const unsafe trait` and `const unsafe auto trait` works.
2+
3+
//@ check-pass
4+
5+
#![feature(const_trait_impl)]
6+
#![feature(auto_traits)]
7+
8+
pub const unsafe trait Owo {}
9+
const unsafe trait OwO {}
10+
pub const unsafe auto trait UwU {}
11+
const unsafe auto trait Uwu {}
12+
13+
fn main() {}

0 commit comments

Comments
 (0)