Skip to content

Commit a992097

Browse files
authored
Rollup merge of #111991 - BoxyUwU:change_error_term_display, r=compiler-errors
Change ty and const error's pretty printing to be in braces `[const error]` and `[type error]` are slightly confusing since they look like either a slice with an error type for the element ty or a slice with a const argument as the type ???. This PR changes them to display as `{const error}` and `{type error}` similar to `{integer}`. This does not update the `Debug` impls for them which is done in #111988. I updated some error logic to avoid printing the substs of trait refs when unable to resolve an assoc item for them, this avoids emitting errors with `{type error}` in them. The substs are not relevant for these errors since we don't take into account the substs when resolving the assoc item. r? ``@compiler-errors``
2 parents dfdbf1b + ad77bc8 commit a992097

File tree

6 files changed

+11
-11
lines changed

6 files changed

+11
-11
lines changed

compiler/rustc_hir_analysis/src/astconv/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1159,7 +1159,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
11591159
// those that do.
11601160
self.one_bound_for_assoc_type(
11611161
|| traits::supertraits(tcx, trait_ref),
1162-
trait_ref.print_only_trait_path(),
1162+
trait_ref.skip_binder().print_only_trait_name(),
11631163
binding.item_name,
11641164
path_span,
11651165
match binding.kind {

compiler/rustc_middle/src/ty/print/pretty.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ pub trait PrettyPrinter<'tcx>:
700700
if verbose { p!(write("{:?}", infer_ty)) } else { p!(write("{}", infer_ty)) }
701701
}
702702
}
703-
ty::Error(_) => p!("[type error]"),
703+
ty::Error(_) => p!("{{type error}}"),
704704
ty::Param(ref param_ty) => p!(print(param_ty)),
705705
ty::Bound(debruijn, bound_ty) => match bound_ty.kind {
706706
ty::BoundTyKind::Anon => debug_bound_var(&mut self, debruijn, bound_ty.var)?,
@@ -1379,8 +1379,8 @@ pub trait PrettyPrinter<'tcx>:
13791379
},
13801380
// FIXME(generic_const_exprs):
13811381
// write out some legible representation of an abstract const?
1382-
ty::ConstKind::Expr(_) => p!("[const expr]"),
1383-
ty::ConstKind::Error(_) => p!("[const error]"),
1382+
ty::ConstKind::Expr(_) => p!("{{const expr}}"),
1383+
ty::ConstKind::Error(_) => p!("{{const error}}"),
13841384
};
13851385
Ok(self)
13861386
}

tests/ui/const-generics/transmute-fail.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ error[E0512]: cannot transmute between types of different sizes, or dependently-
44
LL | std::mem::transmute(v)
55
| ^^^^^^^^^^^^^^^^^^^
66
|
7-
= note: source type: `[[u32; H+1]; W]` (generic size [const expr])
8-
= note: target type: `[[u32; W+1]; H]` (generic size [const expr])
7+
= note: source type: `[[u32; H+1]; W]` (generic size {const expr})
8+
= note: target type: `[[u32; W+1]; H]` (generic size {const expr})
99

1010
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
1111
--> $DIR/transmute-fail.rs:16:5
@@ -34,8 +34,8 @@ error[E0512]: cannot transmute between types of different sizes, or dependently-
3434
LL | std::mem::transmute(v)
3535
| ^^^^^^^^^^^^^^^^^^^
3636
|
37-
= note: source type: `[[u32; H]; W]` (generic size [const expr])
38-
= note: target type: `[u32; W * H * H]` (generic size [const expr])
37+
= note: source type: `[[u32; H]; W]` (generic size {const expr})
38+
= note: target type: `[u32; W * H * H]` (generic size {const expr})
3939

4040
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
4141
--> $DIR/transmute-fail.rs:30:5

tests/ui/unboxed-closures/unboxed-closure-sugar-wrong-number-number-type-parameters-1.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
trait One<A> { fn foo(&self) -> A; }
44

5-
fn foo(_: &dyn One()) //~ ERROR associated type `Output` not found for `One<()>`
5+
fn foo(_: &dyn One()) //~ ERROR associated type `Output` not found for `One`
66
{}
77

88
fn main() { }

tests/ui/unboxed-closures/unboxed-closure-sugar-wrong-number-number-type-parameters-1.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0220]: associated type `Output` not found for `One<()>`
1+
error[E0220]: associated type `Output` not found for `One`
22
--> $DIR/unboxed-closure-sugar-wrong-number-number-type-parameters-1.rs:5:16
33
|
44
LL | fn foo(_: &dyn One())

tests/ui/unboxed-closures/unboxed-closure-sugar-wrong-number-number-type-parameters-3.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ note: trait defined here, with 3 generic parameters: `A`, `B`, `C`
1212
LL | trait Three<A,B,C> { fn dummy(&self) -> (A,B,C); }
1313
| ^^^^^ - - -
1414

15-
error[E0220]: associated type `Output` not found for `Three<(), [type error], [type error]>`
15+
error[E0220]: associated type `Output` not found for `Three`
1616
--> $DIR/unboxed-closure-sugar-wrong-number-number-type-parameters-3.rs:5:16
1717
|
1818
LL | fn foo(_: &dyn Three())

0 commit comments

Comments
 (0)