Skip to content

Commit a4c0d85

Browse files
Rollup merge of rust-lang#121695 - oli-obk:split_ty_utils, r=compiler-errors
Split rustc_type_ir to avoid rustc_ast from depending on it unblocks rust-lang#121576 and resolves a FIXME in `rustc_ast`'s `Cargo.toml` The new crate is tiny, but it will get bigger in rust-lang#121576
2 parents 50ec403 + 8a6d353 commit a4c0d85

File tree

14 files changed

+117
-74
lines changed

14 files changed

+117
-74
lines changed

Cargo.lock

+14-1
Original file line numberDiff line numberDiff line change
@@ -3417,18 +3417,29 @@ version = "0.0.0"
34173417
dependencies = [
34183418
"bitflags 2.4.2",
34193419
"memchr",
3420+
"rustc_ast_ir",
34203421
"rustc_data_structures",
34213422
"rustc_index",
34223423
"rustc_lexer",
34233424
"rustc_macros",
34243425
"rustc_serialize",
34253426
"rustc_span",
3426-
"rustc_type_ir",
34273427
"smallvec",
34283428
"thin-vec",
34293429
"tracing",
34303430
]
34313431

3432+
[[package]]
3433+
name = "rustc_ast_ir"
3434+
version = "0.0.0"
3435+
dependencies = [
3436+
"rustc_data_structures",
3437+
"rustc_macros",
3438+
"rustc_serialize",
3439+
"rustc_span",
3440+
"smallvec",
3441+
]
3442+
34323443
[[package]]
34333444
name = "rustc_ast_lowering"
34343445
version = "0.0.0"
@@ -4181,6 +4192,7 @@ dependencies = [
41814192
"rustc_apfloat",
41824193
"rustc_arena",
41834194
"rustc_ast",
4195+
"rustc_ast_ir",
41844196
"rustc_attr",
41854197
"rustc_data_structures",
41864198
"rustc_error_messages",
@@ -4661,6 +4673,7 @@ version = "0.0.0"
46614673
dependencies = [
46624674
"bitflags 2.4.2",
46634675
"derivative",
4676+
"rustc_ast_ir",
46644677
"rustc_data_structures",
46654678
"rustc_index",
46664679
"rustc_macros",

compiler/rustc_ast/Cargo.toml

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@ edition = "2021"
88
# tidy-alphabetical-start
99
bitflags = "2.4.1"
1010
memchr = "=2.5.0"
11+
rustc_ast_ir = { path = "../rustc_ast_ir" }
1112
rustc_data_structures = { path = "../rustc_data_structures" }
1213
rustc_index = { path = "../rustc_index" }
1314
rustc_lexer = { path = "../rustc_lexer" }
1415
rustc_macros = { path = "../rustc_macros" }
1516
rustc_serialize = { path = "../rustc_serialize" }
1617
rustc_span = { path = "../rustc_span" }
17-
# For Mutability and Movability, which could be uplifted into a common crate.
18-
rustc_type_ir = { path = "../rustc_type_ir" }
1918
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
2019
thin-vec = "0.2.12"
2120
tracing = "0.1"

compiler/rustc_ast/src/ast.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pub use UnsafeSource::*;
2727
use crate::ptr::P;
2828
use crate::token::{self, CommentKind, Delimiter};
2929
use crate::tokenstream::{DelimSpan, LazyAttrTokenStream, TokenStream};
30+
pub use rustc_ast_ir::{Movability, Mutability};
3031
use rustc_data_structures::packed::Pu128;
3132
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
3233
use rustc_data_structures::stack::ensure_sufficient_stack;
@@ -35,7 +36,6 @@ use rustc_macros::HashStable_Generic;
3536
use rustc_span::source_map::{respan, Spanned};
3637
use rustc_span::symbol::{kw, sym, Ident, Symbol};
3738
use rustc_span::{ErrorGuaranteed, Span, DUMMY_SP};
38-
pub use rustc_type_ir::{Movability, Mutability};
3939
use std::fmt;
4040
use std::mem;
4141
use thin_vec::{thin_vec, ThinVec};

compiler/rustc_ast_ir/Cargo.toml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[package]
2+
name = "rustc_ast_ir"
3+
version = "0.0.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
# tidy-alphabetical-start
8+
rustc_data_structures = { path = "../rustc_data_structures", optional = true }
9+
rustc_macros = { path = "../rustc_macros", optional = true }
10+
rustc_serialize = { path = "../rustc_serialize", optional = true }
11+
rustc_span = { path = "../rustc_span", optional = true }
12+
smallvec = { version = "1.8.1" }
13+
# tidy-alphabetical-end
14+
15+
[features]
16+
default = ["nightly"]
17+
nightly = [
18+
"rustc_serialize",
19+
"rustc_data_structures",
20+
"rustc_macros",
21+
"rustc_span",
22+
]

compiler/rustc_ast_ir/src/lib.rs

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#![cfg_attr(feature = "nightly", feature(rustc_attrs))]
2+
#![cfg_attr(feature = "nightly", allow(internal_features))]
3+
4+
#[cfg(feature = "nightly")]
5+
#[macro_use]
6+
extern crate rustc_macros;
7+
8+
/// The movability of a coroutine / closure literal:
9+
/// whether a coroutine contains self-references, causing it to be `!Unpin`.
10+
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Copy)]
11+
#[cfg_attr(feature = "nightly", derive(Encodable, Decodable, HashStable_NoContext))]
12+
pub enum Movability {
13+
/// May contain self-references, `!Unpin`.
14+
Static,
15+
/// Must not contain self-references, `Unpin`.
16+
Movable,
17+
}
18+
19+
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Copy)]
20+
#[cfg_attr(feature = "nightly", derive(Encodable, Decodable, HashStable_NoContext))]
21+
pub enum Mutability {
22+
// N.B. Order is deliberate, so that Not < Mut
23+
Not,
24+
Mut,
25+
}
26+
27+
impl Mutability {
28+
pub fn invert(self) -> Self {
29+
match self {
30+
Mutability::Mut => Mutability::Not,
31+
Mutability::Not => Mutability::Mut,
32+
}
33+
}
34+
35+
/// Returns `""` (empty string) or `"mut "` depending on the mutability.
36+
pub fn prefix_str(self) -> &'static str {
37+
match self {
38+
Mutability::Mut => "mut ",
39+
Mutability::Not => "",
40+
}
41+
}
42+
43+
/// Returns `"&"` or `"&mut "` depending on the mutability.
44+
pub fn ref_prefix_str(self) -> &'static str {
45+
match self {
46+
Mutability::Not => "&",
47+
Mutability::Mut => "&mut ",
48+
}
49+
}
50+
51+
/// Returns `""` (empty string) or `"mutably "` depending on the mutability.
52+
pub fn mutably_str(self) -> &'static str {
53+
match self {
54+
Mutability::Not => "",
55+
Mutability::Mut => "mutably ",
56+
}
57+
}
58+
59+
/// Return `true` if self is mutable
60+
pub fn is_mut(self) -> bool {
61+
matches!(self, Self::Mut)
62+
}
63+
64+
/// Return `true` if self is **not** mutable
65+
pub fn is_not(self) -> bool {
66+
matches!(self, Self::Not)
67+
}
68+
}

compiler/rustc_const_eval/src/errors.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@ use rustc_middle::mir::interpret::{
1111
PointerKind, ResourceExhaustionInfo, UndefinedBehaviorInfo, UnsupportedOpInfo,
1212
ValidationErrorInfo,
1313
};
14-
use rustc_middle::ty::{self, Ty};
14+
use rustc_middle::ty::{self, Mutability, Ty};
1515
use rustc_span::Span;
1616
use rustc_target::abi::call::AdjustForForeignAbiError;
1717
use rustc_target::abi::{Size, WrappingRange};
18-
use rustc_type_ir::Mutability;
1918

2019
use crate::interpret::InternKind;
2120

compiler/rustc_const_eval/src/util/caller_location.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
use rustc_hir::LangItem;
22
use rustc_middle::mir;
33
use rustc_middle::query::TyCtxtAt;
4-
use rustc_middle::ty;
54
use rustc_middle::ty::layout::LayoutOf;
5+
use rustc_middle::ty::{self, Mutability};
66
use rustc_span::symbol::Symbol;
7-
use rustc_type_ir::Mutability;
87

98
use crate::const_eval::{mk_eval_cx_to_read_const_val, CanAccessMutGlobal, CompileTimeEvalContext};
109
use crate::interpret::*;

compiler/rustc_hir_analysis/src/check/errs.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
use rustc_hir as hir;
22
use rustc_hir_pretty::qpath_to_string;
33
use rustc_lint_defs::builtin::STATIC_MUT_REFS;
4-
use rustc_middle::ty::TyCtxt;
4+
use rustc_middle::ty::{Mutability, TyCtxt};
55
use rustc_span::Span;
6-
use rustc_type_ir::Mutability;
76

87
use crate::errors;
98

compiler/rustc_middle/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ rustc-rayon-core = { version = "0.5.0", optional = true }
1717
rustc_apfloat = "0.2.0"
1818
rustc_arena = { path = "../rustc_arena" }
1919
rustc_ast = { path = "../rustc_ast" }
20+
rustc_ast_ir = { path = "../rustc_ast_ir" }
2021
rustc_attr = { path = "../rustc_attr" }
2122
rustc_data_structures = { path = "../rustc_data_structures" }
2223
rustc_error_messages = { path = "../rustc_error_messages" } # Used for intra-doc links

compiler/rustc_middle/src/mir/interpret/error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::error;
44
use crate::mir::{ConstAlloc, ConstValue};
55
use crate::ty::{layout, tls, Ty, TyCtxt, ValTree};
66

7+
use rustc_ast_ir::Mutability;
78
use rustc_data_structures::sync::Lock;
89
use rustc_errors::{
910
DiagnosticArgName, DiagnosticArgValue, DiagnosticMessage, ErrorGuaranteed, IntoDiagnosticArg,
@@ -12,7 +13,6 @@ use rustc_macros::HashStable;
1213
use rustc_session::CtfeBacktrace;
1314
use rustc_span::{def_id::DefId, Span, DUMMY_SP};
1415
use rustc_target::abi::{call, Align, Size, VariantIdx, WrappingRange};
15-
use rustc_type_ir::Mutability;
1616

1717
use std::borrow::Cow;
1818
use std::{any::Any, backtrace::Backtrace, fmt};

compiler/rustc_middle/src/ty/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ pub use generic_args::*;
3232
pub use generics::*;
3333
use rustc_ast as ast;
3434
use rustc_ast::node_id::NodeMap;
35+
pub use rustc_ast_ir::{Movability, Mutability};
3536
use rustc_attr as attr;
3637
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet};
3738
use rustc_data_structures::intern::Interned;

compiler/rustc_type_ir/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ edition = "2021"
77
# tidy-alphabetical-start
88
bitflags = "2.4.1"
99
derivative = "2.2.0"
10+
rustc_ast_ir = { path = "../rustc_ast_ir" }
1011
rustc_data_structures = { path = "../rustc_data_structures", optional = true }
1112
rustc_index = { path = "../rustc_index", default-features = false }
1213
rustc_macros = { path = "../rustc_macros", optional = true }
@@ -25,4 +26,5 @@ nightly = [
2526
"rustc_span",
2627
"rustc_data_structures",
2728
"rustc_macros",
29+
"rustc_ast_ir/nightly"
2830
]

compiler/rustc_type_ir/src/macros.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,6 @@ TrivialTypeTraversalImpls! {
5151
crate::DebruijnIndex,
5252
crate::AliasRelationDirection,
5353
crate::UniverseIndex,
54-
crate::Mutability,
55-
crate::Movability,
54+
rustc_ast_ir::Mutability,
55+
rustc_ast_ir::Movability,
5656
}

compiler/rustc_type_ir/src/ty_kind.rs

+1-61
Original file line numberDiff line numberDiff line change
@@ -11,67 +11,7 @@ use crate::{DebruijnIndex, DebugWithInfcx, InferCtxtLike, WithInfcx};
1111

1212
use self::TyKind::*;
1313

14-
/// The movability of a coroutine / closure literal:
15-
/// whether a coroutine contains self-references, causing it to be `!Unpin`.
16-
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Copy)]
17-
#[cfg_attr(feature = "nightly", derive(Encodable, Decodable, HashStable_NoContext))]
18-
pub enum Movability {
19-
/// May contain self-references, `!Unpin`.
20-
Static,
21-
/// Must not contain self-references, `Unpin`.
22-
Movable,
23-
}
24-
25-
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Copy)]
26-
#[cfg_attr(feature = "nightly", derive(Encodable, Decodable, HashStable_NoContext))]
27-
pub enum Mutability {
28-
// N.B. Order is deliberate, so that Not < Mut
29-
Not,
30-
Mut,
31-
}
32-
33-
impl Mutability {
34-
pub fn invert(self) -> Self {
35-
match self {
36-
Mutability::Mut => Mutability::Not,
37-
Mutability::Not => Mutability::Mut,
38-
}
39-
}
40-
41-
/// Returns `""` (empty string) or `"mut "` depending on the mutability.
42-
pub fn prefix_str(self) -> &'static str {
43-
match self {
44-
Mutability::Mut => "mut ",
45-
Mutability::Not => "",
46-
}
47-
}
48-
49-
/// Returns `"&"` or `"&mut "` depending on the mutability.
50-
pub fn ref_prefix_str(self) -> &'static str {
51-
match self {
52-
Mutability::Not => "&",
53-
Mutability::Mut => "&mut ",
54-
}
55-
}
56-
57-
/// Returns `""` (empty string) or `"mutably "` depending on the mutability.
58-
pub fn mutably_str(self) -> &'static str {
59-
match self {
60-
Mutability::Not => "",
61-
Mutability::Mut => "mutably ",
62-
}
63-
}
64-
65-
/// Return `true` if self is mutable
66-
pub fn is_mut(self) -> bool {
67-
matches!(self, Self::Mut)
68-
}
69-
70-
/// Return `true` if self is **not** mutable
71-
pub fn is_not(self) -> bool {
72-
matches!(self, Self::Not)
73-
}
74-
}
14+
use rustc_ast_ir::Mutability;
7515

7616
/// Specifies how a trait object is represented.
7717
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]

0 commit comments

Comments
 (0)