Skip to content

Commit 548ed40

Browse files
authored
Rollup merge of #99517 - Nilstrieb:display-raw-ptr, r=compiler-errors
Display raw pointer as *{mut,const} T instead of *-ptr in errors The `*-ptr` is rather confusing, and we have the full information for properly displaying the information.
2 parents 0631ea5 + 5021dcd commit 548ed40

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

compiler/rustc_middle/src/ty/error.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -276,10 +276,23 @@ impl<'tcx> Ty<'tcx> {
276276
}
277277
ty::Slice(ty) if ty.is_simple_ty() => format!("slice `{}`", self).into(),
278278
ty::Slice(_) => "slice".into(),
279-
ty::RawPtr(_) => "*-ptr".into(),
279+
ty::RawPtr(tymut) => {
280+
let tymut_string = match tymut.mutbl {
281+
hir::Mutability::Mut => tymut.to_string(),
282+
hir::Mutability::Not => format!("const {}", tymut.ty),
283+
};
284+
285+
if tymut_string != "_" && (tymut.ty.is_simple_text() || tymut_string.len() < "const raw pointer".len()) {
286+
format!("`*{}`", tymut_string).into()
287+
} else {
288+
// Unknown type name, it's long or has type arguments
289+
"raw pointer".into()
290+
}
291+
},
280292
ty::Ref(_, ty, mutbl) => {
281293
let tymut = ty::TypeAndMut { ty, mutbl };
282294
let tymut_string = tymut.to_string();
295+
283296
if tymut_string != "_"
284297
&& (ty.is_simple_text() || tymut_string.len() < "mutable reference".len())
285298
{

src/test/ui/asm/type-check-1.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ error[E0308]: mismatched types
106106
--> $DIR/type-check-1.rs:60:26
107107
|
108108
LL | asm!("{}", const 0 as *mut u8);
109-
| ^^^^^^^^^^^^ expected integer, found *-ptr
109+
| ^^^^^^^^^^^^ expected integer, found `*mut u8`
110110
|
111111
= note: expected type `{integer}`
112112
found raw pointer `*mut u8`
@@ -133,7 +133,7 @@ error[E0308]: mismatched types
133133
--> $DIR/type-check-1.rs:78:25
134134
|
135135
LL | global_asm!("{}", const 0 as *mut u8);
136-
| ^^^^^^^^^^^^ expected integer, found *-ptr
136+
| ^^^^^^^^^^^^ expected integer, found `*mut u8`
137137
|
138138
= note: expected type `{integer}`
139139
found raw pointer `*mut u8`

src/test/ui/dst/dst-bad-coercions.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0308]: mismatched types
22
--> $DIR/dst-bad-coercions.rs:14:17
33
|
44
LL | let y: &S = x;
5-
| -- ^ expected `&S`, found *-ptr
5+
| -- ^ expected `&S`, found `*const S`
66
| |
77
| expected due to this
88
|
@@ -13,7 +13,7 @@ error[E0308]: mismatched types
1313
--> $DIR/dst-bad-coercions.rs:15:21
1414
|
1515
LL | let y: &dyn T = x;
16-
| ------ ^ expected `&dyn T`, found *-ptr
16+
| ------ ^ expected `&dyn T`, found `*const S`
1717
| |
1818
| expected due to this
1919
|
@@ -24,7 +24,7 @@ error[E0308]: mismatched types
2424
--> $DIR/dst-bad-coercions.rs:19:17
2525
|
2626
LL | let y: &S = x;
27-
| -- ^ expected `&S`, found *-ptr
27+
| -- ^ expected `&S`, found `*mut S`
2828
| |
2929
| expected due to this
3030
|
@@ -35,7 +35,7 @@ error[E0308]: mismatched types
3535
--> $DIR/dst-bad-coercions.rs:20:21
3636
|
3737
LL | let y: &dyn T = x;
38-
| ------ ^ expected `&dyn T`, found *-ptr
38+
| ------ ^ expected `&dyn T`, found `*mut S`
3939
| |
4040
| expected due to this
4141
|

src/test/ui/mismatched_types/issue-19109.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0308]: mismatched types
44
LL | fn function(t: &mut dyn Trait) {
55
| - help: try adding a return type: `-> *mut dyn Trait`
66
LL | t as *mut dyn Trait
7-
| ^^^^^^^^^^^^^^^^^^^ expected `()`, found *-ptr
7+
| ^^^^^^^^^^^^^^^^^^^ expected `()`, found `*mut dyn Trait`
88
|
99
= note: expected unit type `()`
1010
found raw pointer `*mut dyn Trait`

0 commit comments

Comments
 (0)