diff options
| author | Yuki Okushi <jtitor@2k36.org> | 2022-06-21 20:08:16 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-06-21 20:08:16 +0900 |
| commit | 1b48f095366f7048457c3f2587970ca55527ed29 (patch) | |
| tree | 87a8a08a4e878fc6fae1ad074a5c1b96e122cbb9 | |
| parent | 21a20b419a2b2f999140504c1650850746096cdc (diff) | |
| parent | d2ea7e2059601fec28f39e250ecef9e160468f8d (diff) | |
| download | rust-1b48f095366f7048457c3f2587970ca55527ed29.tar.gz rust-1b48f095366f7048457c3f2587970ca55527ed29.zip | |
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
| -rw-r--r-- | compiler/rustc_infer/src/infer/nll_relate/mod.rs | 6 | ||||
| -rw-r--r-- | src/test/ui/issues/issue-98299.rs | 18 | ||||
| -rw-r--r-- | src/test/ui/issues/issue-98299.stderr | 9 |
3 files changed, 32 insertions, 1 deletions
diff --git a/compiler/rustc_infer/src/infer/nll_relate/mod.rs b/compiler/rustc_infer/src/infer/nll_relate/mod.rs index ebe156d081d..846e7f7b921 100644 --- a/compiler/rustc_infer/src/infer/nll_relate/mod.rs +++ b/compiler/rustc_infer/src/infer/nll_relate/mod.rs @@ -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), diff --git a/src/test/ui/issues/issue-98299.rs b/src/test/ui/issues/issue-98299.rs new file mode 100644 index 00000000000..63c058f91fc --- /dev/null +++ b/src/test/ui/issues/issue-98299.rs @@ -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() {} diff --git a/src/test/ui/issues/issue-98299.stderr b/src/test/ui/issues/issue-98299.stderr new file mode 100644 index 00000000000..a61bffa91e7 --- /dev/null +++ b/src/test/ui/issues/issue-98299.stderr @@ -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`. |
