Commit graph

118 commits

Author SHA1 Message Date
Yuki Okushi
41fa0dba27
Rollup merge of #80509 - matthiaskrgr:ptr_arg, r=varkor
where possible, pass slices instead of &Vec or &String (clippy::ptr_arg)
2020-12-30 22:49:26 +09:00
Matthias Krüger
e5ead5fc58 remove unused return types such as empty Results or Options that would always be Some(..)
remove unused return type of dropck::check_drop_obligations()
don't wrap return type in Option in get_macro_by_def_id() since we would always return Some(..)
remove redundant return type of back::write::optimize()
don't Option-wrap return type of compute_type_parameters() since we always return Some(..)
don't return empty Result in assemble_generator_candidates()
don't return empty Result in assemble_closure_candidates()
don't return empty result in assemble_fn_pointer_candidates()
don't return empty result in assemble_candidates_from_impls()
don't return empty result in assemble_candidates_from_auto_impls()
don't return emtpy result in assemble_candidates_for_trait_alias()
don't return empty result in assemble_builtin_bound_candidates()
don't return empty results in assemble_extension_candidates_for_traits_in_scope() and assemble_extension_candidates_for_trait()
remove redundant wrapping of return type of StripItem::strip() since it always returns Some(..)
remove unused return type of assemble_extension_candidates_for_all_traits()
2020-12-30 13:15:40 +01:00
Matthias Krüger
bdc9291ed9 where possible, pass slices instead of &Vec or &String (clippy::ptr_arg) 2020-12-30 13:11:52 +01:00
Vadim Petrochenkov
4d2d0bad4e Remove compile-fail test suite 2020-12-29 23:39:56 +03:00
Dylan DPC
80934aba15
Rollup merge of #80411 - petrochenkov:nosymwith, r=matthewjasper
rustc_span: Remove `Symbol::with`

A subset of https://github.com/rust-lang/rust/pull/79425 that is a pure refactoring.
2020-12-28 14:13:21 +01:00
Dylan DPC
c51172f38a
Rollup merge of #80344 - matthiaskrgr:matches, r=Dylan-DPC
use matches!() macro in more places
2020-12-28 14:13:12 +01:00
Vadim Petrochenkov
0ae998e122 rustc_span: Remove Symbol::with 2020-12-27 18:10:58 +03:00
Bastian Kauschke
06cc9c26da stabilize min_const_generics 2020-12-26 18:24:10 +01:00
Matthias Krüger
d12a358673 use matches!() macro in more places 2020-12-24 13:35:12 +01:00
Dániel Buga
6d71cc6750 Move std_path construction into condition 2020-12-20 23:55:03 +01:00
Dániel Buga
66c2872901 Inline a single-use closure 2020-12-20 23:17:56 +01:00
Dániel Buga
f499601dd8 Create closure outside of the loop 2020-12-20 22:49:53 +01:00
Dániel Buga
89bc399d56 Add missing semicolon 2020-12-20 21:41:35 +01:00
Dániel Buga
91ea623f49 Remove unnecessary cloned 2020-12-20 21:41:15 +01:00
Dániel Buga
62f593bda9 Precompute vector length in smart_resolve_path_fragment 2020-12-20 21:38:41 +01:00
Dániel Buga
93d5a8025d Clean up with_generic_param_rib, avoid double hashing 2020-12-20 21:08:55 +01:00
Daiki Ihara
7b9ee11a4c Enhance error message when misspelled label to value in break expression
Apply suggestions from code review

Co-authored-by: lcnr <bastian_kauschke@hotmail.de>
2020-12-17 20:22:22 +09:00
Camelid
5ce3f4c166 Resolve enum field visibility correctly
Previously, this code treated enum fields' visibility as if they were
struct fields. However, that's not correct because the visibility of a
struct field with `ast::VisibilityKind::Inherited` is private to the
module it's defined in, whereas the visibility of an *enum* field with
`ast::VisibilityKind::Inherited` is the visibility of the enum it
belongs to.
2020-12-12 14:04:59 -08:00
Yuki Okushi
cdcce11504 Tweak diagnostics on shadowing lifetimes/labels 2020-12-02 11:39:42 +09:00
Camille GILLOT
032f68d625 Remove ForeignMod struct. 2020-11-26 21:32:27 +01:00
Arlie Davis
5481c1bd6d Move lev_distance to rustc_ast, make non-generic
rustc_ast currently has a few dependencies on rustc_lexer. Ideally, an AST
would not have any dependency its lexer, for minimizing unnecessarily
design-time dependencies. Breaking this dependency would also have practical
benefits, since modifying rustc_lexer would not trigger a rebuild of rustc_ast.

This commit does not remove the rustc_ast --> rustc_lexer dependency,
but it does remove one of the sources of this dependency, which is the
code that handles fuzzy matching between symbol names for making suggestions
in diagnostics. Since that code depends only on Symbol, it is easy to move
it to rustc_span. It might even be best to move it to a separate crate,
since other tools such as Cargo use the same algorithm, and have simply
contain a duplicate of the code.

This changes the signature of find_best_match_for_name so that it is no
longer generic over its input. I checked the optimized binaries, and this
function was duplicated at nearly every call site, because most call sites
used short-lived iterator chains, generic over Map and such. But there's
no good reason for a function like this to be generic, since all it does
is immediately convert the generic input (the Iterator impl) to a concrete
Vec<Symbol>. This has all of the costs of generics (duplicated method bodies)
with no benefit.

Changing find_best_match_for_name to be non-generic removed about 10KB of
code from the optimized binary. I know it's a drop in the bucket, but we have
to start reducing binary size, and beginning to tame over-use of generics
is part of that.
2020-11-24 16:12:23 -08:00
Jonas Schievink
f049b0be96
Rollup merge of #79374 - mendess:const-param-expr-diagnostic, r=lcnr
Add note to use nightly when using expr in const generics

As recommended by `@Icnr` in #73899 and in zulip, I've added a note saying that const expressions can be used in nightly.

```
error: generic parameters may not be used in const operations
  --> $DIR/issue-61935.rs:10:23
   |
 6 |         Self:FooImpl<{N==0}>
   |                       ^ cannot perform const operation using `N`
   |
   = help: const parameters may only be used as standalone arguments, i.e. `N`
   = note: use feature(const_generics) and feature(const_evaluatable_checked) to enable this

error: aborting due to previous error
```

I hope the note is well written 😅
2020-11-24 13:17:51 +01:00
mendess
888055eb4c Swap note for help 2020-11-24 11:05:55 +00:00
mendess
af978e3b63 Requested changes 2020-11-24 10:28:18 +00:00
mendess
b7593e5070 Add note to use nightly when using expr in const generics 2020-11-24 09:35:08 +00:00
bors
6331023708 Auto merge of #79294 - petrochenkov:determ, r=varkor
resolve: Do not put macros into `module.unexpanded_invocations` unless necessary

Macro invocations in modules <sup>(*)</sup> need to be tracked because they can produce named items when expanded.
We cannot give definite answer to queries like "does this module declare name `n`?" until all macro calls in that module are expanded.

Previously we marked too many macros as potentially producing named items.
E.g. in this example
```rust
mod m {
    const C: u32 = line!();
}
```
`line!()` cannot emit any items into module `m`, but it was still marked.
This PR fixes that and marks macro calls as "unexpanded in module" only if they can actually emit named items into that module.

Diagnostics in UI test outputs have different order now because this change affects macro expansion order.

<sup>*</sup> Any containers for named items are called modules in resolve (that includes blocks, traits and enums in addition to `mod` items).
2020-11-24 09:17:33 +00:00
Jonas Schievink
c58c245e2c
Rollup merge of #79236 - lcnr:mcg-resolve-dsb, r=eddyb
const_generics: assert resolve hack causes an error

prevent the min_const_generics `HACK`s in resolve from triggering a fallback path which successfully compiles so that we don't have to worry about future compat issues when removing it

r? `@eddyb` cc `@varkor`
2020-11-23 15:25:42 +01:00
Vadim Petrochenkov
27af650a0d resolve: Do not put macros into module.unexpanded_invocations unless necessary 2020-11-22 14:42:29 +03:00
Bastian Kauschke
c85af74fcd update bug message for cg 2020-11-20 23:31:36 +01:00
Bastian Kauschke
34ea5d02dd const_generics: assert resolve hack causes an error 2020-11-20 23:29:54 +01:00
Vadim Petrochenkov
993bb072ff rustc_expand: Mark inner #![test] attributes as soft-unstable 2020-11-20 19:35:03 +03:00
Vadim Petrochenkov
dfb690eaa9 resolve/expand: Misc cleanup 2020-11-19 19:25:20 +03:00
Vadim Petrochenkov
68f94e94ed resolve: Centralize some error reporting for unexpected macro resolutions 2020-11-19 19:25:20 +03:00
Vadim Petrochenkov
69894ce9ac resolve: Introduce a separate NonMacroAttrKind for legacy derive helpers 2020-11-19 19:25:20 +03:00
Mara Bos
92dcf6d733
Rollup merge of #78999 - petrochenkov:deprid, r=eddyb
stability: More precise location for deprecation lint on macros

One missing piece of https://github.com/rust-lang/rust/pull/73178.
2020-11-18 15:46:25 +01:00
Jonas Schievink
b0178f4cc7
Rollup merge of #79034 - petrochenkov:mrscopes3, r=eddyb
rustc_resolve: Make `macro_rules` scope chain compression lazy

As suggested in https://github.com/rust-lang/rust/pull/78826#issuecomment-723420664.
2020-11-15 13:39:57 +01:00
Jonas Schievink
8825942e86
Rollup merge of #77802 - jyn514:bootstrap-specific, r=nikomatsakis
Allow making `RUSTC_BOOTSTRAP` conditional on the crate name

Motivation: This came up in the [Zulip stream](https://rust-lang.zulipchat.com/#narrow/stream/233931-t-compiler.2Fmajor-changes/topic/Require.20users.20to.20confirm.20they.20know.20RUSTC_.E2.80.A6.20compiler-team.23350/near/208403962) for https://github.com/rust-lang/compiler-team/issues/350.
See also https://github.com/rust-lang/cargo/pull/6608#issuecomment-458546258; this implements https://github.com/rust-lang/cargo/issues/6627.
The goal is for this to eventually allow prohibiting setting `RUSTC_BOOTSTRAP` in build.rs (https://github.com/rust-lang/cargo/issues/7088).

## User-facing changes

- `RUSTC_BOOTSTRAP=1` still works; there is no current plan to remove this.
- Things like `RUSTC_BOOTSTRAP=0` no longer activate nightly features. In practice this shouldn't be a big deal, since `RUSTC_BOOTSTRAP` is the opposite of stable and everyone uses `RUSTC_BOOTSTRAP=1` anyway.
- `RUSTC_BOOTSTRAP=x` will enable nightly features only for crate `x`.
- `RUSTC_BOOTSTRAP=x,y` will enable nightly features only for crates `x` and `y`.

## Implementation changes

The main change is that `UnstableOptions::from_environment` now requires
an (optional) crate name. If the crate name is unknown (`None`), then the new feature is not available and you still have to use `RUSTC_BOOTSTRAP=1`. In practice this means the feature is only available for `--crate-name`, not for `#![crate_name]`; I'm interested in supporting the second but I'm not sure how.

Other major changes:

- Added `Session::is_nightly_build()`, which uses the `crate_name` of
the session
- Added `nightly_options::match_is_nightly_build`, a convenience method
for looking up `--crate-name` from CLI arguments.
`Session::is_nightly_build()`should be preferred where possible, since
it will take into account `#![crate_name]` (I think).
- Added `unstable_features` to `rustdoc::RenderOptions`

I'm not sure whether this counts as T-compiler or T-lang; _technically_ RUSTC_BOOTSTRAP is an implementation detail, but it's been used so much it seems like this counts as a language change too.

r? `@joshtriplett`
cc `@Mark-Simulacrum` `@hsivonen`
2020-11-15 13:39:43 +01:00
Vadim Petrochenkov
ac4c1f58b9 rustc_resolve: Make macro_rules scope chain compression lazy 2020-11-14 00:35:56 +03:00
bors
a38f8fb674 Auto merge of #78826 - petrochenkov:mrscopes2, r=eddyb
resolve: Collapse `macro_rules` scope chains on the fly

Otherwise they grow too long and you have to endlessly walk through them when resolving macros or imports.
Addresses https://rust-lang.zulipchat.com/#narrow/stream/247081-t-compiler.2Fperformance/topic/Slow.20Builtin.20Derives/near/215750815
2020-11-13 05:40:37 +00:00
Vadim Petrochenkov
909c8945b1 stability: More precise location for deprecation lint on macros 2020-11-12 22:53:42 +03:00
Fabian Zaiser
de84ad95b4 Implement destructuring assignment for structs and slices
Co-authored-by: varkor <github@varkor.com>
2020-11-11 12:10:52 +00:00
Mara Bos
829e88032a
Rollup merge of #78860 - petrochenkov:resolvefmt, r=Mark-Simulacrum
rustc_resolve: Use `#![feature(format_args_capture)]`

This is the best new sugar for quite some time.

(I only changed places that already used named arguments.)
2020-11-08 13:36:30 +01:00
Vadim Petrochenkov
907b87fafa rustc_resolve: Use #![feature(format_args_capture)] 2020-11-08 01:38:11 +03:00
Joshua Nelson
622c48e4f1 Allow making RUSTC_BOOTSTRAP conditional on the crate name
The main change is that `UnstableOptions::from_environment` now requires
an (optional) crate name. If the crate name is unknown (`None`), then the new feature is not available and you still have to use `RUSTC_BOOTSTRAP=1`. In practice this means the feature is only available for `--crate-name`, not for `#![crate_name]`; I'm interested in supporting the second but I'm not sure how.

Other major changes:

- Added `Session::is_nightly_build()`, which uses the `crate_name` of
the session
- Added `nightly_options::match_is_nightly_build`, a convenience method
for looking up `--crate-name` from CLI arguments.
`Session::is_nightly_build()`should be preferred where possible, since
it will take into account `#![crate_name]` (I think).
- Added `unstable_features` to `rustdoc::RenderOptions`

  There is a user-facing change here: things like `RUSTC_BOOTSTRAP=0` no
  longer active nightly features. In practice this shouldn't be a big
  deal, since `RUSTC_BOOTSTRAP` is the opposite of stable and everyone
  uses `RUSTC_BOOTSTRAP=1` anyway.

- Add tests

  Check against `Cheat`, not whether nightly features are allowed.
  Nightly features are always allowed on the nightly channel.

- Only call `is_nightly_build()` once within a function

- Use booleans consistently for rustc_incremental

  Sessions can't be passed through threads, so `read_file` couldn't take a
  session. To be consistent, also take a boolean in `write_file_header`.
2020-11-07 13:45:11 -05:00
Vadim Petrochenkov
922107919d resolve: Collapse macro_rules scope chains on the fly 2020-11-07 02:18:29 +03:00
Mark Rousskov
ae4f80b4be Revert "Revert "resolve: Avoid "self-confirming" import resolutions in one more case""
This reverts commit b20bce8ce5.

It retains the test added in that commit as a check-pass test, intended to
prevent future (unintentional) regressions.
2020-11-06 11:22:13 -05:00
Matthias Krüger
bcd2f2df67 fix a couple of clippy warnings:
filter_next
manual_strip
redundant_static_lifetimes
single_char_pattern
unnecessary_cast
unused_unit
op_ref
redundant_closure
useless_conversion
2020-11-04 13:48:50 +01:00
Vadim Petrochenkov
19dbb02a89 Expand NtExpr tokens only in key-value attributes 2020-11-03 00:53:43 +03:00
bors
1d5b7c3c96 Auto merge of #78420 - estebank:suggest-assoc-fn, r=petrochenkov
Suggest calling associated `fn` inside `trait`s

When calling a function that doesn't exist inside of a trait's
associated `fn`, and another associated `fn` in that trait has that
name, suggest calling it with the appropriate fully-qualified path.

Expand the label to be more descriptive.

Prompted by the following user experience:
https://users.rust-lang.org/t/cannot-find-function/50663
2020-11-01 06:49:16 +00:00
Joshua Nelson
5339bd1ebe Add back missing comments 2020-10-30 10:13:41 -04:00