about summary refs log tree commit diff
AgeCommit message (Collapse)AuthorLines
2024-10-07Rollup merge of #128399 - mammothbane:master, r=Amanieu,tgross35Stuart Cook-136/+164
liballoc: introduce String, Vec const-slicing This change `const`-qualifies many methods on `Vec` and `String`, notably `as_slice`, `as_str`, `len`. These changes are made behind the unstable feature flag `const_vec_string_slice`. ## Motivation This is to support simultaneous variance over ownership and constness. I have an enum type that may contain either `String` or `&str`, and I want to produce a `&str` from it in a possibly-`const` context. ```rust enum StrOrString<'s> { Str(&'s str), String(String), } impl<'s> StrOrString<'s> { const fn as_str(&self) -> &str { match self { // In a const-context, I really only expect to see this variant, but I can't switch the implementation // in some mode like #[cfg(const)] -- there has to be a single body Self::Str(s) => s, // so this is a problem, since it's not `const` Self::String(s) => s.as_str(), } } } ``` Currently `String` and `Vec` don't support this, but can without functional changes. Similar logic applies for `len`, `capacity`, `is_empty`. ## Changes The essential thing enabling this change is that `Unique::as_ptr` is `const`. This lets us convert `RawVec::ptr` -> `Vec::as_ptr` -> `Vec::as_slice` -> `String::as_str`. I had to move the `Deref` implementations into `as_{str,slice}` because `Deref` isn't `#[const_trait]`, but I would expect this change to be invisible up to inlining. I moved the `DerefMut` implementations as well for uniformity.
2024-10-07Auto merge of #131068 - RalfJung:immediate-offset-sanity-check, r=nnethercotebors-46/+76
Don't use Immediate::offset to transmute pointers to integers This applies the relatively new `assert_matches_abi` check in the `offset` operation on immediates, which makes sure that if offsets are used to alter the layout (which is possible because the field layout is arbitrarily picked by the caller), this is not done in a way that breaks the invariant of the `Immediate` type. This leads to ICEs in a GVN mir-opt test, so the second commit fixes GVN. Fixes https://github.com/rust-lang/rust/issues/131064.
2024-10-06liballoc: introduce String, Vec const-slicingNathan Perry-136/+164
This change `const`-qualifies many methods on Vec and String, notably `as_slice`, `as_str`, `len`. These changes are made behind the unstable feature flag `const_vec_string_slice` with the following tracking issue: https://github.com/rust-lang/rust/issues/129041
2024-10-06Auto merge of #128651 - folkertdev:naked-asm-macro-v2, r=Amanieubors-519/+551
add `naked_asm!` macro for use in `#[naked]` functions tracking issue: https://github.com/rust-lang/rust/issues/90957 Adds the `core::arch::naked_asm` macro, to be used in `#[naked]` functions, but providing better error messages and a place to explain the restrictions on assembly in naked functions. This PR does not yet require that the `naked_asm!` macro is used inside of `#[naked]` functions: - the `asm!` macro can still be used in `#[naked]` functions currently, with the same restrictions and error messages as before. - the `naked_asm!` macro can be used outside of `#[naked]` functions. It has not yet been decided whether that should be allowed long-term. In this PR, the parsing code of `naked_asm!` now enforces the restrictions on assembly in naked functions, with the exception of checking that the `noreturn` option is specified. It also has not currently been decided if `noreturn` should be implicit or not. This PR looks large because it touches a bunch of tests. The code changes are mostly straightforward I think: we now have 3 flavors of assembly macro, and that information must be propagated through the parsing code and error messages. cc `@Lokathor` r? `@Amanieu`
2024-10-06Auto merge of #131337 - matthiaskrgr:rollup-j37xn8o, r=matthiaskrgrbors-6/+22
Rollup of 4 pull requests Successful merges: - #131001 (add clarity for custom path installation) - #131307 (Android: Debug assertion after setting thread name) - #131322 (Update out-dated link) - #131335 (grammar fix) r? `@ghost` `@rustbot` modify labels: rollup
2024-10-06Rollup merge of #131335 - dacianpascu06:fix-typo, r=joboetMatthias Krüger-1/+1
grammar fix
2024-10-06Rollup merge of #131322 - mu001999-contrib:cleanup/invalid-url, r=jieyouxuMatthias Krüger-1/+1
Update out-dated link
2024-10-06Rollup merge of #131307 - YohDeadfall:prctl-set-name-dbg-assert, ↵Matthias Krüger-1/+3
r=workingjubilee Android: Debug assertion after setting thread name While `prctl` cannot fail if it points to a valid buffer, it's still better to assert the result as it's done for other places.
2024-10-06Rollup merge of #131001 - iyernaveenr:naveen_iyer/installation_clarity, ↵Matthias Krüger-3/+17
r=onur-ozkan add clarity for custom path installation install.sysconfdir is another value, in addition to install.prefix, that could be set for custom path installation.
2024-10-06grammar fixdacian-1/+1
2024-10-06various fixes for `naked_asm!` implementationFolkert de Vries-73/+116
- fix for divergence - fix error message - fix another cranelift test - fix some cranelift things - don't set the NORETURN option for naked asm - fix use of naked_asm! in doc comment - fix use of naked_asm! in run-make test - use `span_bug` in unreachable branch
2024-10-06Auto merge of #129670 - est31:cfg_attr_crate_type_name_error, r=Urgaubors-118/+60
Make deprecated_cfg_attr_crate_type_name a hard error Turns the forward compatibility lint added by #83744 into a hard error, so now, while the `#![crate_name]` and `#![crate_type]` attributes are still allowed in raw form, they are now forbidden to be nested inside a `#![cfg_attr()]` attribute. The following will now be an error: ```Rust #![cfg_attr(foo, crate_name = "foobar")] #![cfg_attr(foo, crate_type = "bin")] ``` This code will continue working and is not deprecated: ```Rust #![crate_name = "foobar"] #![crate_type = "lib"] ``` The reasoning for this is explained in #83744: it allows us to not have to cfg-expand in order to determine the crate's type and name. As of filing the PR, exactly two years have passed since #99784 has been merged, which has turned the lint's default warning level into an error, so there has been ample time to move off the now-forbidden syntax. cc #91632 - tracking issue for the lint
2024-10-06remove checks that are now performed during macro expansion of `naked_asm!`Folkert de Vries-66/+8
2024-10-06more `asm!` -> `naked_asm!` in testsFolkert de Vries-23/+22
2024-10-06disallow `asm!` in `#[naked]` functionsFolkert de Vries-297/+222
also disallow the `noreturn` option, and infer `naked_asm!` as `!`
2024-10-06use `naked_asm!` in feature-gate-naked_functions testFolkert-12/+45
2024-10-06use `naked_asm!` in naked-function testsFolkert-43/+63
2024-10-06use `naked_asm!` in `tests/ui/asm/naked-functions.rs`Folkert-139/+117
2024-10-06implement `naked_asm` macroFolkert-68/+160
2024-10-06Auto merge of #131259 - ↵bors-115/+114
ismailarilik:handle-potential-query-instability-lint-for-librustdoc, r=notriddle Handle `librustdoc` cases of `rustc::potential_query_instability` lint This PR removes `#![allow(rustc::potential_query_instability)]` line from [`src/librustdoc/lib.rs`](https://github.com/rust-lang/rust/blob/master/src/librustdoc/lib.rs#L23) and converts `FxHash{Map,Set}` types into `FxIndex{Map,Set}` to suppress lint errors. A somewhat tracking issue: https://github.com/rust-lang/rust/issues/84447 r? `@compiler-errors`
2024-10-06add clarity for custom path installationNaveen R. Iyer-3/+17
install.sysconfdir is another value, in addition to install.prefix, that could be set for custom path installation. Signed-off-by: Naveen R. Iyer <iyernaveenr@gmail.com>
2024-10-06Auto merge of #131320 - matthiaskrgr:rollup-tom15b3, r=matthiaskrgrbors-111/+850
Rollup of 5 pull requests Successful merges: - #129392 (Do not consider match/let/ref of place that evaluates to `!` to diverge, disallow coercions from them too) - #131279 (update "build/host" symlink comment) - #131312 (On function and method calls in patterns, link to the book) - #131315 (bootstrap: add `std_features` config) - #131316 (Fix typo in primitive_docs.rs) r? `@ghost` `@rustbot` modify labels: rollup
2024-10-06Update out-dated linkmu001999-1/+1
2024-10-06Rollup merge of #131316 - programmerjake:patch-4, r=NoratriebMatthias Krüger-1/+1
Fix typo in primitive_docs.rs typo introduced in #129559
2024-10-06Rollup merge of #131315 - shrirambalaji:issue-129599-fix-shrirambalaji, ↵Matthias Krüger-13/+58
r=onur-ozkan bootstrap: add `std_features` config Adding support for a std-features config under the rust section in config.toml during bootstrap. This allows rustc devs to build with specific feature flags for local development.
2024-10-06Rollup merge of #131312 - estebank:fn-in-pattern, r=compiler-errorsMatthias Krüger-64/+156
On function and method calls in patterns, link to the book ``` error: expected a pattern, found an expression --> f889.rs:3:13 | 3 | let (x, y.drop()) = (1, 2); | ^^^^^^^^ not a pattern | = note: arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html> error[E0532]: expected a pattern, found a function call --> f889.rs:2:13 | 2 | let (x, drop(y)) = (1, 2); | ^^^^ not a tuple struct or tuple variant | = note: function calls are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html> ``` Fix #97200.
2024-10-06Rollup merge of #131279 - onur-ozkan:remove-host-symlink, r=NoratriebMatthias Krüger-1/+1
update "build/host" symlink comment It's needed and can't be removed, so make it clear where it's needed.
2024-10-06Rollup merge of #129392 - ↵Matthias Krüger-32/+634
compiler-errors:raw-ref-op-doesnt-diverge-but-more, r=lcnr Do not consider match/let/ref of place that evaluates to `!` to diverge, disallow coercions from them too Fixes #117288. This PR implements a heuristic which disables two things that are currently being performed on the HIR when we have **expressions that involve place-like expressions that point to `!`**. Specifically, it will (in certain cases explained below): ### (1.) Disable the `NeverToAny` coercion we implicitly insert for `!`. Which fixes this inadvertent, sneaky unsoundness: ``` unsafe { let x: *const ! = &0 as *const u8 as *const !; let _: () = *x; } ``` which is UB because currently rust emits an *implicit* NeverToAny coercion even though we really shouldn't be, since there's no read of the value pointed by `x`. ### (2.) Disable the logic which considers expression which evaluate to `!` to diverge, which affects the type returned by the containing block. Which fixes this unsoundness: ``` fn make_up_a_value<T>() -> T { unsafe { let x: *const ! = &0 as *const u8 as *const !; let _ = *x; } } ``` We disable these two operations **if** the expression is a place-like expression (locals, statics, field projections, index operations, and deref operations), and if the parent expression is either: (1.) the LHS of an assignment (2.) AddrOf (3.) A match or let **unless** all of the *patterns consitute a read*, which is explained below: And finally, a pattern currently is considered to constitute a read **unless** it is a wildcard, or an OR pattern. An OR pattern is considered to constitute a read if all of its subpatterns constitute a read, to remain as conservative as possible in cases like `_ | subpat` or `subpat | _`. All other patterns are considered currently to constitute a read. Specifically, because `NeverToAny` is a coercion performed on a *value* and not a *place*, `Struct { .. }` on a `!` type must be a coercion currently, and we currently rely on this behavior to allow us to perform coercions like `let _: i32 = x;` where `x: !`. This is already considered UB by [miri](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=daf3a2246433fe43fdc07d1389c276c9), but also means it does not affect the preexisting UB in this case: ``` let Struct { .. } = *never_ptr; ``` Even though it's likely up for debate since we're not actually reading any data out of the struct, it almost certainly causes inference changes which I do *NOT* want to fix in this PR.
2024-10-06Auto merge of #131075 - mrkajetanp:bootstrap-editors, r=Kobzolbors-80/+193
bootstrap: Consolidate editor setup into ./x setup editor & add support for vim, emacs & helix Add support for automatically setting up the recommended LSP config for Vim (coc-nvim), Emacs (eglot) and Helix. Additionally, refactor setup.rs to make it easier to add support for more editors in the future. As suggested, r? `@jieyouxu`
2024-10-06Handle `librustdoc` cases of `rustc::potential_query_instability` lintismailarilik-115/+114
2024-10-06Auto merge of #131314 - tgross35:update-builtins, r=tgross35bors-4/+4
Update `compiler-builtins` to 0.1.133 This includes [1], which should help resolve an infinite recusion issue on WASM and SPARC (possibly other platforms). See [2] and [3] for further details. [1]: https://github.com/rust-lang/compiler-builtins/pull/708 [2]: https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/sparc-unknown-none-elf.20regresssion.20between.20compiler-built.2E.2E.2E [3]: https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/.5Bwasm32.5D.20Infinite.20recursion.20.60compiler-builtins.60.20.60__multi3.60
2024-10-05Fix typo in primitive_docs.rsJacob Lifshay-1/+1
2024-10-06bootstrap: add `std_features` configShriram Balaji-13/+58
bootstrap: add std_features to config.example fix: use BTreeSet for std-features; add unit tests * fix formatting of string in front of std_features * rename `std_features` to `std-features` in config.toml fix: remove space before std-features in config.toml fix: remove explicit .into_iter conversion bootstrap: add details for rust.std-features in config.example.toml Co-authored-by: Onur Özkan <onurozkan.dev@outlook.com> fix: remove `Option<T>` from `rust_std_features` fix: move default rust_std_features to config fix: make std_features CI rustc incompatible
2024-10-06Auto merge of #130540 - veera-sivarajan:fix-87525, r=estebankbors-6/+262
Add a Lint for Pointer to Integer Transmutes in Consts Fixes #87525 This PR adds a MirLint for pointer to integer transmutes in const functions and associated consts. The implementation closely follows this comment: https://github.com/rust-lang/rust/pull/85769#issuecomment-880969112. More details about the implementation can be found in the comments. Note: This could break some sound code as mentioned by RalfJung in https://github.com/rust-lang/rust/pull/85769#issuecomment-886491680: > ... technically const-code could transmute/cast an int to a ptr and then transmute it back and that would be correct -- so the lint will deny some sound code. Does not seem terribly likely though. References: 1. https://doc.rust-lang.org/std/mem/fn.transmute.html 2. https://doc.rust-lang.org/reference/items/associated-items.html#associated-constants
2024-10-05Update `compiler-builtins` to 0.1.133Trevor Gross-4/+4
This includes [1], which should help resolve an infinite recusion issue on WASM and SPARC (possibly other platforms). See [2] and [3] for further details. [1]: https://github.com/rust-lang/compiler-builtins/pull/708 [2]: https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/sparc-unknown-none-elf.20regresssion.20between.20compiler-built.2E.2E.2E [3]: https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/.5Bwasm32.5D.20Infinite.20recursion.20.60compiler-builtins.60.20.60__multi3.60
2024-10-06On function and method calls in patterns, link to the bookEsteban Küber-64/+156
``` error: expected a pattern, found an expression --> f889.rs:3:13 | 3 | let (x, y.drop()) = (1, 2); //~ ERROR | ^^^^^^^^ not a pattern | = note: arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html> error[E0532]: expected a pattern, found a function call --> f889.rs:2:13 | 2 | let (x, drop(y)) = (1, 2); //~ ERROR | ^^^^ not a tuple struct or tuple variant | = note: function calls are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html> ``` Fix #97200.
2024-10-05Be far more strict about what we consider to be a read of neverMichael Goulet-55/+177
2024-10-05Be more thorough in expr_constitutes_readMichael Goulet-42/+141
2024-10-05Auto merge of #131293 - DianQK:llvm-19.1.1, r=nikicbors-0/+0
Update to LLVM 19.1.1 No known issues are fixed this time. r? `@rust-lang/wg-llvm`
2024-10-05Document things a bit more carefully, also account for coercion in ↵Michael Goulet-6/+18
check_expr_has_type_or_error
2024-10-05Fix up testsMichael Goulet-16/+245
2024-10-05Do not coerce places if they do not constitute readsMichael Goulet-7/+13
2024-10-05Evaluating place expr that is never read from does not divergeMichael Goulet-12/+146
2024-10-05update "build/host" symlink commentonur-ozkan-1/+1
Signed-off-by: onur-ozkan <work@onurozkan.dev>
2024-10-05Auto merge of #131302 - matthiaskrgr:rollup-56kbpzx, r=matthiaskrgrbors-14/+847
Rollup of 5 pull requests Successful merges: - #130555 ( Initial support for riscv32{e|em|emc}_unknown_none_elf) - #131280 (Handle `rustc_interface` cases of `rustc::potential_query_instability` lint) - #131281 (make Cell unstably const) - #131285 (clarify semantics of ConstantIndex MIR projection) - #131299 (fix typo in 'lang item with track_caller' message) r? `@ghost` `@rustbot` modify labels: rollup
2024-10-05Android: Debug assertion after setting thread nameYoh Deadfall-1/+3
2024-10-05Rollup merge of #131299 - RalfJung:lang-item-track-caller, r=compiler-errorsMatthias Krüger-2/+2
fix typo in 'lang item with track_caller' message Revival of https://github.com/rust-lang/rust/pull/124912
2024-10-05Rollup merge of #131285 - RalfJung:mir-projection-sem, r=cjgillotMatthias Krüger-4/+8
clarify semantics of ConstantIndex MIR projection This documents what Miri does: https://github.com/rust-lang/rust/blob/c4ce8c114b06840c3521a189ee44958b713fb33a/compiler/rustc_const_eval/src/interpret/projection.rs#L272-L275 I am not sure what exactly the purpose of this `min_length` field is, TBH... but this seems like the most obvious meaning it could have?
2024-10-05Rollup merge of #131281 - RalfJung:const-cell, r=AmanieuMatthias Krüger-6/+12
make Cell unstably const Now that we can do interior mutability in `const`, most of the Cell API can be `const fn`. :) The main exception is `set`, because it drops the old value. So from const context one has to use `replace`, which delegates the responsibility for dropping to the caller. Tracking issue: https://github.com/rust-lang/rust/issues/131283 `as_array_of_cells` is itself still unstable to I added the const-ness to the feature gate for that function and not to `const_cell`, Cc #88248. r? libs-api
2024-10-05Rollup merge of #131280 - ↵Matthias Krüger-1/+0
ismailarilik:handle-potential-query-instability-lint-for-rustc-interface, r=cjgillot Handle `rustc_interface` cases of `rustc::potential_query_instability` lint This PR removes `#![allow(rustc::potential_query_instability)]` occurrences from [`compiler/rustc_interface/`](https://github.com/rust-lang/rust/blob/master/compiler/rustc_interface/) <s>and converts `FxHash{Map,Set}` types into `FxIndex{Map,Set}` to suppress lint errors</s> (was not necessary for this PR). A somewhat tracking issue: https://github.com/rust-lang/rust/issues/84447 r? `@compiler-errors`