Skip to content

Improve &-ptr printing - #35611

Merged
bors merged 1 commit into
rust-lang:masterfrom
sophiajt:ptr-helper
Aug 15, 2016
Merged

Improve &-ptr printing#35611
bors merged 1 commit into
rust-lang:masterfrom
sophiajt:ptr-helper

Conversation

@sophiajt

@sophiajtsophiajt commented Aug 11, 2016

Copy link
Copy Markdown
Contributor

This PR replaces printing &-ptr with a more readable description. To do so it uses a few heuristics.

If the name of the type is unknown, too long (longer than just saying "reference"), or too complex (a type with explicit lifetime annotations), it will instead opt to print either "reference" or "mutable reference", depending on the mutability of the type.

Before:

error[E0308]: mismatched types
--> src/test/compile-fail/issue-7061.rs:14:46
|
14 | fn foo(&'a mut self) -> Box<BarStruct> { self }
| ^^^^ expected box, found &-ptr
|
= note: expected type `Box<BarStruct>`
= note: found type `&'a mut BarStruct`
error: aborting due to previous error

After:

error[E0308]: mismatched types
--> src/test/compile-fail/issue-7061.rs:14:46
|
14 | fn foo(&'a mut self) -> Box<BarStruct> { self }
| ^^^^ expected box, found mutable reference
|
= note: expected type `Box<BarStruct>`
= note: found type `&'a mut BarStruct`
error: aborting due to previous error

@rust-highfive

Copy link
Copy Markdown
Contributor

r? @arielb1

(rust_highfive has picked a reviewer for you, use r? to override)

@sophiajt

Copy link
Copy Markdown
ContributorAuthor

r? @nikomatsakis

@sophiajt

Copy link
Copy Markdown
ContributorAuthor

(adding Niko as reviewer since he said he wanted to be)

@steveklabnik

Copy link
Copy Markdown
Contributor

omg yessssssssssss

Comment threadsrc/librustc/ty/error.rs Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should really not call to_string twice, better save it.

@eddyb

Copy link
Copy Markdown
Contributor

LGTM, my nitpicking notwithstanding 👍.

@sophiajt

Copy link
Copy Markdown
ContributorAuthor

@eddyb - hehe, no worries. Refactored with some of your nits fixed.

}
}
} else {
format!("&{}", tymut_string)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to print &mut in the case of mutability?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see, we do, never mind.

@nikomatsakis

Copy link
Copy Markdown
Contributor

@bors r+

@bors

bors commented Aug 12, 2016

Copy link
Copy Markdown
Collaborator

📌 Commit 4224737 has been approved by nikomatsakis

Manishearth added a commit to Manishearth/rust that referenced this pull request Aug 13, 2016
…atsakis
Improve &-ptr printing
This PR replaces printing `&-ptr` with a more readable description. To do so it uses a few heuristics.
If the name of the type is unknown, too long (longer than just saying "reference"), or too complex (a type with explicit lifetime annotations), it will instead opt to print either "reference" or "mutable reference", depending on the mutability of the type.
Before:
```
error[E0308]: mismatched types
--> src/test/compile-fail/issue-7061.rs:14:46
|
14 | fn foo(&'a mut self) -> Box<BarStruct> { self }
| ^^^^ expected box, found &-ptr
|
= note: expected type `Box<BarStruct>`
= note: found type `&'a mut BarStruct`
error: aborting due to previous error
```
After:
```
error[E0308]: mismatched types
--> src/test/compile-fail/issue-7061.rs:14:46
|
14 | fn foo(&'a mut self) -> Box<BarStruct> { self }
| ^^^^ expected box, found mutable reference
|
= note: expected type `Box<BarStruct>`
= note: found type `&'a mut BarStruct`
error: aborting due to previous error
```
@eddyb

Copy link
Copy Markdown
Contributor

@bors rollup

eddyb added a commit to eddyb/rust that referenced this pull request Aug 14, 2016
…atsakis
Improve &-ptr printing
This PR replaces printing `&-ptr` with a more readable description. To do so it uses a few heuristics.
If the name of the type is unknown, too long (longer than just saying "reference"), or too complex (a type with explicit lifetime annotations), it will instead opt to print either "reference" or "mutable reference", depending on the mutability of the type.
Before:
```
error[E0308]: mismatched types
--> src/test/compile-fail/issue-7061.rs:14:46
|
14 | fn foo(&'a mut self) -> Box<BarStruct> { self }
| ^^^^ expected box, found &-ptr
|
= note: expected type `Box<BarStruct>`
= note: found type `&'a mut BarStruct`
error: aborting due to previous error
```
After:
```
error[E0308]: mismatched types
--> src/test/compile-fail/issue-7061.rs:14:46
|
14 | fn foo(&'a mut self) -> Box<BarStruct> { self }
| ^^^^ expected box, found mutable reference
|
= note: expected type `Box<BarStruct>`
= note: found type `&'a mut BarStruct`
error: aborting due to previous error
```
@eddybeddyb mentioned this pull request Aug 14, 2016
eddyb added a commit to eddyb/rust that referenced this pull request Aug 14, 2016
…atsakis
Improve &-ptr printing
This PR replaces printing `&-ptr` with a more readable description. To do so it uses a few heuristics.
If the name of the type is unknown, too long (longer than just saying "reference"), or too complex (a type with explicit lifetime annotations), it will instead opt to print either "reference" or "mutable reference", depending on the mutability of the type.
Before:
```
error[E0308]: mismatched types
--> src/test/compile-fail/issue-7061.rs:14:46
|
14 | fn foo(&'a mut self) -> Box<BarStruct> { self }
| ^^^^ expected box, found &-ptr
|
= note: expected type `Box<BarStruct>`
= note: found type `&'a mut BarStruct`
error: aborting due to previous error
```
After:
```
error[E0308]: mismatched types
--> src/test/compile-fail/issue-7061.rs:14:46
|
14 | fn foo(&'a mut self) -> Box<BarStruct> { self }
| ^^^^ expected box, found mutable reference
|
= note: expected type `Box<BarStruct>`
= note: found type `&'a mut BarStruct`
error: aborting due to previous error
```
@eddybeddyb mentioned this pull request Aug 14, 2016
bors added a commit that referenced this pull request Aug 14, 2016
@bors
bors merged commit 4224737 into rust-lang:masterAug 15, 2016
@sophiajt
sophiajt deleted the ptr-helper branch August 18, 2016 15:59
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

@sophiajt@rust-highfive@steveklabnik@eddyb@nikomatsakis@bors@arielb1