Skip to content

Commit 08956d4

Browse files
authored
Merge pull request #466 from nathanwhit/typename-never
Add never type to `TypeName`
2 parents eaab84b + 2cb1d43 commit 08956d4

File tree

12 files changed

+40
-81
lines changed

12 files changed

+40
-81
lines changed

book/src/clauses/well_known_traits.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ Some common examples of auto traits are `Send` and `Sync`.
3434
| structs ||||||||||
3535
| scalar types | 📚 | 📚 ||||||||
3636
| str | 📚 | 📚 ||||||||
37+
| never type | 📚 | 📚 ||||||||
3738
| trait objects ||||||||||
3839
| functions ptrs ||||||||||
39-
| raw ptrs | | ||||||||
40-
| immutable refs | | ||||||||
40+
| raw ptrs | 📚 | 📚 ||||||||
41+
| immutable refs | 📚 | 📚 ||||||||
4142
| mutable refs ||||||||||
4243
| slices ||||||||||
4344
| arrays❌ ||||||||||

chalk-integration/src/lowering.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1438,6 +1438,12 @@ impl LowerTy for Ty {
14381438
substitution: chalk_ir::Substitution::empty(interner),
14391439
})
14401440
.intern(interner)),
1441+
1442+
Ty::Never => Ok(chalk_ir::TyData::Apply(chalk_ir::ApplicationTy {
1443+
name: chalk_ir::TypeName::Never,
1444+
substitution: chalk_ir::Substitution::empty(interner),
1445+
})
1446+
.intern(interner)),
14411447
}
14421448
}
14431449
}

chalk-ir/src/debug.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ impl<I: Interner> Debug for TypeName<I> {
167167
TypeName::FnDef(fn_def) => write!(fmt, "{:?}", fn_def),
168168
TypeName::Raw(mutability) => write!(fmt, "{:?}", mutability),
169169
TypeName::Ref(mutability) => write!(fmt, "{:?}", mutability),
170+
TypeName::Never => write!(fmt, "Never"),
170171
TypeName::Error => write!(fmt, "{{error}}"),
171172
}
172173
}

chalk-ir/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@ pub enum TypeName<I: Interner> {
175175
/// the string primitive type
176176
Str,
177177

178+
/// the never type `!`
179+
Never,
180+
178181
/// This can be used to represent an error, e.g. during name resolution of a type.
179182
/// Chalk itself will not produce this, just pass it through when given.
180183
Error,

chalk-parse/src/ast.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ pub enum Ty {
222222
ty: Box<Ty>,
223223
},
224224
Str,
225+
Never,
225226
}
226227

227228
#[derive(Copy, Clone, PartialEq, Eq, Debug)]

chalk-parse/src/parser.lalrpop

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ TyWithoutId: Ty = {
224224
},
225225
<ScalarType> => Ty::Scalar { ty: <> },
226226
"str" => Ty::Str,
227+
"!" => Ty::Never,
227228
"fn" "(" <t:Ty> ")" => Ty::ForAll {
228229
lifetime_names: vec![],
229230
ty: Box::new(t)

chalk-solve/src/clauses.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -411,20 +411,19 @@ fn match_type_name<I: Interner>(
411411
.db
412412
.associated_ty_data(type_id)
413413
.to_program_clauses(builder),
414-
TypeName::Scalar(_) => {
415-
builder.push_fact(WellFormed::Ty(application.clone().intern(interner)))
416-
}
417-
TypeName::Str => builder.push_fact(WellFormed::Ty(application.clone().intern(interner))),
418-
TypeName::Tuple(_) => {
419-
builder.push_fact(WellFormed::Ty(application.clone().intern(interner)))
420-
}
421-
TypeName::Slice => builder.push_fact(WellFormed::Ty(application.clone().intern(interner))),
422-
TypeName::Raw(_) => builder.push_fact(WellFormed::Ty(application.clone().intern(interner))),
423-
TypeName::Ref(_) => builder.push_fact(WellFormed::Ty(application.clone().intern(interner))),
424414
TypeName::FnDef(fn_def_id) => builder
425415
.db
426416
.fn_def_datum(fn_def_id)
427417
.to_program_clauses(builder),
418+
TypeName::Tuple(_)
419+
| TypeName::Scalar(_)
420+
| TypeName::Str
421+
| TypeName::Slice
422+
| TypeName::Raw(_)
423+
| TypeName::Ref(_)
424+
| TypeName::Never => {
425+
builder.push_fact(WellFormed::Ty(application.clone().intern(interner)))
426+
}
428427
}
429428
}
430429

chalk-solve/src/clauses/builtin_traits/copy.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::clauses::builtin_traits::needs_impl_for_tys;
22
use crate::clauses::ClauseBuilder;
33
use crate::{Interner, RustIrDatabase, TraitRef};
4-
use chalk_ir::{ApplicationTy, Mutability, Substitution, TyData, TypeName};
4+
use chalk_ir::{ApplicationTy, Substitution, TyData, TypeName};
55

66
fn push_tuple_copy_conditions<I: Interner>(
77
db: &dyn RustIrDatabase<I>,
@@ -41,9 +41,6 @@ pub fn add_copy_program_clauses<I: Interner>(
4141
TypeName::Tuple(arity) => {
4242
push_tuple_copy_conditions(db, builder, trait_ref, *arity, substitution)
4343
}
44-
TypeName::Raw(_) | TypeName::Ref(Mutability::Not) => {
45-
builder.push_fact(trait_ref.clone())
46-
}
4744
_ => return,
4845
},
4946
TyData::Function(_) => builder.push_fact(trait_ref.clone()),

chalk-solve/src/clauses/builtin_traits/sized.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ pub fn add_sized_program_clauses<I: Interner>(
7474
TypeName::Tuple(arity) => {
7575
push_tuple_sized_conditions(db, builder, trait_ref, *arity, substitution)
7676
}
77-
TypeName::Scalar(_) | TypeName::Raw(_) | TypeName::Ref(_) => {
77+
TypeName::Never | TypeName::Scalar(_) | TypeName::Raw(_) | TypeName::Ref(_) => {
7878
builder.push_fact(trait_ref.clone())
7979
}
8080
_ => return,

tests/test/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ mod implied_bounds;
307307
mod impls;
308308
mod misc;
309309
mod negation;
310+
mod never;
310311
mod object_safe;
311312
mod opaque_types;
312313
mod projection;

0 commit comments

Comments
 (0)