Skip to content

Commit de91049

Browse files
authored
Merge pull request #590 from Nadrieril/assoc-ty-defaults
Misc fixes
2 parents ad99af7 + 4d56592 commit de91049

File tree

7 files changed

+99
-4
lines changed

7 files changed

+99
-4
lines changed

charon/src/bin/charon-driver/translate/translate_ctx.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -852,8 +852,7 @@ impl<'tcx, 'ctx> TranslateCtx<'tcx> {
852852
) -> TraitImplId {
853853
let id = id.into();
854854
// Register the corresponding trait early so we can filter on its name.
855-
{
856-
let def = self.hax_def(id).expect("hax failed when translating item");
855+
if let Ok(def) = self.hax_def(id) {
857856
let hax::FullDefKind::TraitImpl { trait_pred, .. } = def.kind() else {
858857
unreachable!()
859858
};

charon/src/bin/charon/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ struct Toolchain {
6767
impl Toolchain {
6868
fn is_installed(&self) -> anyhow::Result<bool> {
6969
// FIXME: check if the right components are installed.
70-
let output = self.run("echo").output()?;
70+
let output = self.run("rustc").arg("--version").output()?;
7171
Ok(output.status.success())
7272
}
7373

charon/src/transform/expand_associated_types.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -935,7 +935,13 @@ impl UpdateItemBody<'_> {
935935
self.lookup_path_on_trait_ref(&path, parent)
936936
}
937937
TraitRefKind::ItemClause(..) => {
938-
unreachable!("item clause should have been removed in a previous pass")
938+
register_error!(
939+
self.ctx,
940+
self.span,
941+
"Found unhandled item clause; \
942+
this is a bug unless the clause is coming from a GAT."
943+
);
944+
None
939945
}
940946
TraitRefKind::BuiltinOrAuto {
941947
parent_trait_refs,
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
error: Generic associated types are not supported
2+
--> tests/ui/gat-causes-unhandled-ty-clause.rs:4:5
3+
|
4+
4 | type GAT<T>;
5+
| ^^^^^^^^^^^
6+
|
7+
8+
error: Item `test_crate::HasGAT` caused errors; ignoring.
9+
--> tests/ui/gat-causes-unhandled-ty-clause.rs:3:1
10+
|
11+
3 | trait HasGAT {
12+
| ^^^^^^^^^^^^
13+
|
14+
15+
error: Found unhandled item clause; this is a bug unless the clause is coming from a GAT.
16+
--> tests/ui/gat-causes-unhandled-ty-clause.rs:12:1
17+
|
18+
12 | / fn floatify<C>() -> <C::Friend as HasAssoc>::Assoc
19+
13 | | where
20+
... |
21+
16 | | todo!()
22+
17 | | }
23+
| |_^
24+
|
25+
26+
error: Found unhandled item clause; this is a bug unless the clause is coming from a GAT.
27+
--> tests/ui/gat-causes-unhandled-ty-clause.rs:12:1
28+
|
29+
12 | / fn floatify<C>() -> <C::Friend as HasAssoc>::Assoc
30+
13 | | where
31+
... |
32+
16 | | todo!()
33+
17 | | }
34+
| |_^
35+
|
36+
37+
ERROR Charon failed to translate this code (4 errors)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//@ known-failure
2+
//! Regression test minimized from the rustc test suite. This used to cause a panic.
3+
trait HasGAT {
4+
type GAT<T>;
5+
type Friend: HasAssoc;
6+
}
7+
8+
trait HasAssoc {
9+
type Assoc;
10+
}
11+
12+
fn floatify<C>() -> <C::Friend as HasAssoc>::Assoc
13+
where
14+
C: HasGAT,
15+
{
16+
todo!()
17+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
thread 'rustc' panicked at /rustc/86d69c705a552236a622eee3fdea94bf13c5f102/compiler/rustc_type_ir/src/binder.rs:697:9:
2+
type parameter `U/#1` (U/#1/1) out of range when instantiating, args=[()]
3+
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
4+
error: Hax panicked when translating `test_crate::{impl#0}`.
5+
--> tests/ui/simple/gat-default.rs:9:1
6+
|
7+
9 | impl Collection for () {}
8+
| ^^^^^^^^^^^^^^^^^^^^^^
9+
|
10+
11+
error: Generic associated types are not supported
12+
--> tests/ui/simple/gat-default.rs:6:5
13+
|
14+
6 | type Sibling<U> = Vec<U>;
15+
| ^^^^^^^^^^^^^^^
16+
|
17+
18+
error: Item `test_crate::Collection` caused errors; ignoring.
19+
--> tests/ui/simple/gat-default.rs:5:1
20+
|
21+
5 | trait Collection {
22+
| ^^^^^^^^^^^^^^^^
23+
|
24+
25+
ERROR Charon failed to translate this code (3 errors)

charon/tests/ui/simple/gat-default.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//@ known-failure
2+
//! Test associated type defaults with parameters
3+
#![feature(associated_type_defaults)]
4+
5+
trait Collection {
6+
type Sibling<U> = Vec<U>;
7+
}
8+
9+
impl Collection for () {}
10+
11+
fn main() {}

0 commit comments

Comments
 (0)