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.
This commit is contained in:
@@ -276,10 +276,23 @@ impl<'tcx> Ty<'tcx> {
|
|||||||
}
|
}
|
||||||
ty::Slice(ty) if ty.is_simple_ty() => format!("slice `{}`", self).into(),
|
ty::Slice(ty) if ty.is_simple_ty() => format!("slice `{}`", self).into(),
|
||||||
ty::Slice(_) => "slice".into(),
|
ty::Slice(_) => "slice".into(),
|
||||||
ty::RawPtr(_) => "*-ptr".into(),
|
ty::RawPtr(tymut) => {
|
||||||
|
let tymut_string = match tymut.mutbl {
|
||||||
|
hir::Mutability::Mut => tymut.to_string(),
|
||||||
|
hir::Mutability::Not => format!("const {}", tymut.ty),
|
||||||
|
};
|
||||||
|
|
||||||
|
if tymut_string != "_" && (tymut.ty.is_simple_text() || tymut_string.len() < "const raw pointer".len()) {
|
||||||
|
format!("`*{}`", tymut_string).into()
|
||||||
|
} else {
|
||||||
|
// Unknown type name, it's long or has type arguments
|
||||||
|
"raw pointer".into()
|
||||||
|
}
|
||||||
|
},
|
||||||
ty::Ref(_, ty, mutbl) => {
|
ty::Ref(_, ty, mutbl) => {
|
||||||
let tymut = ty::TypeAndMut { ty, mutbl };
|
let tymut = ty::TypeAndMut { ty, mutbl };
|
||||||
let tymut_string = tymut.to_string();
|
let tymut_string = tymut.to_string();
|
||||||
|
|
||||||
if tymut_string != "_"
|
if tymut_string != "_"
|
||||||
&& (ty.is_simple_text() || tymut_string.len() < "mutable reference".len())
|
&& (ty.is_simple_text() || tymut_string.len() < "mutable reference".len())
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ error[E0308]: mismatched types
|
|||||||
--> $DIR/type-check-1.rs:60:26
|
--> $DIR/type-check-1.rs:60:26
|
||||||
|
|
|
|
||||||
LL | asm!("{}", const 0 as *mut u8);
|
LL | asm!("{}", const 0 as *mut u8);
|
||||||
| ^^^^^^^^^^^^ expected integer, found *-ptr
|
| ^^^^^^^^^^^^ expected integer, found `*mut u8`
|
||||||
|
|
|
|
||||||
= note: expected type `{integer}`
|
= note: expected type `{integer}`
|
||||||
found raw pointer `*mut u8`
|
found raw pointer `*mut u8`
|
||||||
@@ -133,7 +133,7 @@ error[E0308]: mismatched types
|
|||||||
--> $DIR/type-check-1.rs:78:25
|
--> $DIR/type-check-1.rs:78:25
|
||||||
|
|
|
|
||||||
LL | global_asm!("{}", const 0 as *mut u8);
|
LL | global_asm!("{}", const 0 as *mut u8);
|
||||||
| ^^^^^^^^^^^^ expected integer, found *-ptr
|
| ^^^^^^^^^^^^ expected integer, found `*mut u8`
|
||||||
|
|
|
|
||||||
= note: expected type `{integer}`
|
= note: expected type `{integer}`
|
||||||
found raw pointer `*mut u8`
|
found raw pointer `*mut u8`
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ error[E0308]: mismatched types
|
|||||||
--> $DIR/dst-bad-coercions.rs:14:17
|
--> $DIR/dst-bad-coercions.rs:14:17
|
||||||
|
|
|
|
||||||
LL | let y: &S = x;
|
LL | let y: &S = x;
|
||||||
| -- ^ expected `&S`, found *-ptr
|
| -- ^ expected `&S`, found `*const S`
|
||||||
| |
|
| |
|
||||||
| expected due to this
|
| expected due to this
|
||||||
|
|
|
|
||||||
@@ -13,7 +13,7 @@ error[E0308]: mismatched types
|
|||||||
--> $DIR/dst-bad-coercions.rs:15:21
|
--> $DIR/dst-bad-coercions.rs:15:21
|
||||||
|
|
|
|
||||||
LL | let y: &dyn T = x;
|
LL | let y: &dyn T = x;
|
||||||
| ------ ^ expected `&dyn T`, found *-ptr
|
| ------ ^ expected `&dyn T`, found `*const S`
|
||||||
| |
|
| |
|
||||||
| expected due to this
|
| expected due to this
|
||||||
|
|
|
|
||||||
@@ -24,7 +24,7 @@ error[E0308]: mismatched types
|
|||||||
--> $DIR/dst-bad-coercions.rs:19:17
|
--> $DIR/dst-bad-coercions.rs:19:17
|
||||||
|
|
|
|
||||||
LL | let y: &S = x;
|
LL | let y: &S = x;
|
||||||
| -- ^ expected `&S`, found *-ptr
|
| -- ^ expected `&S`, found `*mut S`
|
||||||
| |
|
| |
|
||||||
| expected due to this
|
| expected due to this
|
||||||
|
|
|
|
||||||
@@ -35,7 +35,7 @@ error[E0308]: mismatched types
|
|||||||
--> $DIR/dst-bad-coercions.rs:20:21
|
--> $DIR/dst-bad-coercions.rs:20:21
|
||||||
|
|
|
|
||||||
LL | let y: &dyn T = x;
|
LL | let y: &dyn T = x;
|
||||||
| ------ ^ expected `&dyn T`, found *-ptr
|
| ------ ^ expected `&dyn T`, found `*mut S`
|
||||||
| |
|
| |
|
||||||
| expected due to this
|
| expected due to this
|
||||||
|
|
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ error[E0308]: mismatched types
|
|||||||
LL | fn function(t: &mut dyn Trait) {
|
LL | fn function(t: &mut dyn Trait) {
|
||||||
| - help: try adding a return type: `-> *mut dyn Trait`
|
| - help: try adding a return type: `-> *mut dyn Trait`
|
||||||
LL | t as *mut dyn Trait
|
LL | t as *mut dyn Trait
|
||||||
| ^^^^^^^^^^^^^^^^^^^ expected `()`, found *-ptr
|
| ^^^^^^^^^^^^^^^^^^^ expected `()`, found `*mut dyn Trait`
|
||||||
|
|
|
|
||||||
= note: expected unit type `()`
|
= note: expected unit type `()`
|
||||||
found raw pointer `*mut dyn Trait`
|
found raw pointer `*mut dyn Trait`
|
||||||
|
|||||||
Reference in New Issue
Block a user