summary refs log tree commit diff
path: root/compiler/rustc_span/src
AgeCommit message (Collapse)AuthorLines
2021-10-14Use correct edition for panic in [debug_]assert!() etc.Mara Bos-0/+1
2021-09-16Revert "Implement Anonymous{Struct, Union} in the AST"Felix S. Klock II-1/+0
This reverts commit 059b68dd677808e14e560802d235ad40beeba71e. Note that this was manually adjusted to retain some of the refactoring introduced by commit 059b68dd677808e14e560802d235ad40beeba71e, so that it could likewise retain the correction introduced in commit 5b4bc05fa57be19bb5962f4b7c0f165e194e3151 (cherry picked from commit 91feb76d133952825e3eb32bed399ec6e4bd9219)
2021-09-03Auto merge of #88363 - michaelwoerister:remapped-diagnostics, r=estebankbors-16/+38
Path remapping: Make behavior of diagnostics output dependent on presence of --remap-path-prefix. This PR fixes a regression (#87745) with `--remap-path-prefix` where the flag stopped causing diagnostic messages to be remapped as well. The regression was introduced in https://github.com/rust-lang/rust/pull/83813 where we erroneously assumed that remapping of diagnostic messages was not desired anymore (because #70642 partially undid that functionality with nobody objecting). The issue is fixed by making `--remap-path-prefix` remap diagnostic messages again, including for paths that have been remapped in upstream crates (e.g. the standard library). This means that "sysroot-localization" (implemented in #70642) is also disabled if `rustc` is invoked with `--remap-path-prefix`. The assumption is that once someone starts explicitly remapping paths they also don't want paths to their local Rust installation in their build output. In the future we might want to give more fine-grained control over this behavior via compiler flags (see https://github.com/rust-lang/rfcs/pull/3127 for a related RFC). For now this PR is intended as a regression fix. This PR is an alternative to https://github.com/rust-lang/rust/pull/88191, which makes diagnostic messages be remapped unconditionally. That approach, however, would effectively revert #70642. Fixes https://github.com/rust-lang/rust/issues/87745. cc `@cbeuw` r? `@ghost`
2021-09-01Rollup merge of #88350 - programmerjake:add-ppc-cr-xer-clobbers, r=AmanieuMara Bos-0/+2
add support for clobbering xer, cr, and cr[0-7] for asm! on OpenPower/PowerPC Fixes #88315
2021-09-01Auto merge of #87688 - camsteffen:let-else, r=cjgillotbors-0/+3
Introduce `let...else` Tracking issue: #87335 The trickiest part for me was enforcing the diverging else block with clear diagnostics. Perhaps the obvious solution is to expand to `let _: ! = ..`, but I decided against this because, when a "mismatched type" error is found in typeck, there is no way to trace where in the HIR the expected type originated, AFAICT. In order to pass down this information, I believe we should introduce `Expectation::LetElseNever(HirId)` or maybe add `HirId` to `Expectation::HasType`, but I left that as a future enhancement. For now, I simply assert that the block is `!` with a custom `ObligationCauseCode`, and I think this is clear enough, at least to start. The downside here is that the error points at the entire block rather than the specific expression with the wrong type. I left a todo to this effect. Overall, I believe this PR is feature-complete with regard to the RFC.
2021-08-31Pull Span::find_ancestor_inside loop into its own function.Mara Bos-0/+8
2021-08-31Auto merge of #88414 - Aaron1011:guess-foreign-head-span, r=estebankbors-0/+11
Don't use `guess_head_span` in `predicates_of` for foreign span Previously, the result of `predicates_of` for a foreign trait would depend on the *current* state of the corresponding source file in the foreign crate. This could lead to ICEs during incremental compilation, since the on-disk contents of the upstream source file could potentially change without the upstream crate being recompiled. Additionally, this ensure that that the metadata we produce for a crate only depends on its *compiled* upstream dependencies (e.g an rlib or rmeta file), *not* the current on-disk state of the upstream crate source files.
2021-08-30Add let_else feature gateCameron Steffen-0/+1
2021-08-30Lower let-else to HIRCameron Steffen-0/+2
2021-08-31Auto merge of #88100 - HTG-YT:edition2021-compopt-stabilization, r=m-ou-sebors-2/+2
Make Edition 2021 Stable An item of #87959. This is an "on-demand" pull request, which means it will be merged when it is the right time to.
2021-08-30Update LATEST_STABLE_EDITION to 2021.Mara Bos-1/+1
2021-08-30make edition 2021 stableHTG-YT-1/+1
2021-08-30`feature(const_param_types)` -> `feature(adt_const_params)`lcnr-1/+1
2021-08-30`feature(const_generics)` -> `feature(const_param_types)`lcnr-0/+1
2021-08-30rename const_evaluatable_checked to generic_const_exprsEllen-0/+1
:sparkles:
2021-08-27Don't use `guess_head_span` in `predicates_of` for foreign spanAaron Hill-0/+11
Previously, the result of `predicates_of` for a foreign trait would depend on the *current* state of the corresponding source file in the foreign crate. This could lead to ICEs during incremental compilation, since the on-disk contents of the upstream source file could potentially change without the upstream crate being recompiled. Additionally, this ensure that that the metadata we produce for a crate only depends on its *compiled* upstream dependencies (e.g an rlib or rmeta file), *not* the current on-disk state of the upstream crate source files.
2021-08-27Path remapping: Make behavior of diagnostics output dependent on presence of ↵Michael Woerister-16/+38
--remap-path-prefix.
2021-08-25add support for clobbering xer, cr, and cr[0-7] for asm! on OpenPower/PowerPCJacob Lifshay-0/+2
Fixes #88315
2021-08-25Use if-let guards in the codebaseLéo Lanteri Thauvin-20/+17
2021-08-22Fix typos “an”→“a” and a few different ones that appeared in the ↵Frank Steffahn-1/+1
same search
2021-08-19Rollup merge of #88050 - Aaron1011:filename-hash-stable, r=michaelwoeristerGuillaume Gomez-2/+2
Remove `HashStable` impls for `FileName` and `RealFileName` These impls were unused, and incorrectly hashed the local (non-remapped) path for `RealFileName::Remapped` (which would break reproducible builds if these impls were used).
2021-08-16Auto merge of #87050 - jyn514:no-doc-primitive, r=manishearthbors-0/+1
Add future-incompat lint for `doc(primitive)` ## What is `doc(primitive)`? `doc(primitive)` is an attribute recognized by rustdoc which adds documentation for the built-in primitive types, such as `usize` and `()`. It has been stable since Rust 1.0. ## Why change anything? `doc(primitive)` is useless for anyone outside the standard library. Since rustdoc provides no way to combine the documentation on two different primitive items, you can only replace the docs, and since the standard library already provides extensive documentation there is no reason to do so. While fixing rustdoc's handling of primitive items (https://github.com/rust-lang/rust/pull/87073) I discovered that even rustdoc's existing handling of primitive items was broken if you had more than two crates using it (it would pick randomly between them). That meant both: - Keeping rustdoc's existing treatment was nigh-impossible, because it was random. - doc(primitive) was even more useless than it would otherwise be. The only use-case for this outside the standard library is for no-std libraries which want to link to primitives (https://github.com/rust-lang/rust/issues/73423) which is being fixed in https://github.com/rust-lang/rust/pull/87073. https://github.com/rust-lang/rust/pull/87073 makes various breaking changes to `doc(primitive)` (breaking in the sense that they change the semantics, not in that they cause code to fail to compile). It's not possible to avoid these and still fix rustdoc's issues. ## What can we do about it? As shown by the crater run (https://github.com/rust-lang/rust/pull/87050#issuecomment-886166706), no one is actually using doc(primitive), there wasn't a single true regression in the whole run. We can either: 1. Feature gate it completely, breaking anyone who crater missed. They can easily fix the breakage just by removing the attribute. 2. add it to the `INVALID_DOC_ATTRIBUTES` future-incompat lint, and at the same time make it a no-op unless you add a feature gate. That would mean rustdoc has to look at the features of dependent crates, because it needs to know where primitives are defined in order to link to them. 3. add it to `INVALID_DOC_ATTRIBUTES`, but still use it to determine where primitives come from 4. do nothing; the behavior will silently change in https://github.com/rust-lang/rust/pull/87073. My preference is for 2, but I would also be happy with 1 or 3. I don't think we should silently change the behavior. This PR currently implements 3.
2021-08-16Auto merge of #84039 - jyn514:uplift-atomic-ordering, r=wesleywiserbors-0/+29
Uplift the invalid_atomic_ordering lint from clippy to rustc This is mostly just a rebase of https://github.com/rust-lang/rust/pull/79654; I've copy/pasted the text from that PR below. r? `@lcnr` since you reviewed the last one, but feel free to reassign. --- This is an implementation of https://github.com/rust-lang/compiler-team/issues/390. As mentioned, in general this turns an unconditional runtime panic into a (compile time) lint failure. It has no false positives, and the only false negatives I'm aware of are if `Ordering` isn't specified directly and is comes from an argument/constant/whatever. As a result of it having no false positives, and the alternative always being strictly wrong, it's on as deny by default. This seems right. In the [zulip stream](https://rust-lang.zulipchat.com/#narrow/stream/233931-t-compiler.2Fmajor-changes/topic/Uplift.20the.20.60invalid_atomic_ordering.60.20lint.20from.20clippy/near/218483957) `@joshtriplett` suggested that lang team should FCP this before landing it. Perhaps libs team cares too? --- Some notes on the code for reviewers / others below ## Changes from clippy The code is changed from [the implementation in clippy](https://github.com/rust-lang/rust-clippy/blob/68cf94f6a66e47234e3adefc6dfbe806cd6ad164/clippy_lints/src/atomic_ordering.rs) in the following ways: 1. Uses `Symbols` and `rustc_diagnostic_item`s instead of string literals. - It's possible I should have just invoked Symbol::intern for some of these instead? Seems better to use symbol, but it did require adding several. 2. The functions are moved to static methods inside the lint struct, as a way to namespace them. - There's a lot of other code in that file — which I picked as the location for this lint because `@jyn514` told me that seemed reasonable. 3. Supports unstable AtomicU128/AtomicI128. - I did this because it was almost easier to support them than not — not supporting them would have (ideally) required finding a way not to give them a `rustc_diagnostic_item`, which would have complicated an already big macro. - These don't have tests since I wasn't sure if/how I should make tests conditional on whether or not the target has the atomic... This is to a certain extent an issue of 64bit atomics too, but 128-bit atomics are much less common. Regardless, the existing tests should be *more* than thorough enough here. 4. Minor changes like: - grammar tweaks ("loads cannot have `Release` **and** `AcqRel` ordering" => "loads cannot have `Release` **or** `AcqRel` ordering") - function renames (`match_ordering_def_path` => `matches_ordering_def_path`), - avoiding clippy-specific helper methods that don't exist in rustc_lint and didn't seem worth adding for this case (for example `cx.struct_span_lint` vs clippy's `span_lint_and_help` helper). ## Potential issues (This is just about the code in this PR, not conceptual issues with the lint or anything) 1. I'm not sure if I should have used a diagnostic item for `Ordering` and its variants (I couldn't figure out how really, so if I should do this some pointers would be appreciated). - It seems possible that failing to do this might possibly mean there are more cases this lint would miss, but I don't really know how `match_def_path` works and if it has any pitfalls like that, so maybe not. 2. I *think* I deprecated the lint in clippy (CC `@flip1995` who asked to be notified about clippy changes in the future in [this comment](https://github.com/rust-lang/rust/pull/75671#issuecomment-718731659)) but I'm not sure if I need to do anything else there. - I'm kind of hoping CI will catch if I missed anything, since `x.py test src/tools/clippy` fails with a lot of errors with and without my changes (and is probably a nonsense command regardless). Running `cargo test` from src/tools/clippy also fails with unrelated errors that seem like refactorings that didnt update clippy? So, honestly no clue. 3. I wasn't sure if the description/example I gave good. Hopefully it is. The example is less thorough than the one from clippy here: https://rust-lang.github.io/rust-clippy/master/index.html#invalid_atomic_ordering. Let me know if/how I should change it if it needs changing. 4. It pulls in the `if_chain` crate. This crate was already used in clippy, and seems like it's used elsewhere in rustc, but I'm willing to rewrite it to not use this if needed (I'd prefer not to, all things being equal).
2021-08-16feature gate doc(primitive)Joshua Nelson-0/+1
2021-08-16Uplift the `invalid_atomic_ordering` lint from clippy to rustcThom Chiovoloni-0/+29
- Deprecate clippy::invalid_atomic_ordering - Use rustc_diagnostic_item for the orderings in the invalid_atomic_ordering lint - Reduce code duplication - Give up on making enum variants diagnostic items and just look for `Ordering` instead I ran into tons of trouble with this because apparently the change to store HIR attrs in a side table also gave the DefIds of the constructor instead of the variant itself. So I had to change `matches_ordering` to also check the grandparent of the defid as well. - Rename `atomic_ordering_x` symbols to just the name of the variant - Fix typos in checks - there were a few places that said "may not be Release" in the diagnostic but actually checked for SeqCst in the lint. - Make constant items const - Use fewer diagnostic items - Only look at arguments after making sure the method matches This prevents an ICE when there aren't enough arguments. - Ignore trait methods - Only check Ctors instead of going through `qpath_res` The functions take values, so this couldn't ever be anything else. - Add if_chain to allowed dependencies - Fix grammar - Remove unnecessary allow
2021-08-15Remove `HashStable` impls for `FileName` and `RealFileName`Aaron Hill-2/+2
These impls were unused, and incorrectly hashed the local (non-remapped) path for `RealFileName::Remapped` (which would break reproducible builds if these impls were used).
2021-08-14Auto merge of #87581 - Amanieu:asm_clobber_abi, r=nagisabors-0/+1
Add support for clobber_abi to asm! This PR adds the `clobber_abi` feature that was proposed in #81092. Fixes #81092 cc `@rust-lang/wg-inline-asm` r? `@nagisa`
2021-08-12Implement `black_box` using intrinsicGary Guo-0/+1
The new implementation allows some `memcpy`s to be optimized away, so the uninit value in ui/sanitize/memory.rs is constructed directly onto the return place. Therefore the sanitizer now says that the value is allocated by `main` rather than `random`.
2021-08-12Add support for clobber_abi to asm!Amanieu d'Antras-0/+1
2021-08-03Auto merge of #87262 - dtolnay:negative, r=Aaron1011bors-0/+4
Support negative numbers in Literal::from_str proc_macro::Literal has allowed negative numbers in a single literal token ever since Rust 1.29, using https://doc.rust-lang.org/stable/proc_macro/struct.Literal.html#method.isize_unsuffixed and similar constructors. ```rust let lit = proc_macro::Literal::isize_unsuffixed(-10); ``` However, the suite of constructors on Literal is not sufficient for all use cases, for example arbitrary precision floats, or custom suffixes in FFI macros. ```rust let lit = proc_macro::Literal::f64_unsuffixed(0.101001000100001000001000000100000001); // :( let lit = proc_macro::Literal::i???_suffixed(10ulong); // :( ``` For those, macros construct the literal using from_str instead, which preserves arbitrary precision, custom suffixes, base, and digit grouping. ```rust let lit = "0.101001000100001000001000000100000001".parse::<Literal>().unwrap(); let lit = "10ulong".parse::<Literal>().unwrap(); let lit = "0b1000_0100_0010_0001".parse::<Literal>().unwrap(); ``` However, until this PR it was not possible to construct a literal token that is **both** negative **and** preserving of arbitrary precision etc. This PR fixes `Literal::from_str` to recognize negative integer and float literals.
2021-08-02Implement a `explicit_generic_args_with_impl_trait` feature gateGary Guo-0/+1
When this gate is enabled, explicit generic arguments can be specified even if `impl Trait` is used in argument position. Generic arguments can only be specified for explicit generic parameters but not for the synthetic type parameters from `impl Trait`
2021-07-31Added feature gate.Alexander Regueiro-0/+1
2021-07-29Add feature gates for `for` and `?` in constsJonas Schievink-0/+2
2021-07-28Add new const_format_args!() macro and use it in panics.Mara Bos-0/+1
2021-07-28Make const panic!("..") work in Rust 2021.Mara Bos-0/+4
During const eval, this replaces calls to core::panicking::panic_fmt and std::panicking::being_panic_fmt with a call to a new const fn: core::panicking::const_panic_fmt. That function uses fmt::Arguments::as_str() to get the str and calls panic_str with that instead. panic!() invocations with formatting arguments are still not accepted, as the creation of such a fmt::Arguments cannot be done in constant functions right now.
2021-07-27Permit deriving default on enums with `#[default]`Jacob Pratt-0/+1
2021-07-26Actually infer args in visitorskadmin-0/+1
2021-07-20Add internal attribute and tests.Charles Lew-0/+1
2021-07-19Auto merge of #87225 - estebank:cleanup, r=oli-obkbors-2/+2
Various diagnostics clean ups/tweaks * Always point at macros, including derive macros * Point at non-local items that introduce a trait requirement * On private associated item, point at definition
2021-07-19Various diagnostics clean ups/tweaksEsteban Küber-2/+2
* Always point at macros, including derive macros * Point at non-local items that introduce a trait requirement * On private associated item, point at definition
2021-07-18Support negative numbers in Literal::from_strDavid Tolnay-0/+4
2021-07-18Rollup merge of #87170 - xFrednet:clippy-5393-add-diagnostic-items, ↵Yuki Okushi-0/+22
r=Manishearth,oli-obk Add diagnostic items for Clippy This adds a bunch of diagnostic items to `std`/`core`/`alloc` functions, structs and traits used in Clippy. The actual refactorings in Clippy to use these items will be done in a different PR in Clippy after the next sync. This PR doesn't include all paths Clippy uses, I've only gone through the first 85 lines of Clippy's [`paths.rs`](https://github.com/rust-lang/rust-clippy/blob/ecf85f4bdc319f9d9d853d1fff68a8a25e64c7a8/clippy_utils/src/paths.rs) (after rust-lang/rust-clippy#7466) to get some feedback early on. I've also decided against adding diagnostic items to methods, as it would be nicer and more scalable to access them in a nicer fashion, like adding a `is_diagnostic_assoc_item(did, sym::Iterator, sym::map)` function or something similar (Suggested by `@camsteffen` [on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/147480-t-compiler.2Fwg-diagnostics/topic/Diagnostic.20Item.20Naming.20Convention.3F/near/225024603)) There seems to be some different naming conventions when it comes to diagnostic items, some use UpperCamelCase (`BinaryHeap`) and some snake_case (`hashmap_type`). This PR uses UpperCamelCase for structs and traits and snake_case with the module name as a prefix for functions. Any feedback on is this welcome. cc: rust-lang/rust-clippy#5393 r? `@Manishearth`
2021-07-17Simplify Expn creation.Camille GILLOT-27/+25
2021-07-17Rename expn_info -> expn_data.Camille GILLOT-8/+8
2021-07-17Pass ExpnData by reference.Camille GILLOT-3/+3
2021-07-17Drop ExpnData::krate.Camille GILLOT-19/+10
2021-07-17Drop orig_id.Camille GILLOT-33/+9
2021-07-17Encode ExpnId using ExpnHash for incr. comp.Camille GILLOT-66/+57
2021-07-17Choose encoding format in caller code.Camille GILLOT-72/+26
2021-07-17Use LocalExpnId where possible.Camille GILLOT-14/+1