Commit Graph

203 Commits

Author SHA1 Message Date
Camille GILLOT 27ef0eeaa4 Track HirId when visiting attributes. 2021-03-09 19:27:59 +01:00
Camille GILLOT c701872a6c Remove hir::Item::attrs. 2021-03-09 19:27:50 +01:00
Camille GILLOT 4bab93a039 Remove hir::ForeignItem::attrs. 2021-03-09 19:23:07 +01:00
Camille GILLOT a987bbb97c Remove hir::Crate::attrs. 2021-03-09 19:22:55 +01:00
Camille GILLOT 8e816056a5 Do not store attrs in FnKind. 2021-03-09 19:09:33 +01:00
Camille GILLOT 99ba08e6d3 Access attrs directly from HirId in rustc_passes::diagnostic_item. 2021-03-09 19:09:32 +01:00
Camille GILLOT 260aa9f554 Access attrs directly from HirId in rustc_passes::lang_items. 2021-03-09 19:09:31 +01:00
Camille GILLOT a50454d6c8 Access attrs directly from HirId in rustc_passes::dead. 2021-03-09 19:09:30 +01:00
Camille GILLOT f8514aaa56 Access attrs directly from HirId in rustc_passes::stability. 2021-03-09 19:09:06 +01:00
Camille GILLOT 7b1dd1a9e8 Access attrs directly from HirId in rustc_passes::check_attr. 2021-03-09 18:51:37 +01:00
Yuki Okushi f3218dfa57
Rollup merge of #82651 - jyn514:rustdoc-warnings, r=GuillaumeGomez
Cleanup rustdoc warnings

## Clean up error reporting for deprecated passes

Using `error!` here goes all the way back to the original commit, https://github.com/rust-lang/rust/pull/8540. I don't see any reason to use logging; rustdoc should use diagnostics wherever possible. See https://github.com/rust-lang/rust/pull/81932#issuecomment-785291244 for further context.

- Use spans for deprecated attributes
- Use a proper diagnostic for unknown passes, instead of error logging
- Add tests for unknown passes
- Improve some wording in diagnostics

##  Report that `doc(plugins)` doesn't work using diagnostics instead of `eprintln!`

This also adds a test for the output.

This was added in https://github.com/rust-lang/rust/pull/52194. I don't see any particular reason not to use diagnostics here, I think it was just missed in https://github.com/rust-lang/rust/pull/50541.
2021-03-07 10:41:13 +09:00
Guillaume Gomez 8867f7f650
Rollup merge of #82708 - GuillaumeGomez:doc-test-attr-check, r=Manishearth
Warn on `#![doc(test(...))]` on items other than the crate root and use future incompatible lint

Part of #82672.

This PR does multiple things:
 * Create a new `INVALID_DOC_ATTRIBUTE` lint which is also "future incompatible", allowing us to use it as a warning for the moment until it turns (eventually) into a hard error.
 * Use this link when `#![doc(test(...))]` isn't used at the crate level.
 * Make #82702 use this new lint as well.

r? ``@jyn514``
2021-03-05 21:44:38 +01:00
Guillaume Gomez a11e87e74d Make invalid_doc_attribute lint plural 2021-03-05 14:44:31 +01:00
bors a0d66b54fb Auto merge of #71481 - estebank:inherit-stability, r=nikomatsakis
Inherit `#[stable(..)]` annotations in enum variants and fields from its item

Lint changes for #65515. The stdlib will have to be updated once this lands in beta and that version is promoted in master.
2021-03-05 05:28:07 +00:00
Guillaume Gomez 55cec9079d Also use INVALID_DOC_ATTRIBUTE for "unknown doc attribute" warnings 2021-03-04 21:48:07 +01:00
Guillaume Gomez a66bf524c2 Add extra check for #[doc(test(...)] attribute 2021-03-04 21:24:35 +01:00
Joshua Nelson 4b2e4e69df Change error about unknown doc attributes to a warning
This prevents breakage across the ecosystem, since the error was just
introduced recently without first having a warning period.
2021-03-03 10:04:36 -05:00
Joshua Nelson d5c300b1f2 Report that `doc(plugins)` doesn't work using diagnostics instead of `println!`
This also adds a test for the output and fixes `rustc_attr` to properly
know that `plugins` is a valid attribute.
2021-03-02 11:38:07 -05:00
Guillaume Gomez 0c6b69aa70
Rollup merge of #82662 - GuillaumeGomez:doc-attr-check, r=jyn514
Warn about unknown doc attributes

Fixes #82652.

For the text error, I decided to go for "invalid" instead of "unknown". What do you think?

r? `@jyn514`
2021-03-02 00:50:10 +01:00
Guillaume Gomez b0b330f143 Validate meta items used in \#\[doc(...)\] 2021-03-01 20:26:28 +01:00
Giacomo Stevanato 2f8fa012ca Use identifier's span in unused lint 2021-02-28 23:21:18 +01:00
Guillaume Gomez 75959fb356
Rollup merge of #82506 - estebank:unused_variable_lint, r=lcnr
Properly account for non-shorthand pattern field in unused variable lint

Fix #82488
2021-02-26 15:52:33 +01:00
bors 98f8cce6db Auto merge of #82447 - Amanieu:legacy_const_generics, r=oli-obk
Add #[rustc_legacy_const_generics]

This is the first step towards removing `#[rustc_args_required_const]`: a new attribute is added which rewrites function calls of the form `func(a, b, c)` to `func::<{b}>(a, c)`. This allows previously stabilized functions in `stdarch` which use `rustc_args_required_const` to use const generics instead.

This new attribute is not intended to ever be stabilized, it is only intended for use in `stdarch` as a replacement for `#[rustc_args_required_const]`.

```rust
#[rustc_legacy_const_generics(1)]
pub fn foo<const Y: usize>(x: usize, z: usize) -> [usize; 3] {
    [x, Y, z]
}

fn main() {
    assert_eq!(foo(0 + 0, 1 + 1, 2 + 2), [0, 2, 4]);
    assert_eq!(foo::<{1 + 1}>(0 + 0, 2 + 2), [0, 2, 4]);
}
```

r? `@oli-obk`
2021-02-25 18:14:50 +00:00
Amanieu d'Antras 00afbe70f2 Improve checking for attribute 2021-02-25 09:04:43 +00:00
Esteban Küber fb24a10ad3 Properly account for non-shorthand pattern field in unused variable lint
Fix #82488
2021-02-24 18:08:37 -08:00
Amanieu d'Antras 2451f124c9 Address review comments 2021-02-25 00:09:33 +00:00
Amanieu d'Antras d87eec1bf6 Add #[rustc_legacy_const_generics] 2021-02-23 17:25:55 +00:00
Dylan DPC 9d378b33de
Rollup merge of #82297 - tmiasko:write-only, r=oli-obk
Consider auto derefs before warning about write only fields

Changes from #81473 extended the dead code lint with an ability to detect
fields that are written to but never read from. The implementation skips
over fields on the left hand side of an assignment, without marking them
as live.

A field access might involve an automatic dereference and de-facto read
the field. Conservatively mark expressions with deref adjustments as
live to avoid generating false positive warnings.

Closes #81626.
2021-02-23 16:10:25 +01:00
Dylan DPC 2982ba50fc
Rollup merge of #82258 - tmiasko:foreign-hir-stats, r=davidtwco
Implement -Z hir-stats for nested foreign items

An attempt to compute HIR stats for crates with nested foreign items results in an ICE.

```rust
fn main() {
    extern "C" { fn f(); }
}
```

```
thread 'rustc' panicked at 'visit_nested_xxx must be manually implemented in this visitor'
```

Provide required implementation of visitor method.
2021-02-23 16:10:22 +01:00
Matthias Krüger da9a588d4f remove redundant wrapping of return types of allow_internal_unstable() and rustc_allow_const_fn_unstable() 2021-02-21 18:11:27 +01:00
Dylan DPC 30f39fee9d
Rollup merge of #82238 - petrochenkov:nocratemod, r=Aaron1011
ast: Keep expansion status for out-of-line module items

I.e. whether a module `mod foo;` is already loaded from a file or not.
This is a pre-requisite to correctly treating inner attributes on such modules (https://github.com/rust-lang/rust/issues/81661).

With this change AST structures for `mod` items diverge even more for AST structure for the crate root, which previously used `ast::Mod`.
Therefore this PR removes `ast::Mod` from `ast::Crate` in the first commit, these two things are sufficiently different from each other, at least at syntactic level.
Customization points for visiting a "`mod` item or crate root" were also removed from AST visitors (`fn visit_mod`).
`ast::Mod` itself was refactored away in the second commit in favor of `ItemKind::Mod(Unsafe, ModKind)`.
2021-02-19 02:49:08 +01:00
Tomasz Miąsko 343b673877 Consider auto derefs before warning about write only fields
Changes from 81473 extended the dead code lint with an ability to detect
fields that are written to but never read from. The implementation skips
over fields on the left hand side of an assignment, without marking them
as live.

A field access might involve an automatic dereference and de-facto read
the field. Conservatively mark expressions with deref adjustments as
live to avoid generating false positive warnings.
2021-02-19 00:00:00 +00:00
Dylan DPC efdcb4301b
Rollup merge of #82256 - eddyb:time-passes-stderr, r=varkor
Print -Ztime-passes (and misc stats/logs) on stderr, not stdout.

I've tried not to change anything that looked similar to `rustc --print`, where people might use automation, and/or any "bulk" prints, such as dumping an entire Graphviz (`dot`) graph on stdout.

The reason I want `-Ztime-passes` to be on stderr like debug logging is I can get a complete (and correctly interleaved) view just by looking at stderr, which is merely a convenience when running `rustc`/Cargo directly, but even more important when it's nested in a build script, as Cargo will split the build script output into stdout (named `output`) and `stderr`.
2021-02-18 16:57:43 +01:00
Eduard-Mihai Burtescu 6165d1cc72 Print -Ztime-passes (and misc stats/logs) on stderr, not stdout. 2021-02-18 14:13:38 +02:00
Vadim Petrochenkov eb65f15c78 ast: Stop using `Mod` in `Crate`
Crate root is sufficiently different from `mod` items, at least at syntactic level.

Also remove customization point for "`mod` item or crate root" from AST visitors.
2021-02-18 13:07:49 +03:00
Tomasz Miąsko bf09e0499e Implement -Z hir-stats for nested foreign items
An attempt to compute HIR stats for crates with nested foreign items results in an ICE.

```
fn main() {
    extern "C" { fn f(); }
}
```

```
thread 'rustc' panicked at 'visit_nested_xxx must be manually implemented in this visitor'
```

Provide required implementation of visitor method.
2021-02-18 00:00:00 +00:00
Takayuki Maeda 0f04875d2e replace if-let and while-let with `if let` and `while let` 2021-02-17 19:26:38 +09:00
Camille GILLOT f395f2ea12 Use less HirId when referring to items. 2021-02-15 19:36:12 +01:00
Camille GILLOT c4e7427081 Only store a LocalDefId in hir::MacroDef. 2021-02-15 19:35:55 +01:00
Camille GILLOT ff14cac621 Index Modules using their LocalDefId. 2021-02-15 19:32:30 +01:00
Camille GILLOT 996dc8d5c5 Only store a LocalDefId in hir::ForeignItem. 2021-02-15 19:32:29 +01:00
Camille GILLOT 786a80e9ea Only store a LocalDefId in hir::ImplItem. 2021-02-15 19:32:29 +01:00
Camille GILLOT a871a0f111 Only store a LocalDefId in hir::TraitItem. 2021-02-15 19:32:28 +01:00
Camille GILLOT cebbba081e Only store a LocalDefId in hir::Item.
Items are guaranteed to be HIR owner.
2021-02-15 19:32:10 +01:00
Camille GILLOT c676e358a5 Use ItemId as a strongly typed index. 2021-02-15 19:24:58 +01:00
Dylan DPC ac1d26bcd3
Rollup merge of #80920 - rylev:check_attr-refactor, r=davidtwco
Visit more targets when validating attributes

This begins to address #80048, allowing for additional validation of attributes.

There are more refactorings that can be done, though I think they should be tackled in additional PRs:
* ICE when a builtin attribute is encountered that is not checked
* Move some of the attr checking done `ast_validation` into `rustc_passes`
  * note that this requires a bit of additional refactoring, especially of extern items which currently parse attributes (and thus are a part of the AST) but do not possess attributes in their HIR representation.
* Rename `Target` to `AttributeTarget`
* Refactor attribute validation completely to go through `Visitor::visit_attribute`.
  * This would require at a minimum passing `Target` into this method which might be too big of a refactoring to be worth it.
  * It's also likely not possible to do all the validation this way as some validation requires knowing what other attributes a target has.

r? `@davidtwco`
2021-02-14 16:54:42 +01:00
Esteban Küber 19806e4514 Tweak stability attribute diagnostic output 2021-02-10 21:35:27 -08:00
Esteban Küber 4cb089bb54 Inherit `#[stable(..)]` annotations in enum variants and fields from its item 2021-02-10 19:10:14 -08:00
Ryan Levick 396022b90b Visit more targets when checking attrs 2021-02-09 21:54:46 +01:00
Ömer Sinan Ağacan c4e3558b8c Rename HIR UnOp variants
This renames the variants in HIR UnOp from

    enum UnOp {
        UnDeref,
        UnNot,
        UnNeg,
    }

to

    enum UnOp {
        Deref,
        Not,
        Neg,
    }

Motivations:

- This is more consistent with the rest of the code base where most enum
  variants don't have a prefix.

- These variants are never used without the `UnOp` prefix so the extra
  `Un` prefix doesn't help with readability. E.g. we don't have any
  `UnDeref`s in the code, we only have `UnOp::UnDeref`.

- MIR `UnOp` type variants don't have a prefix so this is more
  consistent with MIR types.

- "un" prefix reads like "inverse" or "reverse", so as a beginner in
  rustc code base when I see "UnDeref" what comes to my mind is
  something like "&*" instead of just "*".
2021-02-09 11:39:20 +03:00