Skip to content

Commit c00343a

Browse files
Do not trim paths in MIR validator
1 parent ecb170a commit c00343a

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

Diff for: compiler/rustc_mir_transform/src/validate.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use rustc_middle::mir::coverage::CoverageKind;
1212
use rustc_middle::mir::visit::{NonUseContext, PlaceContext, Visitor};
1313
use rustc_middle::mir::*;
1414
use rustc_middle::ty::adjustment::PointerCoercion;
15+
use rustc_middle::ty::print::with_no_trimmed_paths;
1516
use rustc_middle::ty::{
1617
self, CoroutineArgsExt, InstanceKind, ScalarInt, Ty, TyCtxt, TypeVisitableExt, Upcast, Variance,
1718
};
@@ -543,7 +544,13 @@ pub(super) fn validate_types<'tcx>(
543544
caller_body: &Body<'tcx>,
544545
) -> Vec<(Location, String)> {
545546
let mut type_checker = TypeChecker { body, caller_body, tcx, typing_env, failures: Vec::new() };
546-
type_checker.visit_body(body);
547+
// The type checker formats a bunch of strings with type names in it, but these strings
548+
// are not always going to be encountered on the error path since the inliner also uses
549+
// the validator, and there are certain kinds of inlining (even for valid code) that
550+
// can cause validation errors (mostly around where clauses and rigid projections).
551+
with_no_trimmed_paths!({
552+
type_checker.visit_body(body);
553+
});
547554
type_checker.failures
548555
}
549556

Diff for: tests/ui/mir/inline-causes-trimmed-paths.rs

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//@ build-pass
2+
//@ compile-flags: -Zinline-mir
3+
4+
trait Storage {
5+
type Buffer: ?Sized;
6+
}
7+
8+
struct Array<const N: usize>;
9+
impl<const N: usize> Storage for Array<N> {
10+
type Buffer = [(); N];
11+
}
12+
13+
struct Slice;
14+
impl Storage for Slice {
15+
type Buffer = [()];
16+
}
17+
18+
struct Wrap<S: Storage> {
19+
_b: S::Buffer,
20+
}
21+
22+
fn coerce<const N: usize>(this: &Wrap<Array<N>>) -> &Wrap<Slice>
23+
where
24+
Array<N>: Storage,
25+
{
26+
coerce_again(this)
27+
}
28+
29+
fn coerce_again<const N: usize>(this: &Wrap<Array<N>>) -> &Wrap<Slice> {
30+
this
31+
}
32+
33+
fn main() {
34+
let inner: Wrap<Array<1>> = Wrap { _b: [(); 1] };
35+
let _: &Wrap<Slice> = coerce(&inner);
36+
}

0 commit comments

Comments
 (0)