Stream: t-compiler/wg-nll

Topic: #53771 impl trait static


davidtwco (Sep 01 2018 at 22:41, on Zulip):

What's the best way for me to get the span of the return type? I've tried a handful of things like mir.local_decls[mir::RETURN_PLACE].source_info.span.

   |
12 |     fn iter_values<'a>(&'a self) -> impl Iterator<Item=u32> + 'a {
   |                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Matthew Jasper (Sep 02 2018 at 08:35, on Zulip):

If you just care about impl Trait then there's the DefId in TyKind::Anon (sadly there's no equivalent for dyn Trait). Otherwise the best I can find is crawling through the hir to find it:

let id = tcx.hir.as_local_node_id(def_id).unwrap();

match tcx.hir.get(id) {
     Node::Item(Item { node: ItemKind::Fn ... } ) => {  }
     _ => { /* In a closure or something */ }
}
davidtwco (Sep 02 2018 at 09:06, on Zulip):

@Matthew Jasper Thanks, using the DefId from the TyKind::Anon did the trick.

davidtwco (Sep 02 2018 at 09:15, on Zulip):

Submitted #53900.

davidtwco (Sep 04 2018 at 14:13, on Zulip):

@nikomatsakis Could you take a look at the review I left on #53900 (and @Esteban K├╝ber commented on) and provide some high-level pointers on where I should be looking to check for a + 'static bound on a impl Trait return type? Not a priority though, I've got other PRs I can look at.

pnkfelix (Sep 04 2018 at 14:15, on Zulip):

@davidtwco just a stray thought: have you attempted to reverse engineer where the bound comes from by looking at the pretty printing code for type?

pnkfelix (Sep 04 2018 at 14:15, on Zulip):

(I'm not sure this would be an efficient way to answer the Q. but it might at least be a way to unblock yourself here...)

davidtwco (Sep 04 2018 at 14:17, on Zulip):

@pnkfelix I hadn't considered that. I had tried to trace it up from libsyntax briefly (figuring that the representation, or at least what things are named, is normally fairly similar), but ran out of time for the day.

davidtwco (Sep 04 2018 at 14:19, on Zulip):

If I'm not mistaken, it looks like it is this code.

davidtwco (Sep 04 2018 at 14:19, on Zulip):

That's helpful, I can experiment with the functions that it is calling and see what happens.

pnkfelix (Sep 04 2018 at 14:19, on Zulip):

@davidtwco are you on a Linux box?

davidtwco (Sep 04 2018 at 14:20, on Zulip):

Yeah (well, I SSH into one for my Rust stuff).

pnkfelix (Sep 04 2018 at 14:20, on Zulip):

@davidtwco if so, combining rr with stepping backwards through the printing of a type can really narrow things down

davidtwco (Sep 04 2018 at 14:21, on Zulip):

I'll need to look into that. I've been wanting to hook a debugger up when working on things for a while so I can easier see the values of things without adding log statements and waiting a bunch.

davidtwco (Sep 04 2018 at 16:57, on Zulip):

Fixed it now.

davidtwco (Sep 05 2018 at 15:50, on Zulip):

@pnkfelix Do you want me to change anything based on the feedback on #53900?

pnkfelix (Sep 05 2018 at 15:52, on Zulip):

nope. If you prefer passing an extra parameter that is derivable from another parameter, then go ahead. Its not my personal style

pnkfelix (Sep 05 2018 at 15:52, on Zulip):

but its also something that I do not see as worth blocking a useful PR

nikomatsakis (Sep 05 2018 at 16:09, on Zulip):

@davidtwco I left some nits, I'd like to take one more quick look once you add a few more comments

nikomatsakis (Sep 05 2018 at 16:09, on Zulip):

but the new errors look great!

davidtwco (Sep 05 2018 at 19:51, on Zulip):

@nikomatsakis w/r/t this comment - I believe this will only suggest 'a: 'static and wouldn't ever suggest T: 'static. Given that, should I just change this from a suggestion to a help mentioning that 'a should be replaced with 'static?

nikomatsakis (Sep 05 2018 at 19:51, on Zulip):

@davidtwco I think so

nikomatsakis (Sep 05 2018 at 19:51, on Zulip):

I wouldn't want to encourage anyone to write 'a: 'static

davidtwco (Sep 05 2018 at 19:51, on Zulip):

:thumbs_up:

davidtwco (Sep 05 2018 at 19:58, on Zulip):

@nikomatsakis would replace uses of 'a with 'static since 'a must live as long as 'static be alright for the help message? - struggling to come up with a decent one..

nikomatsakis (Sep 05 2018 at 20:03, on Zulip):
error: unsatisfied lifetime constraints
  --> $DIR/must_outlive_least_region_or_bound.rs:22:69
   |
LL | fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'static { x }
   |               -- lifetime `'a` defined here                         ^ returning this value requires that `'a` must outlive `'static`
help: consider replacing `'a` with `'static`
nikomatsakis (Sep 05 2018 at 20:03, on Zulip):

maybe that?

davidtwco (Sep 05 2018 at 20:04, on Zulip):

Well, the error already is:

error: unsatisfied lifetime constraints
  --> $DIR/must_outlive_least_region_or_bound.rs:22:69
   |
LL | fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'static { x }
   |               -- lifetime `'a` defined here                         ^ returning this value requires that `'a` must outlive `'static`
davidtwco (Sep 05 2018 at 20:05, on Zulip):

I see you already used the existing error.

davidtwco (Sep 05 2018 at 20:05, on Zulip):

I thought you were suggesting that.

davidtwco (Sep 05 2018 at 20:05, on Zulip):

:face_palm:

davidtwco (Sep 05 2018 at 20:05, on Zulip):

I see what you mean.

davidtwco (Sep 05 2018 at 20:05, on Zulip):

I'll use that message.

davidtwco (Sep 05 2018 at 21:27, on Zulip):

Updated this PR.

davidtwco (Sep 11 2018 at 10:15, on Zulip):

@nikomatsakis if you have a moment, could you take a look at this? It was approved before and I rebased a few days ago.

Last update: Nov 21 2019 at 13:50UTC