Commit Graph

108343 Commits

Author SHA1 Message Date
Mazdak Farrokhzad
1b0c73baff
Rollup merge of #69881 - Centril:fix-69485, r=oli-obk
VariantSizeDifferences: bail on SizeOverflow

Fixes #69485.

r? @oli-obk
2020-03-17 03:05:14 +01:00
Mazdak Farrokhzad
9fc5c2d00d
Rollup merge of #69870 - petrochenkov:cfgacc, r=matthewjasper
expand: Implement something similar to `#[cfg(accessible(path))]`

cc https://github.com/rust-lang/rust/issues/64797

The feature is implemented as a `#[cfg_accessible(path)]` attribute macro rather than as `#[cfg(accessible(path))]` because it needs to wait until `path` becomes resolvable, and `cfg` cannot wait, but macros can wait.

Later we can think about desugaring or not desugaring `#[cfg(accessible(path))]` into `#[cfg_accessible(path)]`.

This implementation is also incomplete in the sense that it never returns "false" from `cfg_accessible(path)`, it requires some tweaks to resolve, which is not quite ready to answer queries like this during early resolution.

However, the most important part of this PR is not `cfg_accessible` itself, but expansion infrastructure for retrying expansions.
Before this PR we could say "we cannot resolve this macro path, let's try it later", with this PR we can say "we cannot expand this macro, let's try it later" as well.

This is a pre-requisite for
- turning `#[derive(...)]` into a regular attribute macro,
- properly supporting eager expansion for macros that cannot yet be resolved like
    ```
    fn main() {
        println!(not_available_yet!());
    }

    macro_rules! make_available {
        () => { #[macro_export] macro_rules! not_available_yet { () => { "Hello world!" } }}
    }

    make_available!();
    ```
2020-03-17 03:05:12 +01:00
Mazdak Farrokhzad
b691145bd4
Rollup merge of #69811 - petrochenkov:privdiag2, r=estebank
resolve: Print import chains on privacy errors

A part of https://github.com/rust-lang/rust/pull/67951 that doesn't require hacks.
r? @estebank
2020-03-17 03:05:10 +01:00
bors
e24252a12c Auto merge of #68970 - matthewjasper:min-spec, r=nikomatsakis
Implement a feature for a sound specialization subset

This implements a new feature (`min_specialization`) that restricts specialization to a subset that is reasonable for the standard library to use.

The plan is to then:

* Update `libcore` and `liballoc` to compile with `min_specialization`.
* Add a lint to forbid use of `feature(specialization)` (and other unsound, type system extending features) in the standard library.
* Fix the soundness issues around `specialization`.
* Remove `min_specialization`

The rest of this is an overview from a comment in this PR

## Basic approach

To enforce this requirement on specializations we take the following approach:
1. Match up the substs for `impl2` so that the implemented trait and self-type match those for `impl1`.
2. Check for any direct use of `'static` in the substs of `impl2`.
3. Check that all of the generic parameters of `impl1` occur at most once in the *unconstrained* substs for `impl2`. A parameter is constrained if its value is completely determined by an associated type projection predicate.
4. Check that all predicates on `impl1` also exist on `impl2` (after matching substs).

## Example

Suppose we have the following always applicable impl:

```rust
impl<T> SpecExtend<T> for std::vec::IntoIter<T> { /* specialized impl */ }
impl<T, I: Iterator<Item=T>> SpecExtend<T> for I { /* default impl */ }
```

We get that the subst for `impl2` are `[T, std::vec::IntoIter<T>]`. `T` is constrained to be `<I as Iterator>::Item`, so we check only `std::vec::IntoIter<T>` for repeated parameters, which it doesn't have. The predicates of `impl1` are only `T: Sized`, which is also a predicate of impl2`. So this specialization is sound.

## Extensions

Unfortunately not all specializations in the standard library are allowed by this. So there are two extensions to these rules that allow specializing on some traits.

### rustc_specialization_trait

If a trait is always applicable, then it's sound to specialize on it. We check trait is always applicable in the same way as impls, except that step 4 is now "all predicates on `impl1` are always applicable". We require that `specialization` or `min_specialization` is enabled to implement these traits.

### rustc_specialization_marker

There are also some specialization on traits with no methods, including the `FusedIterator` trait which is advertised as allowing optimizations. We allow marking marker traits with an unstable attribute that means we ignore them in point 3 of the checks above. This is unsound but we allow it in the short term because it can't cause use after frees with purely safe code in the same way as specializing on traits methods can.

r? @nikomatsakis
cc #31844 #67194
2020-03-16 20:49:26 +00:00
bors
dd67187965 Auto merge of #67133 - oli-obk:it_must_be_a_sign, r=eddyb
Deduplicate pretty printing of constants

r? @eddyb for the pretty printing logic
cc @RalfJung
2020-03-16 16:31:23 +00:00
bors
59f4ba9504 Auto merge of #70040 - Dylan-DPC:rollup-id1k6lz, r=Dylan-DPC
Rollup of 7 pull requests

Successful merges:

 - #67335 (Refactor the `Qualif` trait)
 - #69122 (Backtrace Debug tweaks)
 - #69520 (Make error message clearer about creating new module)
 - #69738 (More Method -> AssocFn renaming)
 - #69867 (Add long error explanation for E0628 )
 - #69989 (resolve/hygiene: `macro_rules` are not "legacy")
 - #70036 (Make article_and_description primarily use def_kind)

Failed merges:

r? @ghost
2020-03-16 13:22:56 +00:00
Dylan DPC
d8dbb3c041
Rollup merge of #70036 - mark-i-m:describe-it-4, r=eddyb
Make article_and_description primarily use def_kind

r? @eddyb

cc @matthewjasper
2020-03-16 13:16:45 +01:00
Dylan DPC
8872d90572
Rollup merge of #69989 - petrochenkov:nolegacy, r=eddyb,matthewjasper
resolve/hygiene: `macro_rules` are not "legacy"

The "modern" vs "legacy" naming was introduced by jseyfried during initial implementation of macros 2.0.
At this point it's clear that `macro_rules` are not going anywhere and won't be deprecated in the near future.
So this PR changes the naming "legacy" (when it implies "macro_rules") to "macro_rules".
This should also help people reading this code because it's wasn't obvious that "legacy" actually meant "macro_rules" in these contexts.

The most contentious renaming here is probably
```
fn modern -> fn normalize_to_macros_2_0
fn modern_and_legacy -> fn normalize_to_macro_rules
```
Other alternatives that I could think of are `normalize_to_opaque`/`normalize_to_semitransparent`, or `strip_non_opaque`/`strip_transparent`, but they seemed less intuitive.
The documentation to these functions can be found in `symbol.rs`.

r? @matthewjasper
2020-03-16 13:16:44 +01:00
Dylan DPC
8f2482b801
Rollup merge of #69867 - ayushmishra2005:doc/61137-add-long-error-code-e0628, r=Dylan-DPC
Add long error explanation for E0628

Add long explanation for the E0628 error code
Part of #61137

r? @GuillaumeGomez
2020-03-16 13:16:42 +01:00
Dylan DPC
0d7c82e7f2
Rollup merge of #69738 - mark-i-m:assoc-fn-2, r=eddyb
More Method -> AssocFn renaming

r? @Centril @eddyb

cc #60163

Blocked on #69674
2020-03-16 13:16:40 +01:00
Dylan DPC
1685264f12
Rollup merge of #69520 - kornelski:e69492, r=cramertj
Make error message clearer about creating new module

This is a partial improvement for #69492
2020-03-16 13:16:38 +01:00
Dylan DPC
2443eb46cf
Rollup merge of #69122 - dtolnay:backtrace, r=cramertj
Backtrace Debug tweaks

- Change Debug representation of disabled and unsupported backtraces to use \<placeholder\> style, same as what we do for debug printing locked mutexes and mutably borrowed refcells;

    ```diff
    - Error { msg: "...", backtrace: disabled backtrace }
    + Error { msg: "...", backtrace: <disabled> }
    ```

- Remove quotes around unresolved symbol names;

    ```diff
    - Backtrace [{ fn: "<unknown>" }]
    + Backtrace [{ fn: <unknown> }]
    ```

- Add quotes around file paths;

    ```diff
    - Backtrace [{ fn: "krate::main", file: /path/to/main.rs, line: 10 }]
    + Backtrace [{ fn: "krate::main", file: "/path/to/main.rs", line: 10 }]
    ```

- Add test.
2020-03-16 13:16:35 +01:00
Dylan DPC
59b0058c0c
Rollup merge of #67335 - ecstatic-morse:qualif-refactor, r=eddyb
Refactor the `Qualif` trait

This PR attempts to preserve the existing semantics of the `Qualif` trait while reducing its API to two significant methods with descriptive names, `in_any_value_of_ty` and `in_adt_inherently`. The other `in_*` methods have been made into free functions, since they should never be overloaded. Finally, I changed the bounds on the `in_local` argument to be less restrictive (`FnMut` instead of `Fn`), which addresses a FIXME in the const-checker.

r? @eddyb
cc @pnkfelix @oli-obk
2020-03-16 13:16:30 +01:00
bors
8e6de3244c Auto merge of #70010 - Amanieu:fix-opt-catch, r=Mark-Simulacrum
Add a workaround for catch_unwind in stage1 mingw target

Fixes #70001

cc @petrochenkov

r? @Mark-Simulacrum
2020-03-16 08:08:51 +00:00
mark
2c2d41dc00 make article_and_description primarily use def_kind 2020-03-15 23:31:17 -05:00
bors
97eda01bb7 Auto merge of #70034 - Dylan-DPC:rollup-5yg771j, r=Dylan-DPC
Rollup of 8 pull requests

Successful merges:

 - #69686 (Use `pprust` to print attributes in rustdoc)
 - #69858 (std: on Windows, use GetSystemTimePreciseAsFileTime if it is available)
 - #69917 (Cleanup E0412 and E0422)
 - #69964 (Add Node.js to PR CI image)
 - #69992 (Block version-specific docs from search engines)
 - #69995 (Add more context to the literal overflow message)
 - #69998 (Add long error explanation for E0634)
 - #70014 (Small fixes in rustdoc book)

Failed merges:

r? @ghost
2020-03-16 02:52:47 +00:00
Mark Mansi
1b92e86a1c MethodData -> AssocFnData 2020-03-15 19:58:17 -05:00
Mark Mansi
e3c15ae6bc update comment 2020-03-15 19:58:09 -05:00
Dylan DPC
6b50a4cebb
Rollup merge of #70014 - TimotheeGerber:small-fix-rustdoc-book, r=Dylan-DPC
Small fixes in rustdoc book

I read the `rustdoc` book today and noticed some small typos/problems. Mainly:

 - `# fn foo() {}` was displayed when not needed because fenced block code type was `text` instead of `rust`;
 - two path separators were missing and some Windows-style separators were not consistent with the rest of them (mainly Linux-style).

Here are my proposed fixes. It is my first PR for the rust project. Don't hesitate to tell me if I am doing it wrong or if you need anything else.

Have a nice day!
2020-03-16 01:30:41 +01:00
Dylan DPC
9296d770bd
Rollup merge of #69998 - ayushmishra2005:doc/61137-add-long-error-code-e0634, r=Dylan-DPC,GuillaumeGomez
Add long error explanation for E0634

Add long explanation for the E0634 error code
Part of #61137

r? @GuillaumeGomez
2020-03-16 01:30:38 +01:00
Dylan DPC
56c60f2905
Rollup merge of #69995 - contrun:add-context-to-literal-overflow, r=ecstatic-morse
Add more context to the literal overflow message

related to issue https://github.com/rust-lang/rust/issues/63733
2020-03-16 01:30:37 +01:00
Dylan DPC
d34ec3309f
Rollup merge of #69992 - kornelski:robots, r=steveklabnik
Block version-specific docs from search engines

Latest stable, beta and nightly URLs remain accessible because their URLs don't start with a version number. Robots.txt uses simple path prefixes, so it's OK that the disallow rules aren't full directory paths.

Direct links to old docs remain accessible to users, because robots.txt only affects crawlers.

With this change old docs for specific old versions of Rust won't pop up in search results. This is good, because users won't be getting obsolete documentation by accident.
2020-03-16 01:30:35 +01:00
Dylan DPC
fdb5df049c
Rollup merge of #69964 - ollie27:ci_nodejs, r=Mark-Simulacrum,GuillaumeGomez
Add Node.js to PR CI image

This should allow the `rustdoc-js` and `rustdoc-js-std` test suites to run automatically on PRs.
2020-03-16 01:30:33 +01:00
Dylan DPC
bbdc871c53
Rollup merge of #69917 - GuillaumeGomez:cleanup-e0412, r=Dylan-DPC
Cleanup E0412 and E0422

r? @Dylan-DPC
2020-03-16 01:30:31 +01:00
Dylan DPC
957241fcf9
Rollup merge of #69858 - da-x:windows-precise-time, r=Dylan-DPC
std: on Windows, use GetSystemTimePreciseAsFileTime if it is available

This implements #67266.
2020-03-16 01:30:28 +01:00
Dylan DPC
e5de0b13fe
Rollup merge of #69686 - varkor:rustdoc-attributes, r=GuillaumeGomez
Use `pprust` to print attributes in rustdoc

Fixes https://github.com/rust-lang/rust/issues/69559.

I'm not sure what the original motivation was for the `render_attribute`, so I may be missing something, but replacing it with `pprust::attribute_to_string` seems to give the intended output (modulo some spacing idiosyncrasies).

r? @GuillaumeGomez
2020-03-16 01:30:24 +01:00
Mark Mansi
7bd8ce2e50 More Method->Fn renaming 2020-03-15 19:15:55 -05:00
Vadim Petrochenkov
db638bd123 hygiene: modern -> normalize_to_macros_2_0
`modern_and_legacy` -> `normalize_to_macro_rules`
2020-03-16 00:29:42 +03:00
Vadim Petrochenkov
8c9a38f679 Other legacy -> macro_rules 2020-03-16 00:29:42 +03:00
Vadim Petrochenkov
3fbb2549ce resolve: Legacy(Scope,Binding) -> MacroRules(Scope,Binding) 2020-03-16 00:29:42 +03:00
Vadim Petrochenkov
65bf4831d2 ast/hir: MacroDef::legacy -> MacroDef::macro_rules 2020-03-16 00:29:03 +03:00
bors
45ebd5808a Auto merge of #68944 - Zoxc:hir-map, r=eddyb
Use queries for the HIR map

r? @eddyb cc @michaelwoerister
2020-03-15 20:40:16 +00:00
Mazdak Farrokhzad
81099c27dd VariantSizeDifferences: bail on SizeOverflow 2020-03-15 18:54:36 +01:00
bors
e0f5df0173 Auto merge of #70024 - Centril:rollup-cppmaxr, r=Centril
Rollup of 8 pull requests

Successful merges:

 - #69528 (Add undo_leak to reset RefCell borrow state)
 - #69589 (ast: `Mac`/`Macro` -> `MacCall`)
 - #69661 (Implement From<&mut str> for String)
 - #69988 (rustc_metadata: Remove `rmeta::MacroDef`)
 - #70006 (resolve: Fix two issues in fresh binding disambiguation)
 - #70011 (def_collector: Fully visit async functions)
 - #70013 (Return feature gate as a `Symbol` )
 - #70018 (Fix "since" field for `Once::is_complete`'s `#[stable]` attribute)

Failed merges:

r? @ghost
2020-03-15 17:27:47 +00:00
varkor
c599ec4460 Add FIXME note 2020-03-15 15:11:29 +00:00
varkor
621c42c163 Render full attributes in rustdoc 2020-03-15 15:11:29 +00:00
Mazdak Farrokhzad
bde77af094
Rollup merge of #70018 - LukasKalbertodt:fix-once-is-complete-since, r=Centril
Fix "since" field for `Once::is_complete`'s `#[stable]` attribute

It was accidentally merged with the wrong version in #68945.  Thanks @jplatte for noticing.

This also needs to be beta backported.
2020-03-15 15:40:15 +01:00
Mazdak Farrokhzad
b46ef3dd03
Rollup merge of #70013 - ecstatic-morse:check-consts-feature-gate, r=oli-obk
Return feature gate as a `Symbol`

A minor refactoring that will be needed for #68940. That PR is blocked on me changing the error comments in a whole lot of UI tests.

r? @oli-obk
2020-03-15 15:40:13 +01:00
Mazdak Farrokhzad
d74c5cd07c
Rollup merge of #70011 - petrochenkov:asyncice, r=Centril
def_collector: Fully visit async functions

We forgot to visit attributes previously, it caused ICEs.

Special treatment of async functions is also moved from `visit_item` to `visit_fn` to reuse more of the default visitor.

Fixes https://github.com/rust-lang/rust/issues/67778.
2020-03-15 15:40:12 +01:00
Mazdak Farrokhzad
d986a706bd
Rollup merge of #70006 - petrochenkov:fresh, r=Centril
resolve: Fix two issues in fresh binding disambiguation

Prevent fresh bindings from shadowing ambiguity items.
Fixes https://github.com/rust-lang/rust/issues/46079

Correctly treat const generic parameters in fresh binding disambiguation.
Fixes https://github.com/rust-lang/rust/issues/68853
2020-03-15 15:40:10 +01:00
Mazdak Farrokhzad
8bca839fdf
Rollup merge of #69988 - petrochenkov:nomacrodef, r=Centril
rustc_metadata: Remove `rmeta::MacroDef`

And other related cleanups.

Follow-up to https://github.com/rust-lang/rust/pull/66364.
r? @Centril
2020-03-15 15:40:08 +01:00
Mazdak Farrokhzad
cc1623267b
Rollup merge of #69661 - lopopolo:string-from-mut-str, r=sfackler
Implement From<&mut str> for String

I ran into this missing impl when trying to do `String::from` on the result returned from this API in the `uuid` crate:

https://docs.rs/uuid/0.8.1/uuid/adapter/struct.Hyphenated.html#method.encode_lower

I wasn't sure what to put in the stability annotation. I'd appreciate some help with that :)
2020-03-15 15:40:07 +01:00
Mazdak Farrokhzad
d1e943f263
Rollup merge of #69589 - petrochenkov:maccall, r=Centril
ast: `Mac`/`Macro` -> `MacCall`

It's now obvious that these refer to macro calls rather than to macro definitions.

It's also a single name instead of two different names in different places.

`rustc_expand` usually calls macro calls in a wide sense (including attributes and derives) "macro invocations", but structures and variants renamed in this PR are only relevant to fn-like macros, so it's simpler and clearer to just call them calls.

cc https://github.com/rust-lang/rust/pull/63586#discussion_r314232513
r? @eddyb
2020-03-15 15:40:05 +01:00
Mazdak Farrokhzad
83aad6b9a8
Rollup merge of #69528 - HeroicKatora:finalize-ref-cell, r=dtolnay
Add undo_leak to reset RefCell borrow state

This method is complementary for the feature cell_leak added in an
earlier PR. It allows *safely* reverting the effects of leaking a borrow guard by
statically proving that such a guard could not longer exist. This was
not added to the existing `get_mut` out of concern of impacting the
complexity of the otherwise pure pointer cast and because the name
`get_mut` poorly communicates the intent of resetting remaining borrows.

This is a follow-up to #68712 and uses the same tracking issue, #69099,
as these methods deal with the same mechanism and the idea came up
[in a review comment](https://github.com/rust-lang/rust/pull/68712#discussion_r384670041).

@dtolnay who reviewed the prior PR.
cc @RalfJung
2020-03-15 15:40:03 +01:00
bors
5da2e53f47 Auto merge of #69961 - RalfJung:miri, r=RalfJung
update miri

r? @ghost
Cc @oli-obk

Fixes https://github.com/rust-lang/rust/issues/69855
2020-03-15 14:18:14 +00:00
Matthew Jasper
39ee66ab82 Consider well-formed predicates in min-specialization 2020-03-15 13:49:28 +00:00
Matthew Jasper
4377ac3e2f Use min_specialization in libstd and libproc_macro 2020-03-15 13:23:03 +00:00
Matthew Jasper
0bbbe719e8 Implement soundness check for min_specialization 2020-03-15 13:22:58 +00:00
Matthew Jasper
32d330df30 Avoid ICEs when we emit errors constructing the specialization graph 2020-03-15 13:22:34 +00:00
Matthew Jasper
c24b4bf410 Add attributes to allow specializing on traits 2020-03-15 12:44:25 +00:00