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

Clarify and document region nesting rules #10151

Closed
nikomatsakis opened this issue Oct 29, 2013 · 5 comments
Closed

Clarify and document region nesting rules #10151

nikomatsakis opened this issue Oct 29, 2013 · 5 comments

Comments

@nikomatsakis
Copy link
Contributor

We currently infer some special relationships between regions based on region nesting. i.e., if you have fn foo<'a,'b>(x: &'a &'b int), we infer that 'a <= 'b. This is important for type checking impls, though it will become less so (and possibly irrelevant even) after DST (#6308) lands. In any case, in the meantime, as part of formalizing the type system, we should clarify precisely which kinds of nesting relationships yield subtyping relations. I have a FIXME in the code for the spot where this ought to be done.

@nikomatsakis
Copy link
Contributor Author

Today btw we are pretty liberal: if you have &'a T, then 'a must be <= all lifetimes that appear free in T. This is I think stronger than we want to be. We should probably limit it to lifetimes that appear in & pointers or as contravariant/invariant type parameters (not sure about covariant ones). Still I think the current setup is not unsound -- so long as we enforce consistent "sanity check" rules on both the caller/callee, which we do.

@emberian
Copy link
Member

cc @pnkfelix

Any update on this?

@steveklabnik
Copy link
Member

I'll need some help to document this...

@nikomatsakis
Copy link
Contributor Author

@steveklabnik let's talk ;)

@steveklabnik
Copy link
Member

Okay, so after some discussions, this ticket feels like something we'd want well-defined for a formalism, but rarely comes up when you're writing Rust code. as such, i'm going to close it, because once we start formalizing, we'll want a systematic attack, but for now, random issues about it aren't helpful.

Jarcho pushed a commit to Jarcho/rust that referenced this issue Feb 26, 2023
Stop bytes_nth from suggesting code that does not compile

Fixes rust-lang#10151

As discussed in the issue, this PR changes the lint in 2 ways

1. Replace `bytes().nth(n).unwrap()` with `as_bytes()[n]`
2. Replace other `bytes().nth(n)` with `as_bytes().get(n).copied()`

---

changelog: Stop bytes_nth from suggesting code that does not compile in some cases
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants