Skip to content

Commit

Permalink
Improve &-ptr printing
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Turner committed Aug 12, 2016
1 parent 8787a12 commit 4224737
Show file tree
Hide file tree
Showing 17 changed files with 39 additions and 22 deletions.
19 changes: 18 additions & 1 deletion src/librustc/ty/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,24 @@ impl<'a, 'gcx, 'lcx, 'tcx> ty::TyS<'tcx> {
ty::TyArray(_, n) => format!("array of {} elements", n),
ty::TySlice(_) => "slice".to_string(),
ty::TyRawPtr(_) => "*-ptr".to_string(),
ty::TyRef(_, _) => "&-ptr".to_string(),
ty::TyRef(region, tymut) => {
let tymut_string = tymut.to_string();
if tymut_string == "_" || //unknown type name,
tymut_string.len() > 10 || //name longer than saying "reference",
region.to_string() != "" //... or a complex type
{
match tymut {
ty::TypeAndMut{mutbl, ..} => {
format!("{}reference", match mutbl {
hir::Mutability::MutMutable => "mutable ",
_ => ""
})
}
}
} else {
format!("&{}", tymut_string)
}
}
ty::TyFnDef(..) => format!("fn item"),
ty::TyFnPtr(_) => "fn pointer".to_string(),
ty::TyTrait(ref inner) => {
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/coercion-slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ fn main() {
//~^ ERROR mismatched types
//~| expected type `&[i32]`
//~| found type `[{integer}; 1]`
//~| expected &-ptr, found array of 1 elements
//~| expected &[i32], found array of 1 elements
}
2 changes: 1 addition & 1 deletion src/test/compile-fail/cross-borrow-trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ pub fn main() {
let _y: &Trait = x; //~ ERROR mismatched types
//~| expected type `&Trait`
//~| found type `Box<Trait>`
//~| expected &-ptr, found box
//~| expected &Trait, found box
}
4 changes: 2 additions & 2 deletions src/test/compile-fail/destructure-trait-ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ fn main() {
//~^ ERROR mismatched types
//~| expected type `T`
//~| found type `&_`
//~| expected trait T, found &-ptr
//~| expected trait T, found reference
let &&&x = &(&1isize as &T);
//~^ ERROR mismatched types
//~| expected type `T`
//~| found type `&_`
//~| expected trait T, found &-ptr
//~| expected trait T, found reference
let box box x = box 1isize as Box<T>;
//~^ ERROR mismatched types
//~| expected type `T`
Expand Down
4 changes: 2 additions & 2 deletions src/test/compile-fail/dst-bad-coercions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ struct Foo<T: ?Sized> {
}

pub fn main() {
// Test that we cannot convert from *-ptr to &-ptr
// Test that we cannot convert from *-ptr to &S and &T
let x: *const S = &S;
let y: &S = x; //~ ERROR mismatched types
let y: &T = x; //~ ERROR mismatched types

// Test that we cannot convert from *-ptr to &-ptr (mut version)
// Test that we cannot convert from *-ptr to &S and &T (mut version)
let x: *mut S = &mut S;
let y: &S = x; //~ ERROR mismatched types
let y: &T = x; //~ ERROR mismatched types
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/issue-12997-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ fn bar(x: isize) { }
//~^ ERROR mismatched types
//~| expected type `fn(&mut __test::test::Bencher)`
//~| found type `fn(isize) {bar}`
//~| expected &-ptr, found isize
//~| expected mutable reference, found isize
2 changes: 1 addition & 1 deletion src/test/compile-fail/issue-16338.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ fn main() {
//~^ ERROR mismatched types
//~| expected type `&str`
//~| found type `Slice<_>`
//~| expected &-ptr, found struct `Slice`
//~| expected &str, found struct `Slice`
}
2 changes: 1 addition & 1 deletion src/test/compile-fail/issue-17033.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fn f<'r>(p: &'r mut fn(p: &mut ())) {
(*p)(()) //~ ERROR mismatched types
//~| expected type `&mut ()`
//~| found type `()`
//~| expected &-ptr, found ()
//~| expected &mut (), found ()
}

fn main() {}
6 changes: 3 additions & 3 deletions src/test/compile-fail/issue-20225.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@ struct Foo;
impl<'a, T> Fn<(&'a T,)> for Foo {
extern "rust-call" fn call(&self, (_,): (T,)) {}
//~^ ERROR: has an incompatible type for trait
//~| expected &-ptr
//~| expected reference
}

impl<'a, T> FnMut<(&'a T,)> for Foo {
extern "rust-call" fn call_mut(&mut self, (_,): (T,)) {}
//~^ ERROR: has an incompatible type for trait
//~| expected &-ptr
//~| expected reference
}

impl<'a, T> FnOnce<(&'a T,)> for Foo {
type Output = ();

extern "rust-call" fn call_once(self, (_,): (T,)) {}
//~^ ERROR: has an incompatible type for trait
//~| expected &-ptr
//~| expected reference
}

fn main() {}
2 changes: 1 addition & 1 deletion src/test/compile-fail/issue-29084.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ macro_rules! foo {
fn bar(d: u8) { }
bar(&mut $d);
//~^ ERROR mismatched types
//~| expected u8, found &-ptr
//~| expected u8, found &mut u8
//~| expected type `u8`
//~| found type `&mut u8`
}}
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/issue-5100.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fn main() {
//~^ ERROR mismatched types
//~| expected type `(bool, bool)`
//~| found type `&_`
//~| expected tuple, found &-ptr
//~| expected tuple, found reference
}


Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/issue-5500.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ fn main() {
//~^ ERROR mismatched types
//~| expected type `()`
//~| found type `&_`
//~| expected (), found &-ptr
//~| expected (), found reference
}
2 changes: 1 addition & 1 deletion src/test/compile-fail/issue-7061.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ impl<'a> BarStruct {
//~^ ERROR mismatched types
//~| expected type `Box<BarStruct>`
//~| found type `&'a mut BarStruct`
//~| expected box, found &-ptr
//~| expected box, found mutable reference
}

fn main() {}
4 changes: 2 additions & 2 deletions src/test/compile-fail/issue-7867.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ fn main() {
//~^ ERROR mismatched types
//~| expected type `&std::option::Option<{integer}>`
//~| found type `std::option::Option<_>`
//~| expected &-ptr, found enum `std::option::Option`
//~| expected reference, found enum `std::option::Option`
None => ()
//~^ ERROR mismatched types
//~| expected type `&std::option::Option<{integer}>`
//~| found type `std::option::Option<_>`
//~| expected &-ptr, found enum `std::option::Option`
//~| expected reference, found enum `std::option::Option`
}
}
2 changes: 1 addition & 1 deletion src/test/compile-fail/method-self-arg-1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn main() {
Foo::bar(x); //~ ERROR mismatched types
//~| expected type `&Foo`
//~| found type `Foo`
//~| expected &-ptr, found struct `Foo`
//~| expected &Foo, found struct `Foo`
Foo::bar(&42); //~ ERROR mismatched types
//~| expected type `&Foo`
//~| found type `&{integer}`
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/overloaded-calls-bad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fn main() {
y: 3,
};
let ans = s("what"); //~ ERROR mismatched types
//~^ NOTE expected isize, found &-ptr
//~^ NOTE expected isize, found reference
//~| NOTE expected type
//~| NOTE found type
let ans = s();
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/repeat_count.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fn main() {
//~^ ERROR mismatched types
//~| expected type `usize`
//~| found type `&'static str`
//~| expected usize, found &-ptr
//~| expected usize, found reference
//~| ERROR expected `usize` for repeat count, found string literal [E0306]
//~| expected `usize`
let f = [0; -4_isize];
Expand Down

0 comments on commit 4224737

Please sign in to comment.