mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 11:31:15 +00:00
Update to latest rustc_pattern_analysis
This commit is contained in:
parent
c06ca6cff5
commit
3356ebd255
16
Cargo.lock
generated
16
Cargo.lock
generated
@ -1470,12 +1470,12 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ra-ap-rustc_index"
|
name = "ra-ap-rustc_index"
|
||||||
version = "0.36.0"
|
version = "0.37.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f8a41dee58608b1fc93779ea365edaa70ac9927e3335ae914b675be0fa063cd7"
|
checksum = "df5a0ba0d08af366cf235dbe8eb7226cced7a4fe502c98aa434ccf416defd746"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arrayvec",
|
"arrayvec",
|
||||||
"ra-ap-rustc_index_macros 0.36.0",
|
"ra-ap-rustc_index_macros 0.37.0",
|
||||||
"smallvec",
|
"smallvec",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -1493,9 +1493,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ra-ap-rustc_index_macros"
|
name = "ra-ap-rustc_index_macros"
|
||||||
version = "0.36.0"
|
version = "0.37.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "fbfe98def54c4337a2f7d8233850bd5d5349972b185fe8a0db2b979164b30ed8"
|
checksum = "1971ebf9a701e0e68387c264a32517dcb4861ad3a4862f2e2803c1121ade20d5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
@ -1525,11 +1525,11 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ra-ap-rustc_pattern_analysis"
|
name = "ra-ap-rustc_pattern_analysis"
|
||||||
version = "0.36.0"
|
version = "0.37.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b5529bffec7530b4a3425640bfdfd9b95d87c4c620f740266c0de6572561aab4"
|
checksum = "2c3c0e7ca9c5bdc66e3b590688e237a22ac47a48e4eac7f46b05b2abbfaf0abd"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ra-ap-rustc_index 0.36.0",
|
"ra-ap-rustc_index 0.37.0",
|
||||||
"rustc-hash",
|
"rustc-hash",
|
||||||
"rustc_apfloat",
|
"rustc_apfloat",
|
||||||
"smallvec",
|
"smallvec",
|
||||||
|
@ -84,7 +84,7 @@ ra-ap-rustc_lexer = { version = "0.35.0", default-features = false }
|
|||||||
ra-ap-rustc_parse_format = { version = "0.35.0", default-features = false }
|
ra-ap-rustc_parse_format = { version = "0.35.0", default-features = false }
|
||||||
ra-ap-rustc_index = { version = "0.35.0", default-features = false }
|
ra-ap-rustc_index = { version = "0.35.0", default-features = false }
|
||||||
ra-ap-rustc_abi = { version = "0.35.0", default-features = false }
|
ra-ap-rustc_abi = { version = "0.35.0", default-features = false }
|
||||||
ra-ap-rustc_pattern_analysis = { version = "0.36.0", default-features = false }
|
ra-ap-rustc_pattern_analysis = { version = "0.37.0", default-features = false }
|
||||||
|
|
||||||
# local crates that aren't published to crates.io. These should not have versions.
|
# local crates that aren't published to crates.io. These should not have versions.
|
||||||
sourcegen = { path = "./crates/sourcegen" }
|
sourcegen = { path = "./crates/sourcegen" }
|
||||||
|
@ -223,7 +223,7 @@ impl ExprValidator {
|
|||||||
ValidityConstraint::ValidOnly,
|
ValidityConstraint::ValidOnly,
|
||||||
) {
|
) {
|
||||||
Ok(report) => report,
|
Ok(report) => report,
|
||||||
Err(void) => match void {},
|
Err(()) => return,
|
||||||
};
|
};
|
||||||
|
|
||||||
// FIXME Report unreachable arms
|
// FIXME Report unreachable arms
|
||||||
|
@ -26,7 +26,7 @@ use Constructor::*;
|
|||||||
|
|
||||||
// Re-export r-a-specific versions of all these types.
|
// Re-export r-a-specific versions of all these types.
|
||||||
pub(crate) type DeconstructedPat<'p> =
|
pub(crate) type DeconstructedPat<'p> =
|
||||||
rustc_pattern_analysis::pat::DeconstructedPat<'p, MatchCheckCtx<'p>>;
|
rustc_pattern_analysis::pat::DeconstructedPat<MatchCheckCtx<'p>>;
|
||||||
pub(crate) type MatchArm<'p> = rustc_pattern_analysis::MatchArm<'p, MatchCheckCtx<'p>>;
|
pub(crate) type MatchArm<'p> = rustc_pattern_analysis::MatchArm<'p, MatchCheckCtx<'p>>;
|
||||||
pub(crate) type WitnessPat<'p> = rustc_pattern_analysis::pat::WitnessPat<MatchCheckCtx<'p>>;
|
pub(crate) type WitnessPat<'p> = rustc_pattern_analysis::pat::WitnessPat<MatchCheckCtx<'p>>;
|
||||||
|
|
||||||
@ -131,15 +131,15 @@ impl<'p> MatchCheckCtx<'p> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn lower_pat(&self, pat: &Pat) -> DeconstructedPat<'p> {
|
pub(crate) fn lower_pat(&self, pat: &Pat) -> DeconstructedPat<'p> {
|
||||||
let singleton = |pat| std::slice::from_ref(self.pattern_arena.alloc(pat));
|
let singleton = |pat| vec![pat];
|
||||||
let ctor;
|
let ctor;
|
||||||
let fields: &[_];
|
let fields: Vec<_>;
|
||||||
|
|
||||||
match pat.kind.as_ref() {
|
match pat.kind.as_ref() {
|
||||||
PatKind::Binding { subpattern: Some(subpat), .. } => return self.lower_pat(subpat),
|
PatKind::Binding { subpattern: Some(subpat), .. } => return self.lower_pat(subpat),
|
||||||
PatKind::Binding { subpattern: None, .. } | PatKind::Wild => {
|
PatKind::Binding { subpattern: None, .. } | PatKind::Wild => {
|
||||||
ctor = Wildcard;
|
ctor = Wildcard;
|
||||||
fields = &[];
|
fields = Vec::new();
|
||||||
}
|
}
|
||||||
PatKind::Deref { subpattern } => {
|
PatKind::Deref { subpattern } => {
|
||||||
ctor = match pat.ty.kind(Interner) {
|
ctor = match pat.ty.kind(Interner) {
|
||||||
@ -157,7 +157,7 @@ impl<'p> MatchCheckCtx<'p> {
|
|||||||
match pat.ty.kind(Interner) {
|
match pat.ty.kind(Interner) {
|
||||||
TyKind::Tuple(_, substs) => {
|
TyKind::Tuple(_, substs) => {
|
||||||
ctor = Struct;
|
ctor = Struct;
|
||||||
let mut wilds: SmallVec<[_; 2]> = substs
|
let mut wilds: Vec<_> = substs
|
||||||
.iter(Interner)
|
.iter(Interner)
|
||||||
.map(|arg| arg.assert_ty_ref(Interner).clone())
|
.map(|arg| arg.assert_ty_ref(Interner).clone())
|
||||||
.map(DeconstructedPat::wildcard)
|
.map(DeconstructedPat::wildcard)
|
||||||
@ -166,7 +166,7 @@ impl<'p> MatchCheckCtx<'p> {
|
|||||||
let idx: u32 = pat.field.into_raw().into();
|
let idx: u32 = pat.field.into_raw().into();
|
||||||
wilds[idx as usize] = self.lower_pat(&pat.pattern);
|
wilds[idx as usize] = self.lower_pat(&pat.pattern);
|
||||||
}
|
}
|
||||||
fields = self.pattern_arena.alloc_extend(wilds)
|
fields = wilds
|
||||||
}
|
}
|
||||||
TyKind::Adt(adt, substs) if is_box(self.db, adt.0) => {
|
TyKind::Adt(adt, substs) if is_box(self.db, adt.0) => {
|
||||||
// The only legal patterns of type `Box` (outside `std`) are `_` and box
|
// The only legal patterns of type `Box` (outside `std`) are `_` and box
|
||||||
@ -216,33 +216,29 @@ impl<'p> MatchCheckCtx<'p> {
|
|||||||
field_id_to_id[field_idx as usize] = Some(i);
|
field_id_to_id[field_idx as usize] = Some(i);
|
||||||
ty
|
ty
|
||||||
});
|
});
|
||||||
let mut wilds: SmallVec<[_; 2]> =
|
let mut wilds: Vec<_> = tys.map(DeconstructedPat::wildcard).collect();
|
||||||
tys.map(DeconstructedPat::wildcard).collect();
|
|
||||||
for pat in subpatterns {
|
for pat in subpatterns {
|
||||||
let field_idx: u32 = pat.field.into_raw().into();
|
let field_idx: u32 = pat.field.into_raw().into();
|
||||||
if let Some(i) = field_id_to_id[field_idx as usize] {
|
if let Some(i) = field_id_to_id[field_idx as usize] {
|
||||||
wilds[i] = self.lower_pat(&pat.pattern);
|
wilds[i] = self.lower_pat(&pat.pattern);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fields = self.pattern_arena.alloc_extend(wilds);
|
fields = wilds;
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
never!("pattern has unexpected type: pat: {:?}, ty: {:?}", pat, &pat.ty);
|
never!("pattern has unexpected type: pat: {:?}, ty: {:?}", pat, &pat.ty);
|
||||||
ctor = Wildcard;
|
ctor = Wildcard;
|
||||||
fields = &[];
|
fields = Vec::new();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
&PatKind::LiteralBool { value } => {
|
&PatKind::LiteralBool { value } => {
|
||||||
ctor = Bool(value);
|
ctor = Bool(value);
|
||||||
fields = &[];
|
fields = Vec::new();
|
||||||
}
|
}
|
||||||
PatKind::Or { pats } => {
|
PatKind::Or { pats } => {
|
||||||
ctor = Or;
|
ctor = Or;
|
||||||
// Collect here because `Arena::alloc_extend` panics on reentrancy.
|
fields = pats.iter().map(|pat| self.lower_pat(pat)).collect();
|
||||||
let subpats: SmallVec<[_; 2]> =
|
|
||||||
pats.iter().map(|pat| self.lower_pat(pat)).collect();
|
|
||||||
fields = self.pattern_arena.alloc_extend(subpats);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let data = PatData { db: self.db };
|
let data = PatData { db: self.db };
|
||||||
@ -307,7 +303,7 @@ impl<'p> MatchCheckCtx<'p> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'p> TypeCx for MatchCheckCtx<'p> {
|
impl<'p> TypeCx for MatchCheckCtx<'p> {
|
||||||
type Error = Void;
|
type Error = ();
|
||||||
type Ty = Ty;
|
type Ty = Ty;
|
||||||
type VariantIdx = EnumVariantId;
|
type VariantIdx = EnumVariantId;
|
||||||
type StrLit = Void;
|
type StrLit = Void;
|
||||||
@ -463,7 +459,7 @@ impl<'p> TypeCx for MatchCheckCtx<'p> {
|
|||||||
|
|
||||||
fn write_variant_name(
|
fn write_variant_name(
|
||||||
f: &mut fmt::Formatter<'_>,
|
f: &mut fmt::Formatter<'_>,
|
||||||
pat: &rustc_pattern_analysis::pat::DeconstructedPat<'_, Self>,
|
pat: &rustc_pattern_analysis::pat::DeconstructedPat<Self>,
|
||||||
) -> fmt::Result {
|
) -> fmt::Result {
|
||||||
let variant =
|
let variant =
|
||||||
pat.ty().as_adt().and_then(|(adt, _)| Self::variant_id_for_adt(pat.ctor(), adt));
|
pat.ty().as_adt().and_then(|(adt, _)| Self::variant_id_for_adt(pat.ctor(), adt));
|
||||||
@ -485,8 +481,8 @@ impl<'p> TypeCx for MatchCheckCtx<'p> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bug(&self, fmt: fmt::Arguments<'_>) -> ! {
|
fn bug(&self, fmt: fmt::Arguments<'_>) {
|
||||||
panic!("{}", fmt)
|
never!("{}", fmt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user