Commit Graph

5186 Commits

Author SHA1 Message Date
Felix S. Klock II
651f46376a Adjusted diagnostic output so that if there is no use in a item sequence,
then we just suggest the first legal position where you could inject a use.

To do this, I added `inject_use_span` field to `ModSpans`, and populate it in
parser (it is the span of the first token found after inner attributes, if any).
Then I rewrote the use-suggestion code to utilize it, and threw out some stuff
that is now unnecessary with this in place. (I think the result is easier to
understand.)

Then I added a test of issue 87613.
2022-03-03 18:58:37 -05:00
Felix S. Klock II
74876ef4e9 Associate multiple with a crate too. 2022-03-03 18:45:25 -05:00
Felix S. Klock II
4edb757826 refactor: prepare to associate multiple spans with a module. 2022-03-03 14:38:50 -05:00
Yacin Tmimi
272fb42f06 Prevent wrapping markdown headers in doc comments
Fixes 5238

A markdown header is defined by a string that starts with `#`.

Previously, rustfmt would wrap long markdown headers when
`wrap_comments=true`. This lead to issues when rendering these headers
in HTML using rustdoc.

Now, rustfmt leaves markdown headers alone when wrapping comments.
2022-02-28 23:25:49 -06:00
Yacin Tmimi
12048e444f fallback to dir_path when relative external mod resolution fails
We only want to fall back if two conditions are met:

1) Initial module resolution is performed relative to some nested
   directory.
2) Module resolution fails because of a ModError::FileNotFound error.

When these conditions are met we can try to fallback to searching for
the module's file relative to the dir_path instead of the nested
relative directory.

Fixes 5198

As demonstrated by 5198, it's possible that a directory name conflicts
with a rust file name. For example, src/lib/ and src/lib.rs.

If src/lib.rs references an external module like ``mod foo;``, then
module resolution will try to resolve ``foo`` to src/lib/foo.rs or
src/lib/foo/mod.rs. Module resolution would fail with a file not
found error if the ``foo`` module were defined at src/foo.rs.

When encountering these kinds of module resolution issues we now fall
back to the current directory and attempt to resolve the module again.

Given the current example, this means that if we can't find the module
``foo`` at src/lib/foo.rs or src/lib/foo/mod.rs, we'll attempt
to resolve the module to src/foo.rs.
2022-02-28 23:13:11 -06:00
Mark Rousskov
de1ac375f0 Enable rustc_pass_by_value for Span 2022-02-25 08:00:53 -05:00
Caleb Cartwright
89ca3f3a10 fix: unused test imports on non-nightly, prevent regression 2022-02-23 22:51:32 -06:00
Eduard-Mihai Burtescu
5723946081 rustc_errors: take self by value in DiagnosticBuilder::cancel. 2022-02-23 06:08:06 +00:00
Eduard-Mihai Burtescu
7592663e85 rustc_errors: add downgrade_to_delayed_bug to Diagnostic itself. 2022-02-23 03:46:51 +00:00
Caleb Cartwright
281bf03e64 fix: formatting in new test 2022-02-15 21:24:39 -06:00
Cameron Steffen
c63d42e804 Use cargo-fmt in self_tests 2022-02-15 19:44:53 -06:00
Cameron Steffen
d5aabccfeb Format code 2022-02-15 19:44:53 -06:00
Travis Finkenauer
6c476127ae
Add context to get_toml_path() error (#5207)
* rustfmt: print full error chain

* Add context to get_toml_path() error

Instead of an error like:

```
Permission denied (os error 13)
```

Gives error like:

```
Failed to get metadata for config file "/root/.rustfmt.toml": Permission denied (os error 13)
```
2022-02-15 17:25:44 -06:00
Yacin Tmimi
1e78a2b258 Leverage itemized blocks to support formatting markdown block quotes
Fixes 5157

Doc comments support markdown, but rustfmt didn't previously assign any
semantic value to leading '> ' in comments. This lead to poor formatting
when using ``wrap_comments=true``.

Now, rustfmt treats block quotes as itemized blocks, which greatly
improves how block quotes are formatted when ``wrap_comments=true``.
2022-02-11 17:31:06 -06:00
Tharun Rajendran
b05b313800
chore(rustfmt): remove executable path from usage string (#5216)
* chore(rustfmt): remove executable path from usage string

* add unit test for usage string

* rename test and check usage text in a single assert
2022-02-10 22:35:45 -06:00
Stepan Koltsov
813d127c82 Clarify generated marker requires a config option 2022-02-10 22:18:32 -06:00
Gabriel Smith
ace7241087 Fix incorrect string indentation in macro defs with format_strings 2022-02-10 21:02:59 -06:00
Frank King
5df8c8f7e5
Fix doc of generic items formmating error (#5124)
* Fix doc of generic items formmating error

* Remove tracked `attrs_end_with_doc_comment` flag in `RewriteContext`

* Fix duplicated doc comments of const generic params

* Fix `<ast::GenericParam as Spanned>::span()`

* Remove duplicated source file of `doc-of-generic-item.rs`
2022-02-06 20:57:39 -06:00
Stéphane Campinas
fd6e11cc57 Add tests for the One and Crate variants 2022-02-03 18:56:53 -06:00
Stéphane Campinas
b2c7a52ea8 Fix import_granularity option when the use tree has an alias 2022-02-03 18:56:53 -06:00
Yacin Tmimi
606894eb0b Retain trailing separator when extracting the last inline post comment
Fixes 5042

Previously, trailing commas were removed from the last inline comment.
This lead to rustfmt refusing to format code snippets because
the original comment did not match the rewritten comment.

Now, when rustfmt extracts the last inline comment it leaves trailing
separators alone. Rustfmt does not need to remove these separators
because they are commented out.
2022-02-03 18:52:58 -06:00
Stéphane Campinas
368a9b7cef
Handle non-ascii character at boundary (#5089)
* Handle non-ascii character at boundary

* Replace substraction underflow check with early termination
2022-02-01 19:06:14 -06:00
Yacin Tmimi
8b0b213cdd Prevent adding trailing whitespace when rewriting ast::Param
Fixes 5125

Previously, a newline was always added, even if the parameter name was
not preceded by any param attrs.

Now a newline is only added if there were param attrs.
2022-01-29 12:20:34 -06:00
Szymon Gibała
b4a4bf0bf8
Fix formatting of comments in empty structs (#5171)
* Fix formatting of comments in empty structs

* Add tests

* Add single line tests

* Fix block comments

* Revert changes of test source files
2022-01-28 22:55:47 -06:00
Eduard-Mihai Burtescu
3572c542c2 rustc_errors: only box the diagnostic field in DiagnosticBuilder. 2022-01-24 11:23:14 +00:00
Caleb Cartwright
5c558e2c11
Merge pull request #5186 from calebcartwright/subtree-sync-2022-01-23
sync subtree
2022-01-23 12:35:18 -06:00
Caleb Cartwright
9e1973f1d9 chore: bump toolchain, update test 2022-01-23 11:18:17 -06:00
Caleb Cartwright
9b454a5990 Merge remote-tracking branch 'upstream/master' into subtree-sync-2022-01-23 2022-01-23 11:07:20 -06:00
kadmin
7913f130d3 Add term to ExistentialProjection
Also prevent ICE when adding a const in associated const equality.
2022-01-17 20:01:22 +00:00
kadmin
cf86d53202 Add term
Instead of having a separate enum variant for types and consts have one but have either a const
or type.
2022-01-17 17:20:57 +00:00
kadmin
f5ce84e4f2 add eq constraints on associated constants 2022-01-17 17:20:57 +00:00
bors
8ae2312e34 Auto merge of #92816 - tmiasko:rm-llvm-asm, r=Amanieu
Remove deprecated LLVM-style inline assembly

The `llvm_asm!` was deprecated back in #87590 1.56.0, with intention to remove
it once `asm!` was stabilized, which already happened in #91728 1.59.0. Now it
is time to remove `llvm_asm!` to avoid continued maintenance cost.

Closes #70173.
Closes #92794.
Closes #87612.
Closes #82065.

cc `@rust-lang/wg-inline-asm`

r? `@Amanieu`
2022-01-17 09:40:29 +00:00
Caleb Cartwright
bfbf42cecb fix(rustfmt): resolve generated file formatting issue 2022-01-14 18:18:37 -06:00
Tomasz Miąsko
04670a1404 Remove LLVM-style inline assembly from rustfmt 2022-01-12 21:43:35 +01:00
Lamb
6e6300207f Compute most of Public/Exported access level in rustc_resolve
Mak DefId to AccessLevel map in resolve for export

hir_id to accesslevel in resolve and applied in privacy
using local def id
removing tracing probes
making function not recursive and adding comments

Move most of Exported/Public res to rustc_resolve

moving public/export res to resolve

fix missing stability attributes in core, std and alloc

move code to access_levels.rs

return for some kinds instead of going through them

Export correctness, macro changes, comments

add comment for import binding

add comment for import binding

renmae to access level visitor, remove comments, move fn as closure, remove new_key

fmt

fix rebase

fix rebase

fmt

fmt

fix: move macro def to rustc_resolve

fix: reachable AccessLevel for enum variants

fmt

fix: missing stability attributes for other architectures

allow unreachable pub in rustfmt

fix: missing impl access level + renaming export to reexport

Missing impl access level was found thanks to a test in clippy
2022-01-09 21:33:14 +00:00
Matthias Krüger
5056f4cfb3 some minor clippy fixes 2022-01-05 17:53:27 -06:00
Seiichi Uchida
34d374ee5d Use <stdin> when emitting stdin as filename (#4298)
# Conflicts:
#	src/config/file_lines.rs
#	src/rustfmt/main.rs
#	src/test/mod.rs
2022-01-02 10:06:06 -06:00
Tim
894a3c0e77 Fix newlines in JSON output (#4262)
* Fix newlines in JSON output

This changes the JSON output to be more consistent about where newlines are included. Previously it only included them between lines in a multiline diff. That meant single line changes were treated a bit weirdly. This changes it to append a newline to every line.

When feeding the results into `arc lint` this behaves correctly. I have only done limited testing though, in particular there's a possibility it might not work with files with `\r\n` endings (though that would have been the case before too).

Fixes #4259

* Update tests
# Conflicts:
#	tests/writemode/target/output.json
2022-01-02 10:06:06 -06:00
Caleb Cartwright
776baf93f8 refactor: update json emitter to better handle errors (#3953) 2022-01-02 10:06:06 -06:00
Chris Emerson
34263cd6bd Fix --check -l with stdin. (#3910)
* Fix some possible panics when using `--check` with stdin.

One case which doesn't work is when there are only line ending fixes;
with stdin rustfmt is unable to detect the difference as it stores
the input with Unix line endings.

* Add test for `rustfmt --check -l` with stdin.
2022-01-02 10:06:06 -06:00
Chris Emerson
93b7de5b01 Make --check work when running from stdin. (#3896)
# Conflicts:
#	src/bin/main.rs
2022-01-02 10:06:06 -06:00
Yacin Tmimi
737e6f7046 Improve out of line module resolution
Fixes 5119

When the directory structure was laid out as follows:

```
dir
 |---mod_a
 |    |---sub_mod_1.rs
 |    |---sub_mod_2.rs
 |---mod_a.rs
```

And ``mod_a.rs`` contains the following content:

```rust
mod mod_a {
    mod sub_mod_1;
    mod sub_mod_2;
}
```

rustfmt previously tried to find ``sub_mod_1.rs`` and ``sub_mod_2.rs``
in ``./mod_a/mod_a/``. This directory does not exist and this caused
rustfmt to fail with the error message:

    Error writing files: failed to resolve mod

Now, both ``sub_mod_1.rs`` and ``sub_mod_2.rs`` are resolved correctly
and found at ``mod_a/sub_mod_1.rs`` and ``mod_a/sub_mod_2.rs``.
2022-01-01 10:27:49 -06:00
Caleb Cartwright
6db6bafc61 Merge commit '4a053f206fd6799a25823c307f7d7f9d897be118' into sync-rustfmt-subtree 2021-12-29 20:49:39 -06:00
David Lattimore
4a053f206f Do not flatten match arm block with leading attributes
This is a backport of #4124.

Fixes #4109
2021-12-29 17:43:58 -06:00
Caleb Cartwright
f935f0cf89 feat: support parsing asm! args 2021-12-28 20:25:17 -06:00
Caleb Cartwright
50bbb43dab chore: bump toolchain 2021-12-28 20:25:17 -06:00
Caleb Cartwright
e8afb62c71 chore: reduce some vis. for updated unreachable_pub lint 2021-12-27 18:16:04 -06:00
Yacin Tmimi
76eb077fb2 Retain qualified path when rewriting struct literals
Fixes 5151

Details about the qualified path are now passed along so that rustfmt
can include them when formatting struct literals.
2021-12-23 23:04:26 -06:00
David Tolnay
0b2fd9b132 Fix static async closure qualifier order 2021-12-23 23:03:49 -06:00
Caleb Cartwright
7b8303d479 chore: cleanup unused imports 2021-12-21 10:55:39 -06:00