Commit Graph

1584 Commits

Author SHA1 Message Date
Manish Goregaokar f276dd4f28
Rollup merge of #74448 - davidtwco:improper-ctypes-definitions-boxes, r=davidtwco
improper_ctypes_definitions: allow `Box`

Addresses https://github.com/rust-lang/rust/pull/72700#issuecomment-659449386.

This PR stops linting against `Box` in `extern "C" fn`s for the `improper_ctypes_definitions` lint - boxes are documented to be FFI-safe.

cc @alexcrichton @CryZe
2020-07-17 18:13:47 -07:00
Manish Goregaokar cdedae82cc
Rollup merge of #74438 - RalfJung:uninit-lint, r=davidtwco
warn about uninitialized multi-variant enums

Fixes https://github.com/rust-lang/rust/issues/73608
2020-07-17 14:09:29 -07:00
bors 39d5a61f2e Auto merge of #72983 - Lezzz:rename-typeck, r=nikomatsakis
Rename TypeckTables to TypeckResults.

Originally suggested by @eddyb.
2020-07-17 17:25:09 +00:00
David Wood 95df8024e7
improper_ctypes_definitions: allow `Box`
This commit stops linting against `Box` in `extern "C" fn`s for the
`improper_ctypes_definitions` lint - boxes are documented to be
FFI-safe.

Signed-off-by: David Wood <david@davidtw.co>
2020-07-17 17:55:37 +01:00
Ralf Jung 87b49764bc warn about uninit multi-variant enums 2020-07-17 16:39:59 +02:00
Valentin Lazureanu 1e6adad33f Rename TypeckTables to TypeckResults. 2020-07-17 08:47:04 +00:00
Mark Rousskov 647d9b525f apply bootstrap cfgs 2020-07-16 19:36:49 -04:00
bors 567ad7455d Auto merge of #74175 - nnethercote:more-static-symbols, r=oli-obk
More static symbols

These commits add some more static symbols and convert lots of places to use them.

r? @oli-obk
2020-07-15 00:16:25 +00:00
Nicholas Nethercote 5930081f34 Remove lots of `Symbol::as_str()` calls.
In various ways, such as changing functions to take a `Symbol` instead
of a `&str`.
2020-07-15 09:01:35 +10:00
David Wood cccc3109ff
lint: use `transparent_newtype_field` to avoid ICE
This commit re-uses the `transparent_newtype_field` function instead of
manually calling `is_zst` on normalized fields to determine which field
in a transparent type is the non-zero-sized field, thus avoiding an ICE.

Signed-off-by: David Wood <david@davidtw.co>
2020-07-14 19:26:34 +01:00
Tamir Duberstein 62cf767a4a
Avoid "whitelist"
Other terms are more inclusive and precise.
2020-07-10 07:39:28 -04:00
Manish Goregaokar 65ac3948ae
Rollup merge of #74070 - eddyb:forall-tcx-providers, r=nikomatsakis
Use for<'tcx> fn pointers in Providers, instead of having Providers<'tcx>.

In order to work around normalization-under-HRTB (for `provide!` in `rustc_metadata`), we ended up with this:
```rust
struct Providers<'tcx> {
    type_of: fn(TyCtxt<'tcx>, DefId) -> Ty<'tcx>,
    // ...
}
```
But what I initially wanted to do, IIRC, was this:
```rust
struct Providers {
    type_of: for<'tcx> fn(TyCtxt<'tcx>, DefId) -> Ty<'tcx>,
    // ...
}
```

This PR moves to the latter, for the simple reason that only the latter allows keeping a `Providers` value, or a subset of its `fn` pointer fields, around in a `static` or `thread_local!`, which can be really useful for custom drivers that override queries.
(@jyn514 and I came across a concrete usecase of that in `rustdoc`)

The `provide!` macro in `rustc_metadata` is fixed by making the query key/value types available as type aliases under `ty::query::query_{keys,values}`, not just associated types (this is the first commit).

r? @nikomatsakis
2020-07-09 11:50:28 -07:00
bors 5db778affe Auto merge of #74131 - ollie27:rustdoc_invalid_codeblock_attributes_name, r=GuillaumeGomez
rustdoc: Rename invalid_codeblock_attribute lint to be plural

Lint names should be plural as per the lint naming conventions: https://github.com/rust-lang/rfcs/blob/master/text/0344-conventions-galore.md#lints

r? @GuillaumeGomez
2020-07-09 07:00:27 +00:00
Oliver Middleton 56fb71786a rustdoc: Rename invalid_codeblock_attribute lint to be plural 2020-07-07 18:29:26 +01:00
Eduard-Mihai Burtescu f07100afc8 Use for<'tcx> fn pointers in Providers, instead of having Providers<'tcx>. 2020-07-05 23:00:14 +03:00
Eduard-Mihai Burtescu 874f406ffd Use 'tcx for references to AccessLevels wherever possible. 2020-07-03 00:04:48 +03:00
Eduard-Mihai Burtescu 547be8c249 rustc_lint: avoid using TypeckTables::empty for LateContext. 2020-07-02 16:51:04 +03:00
Bastian Kauschke 71b45b97d3 change `skip_binder` to use T by value 2020-06-30 09:13:56 +02:00
Manish Goregaokar 8b92eecbc2
Rollup merge of #73817 - jumbatm:rename-to-clashing-extern-declarations, r=petrochenkov
Rename clashing_extern_decl to clashing_extern_declarations.

Rename clashing_extern_decl to clashing_extern_declarations to bring in-line with lint naming conventions.

Fixes #73802.

r? @petrochenkov
2020-06-28 08:30:33 -07:00
Manish Goregaokar d5205f23d3
Rollup merge of #73758 - davidtwco:issue-60855-remaining-reveal-all, r=matthewjasper
improper_ctypes: fix remaining `Reveal:All`

Fixes #60855.

This PR replaces the remaining uses of `ParamEnv::reveal_all` with `LateContext`'s `param_env` (normally `Reveal::UserFacing`) in the improper ctypes lint.
2020-06-27 22:29:59 -07:00
jumbatm c72a5dd9d3 Rename the lint to clashing_extern_declarations.
Also, run RustFmt on the clashing_extern_fn test case and update
stderrs.
2020-06-28 10:11:29 +10:00
David Wood a6417b9c38
improper_ctypes: fix remaining `Reveal:All`
This commit replaces the remaining uses of `ParamEnv::reveal_all` with
`LateContext`'s `param_env` (normally `Reveal::UserFacing`).

Signed-off-by: David Wood <david@davidtw.co>
2020-06-26 11:21:31 +01:00
bors 14e65d5e95 Auto merge of #73743 - eddyb:lint-on-demand-typeck-tables, r=Manishearth
rustc_lint: only query `typeck_tables_of` when a lint needs it.

This was prompted by @jyn514 running into a situation where `rustdoc` wants to run the `unused_doc` lint without triggering type-checking (as an alternative to the "everybody loops" approach - type-checking may error/ICE because of the `rustdoc` feature of allowing multi-platform docs where the actual bodies of functions may refer to APIs for different platforms).

There was also this comment in the source:
```rust
// FIXME: Make this lazy to avoid running the TypeckTables query?
```

The main effect of this is for lint authors, who now need to use `cx.tables()` to get `&TypeckTables`, as opposed to having them always available in `cx.tables`.

r? @oli-obk or @Manishearth
2020-06-26 06:11:01 +00:00
Manish Goregaokar 23c9ac6b73
Rollup merge of #72770 - crlf0710:mixed_script_confusable, r=Manishearth
Implement mixed script confusable lint.

This implements the mixed script confusable lint defined in RFC 2457.
This is blocked on #72069 and https://github.com/unicode-rs/unicode-security/pull/13, and will need a Cargo.toml version bump after those are resolved.

The lint message warning is sub-optimal for now. We'll need a mechanism to properly output  `AugmentScriptSet` to screen, this is to be added in `unicode-security` crate.

r? @Manishearth
2020-06-25 18:00:05 -07:00
Eduard-Mihai Burtescu 0cf4b9de68 rustc_lint: only query `typeck_tables_of` when a lint needs it. 2020-06-26 02:56:23 +03:00
Charles Lew 25e864e198 Implement mixed script confusable lint. 2020-06-26 01:39:31 +08:00
David Wood 4504648090
improper_ctypes: only allow params in defns mode
This commit adjusts the behaviour introduced in a previous commit so
that generic parameters and projections are only allowed in the
definitions mode - and are otherwise a bug. Generic parameters in
declarations are prohibited earlier in the compiler, so if that branch
were reached, it would be a bug.

Signed-off-by: David Wood <david@davidtw.co>
2020-06-24 12:09:39 +01:00
David Wood 5c8634805c
improper_ctypes: allow pointers to sized types
This commit changes the improper ctypes lint (when operating on
definitions) to consider raw pointers or references to sized types as
FFI-safe.

Signed-off-by: David Wood <david@davidtw.co>
2020-06-24 12:09:37 +01:00
David Wood 14ea7a777f
lints: add `improper_ctypes_definitions`
This commit adds a new lint - `improper_ctypes_definitions` - which
functions identically to `improper_ctypes`, but on `extern "C" fn`
definitions (as opposed to `improper_ctypes`'s `extern "C" {}`
declarations).

Signed-off-by: David Wood <david@davidtw.co>
2020-06-24 12:09:35 +01:00
Charles Lew ef24faf130 Refactor non_ascii_idents lints, exclude ascii pair for confusable_idents lint. 2020-06-23 00:06:14 +08:00
Ralf Jung 1c74ab4226 Make is_freeze and is_copy_modulo_regions take TyCtxtAt 2020-06-21 11:47:19 +02:00
bors 228a0ed7b0 Auto merge of #70946 - jumbatm:clashing-extern-decl, r=nagisa
Add a lint to catch clashing `extern` fn declarations.

Closes #69390.

Adds lint `clashing_extern_decl` to detect when, within a single crate, an extern function of the same name is declared with different types. Because two symbols of the same name cannot be resolved to two different functions at link time, and one function cannot possibly have two types, a clashing extern declaration is almost certainly a mistake.

This lint does not run between crates because a project may have dependencies which both rely on the same extern function, but declare it in a different (but valid) way. For example, they may both declare an opaque type for one or more of the arguments (which would end up distinct types), or use types that are valid conversions in the language the extern fn is defined in. In these cases, we can't say that the clashing declaration is incorrect.

r? @eddyb
2020-06-21 02:20:07 +00:00
David Wood 2e781ddacc
lint: normalize projections using opaque types
This commit normalizes projections which contain opaque types (opaque types
are otherwise linted against, which is would have previously made the
test cases added in this commit fail).

Signed-off-by: David Wood <david@davidtw.co>
2020-06-20 12:07:23 +01:00
jumbatm 6b74e3cbb9 Add ClashingExternDecl lint.
This lint checks that all declarations for extern fns of the same name
are declared with the same types.
2020-06-20 16:54:32 +10:00
Manish Goregaokar 058971cef3
Rollup merge of #73300 - crlf0710:crate_level_only_check, r=petrochenkov
Implement crate-level-only lints checking.

This implements a crate_level_only flag on lints, and when it is true, it becomes an error when user tries  to specify this flag upon nodes other than crate node.

This also turns on this flag for all non_ascii_ident lints.
2020-06-19 09:15:08 -07:00
Manish Goregaokar 17064dae1a
Rollup merge of #73257 - davidtwco:issue-73249-improper-ctypes-projection, r=lcnr,varkor
ty: projections in `transparent_newtype_field`

Fixes #73249.

This PR modifies `transparent_newtype_field` so that it handles
projections with generic parameters, where `normalize_erasing_regions`
would ICE.
2020-06-19 09:15:04 -07:00
David Wood a730d888ae
ty: simplify `transparent_newtype_field`
This commit removes the normalization from `transparent_newtype_field` -
turns out it wasn't necessary and that makes it a bunch simpler -
particularly when handling projections.

Signed-off-by: David Wood <david@davidtw.co>
2020-06-19 11:16:16 +01:00
David Wood 0cccaa0a27
lint: unify enum variant, union and struct logic
This commit applies the changes introduced in #72890 to both enum
variants and unions - where the logic prior to #72890 was duplicated.

Signed-off-by: David Wood <david@davidtw.co>
2020-06-19 11:16:14 +01:00
David Wood 76ad38d992
lint: prohibit fields with opaque types
Opaque types cannot be used in extern declarations, and normally cannot
exist in fields - except with type aliases to `impl Trait` and
projections which normalize to them.

Signed-off-by: David Wood <david@davidtw.co>
2020-06-19 11:16:12 +01:00
Ralf Jung 5e7eec2eaa
Rollup merge of #72497 - RalfJung:tag-term, r=oli-obk
tag/niche terminology cleanup

The term "discriminant" was used in two ways throughout the compiler:
* every enum variant has a corresponding discriminant, that can be given explicitly with `Variant = N`.
* that discriminant is then encoded in memory to store which variant is active -- but this encoded form of the discriminant was also often called "discriminant", even though it is conceptually quite different (e.g., it can be smaller in size, or even use niche-filling).

After discussion with @eddyb, this renames the second term to "tag". The way the tag is encoded can be either `TagEncoding::Direct` (formerly `DiscriminantKind::Tag`) or `TagEncoding::Niche` (formerly `DiscrimianntKind::Niche`).

This finally resolves some long-standing confusion I had about the handling of variant indices and discriminants, which surfaced in https://github.com/rust-lang/rust/pull/72419.

(There is also a `DiscriminantKind` type in libcore, it remains unaffected. I think this corresponds to the discriminant, not the tag, so that seems all right.)

r? @eddyb
2020-06-19 08:56:02 +02:00
Charles Lew f633dd385f Implement crate level only lints checking. 2020-06-18 09:53:12 +08:00
mark 268decbac8 make all uses of ty::Error or ConstKind::Error delay a span bug 2020-06-15 18:25:58 -05:00
bors ce6d3a73b5 Auto merge of #72080 - matthewjasper:uniform-impl-trait, r=nikomatsakis
Clean up type alias impl trait implementation

- Removes special case for top-level impl trait
- Removes associated opaque types
- Forbid lifetime elision in let position impl trait. This is consistent with the behavior for inferred types.
- Handle lifetimes in type alias impl trait more uniformly with other parameters

cc #69323
cc #63063
Closes #57188
Closes #62988
Closes #69136
Closes #73061
2020-06-15 04:10:24 +00:00
Dylan DPC c06799e4c4
Rollup merge of #72906 - lzutao:migrate-numeric-assoc-consts, r=dtolnay
Migrate to numeric associated consts

The deprecation PR is #72885

cc #68490
cc rust-lang/rfcs#2700
2020-06-12 12:28:23 +02:00
Dylan DPC 84b9145076
Rollup merge of #73182 - Aaron1011:feature/call-fn-span, r=matthewjasper
Track span of function in method calls, and use this in #[track_caller]

Fixes #69977

When we parse a chain of method calls like `foo.a().b().c()`, each
`MethodCallExpr` gets assigned a span that starts at the beginning of
the call chain (`foo`). While this is useful for diagnostics, it means
that `Location::caller` will return the same location for every call
in a call chain.

This PR makes us separately record the span of the function name and
arguments for a method call (e.g. `b()` in `foo.a().b().c()`). This
`Span` is passed through HIR lowering and MIR building to
`TerminatorKind::Call`, where it is used in preference to
`Terminator.source_info.span` when determining `Location::caller`.

This new span is also useful for diagnostics where we want to emphasize
a particular method call - for an example, see
https://github.com/rust-lang/rust/pull/72389#discussion_r436035990
2020-06-11 19:04:16 +02:00
Matthew Jasper ee0d3c7f90 Rename `TyKind::Def` to `OpaqueDef` 2020-06-11 17:08:23 +01:00
Matthew Jasper 4e49e67c44 Stop special casing top level TAIT 2020-06-11 16:24:01 +01:00
Aaron Hill 28946b3486
Track span of function in method calls, and use this in #[track_caller]
Fixes #69977

When we parse a chain of method calls like `foo.a().b().c()`, each
`MethodCallExpr` gets assigned a span that starts at the beginning of
the call chain (`foo`). While this is useful for diagnostics, it means
that `Location::caller` will return the same location for every call
in a call chain.

This PR makes us separately record the span of the function name and
arguments for a method call (e.g. `b()` in `foo.a().b().c()`). This
`Span` is passed through HIR lowering and MIR building to
`TerminatorKind::Call`, where it is used in preference to
`Terminator.source_info.span` when determining `Location::caller`.

This new span is also useful for diagnostics where we want to emphasize
a particular method call - for an example, see
https://github.com/rust-lang/rust/pull/72389#discussion_r436035990
2020-06-10 17:30:11 -04:00
Lzu Tao fff822fead Migrate to numeric associated consts 2020-06-10 01:35:47 +00:00
David Wood d4d3d7de68
lint: transitive FFI-safety for transparent types
This commit ensures that if a `repr(transparent)` newtype's only
non-zero-sized field is FFI-safe then the newtype is also FFI-safe.

Previously, ZSTs were ignored for the purposes of linting FFI-safety
in transparent structs - thus, only the single non-ZST would be checked
for FFI-safety. However, if the non-zero-sized field is a generic
parameter, and is substituted for a ZST, then the type would be
considered FFI-unsafe (as when every field is thought to be zero-sized,
the type is considered to be "composed only of `PhantomData`" which is
FFI-unsafe).

In this commit, for transparent structs, the non-zero-sized field is
identified (before any substitutions are applied, necessarily) and then
that field's type (now with substitutions) is checked for FFI-safety
(where previously it would have been skipped for being zero-sized in
this case).

To handle the case where the non-zero-sized field is a generic
parameter, which is substituted for `()` (a ZST), and is being used
as a return type - the `FfiUnsafe` result (previously `FfiPhantom`) is
caught and silenced.

Signed-off-by: David Wood <david@davidtw.co>
2020-06-09 14:37:08 +01:00