Commit Graph

755 Commits

Author SHA1 Message Date
Dylan DPC
5d55009b79
Rollup merge of #101142 - nnethercote:improve-hir-stats, r=davidtwco
Improve HIR stats

#100398 improve the AST stats collection done by `-Zhir-stats`. This PR does the same for HIR stats collection.

r? `@davidtwco`
2022-09-05 14:15:51 +05:30
Camille GILLOT
e7164267a2 Do not call object_lifetime_default on lifetime params. 2022-09-03 21:11:42 +02:00
bors
8c6ce6b91b Auto merge of #97802 - Enselic:add-no_ignore_sigkill-feature, r=joshtriplett
Support `#[unix_sigpipe = "inherit|sig_dfl"]` on `fn main()` to prevent ignoring `SIGPIPE`

When enabled, programs don't have to explicitly handle `ErrorKind::BrokenPipe` any longer. Currently, the program

```rust
fn main() { loop { println!("hello world"); } }
```

will print an error if used with a short-lived pipe, e.g.

    % ./main | head -n 1
    hello world
    thread 'main' panicked at 'failed printing to stdout: Broken pipe (os error 32)', library/std/src/io/stdio.rs:1016:9
    note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

by enabling `#[unix_sigpipe = "sig_dfl"]` like this

```rust
#![feature(unix_sigpipe)]
#[unix_sigpipe = "sig_dfl"]
fn main() { loop { println!("hello world"); } }
```

there is no error, because `SIGPIPE` will not be ignored and thus the program will be killed appropriately:

    % ./main | head -n 1
    hello world

The current libstd behaviour of ignoring `SIGPIPE` before `fn main()` can be explicitly requested by using `#[unix_sigpipe = "sig_ign"]`.

With `#[unix_sigpipe = "inherit"]`, no change at all is made to `SIGPIPE`, which typically means the behaviour will be the same as `#[unix_sigpipe = "sig_dfl"]`.

See https://github.com/rust-lang/rust/issues/62569 and referenced issues for discussions regarding the `SIGPIPE` problem itself

See the [this](https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Proposal.3A.20First.20step.20towards.20solving.20the.20SIGPIPE.20problem) Zulip topic for more discussions, including about this PR.

Tracking issue: https://github.com/rust-lang/rust/issues/97889
2022-09-02 21:08:08 +00:00
Matthias Krüger
5a23efd31e
Rollup merge of #101215 - est31:rustdoc_version_placeholder, r=Mark-Simulacrum
Also replace the version placeholder in rustc_attr

Replace the version placeholder with the current version in the rustc_attr crate too so that users won't see the placeholder but instead the explicit version. This especially fixes the bug for rustdoc not showing it but instead the placeholder.

Originally reported [here](https://rust-lang.zulipchat.com/#narrow/stream/241545-t-release/topic/libs.20stabilization.20placeholder/near/296057188).

cc #100591

![Screenshot_20220830_233727](https://user-images.githubusercontent.com/8872119/187548079-6207776b-4481-4351-afff-607f5b3fe03a.png)
2022-09-02 18:22:01 +02:00
est31
0c4ec5df58 Also replace the version placeholder in rustc_attr
This fixes rustdoc not showing the current version as stabilization version
for recently stabilized lang features.
2022-09-02 01:47:01 +02:00
Oli Scherer
d3b22c7267 Directly use the instrument macro instead of its full path 2022-09-01 14:53:46 +00:00
Dezhi Wu
b1430fb7ca Fix a bunch of typo
This PR will fix some typos detected by [typos].

I only picked the ones I was sure were spelling errors to fix, mostly in
the comments.

[typos]: https://github.com/crate-ci/typos
2022-08-31 18:24:55 +08:00
Dylan DPC
467d2c1833
Rollup merge of #100941 - lyming2007:issue-100584, r=oli-obk
Point at the string inside literal and mention if we need string inte…

…rpolation

	modified:   compiler/rustc_passes/src/liveness.rs
2022-08-30 16:56:10 +05:30
bors
a0d07093f8 Auto merge of #100812 - Nilstrieb:revert-let-chains-nightly, r=Mark-Simulacrum
Revert let_chains stabilization

This is the revert against master, the beta revert was already done in #100538.

Bumps the stage0 compiler which already has it reverted.
2022-08-30 05:48:22 +00:00
Yiming Lei
39ffabbb40 Point at the string inside literal and mention if we need string interpolation
modified:   compiler/rustc_passes/src/liveness.rs

	new file:   src/test/ui/type/issue-100584.rs
	new file:   src/test/ui/type/issue-100584.stderr
2022-08-29 11:58:20 -07:00
Nilstrieb
d1ef8180f9 Revert let_chains stabilization
This reverts commit 3266460749.

This is the revert against master, the beta revert was already done in #100538.
2022-08-29 19:34:11 +02:00
Dylan DPC
5555e13a6e
Rollup merge of #99821 - cjgillot:ast-lifetimes-2, r=compiler-errors
Remove separate indexing of early-bound regions

~Based on https://github.com/rust-lang/rust/pull/99728.~

This PR copies some modifications from https://github.com/rust-lang/rust/pull/97839 around object lifetime defaults.
These modifications allow to stop counting generic parameters during lifetime resolution, and rely on the indexing given by `rustc_typeck::collect`.
2022-08-29 16:49:39 +05:30
Matthias Krüger
6667754694
Rollup merge of #100959 - LuisCardosoOliveira:translation-rename-attr-warning, r=davidtwco
translations: rename warn_ to warning

## Description

This MR renames the the macro `warn_` to `warning`.

To give a little bit of context, as [explained](https://rust-lang.zulipchat.com/#narrow/stream/336883-i18n/topic/.23100717.20diag.20translation/near/295074146) by ```````@davidtwco``````` in the Zulip channel, `warn_`  was named like that because the keyword `warn` is a built-in attribute and at the time this macro was created the word `warning` was also
taken.

However, it is no longer the case and we can rename `warn_` to `warning`.
2022-08-29 06:34:47 +02:00
Nicholas Nethercote
f26fdce991 Improve HIR stats collector.
Adds and removes some `visit_*` methods accordingly, improving
coverage, and avoiding some double counting. Brings it in line with the
AST stats collector.
2022-08-29 14:16:53 +10:00
Nicholas Nethercote
ad7b4d5d22 Move a comment to the right place.
This comment on the HIR `visit_path_segment` is supposed be on the AST
`visit_path_segment`.
2022-08-29 11:13:36 +10:00
Nicholas Nethercote
9ee0192095 Add prefix to every line of -Zhir-stats output.
This is based on `-Zprint-type-sizes` which does the same thing. It
makes the output provenance clearer, and helps with post-processing.
E.g. if you have `-Zhir-stats` output from numerous compiler invocations
you can now easily extract the pre-expansion stats separately from the
post-expansion stats.
2022-08-29 06:35:14 +10:00
Martin Nordholts
ddee45e1d7 Support #[unix_sigpipe = "inherit|sig_dfl|sig_ign"] on fn main()
This makes it possible to instruct libstd to never touch the signal
handler for `SIGPIPE`, which makes programs pipeable by default (e.g.
with `./your-program | head -n 1`) without `ErrorKind::BrokenPipe`
errors.
2022-08-28 19:46:45 +02:00
est31
7a5b1d7939 Expand the version placeholder to the current version in stability attribute parsing
That way, the current version is shown in rustdoc etc.
2022-08-27 17:08:52 +02:00
Luis Cardoso
b508b50617 translations: rename warn_ to warning
The macro warn_ was named like that because it the
keyword warn is a built-in attribute and at the time
this macro was created the word 'warning' was also
taken.

However it is no longer the case and we can rename
warn_ to warning.
2022-08-24 19:12:36 +02:00
Seo Sanghyeon
f280138c7c Use par_body_owners for liveness 2022-08-23 20:53:02 +09:00
Xiretza
7f3a6fd7f6 Replace #[lint/warning/error] with #[diag] 2022-08-21 09:17:43 +02:00
Xiretza
bd0d3f745d Disallow #[primary_span] on LintDiagnostics 2022-08-21 09:17:43 +02:00
Matthias Krüger
710bd23df1
Rollup merge of #100031 - GoldsteinE:try-removing-the-field, r=michaelwoerister
improve "try ignoring the field" diagnostic

Closes #95795
2022-08-15 20:11:32 +02:00
bors
6ce76091c7 Auto merge of #96745 - ehuss:even-more-attribute-validation, r=cjgillot
Visit attributes in more places.

This adds 3 loosely related changes (I can split PRs if desired):

- Attribute checking on pattern struct fields.
- Attribute checking on struct expression fields.
- Lint level visiting on pattern struct fields, struct expression fields, and generic parameters.

There are still some lints which ignore lint levels in various positions. This is a consequence of how the lints themselves are implemented. For example, lint levels on associated consts don't work with `unused_braces`.
2022-08-15 05:50:54 +00:00
Michael Goulet
d46451ce2c
Rollup merge of #100431 - compiler-errors:enum-ctor-variant-stab, r=estebank
Enum variant ctor inherits the stability of the enum variant

Fixes #100399
Fixes #100420

Context #71481 for why enum variants don't need stability
2022-08-13 21:06:50 -07:00
Mark Rousskov
154a09dd91 Adjust cfgs 2022-08-12 16:28:15 -04:00
Michael Goulet
6925f4101b Check ctor for missing stability 2022-08-12 15:16:28 +00:00
Michael Goulet
b821ce6097 enum variant ctor inherits stability of variant 2022-08-12 15:15:36 +00:00
bors
0068b8bf4b Auto merge of #100328 - davidtwco:perf-implications, r=nnethercote
passes: load `defined_lib_features` query less

Hopefully addresses the perf regressions from #99212 (see #99905).

Re-structure the stability checks for library features to avoid calling `defined_lib_features` for any more crates than necessary for each of the implications or local feature attributes that need validation.

r? `@ghost` (just checking perf at first)
2022-08-12 13:51:26 +00:00
Goldstein
3fb249bebc
improve "try ignoring the field" diagnostic
Closes #95795
2022-08-12 12:32:43 +03:00
Eric Huss
dcd5177fd4 Add visitors for PatField and ExprField.
This helps simplify the code. It also fixes it to use the correct parent
when lowering. One consequence is the `non_snake_case` lint needed
to change the way it looked for parent nodes in a struct pattern.

This also includes a small fix to use the correct `Target` for
expression field attribute validation.
2022-08-11 21:48:39 -07:00
Eric Huss
b651c1cebe Check attributes on struct expression fields.
Attributes on struct expression fields were not being checked for
validity. This adds the fields as HIR nodes so that `CheckAttrVisitor`
can visit those nodes to check their attributes.
2022-08-11 21:48:39 -07:00
Eric Huss
1b464c73b7 Check attributes on pattern fields.
Attributes on pattern struct fields were not being checked for validity.
This adds the fields as HIR nodes so that the `CheckAttrVisitor` can
visit those nodes to check their attributes.
2022-08-11 21:48:39 -07:00
Matthias Krüger
8237efc52d
Rollup merge of #100392 - nnethercote:simplify-visitors, r=cjgillot
Simplify visitors

By removing some unused arguments.

r? `@cjgillot`
2022-08-11 22:53:08 +02:00
Dylan DPC
7ecc8923db
Rollup merge of #100398 - nnethercote:improve-Zhir-stats, r=michaelwoerister
Improve `-Zhir-stats`

Add testing, improve coverage, avoid some double counting, and add more detail.

r? `@michaelwoerister`
2022-08-11 22:47:06 +05:30
Nicholas Nethercote
4f8a1702ba Add a second level to the AST size reporting.
This tells you which variants of the enums are most common, which is
very useful. I've only done it for the AST for now, HIR can be done
later.
2022-08-11 20:46:41 +10:00
Nicholas Nethercote
85c749266d Add percentages to -Zhir-stats output. 2022-08-11 13:46:26 +10:00
Nicholas Nethercote
6a3c663cbb Change how AssocItem is reported.
Currently it's reported as either `TraitItem` or `ImplItem`. This commit
changes it to `AssocItem`, because having the report match the type name
is (a) consistent with other types, and (b) the trait/impl split isn't
that important here.
2022-08-11 12:46:55 +10:00
Nicholas Nethercote
288b6672be Improve AST stat collector.
This commit:
- Adds a comment explaining which `visit_*` methods should be
  implemented.
- Adds and removes some `visit_*` methods accordingly, improving
  coverage, and avoiding some double counting.
2022-08-11 12:46:49 +10:00
Nicholas Nethercote
8c5303898e Simplify rustc_hir::intravisit::Visitor::visit_variant_data.
It has four arguments that are never used. This avoids lots of argument
passing in functions that feed into `visit_variant_data`.
2022-08-11 10:54:01 +10:00
David Wood
5e2e478a47 passes: load defined_lib_features query less
Re-structure the stability checks for library features to avoid calling
`defined_lib_features` for any more crates than necessary for each of
the implications or local feature attributes that need validation.
2022-08-09 17:21:59 +01:00
Dylan DPC
1dc4858914
Rollup merge of #96478 - WaffleLapkin:rustc_default_body_unstable, r=Aaron1011
Implement `#[rustc_default_body_unstable]`

This PR implements a new stability attribute — `#[rustc_default_body_unstable]`.

`#[rustc_default_body_unstable]` controls the stability of default bodies in traits.
For example:
```rust
pub trait Trait {
    #[rustc_default_body_unstable(feature = "feat", isssue = "none")]
    fn item() {}
}
```
In order to implement `Trait` user needs to either
- implement `item` (even though it has a default implementation)
- enable `#![feature(feat)]`

This is useful in conjunction with [`#[rustc_must_implement_one_of]`](https://github.com/rust-lang/rust/pull/92164), we may want to relax requirements for a trait, for example allowing implementing either of `PartialEq::{eq, ne}`, but do so in a safe way — making implementation of only `PartialEq::ne` unstable.

r? `@Aaron1011`
cc `@nrc` (iirc you were interested in this wrt `read_buf`), `@danielhenrymantilla` (you were interested in the related `#[rustc_must_implement_one_of]`)
P.S. This is my first time working with stability attributes, so I'm not sure if I did everything right 😅
2022-08-09 17:34:50 +05:30
bors
9b8cfc1eed Auto merge of #98489 - cjgillot:naked-nohir, r=davidtwco,tmiasko
Only fetch HIR for naked functions that have the attribute.
2022-08-08 07:31:12 +00:00
bors
5651759746 Auto merge of #100091 - chenyukang:add-check-for-link-ordinal, r=michaelwoerister
Check link ordinal to make sure it is targetted  for foreign function

Fix #100009, when link ordinal is not target for foreign functions, emit an error.

cc `@dpaoliello`
2022-08-07 05:37:29 +00:00
bors
d77da9da84 Auto merge of #100073 - dpaoliello:externvar, r=michaelwoerister
Add test for raw-dylib with an external variable

All existing tests of link kind `raw-dylib` only validate the ability to link against functions, but it is also possible to link against variables.

This adds tests for linking against a variable using `raw-dylib` both by-name and by-ordinal.
2022-08-05 13:05:34 +00:00
bors
9bbbf60b04 Auto merge of #95977 - FabianWolff:issue-92790-dead-tuple, r=estebank
Warn about dead tuple struct fields

Continuation of #92972. Fixes #92790.

The language team has already commented on this in https://github.com/rust-lang/rust/pull/92972#issuecomment-1021511970; I have incorporated their requests here. Specifically, there is now a new allow-by-default `unused_tuple_struct_fields` lint (name bikesheddable), and fields of unit type are ignored (https://github.com/rust-lang/rust/pull/92972#issuecomment-1021815408), so error messages look like this:
```
error: field is never read: `1`
  --> $DIR/tuple-struct-field.rs:6:21
   |
LL | struct Wrapper(i32, [u8; LEN], String);
   |                     ^^^^^^^^^
   |
help: change the field to unit type to suppress this warning while preserving the field numbering
   |
LL | struct Wrapper(i32, (), String);
   |                     ~~
```
r? `@joshtriplett`
2022-08-05 09:32:26 +00:00
Daniel Paoliello
0a754b309c Add test for raw-dylib with an external variable 2022-08-04 12:47:13 -07:00
yukang
e614bbcd30 link_ordinal is available for foreign static 2022-08-04 09:28:59 +08:00
Matthias Krüger
f8e6617239
Rollup merge of #100029 - hdelc:master, r=cjgillot
Prevent ICE for `doc_alias` on match arm, statement, expression

Fixes #99777.

This is a pretty minimal fix that should be safe, since rustdoc doesn't generate documentation for match arms, statements, or expressions. I mentioned in the linked issue that the `doc_alias` target checking should probably be improved to avoid future ICEs, but as a new contributor, I'm not confident enough with the HIR types to make a larger change.
2022-08-03 22:29:31 +02:00
Camille GILLOT
845009d071 Only fetch HIR for naked functions that have the attribute. 2022-08-03 19:14:29 +02:00