Skip to content

Commit 1b48f09

Browse files
authored
Rollup merge of #98329 - oli-obk:fast_path_ice, r=cjgillot
Avoid an ICE and instead let the compiler report a useful error Fixes #98299
2 parents 21a20b4 + d2ea7e2 commit 1b48f09

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

compiler/rustc_infer/src/infer/nll_relate/mod.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,11 @@ where
662662
match b.kind() {
663663
ty::ConstKind::Infer(InferConst::Var(_)) if D::forbid_inference_vars() => {
664664
// Forbid inference variables in the RHS.
665-
bug!("unexpected inference var {:?}", b)
665+
self.infcx.tcx.sess.delay_span_bug(
666+
self.delegate.span(),
667+
format!("unexpected inference var {:?}", b,),
668+
);
669+
Ok(a)
666670
}
667671
// FIXME(invariance): see the related FIXME above.
668672
_ => self.infcx.super_combine_consts(self, a, b),

src/test/ui/issues/issue-98299.rs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
use std::convert::TryFrom;
2+
3+
pub fn test_usage(p: ()) {
4+
SmallCString::try_from(p).map(|cstr| cstr);
5+
//~^ ERROR: type annotations needed
6+
}
7+
8+
pub struct SmallCString<const N: usize> {}
9+
10+
impl<const N: usize> TryFrom<()> for SmallCString<N> {
11+
type Error = ();
12+
13+
fn try_from(path: ()) -> Result<Self, Self::Error> {
14+
unimplemented!();
15+
}
16+
}
17+
18+
fn main() {}

src/test/ui/issues/issue-98299.stderr

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0282]: type annotations needed
2+
--> $DIR/issue-98299.rs:4:5
3+
|
4+
LL | SmallCString::try_from(p).map(|cstr| cstr);
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for enum `Result<SmallCString<{_: usize}>, ()>`
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0282`.

0 commit comments

Comments
 (0)