Skip to content

Avoid ICE by accounting for missing type #105340

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1607,7 +1607,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
| ObligationCauseCode::ObjectCastObligation(..)
| ObligationCauseCode::OpaqueType
);
let expected_ty = data.term.ty().unwrap();
let expected_ty = data.term.ty().unwrap_or_else(|| self.tcx.ty_error());

// constrain inference variables a bit more to nested obligations from normalize so
// we can have more helpful errors.
Expand Down
21 changes: 21 additions & 0 deletions src/test/ui/issues/issue-105330.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
pub trait TraitWAssocConst {
const A: usize;
}
pub struct Demo {}

impl TraitWAssocConst for impl Demo { //~ ERROR E0404
//~^ ERROR E0562
pubconst A: str = 32; //~ ERROR expected one of
}

fn foo<A: TraitWAssocConst<A=32>>() { //~ ERROR E0658
foo::<Demo>()(); //~ ERROR E0271
//~^ ERROR E0618
//~| ERROR E0277
}

fn main<A: TraitWAssocConst<A=32>>() { //~ ERROR E0131
//~^ ERROR E0658
foo::<Demo>(); //~ ERROR E0277
//~^ ERROR E0271
}
109 changes: 109 additions & 0 deletions src/test/ui/issues/issue-105330.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
error: expected one of `!` or `::`, found `A`
--> $DIR/issue-105330.rs:8:14
|
LL | impl TraitWAssocConst for impl Demo {
| - while parsing this item list starting here
LL |
LL | pubconst A: str = 32;
| ^ expected one of `!` or `::`
LL | }
| - the item list ends here

error[E0404]: expected trait, found struct `Demo`
--> $DIR/issue-105330.rs:6:32
|
LL | impl TraitWAssocConst for impl Demo {
| ^^^^ not a trait

error[E0658]: associated const equality is incomplete
--> $DIR/issue-105330.rs:11:28
|
LL | fn foo<A: TraitWAssocConst<A=32>>() {
| ^^^^
|
= note: see issue #92827 <https://github.com/rust-lang/rust/issues/92827> for more information
= help: add `#![feature(associated_const_equality)]` to the crate attributes to enable

error[E0658]: associated const equality is incomplete
--> $DIR/issue-105330.rs:17:29
|
LL | fn main<A: TraitWAssocConst<A=32>>() {
| ^^^^
|
= note: see issue #92827 <https://github.com/rust-lang/rust/issues/92827> for more information
= help: add `#![feature(associated_const_equality)]` to the crate attributes to enable

error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in type
--> $DIR/issue-105330.rs:6:27
|
LL | impl TraitWAssocConst for impl Demo {
| ^^^^^^^^^

error[E0277]: the trait bound `Demo: TraitWAssocConst` is not satisfied
--> $DIR/issue-105330.rs:12:11
|
LL | foo::<Demo>()();
| ^^^^ the trait `TraitWAssocConst` is not implemented for `Demo`
|
note: required by a bound in `foo`
--> $DIR/issue-105330.rs:11:11
|
LL | fn foo<A: TraitWAssocConst<A=32>>() {
| ^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `foo`

error[E0271]: type mismatch resolving `<Demo as TraitWAssocConst>::A == 32`
--> $DIR/issue-105330.rs:12:11
|
LL | foo::<Demo>()();
| ^^^^ types differ
|
note: required by a bound in `foo`
--> $DIR/issue-105330.rs:11:28
|
LL | fn foo<A: TraitWAssocConst<A=32>>() {
| ^^^^ required by this bound in `foo`

error[E0618]: expected function, found `()`
--> $DIR/issue-105330.rs:12:5
|
LL | fn foo<A: TraitWAssocConst<A=32>>() {
| ----------------------------------- `foo::<Demo>` defined here returns `()`
LL | foo::<Demo>()();
| ^^^^^^^^^^^^^--
| |
| call expression requires function

error[E0277]: the trait bound `Demo: TraitWAssocConst` is not satisfied
--> $DIR/issue-105330.rs:19:11
|
LL | foo::<Demo>();
| ^^^^ the trait `TraitWAssocConst` is not implemented for `Demo`
|
note: required by a bound in `foo`
--> $DIR/issue-105330.rs:11:11
|
LL | fn foo<A: TraitWAssocConst<A=32>>() {
| ^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `foo`

error[E0271]: type mismatch resolving `<Demo as TraitWAssocConst>::A == 32`
--> $DIR/issue-105330.rs:19:11
|
LL | foo::<Demo>();
| ^^^^ types differ
|
note: required by a bound in `foo`
--> $DIR/issue-105330.rs:11:28
|
LL | fn foo<A: TraitWAssocConst<A=32>>() {
| ^^^^ required by this bound in `foo`

error[E0131]: `main` function is not allowed to have generic parameters
--> $DIR/issue-105330.rs:17:8
|
LL | fn main<A: TraitWAssocConst<A=32>>() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ `main` cannot have generic parameters

error: aborting due to 11 previous errors

Some errors have detailed explanations: E0131, E0271, E0277, E0404, E0562, E0618, E0658.
For more information about an error, try `rustc --explain E0131`.