Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor fmt::Display and fmt::Debug impls in ppaux #44888

Merged
merged 3 commits into from
Oct 11, 2017

Conversation

tirr-c
Copy link
Contributor

@tirr-c tirr-c commented Sep 27, 2017

Also fixes #44887.

There was a problem that unnamed late-bound regions are always named 'r while they are displayed using std::fmt::Display.


fn main() {
    f(|_: (), _: ()| {});
}
fn f<F>(_: F) where F: Fn(&(), for<'r> fn(&'r ())) {}

Before (incorrectly shadows lifetime, for<'r> omitted for the second argument):

error[E0631]: type mismatch in closure arguments
 --> test.rs:2:5
  |
2 |     f(|_: (), _: ()| {});
  |     ^ ----------------- found signature of `fn((), ()) -> _`
  |     |
  |     expected signature of `for<'r> fn(&'r (), fn(&'r ())) -> _`
  |
  = note: required by `f`

After:

error[E0631]: type mismatch in closure arguments
 --> test.rs:2:5
  |
2 |     f(|_: (), _: ()| {});
  |     ^ ----------------- found signature of `fn((), ()) -> _`
  |     |
  |     expected signature of `for<'s> fn(&'s (), for<'r> fn(&'r ())) -> _`
  |
  = note: required by `f`

r? @nikomatsakis

@@ -882,6 +882,10 @@ pub struct GlobalCtxt<'tcx> {
/// Maps Expr NodeId's to `true` iff `&expr` can have 'static lifetime.
pub rvalue_promotable_to_static: RefCell<NodeMap<bool>>,

pub display_used_late_bound_region_names: RefCell<Option<FxHashSet<Name>>>,
Copy link
Contributor

Choose a reason for hiding this comment

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

This is likely to cause problems with incremental compilation. I think the amount of globals ppaux is depending on is getting far out of hand, and we should stop using Display & Debug and start using our own trait.

@aidanhs aidanhs added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Sep 28, 2017
@tirr-c tirr-c force-pushed the binder-hr-region branch 2 times, most recently from 88ced5d to 257bf32 Compare October 1, 2017 16:52
@tirr-c tirr-c changed the title Name higher-ranked lifetimes properly while displaying Refactor fmt::Display and fmt::Debug impls in ppaux Oct 1, 2017
@tirr-c
Copy link
Contributor Author

tirr-c commented Oct 1, 2017

I've refactored ppaux, and I think it's halfway done. I believe we can make this better, especially those macros; they are very rough. I defined macros because I can't just write impl<T> fmt::Display for T where T: Print.

r? @arielb1

@rust-highfive rust-highfive assigned arielb1 and unassigned nikomatsakis Oct 1, 2017
@arielb1
Copy link
Contributor

arielb1 commented Oct 2, 2017

[00:35:42] ---- [ui] ui/regions-fn-subtyping-return-static.rs stdout ----
[00:35:42] 	normalized stderr:
[00:35:42] error[E0308]: mismatched types
[00:35:42]   --> $DIR/regions-fn-subtyping-return-static.rs:51:12
[00:35:42]    |
[00:35:42] 51 |     want_F(bar); //~ ERROR E0308
[00:35:42]    |            ^^^ expected concrete lifetime, found bound lifetime parameter 'cx
[00:35:42]    |
[00:35:42]    = note: expected type `for<'cx> fn(&'cx S) -> &'cx S`
[00:35:42]               found type `for<'a> fn(&'a S) -> &S {bar::<'_>}`
[00:35:42] 
[00:35:42] error: aborting due to previous error
[00:35:42] 
[00:35:42] 
[00:35:42] 
[00:35:42] expected stderr:
[00:35:42] error[E0308]: mismatched types
[00:35:42]   --> $DIR/regions-fn-subtyping-return-static.rs:51:12
[00:35:42]    |
[00:35:42] 51 |     want_F(bar); //~ ERROR E0308
[00:35:42]    |            ^^^ expected concrete lifetime, found bound lifetime parameter 'cx
[00:35:42]    |
[00:35:42]    = note: expected type `for<'cx> fn(&'cx S) -> &'cx S`
[00:35:42]               found type `fn(&'a S) -> &S {bar::<'_>}`
[00:35:42] 
[00:35:42] error: aborting due to previous error
[00:35:42] 
[00:35:42] 
[00:35:42] 
[00:35:42] diff of stderr:
[00:35:42] 
[00:35:42]  error[E0308]: mismatched types
[00:35:42]    --> $DIR/regions-fn-subtyping-return-static.rs:51:12
[00:35:42]     |
[00:35:42]  51 |     want_F(bar); //~ ERROR E0308
[00:35:42]     |            ^^^ expected concrete lifetime, found bound lifetime parameter 'cx
[00:35:42]     |
[00:35:42]     = note: expected type `for<'cx> fn(&'cx S) -> &'cx S`
[00:35:42] -              found type `fn(&'a S) -> &S {bar::<'_>}`
[00:35:42] +              found type `for<'a> fn(&'a S) -> &S {bar::<'_>}`
[00:35:42]  
[00:35:42]  error: aborting due to previous error

};
default impl<T> DefaultWith<T> for PrintContext {}

impl<'tcx, T> DefaultWith<T> for PrintContext
Copy link
Contributor

Choose a reason for hiding this comment

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

that's an... ok use of specialization. I suppose we can avoid it if we have to?

Copy link
Contributor Author

@tirr-c tirr-c Oct 2, 2017

Choose a reason for hiding this comment

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

Oops, I've missed your review -- what do you mean by that? I can't quite get it...

@arielb1
Copy link
Contributor

arielb1 commented Oct 2, 2017

still same test needs updating

@arielb1
Copy link
Contributor

arielb1 commented Oct 2, 2017

Nice cleanup with the macros. There were a few directions I wanted to go there, but they can be in a separate PRs.

LGTM, r=me after this passes travis.

@tirr-c
Copy link
Contributor Author

tirr-c commented Oct 2, 2017

I haven't fully tested this, I'll let travis do necessary tests.

})
}
fn prepare_late_bound_region_info<'tcx, T>(&mut self, value: &ty::Binder<T>)
where T: TypeFoldable<'tcx>
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: indentation, should be

    fn prepare_late_bound_region_info<'tcx, T>(&mut self, value: &ty::Binder<T>)
        where T: TypeFoldable<'tcx>

@arielb1
Copy link
Contributor

arielb1 commented Oct 3, 2017

nah you don't have to fix the indentation

@bors r+

@bors
Copy link
Contributor

bors commented Oct 3, 2017

📌 Commit b9b45ed has been approved by arielb1

@arielb1
Copy link
Contributor

arielb1 commented Oct 3, 2017

Thanks for the PR! That's a very cool use of macros.

@bors
Copy link
Contributor

bors commented Oct 3, 2017

⌛ Testing commit b9b45ed1a4f1168906f2725a2696e79b07843ef6 with merge c914972d622e7c4f44a62adf06fbba4c30fb5084...

@bors
Copy link
Contributor

bors commented Oct 3, 2017

💔 Test failed - status-travis

@bors
Copy link
Contributor

bors commented Oct 8, 2017

☔ The latest upstream changes (presumably #45100) made this pull request unmergeable. Please resolve the merge conflicts.

@arielb1
Copy link
Contributor

arielb1 commented Oct 11, 2017

@bors r+

@bors
Copy link
Contributor

bors commented Oct 11, 2017

📌 Commit 84cb90f has been approved by arielb1

@bors
Copy link
Contributor

bors commented Oct 11, 2017

⌛ Testing commit 84cb90f with merge cbf5d39...

bors added a commit that referenced this pull request Oct 11, 2017
Refactor fmt::Display and fmt::Debug impls in ppaux

Also fixes #44887.

There was a problem that unnamed late-bound regions are *always* named `'r` while they are displayed using `std::fmt::Display`.

---

```rust
fn main() {
    f(|_: (), _: ()| {});
}
fn f<F>(_: F) where F: Fn(&(), for<'r> fn(&'r ())) {}
```

Before (incorrectly shadows lifetime, `for<'r>` omitted for the second argument):

```
error[E0631]: type mismatch in closure arguments
 --> test.rs:2:5
  |
2 |     f(|_: (), _: ()| {});
  |     ^ ----------------- found signature of `fn((), ()) -> _`
  |     |
  |     expected signature of `for<'r> fn(&'r (), fn(&'r ())) -> _`
  |
  = note: required by `f`
```

After:

```
error[E0631]: type mismatch in closure arguments
 --> test.rs:2:5
  |
2 |     f(|_: (), _: ()| {});
  |     ^ ----------------- found signature of `fn((), ()) -> _`
  |     |
  |     expected signature of `for<'s> fn(&'s (), for<'r> fn(&'r ())) -> _`
  |
  = note: required by `f`
```

r? @nikomatsakis
@bors
Copy link
Contributor

bors commented Oct 11, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: arielb1
Pushing cbf5d39 to master...

@bors bors merged commit 84cb90f into rust-lang:master Oct 11, 2017
@tirr-c tirr-c deleted the binder-hr-region branch October 11, 2017 18:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Function pointer types never display higher-ranked region when they are used as argument types
5 participants