Skip to content

Avoid an ICE and instead let the compiler report a useful error #98329

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
Jun 21, 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
6 changes: 5 additions & 1 deletion compiler/rustc_infer/src/infer/nll_relate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,11 @@ where
match b.kind() {
ty::ConstKind::Infer(InferConst::Var(_)) if D::forbid_inference_vars() => {
// Forbid inference variables in the RHS.
bug!("unexpected inference var {:?}", b)
self.infcx.tcx.sess.delay_span_bug(
self.delegate.span(),
format!("unexpected inference var {:?}", b,),
);
Ok(a)
}
// FIXME(invariance): see the related FIXME above.
_ => self.infcx.super_combine_consts(self, a, b),
Expand Down
18 changes: 18 additions & 0 deletions src/test/ui/issues/issue-98299.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use std::convert::TryFrom;

pub fn test_usage(p: ()) {
SmallCString::try_from(p).map(|cstr| cstr);
//~^ ERROR: type annotations needed
}

pub struct SmallCString<const N: usize> {}

impl<const N: usize> TryFrom<()> for SmallCString<N> {
type Error = ();

fn try_from(path: ()) -> Result<Self, Self::Error> {
unimplemented!();
}
}

fn main() {}
9 changes: 9 additions & 0 deletions src/test/ui/issues/issue-98299.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
error[E0282]: type annotations needed
--> $DIR/issue-98299.rs:4:5
|
LL | SmallCString::try_from(p).map(|cstr| cstr);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for enum `Result<SmallCString<{_: usize}>, ()>`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0282`.