summary refs log tree commit diff
path: root/compiler
AgeCommit message (Collapse)AuthorLines
2024-11-19Make `TypeChecker::region_bound_pairs` owned.Nicholas Nethercote-4/+4
No reason not to be, and it's simpler that way.
2024-11-19Make `TypeChecker::known_type_outlives_obligations` owned.Nicholas Nethercote-9/+7
This avoids the need to arena allocate it. `ConstraintConversion` needs some simple lifetime adjustments to allow this.
2024-11-19Don't pass `universal_regions` unnecessarily.Nicholas Nethercote-6/+5
`TypeChecker` already has it in a field.
2024-11-18Auto merge of #132460 - lcnr:questionable-uwu, r=compiler-errorsbors-1242/+1624
Use `TypingMode` throughout the compiler instead of `ParamEnv` Hopefully the biggest single PR as part of https://github.com/rust-lang/types-team/issues/128. ## `infcx.typing_env` while defining opaque types I don't know how'll be able to correctly handle opaque types when using something taking a `TypingEnv` while defining opaque types. To correctly handle the opaques we need to be able to pass in the current `opaque_type_storage` and return constraints, i.e. we need to use a proper canonical query. We should migrate all the queries used during HIR typeck and borrowck where this matters to proper canonical queries. This is ## `layout_of` and `Reveal::All` We convert the `ParamEnv` to `Reveal::All` right at the start of the `layout_of` query, so I've changed callers of `layout_of` to already use a post analysis `TypingEnv` when encountering it. https://github.com/rust-lang/rust/blob/ca87b535a05097df6abbe2a031b057de2cefac5b/compiler/rustc_ty_utils/src/layout.rs#L51 ## `Ty::is_[unpin|sized|whatever]` I haven't migrated `fn is_item_raw` to use `TypingEnv`, will do so in a followup PR, this should significantly reduce the amount of `typing_env.param_env`. At some point there will probably be zero such uses as using the type system while ignoring the `typing_mode` is incorrect. ## `MirPhase` and phase-transitions When inside of a MIR-body, we can mostly use its `MirPhase` to figure out the right `typing_mode`. This does not work during phase transitions, most notably when transitioning from `Analysis` to `Runtime`: https://github.com/rust-lang/rust/blob/dae7ac133b9eda152784c075facb31a6688c92b1/compiler/rustc_mir_transform/src/lib.rs#L606-L625 All these passes still run with `MirPhase::Analysis`, but we should only use `Reveal::All` once we're run the `RevealAll` pass. This required me to manually construct the right `TypingEnv` in all these passes. Given that it feels somewhat easy to accidentally miss this going forward, I would maybe like to change `Body::phase` to an `Option` and replace it at the start of phase transitions. This then makes it clear that the MIR is currently in a weird state. r? `@ghost`
2024-11-18Make rustc --explain busybox less compatibleomni-1/+1
busybox less does not support the -r flag and less(1) says: USE OF THE -r OPTION IS NOT RECOMMENDED.
2024-11-18interpret: do not ICE when a promoted fails with OOMRalf Jung-3/+24
2024-11-18Add MutVisitor::visit_fn_ret_tymaxcabrajac-2/+6
2024-11-18Add Visitor::visit_qselfmaxcabrajac-11/+14
2024-11-18Add Visitor::visit_fn_declmaxcabrajac-3/+6
2024-11-18Report `unexpected_cfgs` lint in external macrosUrgau-0/+1
2024-11-18Rollup merge of #133163 - RalfJung:cold, r=saethlinGuillaume Gomez-3/+1
remove pointless cold_path impl in interpreter This has a fallback impl so the interpreter impl is not needed. r? ``@saethlin``
2024-11-18Rollup merge of #133157 - RalfJung:skip_stability_check_due_to_privacy, ↵Guillaume Gomez-28/+1
r=compiler-errors stability: remove skip_stability_check_due_to_privacy This was added in https://github.com/rust-lang/rust/pull/38689 to deal with https://github.com/rust-lang/rust/issues/38412. However, even after removing the check, the relevant tests still pass. Let's see if CI finds any other tests that rely on this. If not, it seems like logic elsewhere in the compiler changed so this is not required any more.
2024-11-18reviewlcnr-6/+11
2024-11-18use `TypingEnv` when no `infcx` is availablelcnr-1241/+1618
the behavior of the type system not only depends on the current assumptions, but also the currentnphase of the compiler. This is mostly necessary as we need to decide whether and how to reveal opaque types. We track this via the `TypingMode`.
2024-11-18remove pointless cold_path impl in interpreterRalf Jung-3/+1
2024-11-18Rollup merge of #133142 - RalfJung:naming-is-hard, r=compiler-errorsJacob Pratt-5/+5
rename rustc_const_stable_intrinsic -> rustc_intrinsic_const_stable_indirect In https://github.com/rust-lang/rust/pull/120370 this name caused confusion as the author thought the intrinsic was stable. So let's try a different name... If we can land this before the beta cutoff we can avoid needing `cfg(bootstrap)` for this. ;) Cc `@compiler-errors` `@saethlin`
2024-11-18Rollup merge of #132934 - Zalathar:native-libs, r=jieyouxuJacob Pratt-144/+251
Overhaul the `-l` option parser (for linking to native libs) The current parser for `-l` options has accumulated over time, making it hard to follow. This PR tries to clean it up in several ways. Key changes: - This code now gets its own submodule, to slightly reduce clutter in `rustc_session::config`. - Cleaner division between iterating over multiple `-l` options, and processing each individual one. - Separate “split” step that breaks up the value string into `[KIND[:MODIFIERS]=]NAME[:NEW_NAME]`, but leaves parsing/validating those parts to later steps. - This step also gets its own (disposable) unit test, to make sure it works as expected. - A context struct reduces the burden of parameter passing, and makes it easier to write error messages that adapt to nightly/stable compilers. - Fewer calls to `nightly_options` helper functions, because at this point we can get the same information from `UnstableOptions` and `UnstableFeatures` (which are downstream of earlier calls to those helper functions). There should be no overall change in compiler behaviour.
2024-11-18stability: remove skip_stability_check_due_to_privacyRalf Jung-28/+1
2024-11-18rename rustc_const_stable_intrinsic -> rustc_intrinsic_const_stable_indirectRalf Jung-5/+5
2024-11-18Overhaul the `-l` option parser (for linking to native libs)Zalathar-121/+224
2024-11-18Move `-l` option parsing into its own submoduleZalathar-140/+144
No functional change (yet).
2024-11-17Rollup merge of #133143 - kornelski:let-mut-global, r=compiler-errorsJacob Pratt-8/+25
Diagnostics for let mut in item context The diagnostics for `let` at the top level did not account for `let mut`, which [made the error unclear](https://users.rust-lang.org/t/create-a-vector-of-constants-outside-main/121251/1). I've made the diagnostic always display a link to valid items. I've added dedicated help for `let mut` case that suggests using a `Mutex` (to steer novice users away from the `static mut` trap). Unfortunately, neither the Rust book, nor libstd docs have dedicated section listing all other types for interior-mutable `static`s.
2024-11-17Rollup merge of #133130 - dianne:fix-133118, r=compiler-errorsJacob Pratt-16/+10
`suggest_borrow_generic_arg`: instantiate clauses properly This simplifies and fixes the way `suggest_borrow_generic_arg` instantiates callees' predicates when testing them to see if a moved argument can instead be borrowed. Previously, it would ICE if the moved argument's type included a region variable, since it was getting passed to a call of `EarlyBinder::instantiate`. This makes the instantiation much more straightforward, which also fixes the ICE. Fixes #133118 This also modifies `tests/ui/moves/moved-value-on-as-ref-arg.rs` to have more useful bounds on the tests for suggestions to borrow `Borrow` and `BorrowMut` arguments. With its old tautological `T: BorrowMut<T>` bound, this fix would make it suggest a shared borrow for that argument.
2024-11-17Rollup merge of #132993 - jieyouxu:i_am_very_stable, r=chenyukangJacob Pratt-9/+24
Make rustc consider itself a stable compiler when `RUSTC_BOOTSTRAP=-1` Addresses https://github.com/rust-lang/rust/issues/123404 to allow test writers to specify `//@ rustc-env:RUSTC_BOOTSTRAP=-1` to have a given rustc consider itself a stable rustc. This is only intended for testing usages. I did not use `RUSTC_BOOTSTRAP=0` because that can be confusing, i.e. one might think that means "not bootstrapping", but "forcing a given rustc to consider itself a stable compiler" is a different use case. I also added a specific test to check `RUSTC_BOOTSTRAP`'s various values and how that interacts with rustc's stability story w.r.t. features and cli flags. Noticed when trying to write a test for enabling ICE file dumping on stable. Dunno if this needs a compiler FCP or MCP, but I can file an MCP or ask someone to start an FCP if needed. Note that `RUSTC_BOOTSTRAP` is a perma-unstable env var and has no stability guarantees (heh) whatsoever. This does not affect bootstrapping because bootstrap never sets `RUSTC_BOOTSTRAP=-1`. If someone does set that when bootstrapping, it is considered PEBKAC. Accompanying dev-guide PR: https://github.com/rust-lang/rustc-dev-guide/pull/2136 cc `@estebank` and `@rust-lang/wg-diagnostics` for FYI
2024-11-17Rollup merge of #132944 - linyihai:needing-parenthases-issue-132924, ↵Jacob Pratt-9/+24
r=chenyukang add parentheses when unboxing suggestion needed This PR tried to `add parentheses when unboxing suggestion needed` Fixes #132924
2024-11-17Rollup merge of #132795 - compiler-errors:refine-rpitit, r=lcnrJacob Pratt-1/+116
Check `use<..>` in RPITIT for refinement `#![feature(precise_capturing_in_traits)]` allows users to write `+ use<>` bounds on RPITITs to control what lifetimes are captured by the RPITIT. Since RPITITs currently also warn for refinement in implementations, this PR extends that refinement check for cases where we *undercapture* in an implementation, since that may be indirectly "promising" a more relaxed outlives bound than the impl author intended. For an opaque to be refining, we need to capture *fewer* parameters than those mentioned in the captured params of the trait. For example: ``` trait TypeParam<T> { fn test() -> impl Sized; } // Indirectly capturing a lifetime param through a type param substitution. impl<'a> TypeParam<&'a ()> for i32 { fn test() -> impl Sized + use<> {} //~^ WARN impl trait in impl method captures fewer lifetimes than in trait } ``` Since the opaque in the method (implicitly) captures `use<Self, T>`, and `Self = i32, T = &'a ()` in the impl, we must mention `'a` in our `use<..>` on the impl. Tracking: * https://github.com/rust-lang/rust/issues/130044
2024-11-17`suggest_borrow_generic_arg`: instantiate clauses properlydianne-16/+10
Fixes issue 133118. This also modifies `tests/ui/moves/moved-value-on-as-ref-arg.rs` to have more useful bounds on the tests for suggestions to borrow `Borrow` and `BorrowMut` arguments. With its old tautological `T: BorrowMut<T>` bound, this fix would make it suggest a shared borrow for that argument.
2024-11-17PatFieldmaxcabrajac-5/+13
2024-11-17ExprFieldmaxcabrajac-5/+13
2024-11-17GenericParammaxcabrajac-5/+13
2024-11-17Parammaxcabrajac-2/+10
2024-11-17Variantmaxcabrajac-5/+13
2024-11-17Armmaxcabrajac-2/+10
2024-11-17FieldDefmaxcabrajac-5/+13
2024-11-18Check use<..> in RPITIT for refinementMichael Goulet-1/+116
2024-11-17Account for `ExpandedConstant` in `parse_match`Esteban Küber-6/+14
2024-11-17Auto merge of #120370 - x17jiri:likely_unlikely_fix, r=saethlinbors-18/+93
Likely unlikely fix RFC 1131 ( https://github.com/rust-lang/rust/issues/26179 ) added likely/unlikely intrinsics, but they have been broken for a while: https://github.com/rust-lang/rust/issues/96276 , https://github.com/rust-lang/rust/issues/96275 , https://github.com/rust-lang/rust/issues/88767 . This PR tries to fix them. Changes: - added a new `cold_path()` intrinsic - `likely()` and `unlikely()` changed to regular functions implemented using `cold_path()`
2024-11-17review comment: modify doc commentEsteban Küber-4/+2
2024-11-17review commentsEsteban Küber-21/+26
- Remove check for "how many path segments is the pattern" - Check before suggesting if the path has multiple path segments
2024-11-17review commentsEsteban Küber-6/+5
2024-11-17Make suggestion verboseEsteban Küber-1/+2
2024-11-17Unify expanded constants and named constants in `PatKind`Esteban Küber-46/+71
2024-11-17Point at const when intended binding fall-through pattern is a constEsteban Küber-4/+25
``` error[E0004]: non-exhaustive patterns: `i32::MIN..=3_i32` and `5_i32..=i32::MAX` not covered --> $DIR/intended-binding-pattern-is-const.rs:2:11 | LL | match 1 { | ^ patterns `i32::MIN..=3_i32` and `5_i32..=i32::MAX` not covered LL | x => {} | - this pattern doesn't introduce a new catch-all binding, but rather pattern matches against the value of constant `x` | = note: the matched value is of type `i32` note: constant `x` defined here --> $DIR/intended-binding-pattern-is-const.rs:7:5 | LL | const x: i32 = 4; | ^^^^^^^^^^^^ help: if you meant to introduce a binding, use a different name | LL | x_var => {} | ++++ help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern, a match arm with multiple or-patterns as shown, or multiple match arms | LL | x => {}, i32::MIN..=3_i32 | 5_i32..=i32::MAX => todo!() | ++++++++++++++++++++++++++++++++++++++++++++++++ ```
2024-11-17Use `item_name` instead of a span snippet when talking about const patternEsteban Küber-3/+2
2024-11-17Fold `PatKind::NamedConstant` into `PatKind::Constant`Esteban Küber-33/+21
2024-11-17Point at `const` definition when used instead of a binding in a `let` statementEsteban Küber-14/+52
After: ``` error[E0005]: refutable pattern in local binding --> $DIR/bad-pattern.rs:19:13 | LL | const PAT: u32 = 0; | -------------- missing patterns are not covered because `PAT` is interpreted as a constant pattern, not a new variable ... LL | let PAT = v1; | ^^^ | | | pattern `1_u32..=u32::MAX` not covered | help: introduce a variable instead: `PAT_var` | = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html = note: the matched value is of type `u32` ``` Before: ``` error[E0005]: refutable pattern in local binding --> $DIR/bad-pattern.rs:19:13 | LL | let PAT = v1; | ^^^ | | | pattern `1_u32..=u32::MAX` not covered | missing patterns are not covered because `PAT` is interpreted as a constant pattern, not a new variable | help: introduce a variable instead: `PAT_var` | = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html = note: the matched value is of type `u32` ```
2024-11-17Diagnostics for let mut in item contextKornel-8/+25
2024-11-17Likely unlikely fixJiri Bobek-18/+93
2024-11-17Rollup merge of #133116 - RalfJung:const-null-ptr, r=dtolnay许杰友 Jieyou Xu (Joe)-0/+6
stabilize const_ptr_is_null FCP passed in https://github.com/rust-lang/rust/issues/74939. The second commit cleans up const stability around UB checks a bit, now that everything they need (except for `const_eval_select`) is stable. Fixes https://github.com/rust-lang/rust/issues/74939
2024-11-17Rollup merge of #133060 - tyrone-wu:removelet-span-suggestion, r=jieyouxu许杰友 Jieyou Xu (Joe)-2/+3
Trim whitespace in RemoveLet primary span Separate `RemoveLet` span into primary span for `let` and removal suggestion span for `let `, so that primary span does not include whitespace. Fixes: #133031