Commit graph

213 commits

Author SHA1 Message Date
Vadim Petrochenkov
b25d3ba781 ast/hir: Rename field-related structures
StructField -> FieldDef ("field definition")
Field -> ExprField ("expression field", not "field expression")
FieldPat -> PatField ("pattern field", not "field pattern")

Also rename visiting and other methods working on them.
2021-03-16 11:41:24 +03:00
Dylan DPC
75a15bf275
Rollup merge of #83098 - camelid:more-doc-attr-check, r=davidtwco
Find more invalid doc attributes

- Lint on `#[doc(123)]`, `#[doc("hello")]`, etc.
- Lint every attribute; e.g., will now report two warnings for `#[doc(foo, bar)]`
- Add hyphen to "crate level"
- Display paths like `#[doc(foo::bar)]` correctly instead of as an empty string
2021-03-15 16:22:52 +01:00
Camelid
8f40e1180f Use pretty-printer instead of span_to_snippet 2021-03-14 14:39:25 -07:00
Camelid
13076f90d2 Tweak diagnostics
- Tweak lint message
- Display multi-segment paths correctly
2021-03-14 14:00:02 -07:00
Camelid
5134047c40 Add hyphen to "crate level"
"crate level attribute" -> "crate-level attribute"
2021-03-13 16:29:49 -08:00
Camelid
7e972a39b8 Report error for each invalid nested attribute 2021-03-13 13:55:15 -08:00
Camelid
7189c05bf8 Lint non-meta doc attributes
E.g., `#[doc(123)]`.
2021-03-13 13:25:27 -08:00
Camelid
9613a88db5 Refactor check_doc_attrs body
This change makes it easier to follow the control flow.

I also moved the end-of-line comments attached to some symbols to before
the symbol listing. This allows rustfmt to format the code; otherwise no
formatting occurs (see rust-lang/rustfmt#4750).
2021-03-13 13:13:27 -08:00
Tomasz Miąsko
49431909a6 Validate rustc_layout_scalar_valid_range_{start,end} attributes 2021-03-11 00:00:00 +00:00
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