about summary refs log tree commit diff
path: root/compiler/rustc_span
AgeCommit message (Collapse)AuthorLines
2022-08-02Auto merge of #92268 - jswrenn:transmute, r=oli-obkbors-0/+1
Initial implementation of transmutability trait. *T'was the night before Christmas and all through the codebase, not a miri was stirring — no hint of `unsafe`!* This PR provides an initial, **incomplete** implementation of *[MCP 411: Lang Item for Transmutability](https://github.com/rust-lang/compiler-team/issues/411)*. The `core::mem::BikeshedIntrinsicFrom` trait provided by this PR is implemented on-the-fly by the compiler for types `Src` and `Dst` when the bits of all possible values of type `Src` are safely reinterpretable as a value of type `Dst`. What this PR provides is: - [x] [support for transmutations involving primitives](https://github.com/jswrenn/rust/tree/transmute/src/test/ui/transmutability/primitives) - [x] [support for transmutations involving arrays](https://github.com/jswrenn/rust/tree/transmute/src/test/ui/transmutability/arrays) - [x] [support for transmutations involving structs](https://github.com/jswrenn/rust/tree/transmute/src/test/ui/transmutability/structs) - [x] [support for transmutations involving enums](https://github.com/jswrenn/rust/tree/transmute/src/test/ui/transmutability/enums) - [x] [support for transmutations involving unions](https://github.com/jswrenn/rust/tree/transmute/src/test/ui/transmutability/unions) - [x] [support for weaker validity checks](https://github.com/jswrenn/rust/blob/transmute/src/test/ui/transmutability/unions/should_permit_intersecting_if_validity_is_assumed.rs) (i.e., `Assume::VALIDITY`) - [x] visibility checking What isn't yet implemented: - [ ] transmutability options passed using the `Assume` struct - [ ] [support for references](https://github.com/jswrenn/rust/blob/transmute/src/test/ui/transmutability/references.rs) - [ ] smarter error messages These features will be implemented in future PRs.
2022-07-28Use line numbers relative to function in mir opt testsNilstrieb-0/+27
This adds a new option, `-Zmir-pretty-relative-line-numbers`, that is then used in compiletest for the mir-opt tests.
2022-07-27Initial (incomplete) implementation of transmutability trait.Jack Wrenn-0/+1
This initial implementation handles transmutations between types with specified layouts, except when references are involved. Co-authored-by: Igor null <m1el.2027@gmail.com>
2022-07-27lint: add bad opt access internal lintDavid Wood-0/+2
Some command-line options accessible through `sess.opts` are best accessed through wrapper functions on `Session`, `TyCtxt` or otherwise, rather than through field access on the option struct in the `Session`. Adds a new lint which triggers on those options that should be accessed through a wrapper function so that this is prohibited. Options are annotated with a new attribute `rustc_lint_opt_deny_field_access` which can specify the error message (i.e. "use this other function instead") to be emitted. A simpler alternative would be to simply rename the options in the option type so that it is clear they should not be used, however this doesn't prevent uses, just discourages them. Another alternative would be to make the option fields private, and adding accessor functions on the option types, however the wrapper functions sometimes rely on additional state from `Session` or `TyCtxt` which wouldn't be available in an function on the option type, so the accessor would simply make the field available and its use would be discouraged too. Signed-off-by: David Wood <david.wood@huawei.com>
2022-07-26Auto merge of #99574 - durin42:allocator-patch-redux, r=nikicbors-0/+3
codegen: use new {re,de,}allocator annotations in llvm This obviates the patch that teaches LLVM internals about _rust_{re,de}alloc functions by putting annotations directly in the IR for the optimizer. The sole test change is required to anchor FileCheck to the body of the `box_uninitialized` method, so it doesn't see the `allocalign` on `__rust_alloc` and get mad about the string `alloca` showing up. Since I was there anyway, I added some checks on the attributes to prove the right attributes got set. r? `@nikic`
2022-07-26codegen: use new {re,de,}allocator annotations in llvmAugie Fackler-0/+3
This obviates the patch that teaches LLVM internals about _rust_{re,de}alloc functions by putting annotations directly in the IR for the optimizer. The sole test change is required to anchor FileCheck to the body of the `box_uninitialized` method, so it doesn't see the `allocalign` on `__rust_alloc` and get mad about the string `alloca` showing up. Since I was there anyway, I added some checks on the attributes to prove the right attributes got set. While we're here, we also emit allocator attributes on __rust_alloc_zeroed. This should allow LLVM to perform more optimizations for zeroed blocks, and probably fixes #90032. [This comment](https://github.com/rust-lang/rust/issues/24194#issuecomment-308791157) mentions "weird UB-like behaviour with bitvec iterators in rustc_data_structures" so we may need to back this change out if things go wrong. The new test cases require LLVM 15, so we copy them into LLVM 14-supporting versions, which we can delete when we drop LLVM 14.
2022-07-26Implement `#[rustc_default_body_unstable]`Maybe Waffle-0/+1
This attribute allows to mark default body of a trait function as unstable. This means that implementing the trait without implementing the function will require enabling unstable feature. This is useful in conjunction with `#[rustc_must_implement_one_of]`, 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.
2022-07-26Rollup merge of #99718 - TaKO8Ki:avoid-&str-symbol-to-string-conversions, ↵Yuki Okushi-11/+0
r=michaelwoerister Avoid `&str`/`Symbol` to `String` conversions follow-up to #99342 and #98668
2022-07-25remove `is_local_span` as it is no longer usedTakayuki Maeda-11/+0
2022-07-25Auto merge of #98770 - klensy:no-string-dupes-ugly, r=cjgillotbors-0/+3
rmeta: avoid embedding `StabilityLevel::Unstable` reason multiple times into .rmeta\.rlib files Avoids bloating size of some rmeta\rlib files by not placing default string for `StabilityLevel::Unstable` reason multiple times, affects only stdlib\rustc artifacts. For stdlib cuts about 3% (diff of total size for patched\unpatched *.rmeta files of stage1-std) of file size, depending on crates. fixes #88180
2022-07-23Auto merge of #98208 - ivanloz:master, r=nagisabors-0/+1
Add support for LLVM ShadowCallStack. LLVMs ShadowCallStack provides backward edge control flow integrity protection by using a separate shadow stack to store and retrieve a function's return address. LLVM currently only supports this for AArch64 targets. The x18 register is used to hold the pointer to the shadow stack, and therefore this only works on ABIs which reserve x18. Further details are available in the [LLVM ShadowCallStack](https://clang.llvm.org/docs/ShadowCallStack.html) docs. # Usage `-Zsanitizer=shadow-call-stack` # Comments/Caveats * Currently only enabled for the aarch64-linux-android target * Requires the platform to define a runtime to initialize the shadow stack, see the [LLVM docs](https://clang.llvm.org/docs/ShadowCallStack.html) for more detail.
2022-07-22Add simd_cast_ptr, simd_expose_addr, and simd_from_exposed_addr intrinsicsCaleb Zulawski-0/+3
2022-07-22Auto merge of #99420 - RalfJung:vtable, r=oli-obkbors-0/+2
make vtable pointers entirely opaque This implements the scheme discussed in https://github.com/rust-lang/unsafe-code-guidelines/issues/338: vtable pointers should be considered entirely opaque and not even readable by Rust code, similar to function pointers. - We have a new kind of `GlobalAlloc` that symbolically refers to a vtable. - Miri uses that kind of allocation when generating a vtable. - The codegen backends, upon encountering such an allocation, call `vtable_allocation` to obtain an actually dataful allocation for this vtable. - We need new intrinsics to obtain the size and align from a vtable (for some `ptr::metadata` APIs), since direct accesses are UB now. I had to touch quite a bit of code that I am not very familiar with, so some of this might not make much sense... r? `@oli-obk`
2022-07-21avoid embedding StabilityLevel::Unstable reason string into metadata ↵klensy-0/+3
multiple times
2022-07-20add intrinsic to access vtable size and alignRalf Jung-0/+2
2022-07-20span: add `span_extend_to_line` helperDavid Wood-0/+5
Adds a simple helper function to the `SourceMap` for extending a `Span` to encompass the entire line it is on - useful for suggestions where removing a line is the suggested action. Signed-off-by: David Wood <david.wood@huawei.com>
2022-07-20middle: add `implies_by` to `#[unstable]`David Wood-0/+1
If part of a feature is stabilized and a new feature is added for the remaining parts, then the `implied_by` attribute can be used to indicate which now-stable feature previously contained a item. If the now-stable feature is still active (if the user has only just updated rustc, for example) then there will not be an stability error for uses of the item from the implied feature. Signed-off-by: David Wood <david.wood@huawei.com>
2022-07-20Add ShadowCallStack SupportIvan Lozano-0/+1
Adds support for the LLVM ShadowCallStack sanitizer.
2022-07-19Auto merge of #98180 - notriddle:notriddle/rustdoc-fn, ↵bors-1/+1
r=petrochenkov,GuillaumeGomez Improve the function pointer docs This is #97842 but for function pointers instead of tuples. The concept is basically the same. * Reduce duplicate impls; show `fn (T₁, T₂, …, Tₙ)` and include a sentence saying that there exists up to twelve of them. * Show `Copy` and `Clone`. * Show auto traits like `Send` and `Sync`, and blanket impls like `Any`. https://notriddle.com/notriddle-rustdoc-test/std/primitive.fn.html
2022-07-19Rollup merge of #99438 - WaffleLapkin:dont_wrap_in_non_zero, r=compiler-errorsMatthias Krüger-0/+10
Improve suggestions for `NonZeroT` <- `T` coercion error Currently, when encountering a type mismatch error with `NonZeroT` and `T` (for example `NonZeroU8` and `u8`) we errorneusly suggest wrapping expression in `NonZeroT`: ```text error[E0308]: mismatched types --> ./t.rs:7:35 | 7 | let _: std::num::NonZeroU64 = 1; | -------------------- ^ expected struct `NonZeroU64`, found integer | | | expected due to this | help: try wrapping the expression in `std::num::NonZeroU64` | 7 | let _: std::num::NonZeroU64 = std::num::NonZeroU64(1); | +++++++++++++++++++++ + ``` I've removed this suggestion and added suggestions to call `new` (for `Option<NonZeroT>` <- `T` case) or `new` and `unwrap` (for `NonZeroT` <- `T` case): ```text error[E0308]: mismatched types --> ./t.rs:7:35 | 7 | let _: std::num::NonZeroU64 = 1; | -------------------- ^ expected struct `NonZeroU64`, found integer | | | expected due to this | help: Consider calling `NonZeroU64::new` | 7 | let _: std::num::NonZeroU64 = NonZeroU64::new(1).unwrap(); | ++++++++++++++++ ++++++++++ error[E0308]: mismatched types --> ./t.rs:8:43 | 8 | let _: Option<std::num::NonZeroU64> = 1; | ---------------------------- ^ expected enum `Option`, found integer | | | expected due to this | = note: expected enum `Option<NonZeroU64>` found type `{integer}` help: Consider calling `NonZeroU64::new` | 8 | let _: Option<std::num::NonZeroU64> = NonZeroU64::new(1); | ++++++++++++++++ + ``` r? `@compiler-errors`
2022-07-19Rollup merge of #99401 - TaKO8Ki:avoid-symbol-to-&str-conversions, r=nnethercoteMatthias Krüger-0/+1
Avoid `Symbol` to `&str` conversions `Symbol::as_str` is a slowish operation, so this patch removes some usages of it.
2022-07-19Suggest a fix for `NonZero*` <- `*` coercion errorMaybe Waffle-0/+10
2022-07-18avoid `Symbol` to `&str` conversionsTakayuki Maeda-0/+1
2022-07-17rustdoc: extend `#[doc(tuple_variadic)]` to fn pointersMichael Howell-1/+1
The attribute is also renamed `fake_variadic`.
2022-07-15Rollup merge of #99119 - TaKO8Ki:remove-string-matching-about-methods, ↵Dylan DPC-0/+2
r=cjgillot Refactor: remove a string matching about methods This patch remove a string matching about methods and adds some rustfix tests.
2022-07-15simplify `suggest_deref_ref_or_into`Takayuki Maeda-0/+2
2022-07-14Auto merge of #95956 - yaahc:stable-in-unstable, r=cjgillotbors-0/+1
Support unstable moves via stable in unstable items part of https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/moving.20items.20to.20core.20unstably and a blocker of https://github.com/rust-lang/rust/pull/90328. The libs-api team needs the ability to move an already stable item to a new location unstably, in this case for Error in core. Otherwise these changes are insta-stable making them much harder to merge. This PR attempts to solve the problem by checking the stability of path segments as well as the last item in the path itself, which is currently the only thing checked.
2022-07-14Auto merge of #99231 - Dylan-DPC:rollup-0tl8c0o, r=Dylan-DPCbors-1/+8
Rollup of 5 pull requests Successful merges: - #97720 (Always create elided lifetime parameters for functions) - #98315 (Stabilize `core::ffi:c_*` and rexport in `std::ffi`) - #98705 (Implement `for<>` lifetime binder for closures) - #99126 (remove allow(rustc::potential_query_instability) in rustc_span) - #99139 (Give a better error when `x dist` fails for an optional tool) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2022-07-14Rollup merge of #99126 - NiklasJonsson:84447/rustc_span, r=petrochenkovDylan DPC-1/+6
remove allow(rustc::potential_query_instability) in rustc_span Also, avoid sorting before debug output as iteration order can now be relied upon. Related #84447
2022-07-14Rollup merge of #98705 - WaffleLapkin:closure_binder, r=cjgillotDylan DPC-0/+1
Implement `for<>` lifetime binder for closures This PR implements RFC 3216 ([TI](https://github.com/rust-lang/rust/issues/97362)) and allows code like the following: ```rust let _f = for<'a, 'b> |a: &'a A, b: &'b B| -> &'b C { b.c(a) }; // ^^^^^^^^^^^--- new! ``` cc ``@Aaron1011`` ``@cjgillot``
2022-07-14Rollup merge of #97720 - cjgillot:all-fresh, r=petrochenkovDylan DPC-0/+1
Always create elided lifetime parameters for functions Anonymous and elided lifetimes in functions are sometimes (async fns) --and sometimes not (regular fns)-- desugared to implicit generic parameters. This difference of treatment makes it some downstream analyses more complicated to handle. This step is a pre-requisite to perform lifetime elision resolution on AST. There is currently an inconsistency in the treatment of argument-position impl-trait for functions and async fns: ```rust trait Foo<'a> {} fn foo(t: impl Foo<'_>) {} //~ ERROR missing lifetime specifier async fn async_foo(t: impl Foo<'_>) {} //~ OK fn bar(t: impl Iterator<Item = &'_ u8>) {} //~ ERROR missing lifetime specifier async fn async_bar(t: impl Iterator<Item = &'_ u8>) {} //~ OK ``` The current implementation reports "missing lifetime specifier" on `foo`, but **accepts it** in `async_foo`. This PR **proposes to accept** the anonymous lifetime in both cases as an extra generic lifetime parameter. This change would be insta-stable, so let's ping t-lang. Anonymous lifetimes in GAT bindings keep being forbidden: ```rust fn foo(t: impl Foo<Assoc<'_> = Bar<'_>>) {} ^^ ^^ forbidden ok ``` I started a discussion here: https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/Anonymous.20lifetimes.20in.20universal.20impl-trait/near/284968606 r? ``@petrochenkov``
2022-07-13Rename `debugging_opts` to `unstable_opts`Joshua Nelson-3/+3
This is no longer used only for debugging options (e.g. `-Zoutput-width`, `-Zallow-features`). Rename it to be more clear.
2022-07-13reduce scope of allow(rustc::potential_query_instability) in rustc_spanNiklas Jonsson-1/+6
2022-07-13Rollup merge of #99011 - oli-obk:UnsoundCell, r=eddybDylan DPC-2/+0
`UnsafeCell` blocks niches inside its nested type from being available outside fixes #87341 This implements the plan by `@eddyb` in https://github.com/rust-lang/rust/issues/87341#issuecomment-886083646 Somewhat related PR (not strictly necessary, but that cleanup made this PR simpler): #94527
2022-07-13Add feature gate.Camille GILLOT-0/+1
2022-07-12Parse closure bindersMaybe Waffle-0/+1
This is first step in implementing RFC 3216. - Parse `for<'a>` before closures in ast - Error in lowering - Add `closure_lifetime_binder` feature
2022-07-11lower let-else in MIR insteadDing Xiang Fei-2/+0
2022-07-11Rollup merge of #99140 - TaKO8Ki:implement-is-accessible-span, r=fee1-deadDylan DPC-0/+7
Implement `SourceMap::is_span_accessible` This patch adds `SourceMap::is_span_accessible` and replaces `span_to_snippet(span).is_ok()` and `span_to_snippet(span).is_err()` with it. This removes a `&str` to `String` conversion.
2022-07-11rename a methodTakayuki Maeda-1/+1
2022-07-11implement `is_accessible_span`Takayuki Maeda-0/+7
2022-07-10Rollup merge of #99103 - TaKO8Ki:avoid-&str-to-string-conversions, r=oli-obkMatthias Krüger-2/+1
Avoid some `&str` to `String` conversions This patch removes some `&str` to `String` conversions.
2022-07-10avoid some `&str` to `String` conversionsTakayuki Maeda-2/+1
2022-07-09Auto merge of #99028 - tmiasko:inline, r=estebankbors-0/+1
Miscellaneous inlining improvements Add `#[inline]` to a few trivial non-generic methods from a perf report that otherwise wouldn't be candidates for inlining.
2022-07-08add opt in attribute for stable-in-unstable itemsJane Lusby-0/+1
2022-07-08Auto merge of #98638 - bjorn3:less_string_interning, r=tmiaskobors-0/+2
Use less string interning This removes string interning in a couple of places where doing so won't result in perf improvements. I also switched one place to use pre-interned symbols.
2022-07-07Miscellaneous inlining improvementsTomasz Miąsko-0/+1
Add `#[inline]` to a few trivial non-generic methods from a perf report that otherwise wouldn't be candidates for inlining.
2022-07-07`UnsafeCell` now has no niches, ever.Oli Scherer-2/+0
2022-07-05errors: introduce `DecorateLint`David Wood-0/+1
Add a new trait to be generated by diagnostic derives which uses a `LintDiagnosticBuilder`. Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-29Auto merge of #98376 - nnethercote:improve-derive-PartialEq, r=petrochenkovbors-0/+3
Improve some deriving code and add a test The `.stdout` test is particularly useful. r? `@petrochenkov`
2022-06-28Use pre-interned symbols in import recoverybjorn3-0/+2