Disentangle Debug and Display for Ty.

The `Debug` impl for `Ty` just calls the `Display` impl for `Ty`. This
is surprising and annoying. In particular, it means `Debug` doesn't show
as much information as `Debug` for `TyKind` does. And `Debug` is used in
some user-facing error messages, which seems bad.

This commit changes the `Debug` impl for `Ty` to call the `Debug` impl
for `TyKind`. It also does a number of follow-up changes to preserve
existing output, many of which involve inserting
`with_no_trimmed_paths!` calls. It also adds `Display` impls for
`UserType` and `Canonical`.

Some tests have changes to expected output:
- Those that use the `rustc_abi(debug)` attribute.
- Those that use the `EMIT_MIR` annotation.

In each case the output is slightly uglier than before. This isn't
ideal, but it's pretty weird (particularly for the attribute) that the
output is using `Debug` in the first place. They're fairly obscure
attributes (I hadn't heard of them) so I'm not worried by this.

For `async-is-unwindsafe.stderr`, there is one line that now lacks a
full path. This is a consistency improvement, because all the other
mentions of `Context` in this test lack a path.
This commit is contained in:
Nicholas Nethercote 2023-09-07 15:14:40 +10:00
parent c0583a0221
commit 64ea8eb1a9
27 changed files with 502 additions and 77 deletions

View file

@ -10,6 +10,7 @@
Body, ClosureOutlivesSubject, ClosureRegionRequirements, LocalKind, Location, Promoted,
START_BLOCK,
};
use rustc_middle::ty::print::with_no_trimmed_paths;
use rustc_middle::ty::{self, OpaqueHiddenType, TyCtxt};
use rustc_span::symbol::sym;
use std::env;
@ -441,7 +442,10 @@ fn for_each_region_constraint<'tcx>(
let subject = match req.subject {
ClosureOutlivesSubject::Region(subject) => format!("{subject:?}"),
ClosureOutlivesSubject::Ty(ty) => {
format!("{:?}", ty.instantiate(tcx, |vid| ty::Region::new_var(tcx, vid)))
with_no_trimmed_paths!(format!(
"{}",
ty.instantiate(tcx, |vid| ty::Region::new_var(tcx, vid))
))
}
};
with_msg(format!("where {}: {:?}", subject, req.outlived_free_region,))?;

View file

@ -21,6 +21,7 @@
use rustc_index::IndexVec;
use rustc_infer::infer::NllRegionVariableOrigin;
use rustc_middle::ty::fold::TypeFoldable;
use rustc_middle::ty::print::with_no_trimmed_paths;
use rustc_middle::ty::{self, InlineConstArgs, InlineConstArgsParts, RegionVid, Ty, TyCtxt};
use rustc_middle::ty::{GenericArgs, GenericArgsRef};
use rustc_span::symbol::{kw, sym};
@ -332,10 +333,16 @@ pub fn to_region_vid(&self, r: ty::Region<'tcx>) -> RegionVid {
pub(crate) fn annotate(&self, tcx: TyCtxt<'tcx>, err: &mut Diagnostic) {
match self.defining_ty {
DefiningTy::Closure(def_id, args) => {
let v = with_no_trimmed_paths!(
args[tcx.generics_of(def_id).parent_count..]
.iter()
.map(|arg| arg.to_string())
.collect::<Vec<_>>()
);
err.note(format!(
"defining type: {} with closure args {:#?}",
"defining type: {} with closure args [\n {},\n]",
tcx.def_path_str_with_args(def_id, args),
&args[tcx.generics_of(def_id).parent_count..],
v.join(",\n "),
));
// FIXME: It'd be nice to print the late-bound regions
@ -348,10 +355,16 @@ pub(crate) fn annotate(&self, tcx: TyCtxt<'tcx>, err: &mut Diagnostic) {
});
}
DefiningTy::Generator(def_id, args, _) => {
let v = with_no_trimmed_paths!(
args[tcx.generics_of(def_id).parent_count..]
.iter()
.map(|arg| arg.to_string())
.collect::<Vec<_>>()
);
err.note(format!(
"defining type: {} with generator args {:#?}",
"defining type: {} with generator args [\n {},\n]",
tcx.def_path_str_with_args(def_id, args),
&args[tcx.generics_of(def_id).parent_count..],
v.join(",\n "),
));
// FIXME: As above, we'd like to print out the region

View file

@ -27,6 +27,7 @@
use crate::ty::{self, BoundVar, List, Region, Ty, TyCtxt};
use rustc_macros::HashStable;
use smallvec::SmallVec;
use std::fmt::Display;
use std::ops::Index;
/// A "canonicalized" type `V` is one where all free inference
@ -40,6 +41,16 @@ pub struct Canonical<'tcx, V> {
pub variables: CanonicalVarInfos<'tcx>,
}
impl<'tcx, V: Display> std::fmt::Display for Canonical<'tcx, V> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"Canonical {{ value: {}, max_universe: {:?}, variables: {:?} }}",
self.value, self.max_universe, self.variables
)
}
}
pub type CanonicalVarInfos<'tcx> = &'tcx List<CanonicalVarInfo<'tcx>>;
impl<'tcx> ty::TypeFoldable<TyCtxt<'tcx>> for CanonicalVarInfos<'tcx> {

View file

@ -8,6 +8,7 @@
use crate::mir::visit::MirVisitable;
use crate::ty::codec::{TyDecoder, TyEncoder};
use crate::ty::fold::{FallibleTypeFolder, TypeFoldable};
use crate::ty::print::with_no_trimmed_paths;
use crate::ty::print::{FmtPrinter, Printer};
use crate::ty::visit::TypeVisitableExt;
use crate::ty::{self, List, Ty, TyCtxt};
@ -1794,7 +1795,7 @@ fn post_fmt_projection(projection: &[PlaceElem<'_>], fmt: &mut Formatter<'_>) ->
write!(fmt, ")")?;
}
ProjectionElem::Field(field, ty) => {
write!(fmt, ".{:?}: {:?})", field.index(), ty)?;
with_no_trimmed_paths!(write!(fmt, ".{:?}: {})", field.index(), ty)?);
}
ProjectionElem::Index(ref index) => {
write!(fmt, "[{index:?}]")?;
@ -2077,7 +2078,7 @@ fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result {
}
Len(ref a) => write!(fmt, "Len({a:?})"),
Cast(ref kind, ref place, ref ty) => {
write!(fmt, "{place:?} as {ty:?} ({kind:?})")
with_no_trimmed_paths!(write!(fmt, "{place:?} as {ty} ({kind:?})"))
}
BinaryOp(ref op, box (ref a, ref b)) => write!(fmt, "{op:?}({a:?}, {b:?})"),
CheckedBinaryOp(ref op, box (ref a, ref b)) => {
@ -2085,11 +2086,14 @@ fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result {
}
UnaryOp(ref op, ref a) => write!(fmt, "{op:?}({a:?})"),
Discriminant(ref place) => write!(fmt, "discriminant({place:?})"),
NullaryOp(ref op, ref t) => match op {
NullOp::SizeOf => write!(fmt, "SizeOf({t:?})"),
NullOp::AlignOf => write!(fmt, "AlignOf({t:?})"),
NullOp::OffsetOf(fields) => write!(fmt, "OffsetOf({t:?}, {fields:?})"),
},
NullaryOp(ref op, ref t) => {
let t = with_no_trimmed_paths!(format!("{}", t));
match op {
NullOp::SizeOf => write!(fmt, "SizeOf({t})"),
NullOp::AlignOf => write!(fmt, "AlignOf({t})"),
NullOp::OffsetOf(fields) => write!(fmt, "OffsetOf({t}, {fields:?})"),
}
}
ThreadLocalRef(did) => ty::tls::with(|tcx| {
let muta = tcx.static_mutability(did).unwrap().prefix_str();
write!(fmt, "&/*tls*/ {}{}", muta, tcx.def_path_str(did))
@ -2225,7 +2229,7 @@ fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result {
}
ShallowInitBox(ref place, ref ty) => {
write!(fmt, "ShallowInitBox({place:?}, {ty:?})")
with_no_trimmed_paths!(write!(fmt, "ShallowInitBox({place:?}, {ty})"))
}
}
}

View file

@ -583,8 +583,10 @@ fn write_scope_tree(
let mut_str = local_decl.mutability.prefix_str();
let mut indented_decl =
format!("{0:1$}let {2}{3:?}: {4:?}", INDENT, indent, mut_str, local, local_decl.ty);
let mut indented_decl = ty::print::with_no_trimmed_paths!(format!(
"{0:1$}let {2}{3:?}: {4}",
INDENT, indent, mut_str, local, local_decl.ty
));
if let Some(user_ty) = &local_decl.user_ty {
for user_ty in user_ty.projections() {
write!(indented_decl, " as {user_ty:?}").unwrap();
@ -1058,11 +1060,11 @@ fn write_user_type_annotations(
for (index, annotation) in body.user_type_annotations.iter_enumerated() {
writeln!(
w,
"| {:?}: user_ty: {:?}, span: {}, inferred_ty: {:?}",
"| {:?}: user_ty: {}, span: {}, inferred_ty: {}",
index.index(),
annotation.user_ty,
tcx.sess.source_map().span_to_embeddable_string(annotation.span),
annotation.inferred_ty,
with_no_trimmed_paths!(format!("{}", annotation.inferred_ty)),
)?;
}
if !body.user_type_annotations.is_empty() {

View file

@ -450,6 +450,11 @@ pub fn truncate_to(&self, tcx: TyCtxt<'tcx>, generics: &ty::Generics) -> Generic
pub fn host_effect_param(&'tcx self) -> Option<ty::Const<'tcx>> {
self.consts().rfind(|x| matches!(x.kind(), ty::ConstKind::Param(p) if p.name == sym::host))
}
pub fn print_as_list(&self) -> String {
let v = self.iter().map(|arg| arg.to_string()).collect::<Vec<_>>();
format!("[{}]", v.join(", "))
}
}
impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for GenericArgsRef<'tcx> {

View file

@ -760,9 +760,12 @@ fn pretty_print_type(mut self, ty: Ty<'tcx>) -> Result<Self::Type, Self::Error>
// only affect certain debug messages (e.g. messages printed
// from `rustc_middle::ty` during the computation of `tcx.predicates_of`),
// and should have no effect on any compiler output.
// [Unless `-Zverbose` is used, e.g. in the output of
// `tests/ui/nll/ty-outlives/impl-trait-captures.rs`, for
// example.]
if self.should_print_verbose() {
// FIXME(eddyb) print this with `print_def_path`.
p!(write("Opaque({:?}, {:?})", def_id, args));
p!(write("Opaque({:?}, {})", def_id, args.print_as_list()));
return Ok(self);
}
@ -894,7 +897,7 @@ fn pretty_print_type(mut self, ty: Ty<'tcx>) -> Result<Self::Type, Self::Error>
p!(print_def_path(did, args));
if !args.as_closure().is_valid() {
p!(" closure_args=(unavailable)");
p!(write(" args={:?}", args));
p!(write(" args={}", args.print_as_list()));
} else {
p!(" closure_kind_ty=", print(args.as_closure().kind_ty()));
p!(

View file

@ -154,7 +154,7 @@ fn fmt<InfCtx: InferCtxtLike<TyCtxt<'tcx>>>(
}
impl<'tcx> fmt::Debug for Ty<'tcx> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
with_no_trimmed_paths!(fmt::Display::fmt(self, f))
with_no_trimmed_paths!(fmt::Debug::fmt(self.kind(), f))
}
}

View file

@ -722,3 +722,14 @@ pub enum UserType<'tcx> {
/// given substitutions applied.
TypeOf(DefId, UserArgs<'tcx>),
}
impl<'tcx> std::fmt::Display for UserType<'tcx> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Ty(arg0) => {
ty::print::with_no_trimmed_paths!(write!(f, "Ty({})", arg0))
}
Self::TypeOf(arg0, arg1) => write!(f, "TypeOf({:?}, {:?})", arg0, arg1),
}
}
}

View file

@ -89,6 +89,7 @@ fn dump_abi_of_fn_item(tcx: TyCtxt<'_>, item_def_id: LocalDefId, attr: &Attribut
tcx.sess.emit_err(AbiOf {
span: tcx.def_span(item_def_id),
fn_name,
// FIXME: using the `Debug` impl here isn't ideal.
fn_abi: format!("{:#?}", abi),
});
}

View file

@ -107,12 +107,13 @@ fn dump_layout_of(tcx: TyCtxt<'_>, item_def_id: LocalDefId, attr: &Attribute) {
sym::debug => {
let normalized_ty = format!(
"{:?}",
"{}",
tcx.normalize_erasing_regions(
param_env.with_reveal_all_normalized(tcx),
ty,
)
);
// FIXME: using the `Debug` impl here isn't ideal.
let ty_layout = format!("{:#?}", *ty_layout);
tcx.sess.emit_err(LayoutOf { span, normalized_ty, ty_layout });
}

View file

@ -1805,7 +1805,7 @@ fn suggest_change_mut(
);
} else {
err.note(format!(
"`{}` is implemented for `{:?}`, but not for `{:?}`",
"`{}` is implemented for `{}`, but not for `{}`",
trait_pred.print_modifiers_and_trait_path(),
suggested_ty,
trait_pred.skip_binder().self_ty(),

View file

@ -7,6 +7,7 @@
use rustc_middle::ty::layout::{
IntegerExt, LayoutCx, LayoutError, LayoutOf, TyAndLayout, MAX_SIMD_LANES,
};
use rustc_middle::ty::print::with_no_trimmed_paths;
use rustc_middle::ty::{
self, AdtDef, EarlyBinder, GenericArgsRef, ReprOptions, Ty, TyCtxt, TypeVisitableExt,
};
@ -937,7 +938,7 @@ fn record_layout_for_printing_outlined<'tcx>(
// (delay format until we actually need it)
let record = |kind, packed, opt_discr_size, variants| {
let type_desc = format!("{:?}", layout.ty);
let type_desc = with_no_trimmed_paths!(format!("{}", layout.ty));
cx.tcx.sess.code_stats.record_type_size(
kind,
type_desc,

View file

@ -2,7 +2,14 @@
/* generator_layout = GeneratorLayout {
field_tys: {
_0: GeneratorSavedTy {
ty: impl std::future::Future<Output = ()>,
ty: Alias(
Opaque,
AliasTy {
args: [
],
def_id: DefId(0:7 ~ async_await[ccf8]::a::{opaque#0}),
},
),
source_info: SourceInfo {
span: $DIR/async_await.rs:15:9: 15:14 (#8),
scope: scope[0],
@ -10,7 +17,14 @@
ignore_for_traits: false,
},
_1: GeneratorSavedTy {
ty: impl std::future::Future<Output = ()>,
ty: Alias(
Opaque,
AliasTy {
args: [
],
def_id: DefId(0:7 ~ async_await[ccf8]::a::{opaque#0}),
},
),
source_info: SourceInfo {
span: $DIR/async_await.rs:16:9: 16:14 (#10),
scope: scope[0],

View file

@ -2,7 +2,11 @@
/* generator_layout = GeneratorLayout {
field_tys: {
_0: GeneratorSavedTy {
ty: std::string::String,
ty: Adt(
std::string::String,
[
],
),
source_info: SourceInfo {
span: $DIR/generator_drop_cleanup.rs:11:13: 11:15 (#0),
scope: scope[0],

View file

@ -2,7 +2,11 @@
/* generator_layout = GeneratorLayout {
field_tys: {
_0: GeneratorSavedTy {
ty: std::string::String,
ty: Adt(
std::string::String,
[
],
),
source_info: SourceInfo {
span: $DIR/generator_drop_cleanup.rs:11:13: 11:15 (#0),
scope: scope[0],

View file

@ -2,7 +2,11 @@
/* generator_layout = GeneratorLayout {
field_tys: {
_0: GeneratorSavedTy {
ty: HasDrop,
ty: Adt(
HasDrop,
[
],
),
source_info: SourceInfo {
span: $DIR/generator_tiny.rs:20:13: 20:15 (#0),
scope: scope[0],

View file

@ -1,8 +1,8 @@
// MIR for `main` after built
| User Type Annotations
| 0: user_ty: Canonical { value: TypeOf(DefId(0:3 ~ issue_99325[22bb]::function_with_bytes), UserArgs { args: [Const { ty: &'static [u8; 4], kind: Branch([Leaf(0x41), Leaf(0x41), Leaf(0x41), Leaf(0x41)]) }], user_self_ty: None }), max_universe: U0, variables: [] }, span: $DIR/issue_99325.rs:10:16: 10:46, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">}
| 1: user_ty: Canonical { value: TypeOf(DefId(0:3 ~ issue_99325[22bb]::function_with_bytes), UserArgs { args: [Const { ty: &'static [u8; 4], kind: UnevaluatedConst { def: DefId(0:8 ~ issue_99325[22bb]::main::{constant#1}), args: [] } }], user_self_ty: None }), max_universe: U0, variables: [] }, span: $DIR/issue_99325.rs:11:16: 11:68, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">}
| 0: user_ty: Canonical { value: TypeOf(DefId(0:3 ~ issue_99325[22bb]::function_with_bytes), UserArgs { args: [Const { ty: &ReStatic [u8; Const { ty: usize, kind: Leaf(0x00000004) }], kind: Branch([Leaf(0x41), Leaf(0x41), Leaf(0x41), Leaf(0x41)]) }], user_self_ty: None }), max_universe: U0, variables: [] }, span: $DIR/issue_99325.rs:12:16: 12:46, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">}
| 1: user_ty: Canonical { value: TypeOf(DefId(0:3 ~ issue_99325[22bb]::function_with_bytes), UserArgs { args: [Const { ty: &ReStatic [u8; Const { ty: usize, kind: Leaf(0x00000004) }], kind: UnevaluatedConst { def: DefId(0:8 ~ issue_99325[22bb]::main::{constant#1}), args: [] } }], user_self_ty: None }), max_universe: U0, variables: [] }, span: $DIR/issue_99325.rs:13:16: 13:68, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">}
|
fn main() -> () {
let mut _0: ();

View file

@ -0,0 +1,276 @@
// MIR for `main` after built
| User Type Annotations
| 0: user_ty: Canonical { value: TypeOf(DefId(0:3 ~ issue_99325[22bb]::function_with_bytes), UserArgs { args: [Const { ty: &ReStatic [u8; Const { ty: usize, kind: Leaf(0x0000000000000004) }], kind: Branch([Leaf(0x41), Leaf(0x41), Leaf(0x41), Leaf(0x41)]) }], user_self_ty: None }), max_universe: U0, variables: [] }, span: $DIR/issue_99325.rs:12:16: 12:46, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">}
| 1: user_ty: Canonical { value: TypeOf(DefId(0:3 ~ issue_99325[22bb]::function_with_bytes), UserArgs { args: [Const { ty: &ReStatic [u8; Const { ty: usize, kind: Leaf(0x0000000000000004) }], kind: UnevaluatedConst { def: DefId(0:8 ~ issue_99325[22bb]::main::{constant#1}), args: [] } }], user_self_ty: None }), max_universe: U0, variables: [] }, span: $DIR/issue_99325.rs:13:16: 13:68, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">}
|
fn main() -> () {
let mut _0: ();
let _1: ();
let mut _2: (&&[u8], &&[u8; 4]);
let mut _3: &&[u8];
let _4: &[u8];
let mut _5: &&[u8; 4];
let _6: &[u8; 4];
let _7: [u8; 4];
let _8: &&[u8];
let _9: &&[u8; 4];
let mut _10: bool;
let mut _11: &&[u8];
let mut _12: &&[u8; 4];
let mut _13: !;
let _15: !;
let mut _16: core::panicking::AssertKind;
let mut _17: &&[u8];
let _18: &&[u8];
let mut _19: &&[u8; 4];
let _20: &&[u8; 4];
let mut _21: std::option::Option<std::fmt::Arguments<'_>>;
let _22: ();
let mut _23: (&&[u8], &&[u8; 4]);
let mut _24: &&[u8];
let _25: &[u8];
let mut _26: &&[u8; 4];
let _27: &[u8; 4];
let _28: &&[u8];
let _29: &&[u8; 4];
let mut _30: bool;
let mut _31: &&[u8];
let mut _32: &&[u8; 4];
let mut _33: !;
let _35: !;
let mut _36: core::panicking::AssertKind;
let mut _37: &&[u8];
let _38: &&[u8];
let mut _39: &&[u8; 4];
let _40: &&[u8; 4];
let mut _41: std::option::Option<std::fmt::Arguments<'_>>;
scope 1 {
debug left_val => _8;
debug right_val => _9;
let _14: core::panicking::AssertKind;
scope 2 {
debug kind => _14;
}
}
scope 3 {
debug left_val => _28;
debug right_val => _29;
let _34: core::panicking::AssertKind;
scope 4 {
debug kind => _34;
}
}
bb0: {
StorageLive(_1);
StorageLive(_2);
StorageLive(_3);
StorageLive(_4);
_4 = function_with_bytes::<&*b"AAAA">() -> [return: bb1, unwind: bb21];
}
bb1: {
_3 = &_4;
StorageLive(_5);
StorageLive(_6);
StorageLive(_7);
_7 = [const 65_u8, const 65_u8, const 65_u8, const 65_u8];
_6 = &_7;
_5 = &_6;
_2 = (move _3, move _5);
StorageDead(_5);
StorageDead(_3);
FakeRead(ForMatchedPlace(None), _2);
StorageLive(_8);
_8 = (_2.0: &&[u8]);
StorageLive(_9);
_9 = (_2.1: &&[u8; 4]);
StorageLive(_10);
StorageLive(_11);
_11 = &(*_8);
StorageLive(_12);
_12 = &(*_9);
_10 = <&[u8] as PartialEq<&[u8; 4]>>::eq(move _11, move _12) -> [return: bb2, unwind: bb21];
}
bb2: {
switchInt(move _10) -> [0: bb4, otherwise: bb3];
}
bb3: {
StorageDead(_12);
StorageDead(_11);
goto -> bb8;
}
bb4: {
goto -> bb5;
}
bb5: {
StorageDead(_12);
StorageDead(_11);
StorageLive(_14);
_14 = core::panicking::AssertKind::Eq;
FakeRead(ForLet(None), _14);
StorageLive(_15);
StorageLive(_16);
_16 = move _14;
StorageLive(_17);
StorageLive(_18);
_18 = &(*_8);
_17 = &(*_18);
StorageLive(_19);
StorageLive(_20);
_20 = &(*_9);
_19 = &(*_20);
StorageLive(_21);
_21 = Option::<Arguments<'_>>::None;
_15 = core::panicking::assert_failed::<&[u8], &[u8; 4]>(move _16, move _17, move _19, move _21) -> bb21;
}
bb6: {
StorageDead(_21);
StorageDead(_19);
StorageDead(_17);
StorageDead(_16);
StorageDead(_20);
StorageDead(_18);
StorageDead(_15);
StorageDead(_14);
unreachable;
}
bb7: {
goto -> bb9;
}
bb8: {
_1 = const ();
goto -> bb9;
}
bb9: {
StorageDead(_10);
StorageDead(_9);
StorageDead(_8);
goto -> bb10;
}
bb10: {
StorageDead(_7);
StorageDead(_6);
StorageDead(_4);
StorageDead(_2);
StorageDead(_1);
StorageLive(_22);
StorageLive(_23);
StorageLive(_24);
StorageLive(_25);
_25 = function_with_bytes::<&*b"AAAA">() -> [return: bb11, unwind: bb21];
}
bb11: {
_24 = &_25;
StorageLive(_26);
StorageLive(_27);
_27 = const b"AAAA";
_26 = &_27;
_23 = (move _24, move _26);
StorageDead(_26);
StorageDead(_24);
FakeRead(ForMatchedPlace(None), _23);
StorageLive(_28);
_28 = (_23.0: &&[u8]);
StorageLive(_29);
_29 = (_23.1: &&[u8; 4]);
StorageLive(_30);
StorageLive(_31);
_31 = &(*_28);
StorageLive(_32);
_32 = &(*_29);
_30 = <&[u8] as PartialEq<&[u8; 4]>>::eq(move _31, move _32) -> [return: bb12, unwind: bb21];
}
bb12: {
switchInt(move _30) -> [0: bb14, otherwise: bb13];
}
bb13: {
StorageDead(_32);
StorageDead(_31);
goto -> bb18;
}
bb14: {
goto -> bb15;
}
bb15: {
StorageDead(_32);
StorageDead(_31);
StorageLive(_34);
_34 = core::panicking::AssertKind::Eq;
FakeRead(ForLet(None), _34);
StorageLive(_35);
StorageLive(_36);
_36 = move _34;
StorageLive(_37);
StorageLive(_38);
_38 = &(*_28);
_37 = &(*_38);
StorageLive(_39);
StorageLive(_40);
_40 = &(*_29);
_39 = &(*_40);
StorageLive(_41);
_41 = Option::<Arguments<'_>>::None;
_35 = core::panicking::assert_failed::<&[u8], &[u8; 4]>(move _36, move _37, move _39, move _41) -> bb21;
}
bb16: {
StorageDead(_41);
StorageDead(_39);
StorageDead(_37);
StorageDead(_36);
StorageDead(_40);
StorageDead(_38);
StorageDead(_35);
StorageDead(_34);
unreachable;
}
bb17: {
goto -> bb19;
}
bb18: {
_22 = const ();
goto -> bb19;
}
bb19: {
StorageDead(_30);
StorageDead(_29);
StorageDead(_28);
goto -> bb20;
}
bb20: {
StorageDead(_27);
StorageDead(_25);
StorageDead(_23);
StorageDead(_22);
_0 = const ();
return;
}
bb21 (cleanup): {
resume;
}
}
alloc4 (size: 4, align: 1) {
41 41 41 41 AAAA
}

View file

@ -1,3 +1,5 @@
// EMIT_MIR_FOR_EACH_BIT_WIDTH
#![feature(adt_const_params)]
#![allow(incomplete_features)]

View file

@ -4,6 +4,7 @@
// normalize-stderr-test "(valid_range): 0\.\.=(4294967295|18446744073709551615)" -> "$1: $$FULL"
// This pattern is prepared for when we account for alignment in the niche.
// normalize-stderr-test "(valid_range): [1-9]\.\.=(429496729[0-9]|1844674407370955161[0-9])" -> "$1: $$NON_NULL"
// normalize-stderr-test "Leaf\(0x0*20\)" -> "Leaf(0x0...20)"
// Some attributes are only computed for release builds:
// compile-flags: -O
#![feature(rustc_attrs)]

View file

@ -87,7 +87,7 @@ error: fn_abi_of(test) = FnAbi {
conv: Rust,
can_unwind: $SOME_BOOL,
}
--> $DIR/debug.rs:15:1
--> $DIR/debug.rs:16:1
|
LL | fn test(_x: u8) -> bool { true }
| ^^^^^^^^^^^^^^^^^^^^^^^
@ -181,7 +181,7 @@ error: fn_abi_of(TestFnPtr) = FnAbi {
conv: Rust,
can_unwind: $SOME_BOOL,
}
--> $DIR/debug.rs:18:1
--> $DIR/debug.rs:19:1
|
LL | type TestFnPtr = fn(bool) -> u8;
| ^^^^^^^^^^^^^^
@ -190,7 +190,7 @@ error: fn_abi_of(test_generic) = FnAbi {
args: [
ArgAbi {
layout: TyAndLayout {
ty: *const T,
ty: *const T/#0,
layout: Layout {
size: $SOME_SIZE,
align: AbiAndPrefAlign {
@ -257,13 +257,13 @@ error: fn_abi_of(test_generic) = FnAbi {
conv: Rust,
can_unwind: $SOME_BOOL,
}
--> $DIR/debug.rs:21:1
--> $DIR/debug.rs:22:1
|
LL | fn test_generic<T>(_x: *const T) { }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: `#[rustc_abi]` can only be applied to function items, type aliases, and associated functions
--> $DIR/debug.rs:24:1
--> $DIR/debug.rs:25:1
|
LL | const C: () = ();
| ^^^^^^^^^^^
@ -409,7 +409,7 @@ error: ABIs are not compatible
conv: Rust,
can_unwind: $SOME_BOOL,
}
--> $DIR/debug.rs:40:1
--> $DIR/debug.rs:41:1
|
LL | type TestAbiNe = (fn(u8), fn(u32));
| ^^^^^^^^^^^^^^
@ -419,7 +419,7 @@ error: ABIs are not compatible
args: [
ArgAbi {
layout: TyAndLayout {
ty: [u8; 32],
ty: [u8; Const { ty: usize, kind: Leaf(0x0...20) }],
layout: Layout {
size: Size(32 bytes),
align: AbiAndPrefAlign {
@ -490,7 +490,7 @@ error: ABIs are not compatible
args: [
ArgAbi {
layout: TyAndLayout {
ty: [u32; 32],
ty: [u32; Const { ty: usize, kind: Leaf(0x0...20) }],
layout: Layout {
size: Size(128 bytes),
align: AbiAndPrefAlign {
@ -557,7 +557,7 @@ error: ABIs are not compatible
conv: Rust,
can_unwind: $SOME_BOOL,
}
--> $DIR/debug.rs:43:1
--> $DIR/debug.rs:44:1
|
LL | type TestAbiNeLarger = (fn([u8; 32]), fn([u32; 32]));
| ^^^^^^^^^^^^^^^^^^^^
@ -700,7 +700,7 @@ error: ABIs are not compatible
conv: Rust,
can_unwind: $SOME_BOOL,
}
--> $DIR/debug.rs:46:1
--> $DIR/debug.rs:47:1
|
LL | type TestAbiNeFloat = (fn(f32), fn(u32));
| ^^^^^^^^^^^^^^^^^^^
@ -846,13 +846,13 @@ error: ABIs are not compatible
conv: Rust,
can_unwind: $SOME_BOOL,
}
--> $DIR/debug.rs:50:1
--> $DIR/debug.rs:51:1
|
LL | type TestAbiNeSign = (fn(i32), fn(u32));
| ^^^^^^^^^^^^^^^^^^
error[E0277]: the size for values of type `str` cannot be known at compilation time
--> $DIR/debug.rs:53:46
--> $DIR/debug.rs:54:46
|
LL | type TestAbiEqNonsense = (fn((str, str)), fn((str, str)));
| ^^^^^^^^^^ doesn't have a size known at compile-time
@ -861,7 +861,7 @@ LL | type TestAbiEqNonsense = (fn((str, str)), fn((str, str)));
= note: only the last element of a tuple may have a dynamically sized type
error: `#[rustc_abi]` can only be applied to function items, type aliases, and associated functions
--> $DIR/debug.rs:28:5
--> $DIR/debug.rs:29:5
|
LL | const C: () = ();
| ^^^^^^^^^^^
@ -870,7 +870,7 @@ error: fn_abi_of(assoc_test) = FnAbi {
args: [
ArgAbi {
layout: TyAndLayout {
ty: &S,
ty: &ReErased Adt(S, []),
layout: Layout {
size: $SOME_SIZE,
align: AbiAndPrefAlign {
@ -949,7 +949,7 @@ error: fn_abi_of(assoc_test) = FnAbi {
conv: Rust,
can_unwind: $SOME_BOOL,
}
--> $DIR/debug.rs:33:5
--> $DIR/debug.rs:34:5
|
LL | fn assoc_test(&self) { }
| ^^^^^^^^^^^^^^^^^^^^

View file

@ -15,7 +15,7 @@ LL | | });
| within this `[async block@$DIR/async-is-unwindsafe.rs:12:19: 29:6]`
|
= help: within `[async block@$DIR/async-is-unwindsafe.rs:12:19: 29:6]`, the trait `UnwindSafe` is not implemented for `&mut Context<'_>`
= note: `UnwindSafe` is implemented for `&std::task::Context<'_>`, but not for `&mut std::task::Context<'_>`
= note: `UnwindSafe` is implemented for `&Context<'_>`, but not for `&mut Context<'_>`
note: future does not implement `UnwindSafe` as this value is used across an await
--> $DIR/async-is-unwindsafe.rs:25:18
|

View file

@ -162,7 +162,7 @@ error: layout_of(U) = Layout {
LL | union U { f1: (i32, i32), f3: i32 }
| ^^^^^^^
error: layout_of(std::result::Result<i32, i32>) = Layout {
error: layout_of(Result<i32, i32>) = Layout {
size: Size(8 bytes),
align: AbiAndPrefAlign {
abi: Align(4 bytes),
@ -522,7 +522,7 @@ error: layout_of(P5) = Layout {
LL | union P5 { zst: [u16; 0], byte: u8 }
| ^^^^^^^^
error: layout_of(std::mem::MaybeUninit<u8>) = Layout {
error: layout_of(MaybeUninit<u8>) = Layout {
size: Size(1 bytes),
align: AbiAndPrefAlign {
abi: Align(1 bytes),

View file

@ -1,4 +1,4 @@
error: layout_of(std::result::Result<[u32; 0], bool>) = Layout {
error: layout_of(Result<[u32; 0], bool>) = Layout {
size: Size(4 bytes),
align: AbiAndPrefAlign {
abi: Align(4 bytes),
@ -232,7 +232,7 @@ error: layout_of(MultipleAlignments) = Layout {
LL | enum MultipleAlignments {
| ^^^^^^^^^^^^^^^^^^^^^^^
error: layout_of(std::result::Result<[u32; 0], Packed<std::num::NonZeroU16>>) = Layout {
error: layout_of(Result<[u32; 0], Packed<NonZeroU16>>) = Layout {
size: Size(4 bytes),
align: AbiAndPrefAlign {
abi: Align(4 bytes),
@ -337,7 +337,7 @@ error: layout_of(std::result::Result<[u32; 0], Packed<std::num::NonZeroU16>>) =
LL | type NicheLosesToTagged = Result<[u32; 0], Packed<std::num::NonZeroU16>>;
| ^^^^^^^^^^^^^^^^^^^^^^^
error: layout_of(std::result::Result<[u32; 0], Packed<U16IsZero>>) = Layout {
error: layout_of(Result<[u32; 0], Packed<U16IsZero>>) = Layout {
size: Size(4 bytes),
align: AbiAndPrefAlign {
abi: Align(4 bytes),

View file

@ -1,7 +1,11 @@
DefId(0:8 ~ thir_flat_const_variant[1f54]::{impl#0}::BAR1):
Thir {
body_type: Const(
Foo,
Adt(
Foo,
[
],
),
),
arms: [],
blocks: [],
@ -46,7 +50,11 @@ Thir {
base: None,
},
),
ty: Foo,
ty: Adt(
Foo,
[
],
),
temp_lifetime: Some(
Node(3),
),
@ -60,7 +68,11 @@ Thir {
),
value: e2,
},
ty: Foo,
ty: Adt(
Foo,
[
],
),
temp_lifetime: Some(
Node(3),
),
@ -72,7 +84,11 @@ Thir {
lint_level: Inherited,
value: e3,
},
ty: Foo,
ty: Adt(
Foo,
[
],
),
temp_lifetime: Some(
Node(3),
),
@ -86,7 +102,11 @@ Thir {
DefId(0:9 ~ thir_flat_const_variant[1f54]::{impl#0}::BAR2):
Thir {
body_type: Const(
Foo,
Adt(
Foo,
[
],
),
),
arms: [],
blocks: [],
@ -131,7 +151,11 @@ Thir {
base: None,
},
),
ty: Foo,
ty: Adt(
Foo,
[
],
),
temp_lifetime: Some(
Node(3),
),
@ -145,7 +169,11 @@ Thir {
),
value: e2,
},
ty: Foo,
ty: Adt(
Foo,
[
],
),
temp_lifetime: Some(
Node(3),
),
@ -157,7 +185,11 @@ Thir {
lint_level: Inherited,
value: e3,
},
ty: Foo,
ty: Adt(
Foo,
[
],
),
temp_lifetime: Some(
Node(3),
),
@ -171,7 +203,11 @@ Thir {
DefId(0:10 ~ thir_flat_const_variant[1f54]::{impl#0}::BAR3):
Thir {
body_type: Const(
Foo,
Adt(
Foo,
[
],
),
),
arms: [],
blocks: [],
@ -216,7 +252,11 @@ Thir {
base: None,
},
),
ty: Foo,
ty: Adt(
Foo,
[
],
),
temp_lifetime: Some(
Node(3),
),
@ -230,7 +270,11 @@ Thir {
),
value: e2,
},
ty: Foo,
ty: Adt(
Foo,
[
],
),
temp_lifetime: Some(
Node(3),
),
@ -242,7 +286,11 @@ Thir {
lint_level: Inherited,
value: e3,
},
ty: Foo,
ty: Adt(
Foo,
[
],
),
temp_lifetime: Some(
Node(3),
),
@ -256,7 +304,11 @@ Thir {
DefId(0:11 ~ thir_flat_const_variant[1f54]::{impl#0}::BAR4):
Thir {
body_type: Const(
Foo,
Adt(
Foo,
[
],
),
),
arms: [],
blocks: [],
@ -301,7 +353,11 @@ Thir {
base: None,
},
),
ty: Foo,
ty: Adt(
Foo,
[
],
),
temp_lifetime: Some(
Node(3),
),
@ -315,7 +371,11 @@ Thir {
),
value: e2,
},
ty: Foo,
ty: Adt(
Foo,
[
],
),
temp_lifetime: Some(
Node(3),
),
@ -327,7 +387,11 @@ Thir {
lint_level: Inherited,
value: e3,
},
ty: Foo,
ty: Adt(
Foo,
[
],
),
temp_lifetime: Some(
Node(3),
),

View file

@ -1,13 +1,13 @@
DefId(0:16 ~ thir_tree_match[fcf8]::has_match):
params: [
Param {
ty: Foo
ty: Adt(Foo, [])
ty_span: Some($DIR/thir-tree-match.rs:15:19: 15:22 (#0))
self_kind: None
hir_id: Some(HirId(DefId(0:16 ~ thir_tree_match[fcf8]::has_match).1))
param: Some(
Pat: {
ty: Foo
ty: Adt(Foo, [])
span: $DIR/thir-tree-match.rs:15:14: 15:17 (#0)
kind: PatKind {
Binding {
@ -15,7 +15,7 @@ params: [
name: "foo"
mode: ByValue
var: LocalVarId(HirId(DefId(0:16 ~ thir_tree_match[fcf8]::has_match).2))
ty: Foo
ty: Adt(Foo, [])
is_primary: true
subpattern: None
}
@ -73,7 +73,7 @@ body:
Match {
scrutinee:
Expr {
ty: Foo
ty: Adt(Foo, [])
temp_lifetime: Some(Node(26))
span: $DIR/thir-tree-match.rs:16:11: 16:14 (#0)
kind:
@ -82,7 +82,7 @@ body:
lint_level: Explicit(HirId(DefId(0:16 ~ thir_tree_match[fcf8]::has_match).4))
value:
Expr {
ty: Foo
ty: Adt(Foo, [])
temp_lifetime: Some(Node(26))
span: $DIR/thir-tree-match.rs:16:11: 16:14 (#0)
kind:
@ -96,7 +96,7 @@ body:
Arm {
pattern:
Pat: {
ty: Foo
ty: Adt(Foo, [])
span: $DIR/thir-tree-match.rs:17:9: 17:32 (#0)
kind: PatKind {
Variant {
@ -110,7 +110,7 @@ body:
variant_index: 0
subpatterns: [
Pat: {
ty: Bar
ty: Adt(Bar, [])
span: $DIR/thir-tree-match.rs:17:21: 17:31 (#0)
kind: PatKind {
Variant {
@ -169,7 +169,7 @@ body:
Arm {
pattern:
Pat: {
ty: Foo
ty: Adt(Foo, [])
span: $DIR/thir-tree-match.rs:18:9: 18:23 (#0)
kind: PatKind {
Variant {
@ -183,7 +183,7 @@ body:
variant_index: 0
subpatterns: [
Pat: {
ty: Bar
ty: Adt(Bar, [])
span: $DIR/thir-tree-match.rs:18:21: 18:22 (#0)
kind: PatKind {
Wild
@ -232,7 +232,7 @@ body:
Arm {
pattern:
Pat: {
ty: Foo
ty: Adt(Foo, [])
span: $DIR/thir-tree-match.rs:19:9: 19:20 (#0)
kind: PatKind {
Variant {