Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 4a204be

Browse files
committedDec 13, 2024·
Auto merge of rust-lang#134269 - matthiaskrgr:rollup-fkshwux, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#133900 (Advent of `tests/ui` (misc cleanups and improvements) [1/N]) - rust-lang#133937 (Keep track of parse errors in `mod`s and don't emit resolve errors for paths involving them) - rust-lang#133938 (`rustc_mir_dataflow` cleanups, including some renamings) - rust-lang#134058 (interpret: reduce usage of TypingEnv::fully_monomorphized) - rust-lang#134130 (Stop using driver queries in the public API) - rust-lang#134140 (Add AST support for unsafe binders) - rust-lang#134229 (Fix typos in docs on provenance) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 327c7ee + 8cce32a commit 4a204be

File tree

119 files changed

+1337
-635
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

119 files changed

+1337
-635
lines changed
 

‎compiler/rustc_ast/src/ast.rs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,6 +1382,7 @@ impl Expr {
13821382
| ExprKind::Tup(_)
13831383
| ExprKind::Type(..)
13841384
| ExprKind::Underscore
1385+
| ExprKind::UnsafeBinderCast(..)
13851386
| ExprKind::While(..)
13861387
| ExprKind::Err(_)
13871388
| ExprKind::Dummy => ExprPrecedence::Unambiguous,
@@ -1509,7 +1510,13 @@ pub enum ExprKind {
15091510
/// `'label: for await? pat in iter { block }`
15101511
///
15111512
/// This is desugared to a combination of `loop` and `match` expressions.
1512-
ForLoop { pat: P<Pat>, iter: P<Expr>, body: P<Block>, label: Option<Label>, kind: ForLoopKind },
1513+
ForLoop {
1514+
pat: P<Pat>,
1515+
iter: P<Expr>,
1516+
body: P<Block>,
1517+
label: Option<Label>,
1518+
kind: ForLoopKind,
1519+
},
15131520
/// Conditionless loop (can be exited with `break`, `continue`, or `return`).
15141521
///
15151522
/// `'label: loop { block }`
@@ -1614,6 +1621,8 @@ pub enum ExprKind {
16141621
/// A `format_args!()` expression.
16151622
FormatArgs(P<FormatArgs>),
16161623

1624+
UnsafeBinderCast(UnsafeBinderCastKind, P<Expr>, Option<P<Ty>>),
1625+
16171626
/// Placeholder for an expression that wasn't syntactically well formed in some way.
16181627
Err(ErrorGuaranteed),
16191628

@@ -1652,6 +1661,16 @@ impl GenBlockKind {
16521661
}
16531662
}
16541663

1664+
/// Whether we're unwrapping or wrapping an unsafe binder
1665+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
1666+
#[derive(Encodable, Decodable, HashStable_Generic)]
1667+
pub enum UnsafeBinderCastKind {
1668+
// e.g. `&i32` -> `unsafe<'a> &'a i32`
1669+
Wrap,
1670+
// e.g. `unsafe<'a> &'a i32` -> `&i32`
1671+
Unwrap,
1672+
}
1673+
16551674
/// The explicit `Self` type in a "qualified path". The actual
16561675
/// path, including the trait and the associated item, is stored
16571676
/// separately. `position` represents the index of the associated
@@ -2223,6 +2242,12 @@ pub struct BareFnTy {
22232242
pub decl_span: Span,
22242243
}
22252244

2245+
#[derive(Clone, Encodable, Decodable, Debug)]
2246+
pub struct UnsafeBinderTy {
2247+
pub generic_params: ThinVec<GenericParam>,
2248+
pub inner_ty: P<Ty>,
2249+
}
2250+
22262251
/// The various kinds of type recognized by the compiler.
22272252
//
22282253
// Adding a new variant? Please update `test_ty` in `tests/ui/macros/stringify.rs`.
@@ -2242,6 +2267,8 @@ pub enum TyKind {
22422267
PinnedRef(Option<Lifetime>, MutTy),
22432268
/// A bare function (e.g., `fn(usize) -> bool`).
22442269
BareFn(P<BareFnTy>),
2270+
/// An unsafe existential lifetime binder (e.g., `unsafe<'a> &'a ()`).
2271+
UnsafeBinder(P<UnsafeBinderTy>),
22452272
/// The never type (`!`).
22462273
Never,
22472274
/// A tuple (`(A, B, C, D,...)`).
@@ -2877,7 +2904,7 @@ pub enum ModKind {
28772904
/// or with definition outlined to a separate file `mod foo;` and already loaded from it.
28782905
/// The inner span is from the first token past `{` to the last token until `}`,
28792906
/// or from the first to the last token in the loaded file.
2880-
Loaded(ThinVec<P<Item>>, Inline, ModSpans),
2907+
Loaded(ThinVec<P<Item>>, Inline, ModSpans, Result<(), ErrorGuaranteed>),
28812908
/// Module with definition outlined to a separate file `mod foo;` but not yet loaded from it.
28822909
Unloaded,
28832910
}

‎compiler/rustc_ast/src/mut_visit.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,11 @@ pub fn walk_ty<T: MutVisitor>(vis: &mut T, ty: &mut P<Ty>) {
558558
vis.visit_fn_decl(decl);
559559
vis.visit_span(decl_span);
560560
}
561+
TyKind::UnsafeBinder(binder) => {
562+
let UnsafeBinderTy { generic_params, inner_ty } = binder.deref_mut();
563+
generic_params.flat_map_in_place(|param| vis.flat_map_generic_param(param));
564+
vis.visit_ty(inner_ty);
565+
}
561566
TyKind::Tup(tys) => visit_thin_vec(tys, |ty| vis.visit_ty(ty)),
562567
TyKind::Paren(ty) => vis.visit_ty(ty),
563568
TyKind::Pat(ty, pat) => {
@@ -1212,7 +1217,12 @@ impl WalkItemKind for ItemKind {
12121217
ItemKind::Mod(safety, mod_kind) => {
12131218
visit_safety(vis, safety);
12141219
match mod_kind {
1215-
ModKind::Loaded(items, _inline, ModSpans { inner_span, inject_use_span }) => {
1220+
ModKind::Loaded(
1221+
items,
1222+
_inline,
1223+
ModSpans { inner_span, inject_use_span },
1224+
_,
1225+
) => {
12161226
items.flat_map_in_place(|item| vis.flat_map_item(item));
12171227
vis.visit_span(inner_span);
12181228
vis.visit_span(inject_use_span);
@@ -1775,6 +1785,12 @@ pub fn walk_expr<T: MutVisitor>(vis: &mut T, Expr { kind, id, span, attrs, token
17751785
ExprKind::TryBlock(body) => vis.visit_block(body),
17761786
ExprKind::Lit(_token) => {}
17771787
ExprKind::IncludedBytes(_bytes) => {}
1788+
ExprKind::UnsafeBinderCast(_kind, expr, ty) => {
1789+
vis.visit_expr(expr);
1790+
if let Some(ty) = ty {
1791+
vis.visit_ty(ty);
1792+
}
1793+
}
17781794
ExprKind::Err(_guar) => {}
17791795
ExprKind::Dummy => {}
17801796
}

0 commit comments

Comments
 (0)
This repository has been archived.