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

RFC: Centralize on special types as a way of informing inference about special constraints #10834

Closed
nikomatsakis opened this issue Dec 6, 2013 · 8 comments · Fixed by #11768
Milestone

Comments

@nikomatsakis
Copy link
Contributor

As part of the discussion in #5922, it became clear that there are a number of cases in which we must inform the compiler about special constraints that pertain to specific types. These constraints almost always arise because of unsafe code that does things the compiler can't know about. We don't have a central mechanism for propagating such constraints:

  1. Annotations like #[no_freeze] are used to inform the builtin-bounds.
  2. Except for non-copyable, which has a special type.
  3. Variance currently has no mechanism, so unused lifetime parameters don't necessarily behave like people expect.

I think we should centralize on one mechanism. My current thought is to employ 0-sized types for this. So we would remove the #[no_freeze] annotations and add types like Nonfreezable, as well as CovariantLifetime<'a> and so on. These would be lang items specially recognized by the compiler.

Nominating and adding to the agenda for next week.

@nikomatsakis
Copy link
Contributor Author

Some arguments I considered in favor of using marker types:

  1. They are discoverable and documentable, in contrast to annotations.
  2. They are less intimidating than special syntax.
  3. It's easy to add more, unlike special syntax.

@zkamsler
Copy link
Contributor

zkamsler commented Dec 6, 2013

Marker types seem relatively straightforward to use for structs, but could it result in awkwardness for enum variants, especially because they are more frequently destructured? Even if there they are easily ignored, there is still some programmer overhead in ignoring a field that does not contain any data.

@sfackler
Copy link
Member

sfackler commented Dec 6, 2013

NonCopyable as it is currenlty implemented (with a Drop impl) has some problems as it should - but doesn't currently - prevent the type from being used in a static variable. The std::unstable::atomics family uses NonCopyable which causes some strange issues like #10577.

@glaebhoerl
Copy link
Contributor

One positive aspect of this is that it commits us to basically nothing in terms of backwards compatibility at the language level. If we later come up with a better way to do these, we can add that and also keep the marker types around without any awkwardness.

@nikomatsakis
Copy link
Contributor Author

On Fri, Dec 06, 2013 at 06:41:20AM -0800, zkamsler wrote:

...Marker types seem relatively straightforward to use for structs, but could it result in awkwardness for enum variants..

There is an easy workaround. Convert

enum Foo { A(..), B(.., Noncopyable) }

to

struct Foo { v: Foo1, _nc: Noncopyable }
enum Foo1 { A(..), B(..) }
``

and then match on `x.v` instead of `x`.

I think it's not so common though to use enums as the "top-level" type
for unsafe things like `Rc` etc.

@nikomatsakis
Copy link
Contributor Author

@sfackler I agree that non copyable should be integrated as a lang item into the compiler, though I don't think that we should necessarily prohibit types that contain dtors from appearing as static items (as I explained in that issue at some point).

@nikomatsakis
Copy link
Contributor Author

cc @thestinger, as one of the bigger users of these sorts of annotations. This was discussed in meeting on dec 10 and generally approved of.

@pnkfelix
Copy link
Member

pnkfelix commented Jan 9, 2014

Accepted for 1.0, P-backcompat-libs

alexcrichton added a commit to alexcrichton/rust that referenced this issue Jan 21, 2014
bors added a commit that referenced this issue Feb 1, 2014
…e, r=pnkfelix

Introduce marker types for indicating variance and for opting out
of builtin bounds.

Fixes #10834.
Fixes #11385.
cc #5922.

r? @pnkfelix (since you reviewed the variance inference in the first place)
flaper87 added a commit to flaper87/rust that referenced this issue Feb 3, 2014
bors added a commit that referenced this issue Feb 27, 2014
This pull request partially addresses the 2 issues listed before. As part of the work required for this PR, `NonCopyable` was completely removed.

This PR also replaces the content of `type_is_pod` with `TypeContents::is_pod`, although `type_is_content` is currently not being used anywhere. I kept it for consistency with the other functions that exist in this module.

cc #10834
cc #10577

Proposed static restrictions
=====================

Taken from [this](#11979 (comment)) comment.

I expect some code that, at a high-level, works like this:

- For each *mutable* static item, check that the **type**:
    - cannot own any value whose type has a dtor
    - cannot own any values whose type is an owned pointer
- For each *immutable* static item, check that the **value**:
      - does not contain any ~ or box expressions (including ~[1, 2, 3] sort of things, for now)
      - does not contain a struct literal or call to an enum variant / struct constructor where
          - the type of the struct/enum is freeze
          - the type of the struct/enum has a dtor
bors added a commit that referenced this issue Feb 28, 2014
This pull request partially addresses the 2 issues listed before. As part of the work required for this PR, `NonCopyable` was completely removed.

This PR also replaces the content of `type_is_pod` with `TypeContents::is_pod`, although `type_is_content` is currently not being used anywhere. I kept it for consistency with the other functions that exist in this module.

cc #10834
cc #10577

Proposed static restrictions
=====================

Taken from [this](#11979 (comment)) comment.

I expect some code that, at a high-level, works like this:

- For each *mutable* static item, check that the **type**:
    - cannot own any value whose type has a dtor
    - cannot own any values whose type is an owned pointer
- For each *immutable* static item, check that the **value**:
      - does not contain any ~ or box expressions (including ~[1, 2, 3] sort of things, for now)
      - does not contain a struct literal or call to an enum variant / struct constructor where
          - the type of the struct/enum is freeze
          - the type of the struct/enum has a dtor
flip1995 pushed a commit to flip1995/rust that referenced this issue Jun 30, 2023
…xFrednet

Use URL parameters for filter states

This fixes rust-lang#8510 by storing Clippy Lints page filter configuration in the URL parameters.

This includes:
- Lint levels
- Lint groups
- Version filters

"Filter" was already present in the URL and its behavior is retained. There is existing support for passing a `sel` query parameter; this is also retained, but I am not sure if it used in the wild.

The URL parameters only get included if they are modified after loading the page.

I have these changes available here in case people want to play with it: https://whee.github.io/rust-clippy/master/

An example with levels, groups, and versions set (oddly):

https://whee.github.io/rust-clippy/master/#/?groups=pedantic,perf&levels=allow,warn&versions=gte:53,lte:57,eq:54

Adding a filter:

https://whee.github.io/rust-clippy/master/#/manual_str_repeat?groups=pedantic,perf&levels=allow,warn&versions=gte:53,lte:57,eq:54

---

changelog: Docs: [`Clippy's lint list`] now stores filter parameters in the URL, to allow easy sharing
[rust-lang#10834](rust-lang/rust-clippy#10834)
<!-- changelog_checked -->
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

Successfully merging a pull request may close this issue.

5 participants