about summary refs log tree commit diff
path: root/compiler/rustc_borrowck/src
AgeCommit message (Collapse)AuthorLines
2024-10-04Avoid `&Rc<T>` arguments.Nicholas Nethercote-25/+22
Either `&T` or `Rc<T>` is preferable.
2024-10-04Avoid `Rc` in `BodyWithBorrowckFacts`.Nicholas Nethercote-7/+4
It can own these two fields.
2024-10-04Use `Box` instead of `Rc` for `polonius_output`.Nicholas Nethercote-7/+9
Refcounting isn't needed.
2024-10-04Use `Rc` less in `MirBorrowckCtxt`.Nicholas Nethercote-25/+17
The `regioncx` and `borrow_set` fields can be references instead of `Rc`. They use the existing `'a` lifetime. This avoids some heap allocations and is a bit simpler.
2024-10-02Move in_trait into OpaqueTyOriginMichael Goulet-2/+2
2024-10-02Use named fields for OpaqueTyOriginMichael Goulet-2/+2
2024-10-02Remove redundant in_trait from hir::TyKind::OpaqueDefMichael Goulet-1/+1
2024-10-02make `Borrows` dataflow dumps about its loan domainRémy Rakic-11/+1
2024-09-27borrowck: use subtyping instead of equality for ptr-to-ptr castsLukas Markeffsky-1/+1
2024-09-25Stabilize the `map`/`value` methods on `ControlFlow`Scott McMurray-1/+0
And fix the stability attribute on the `pub use` in `core::ops`.
2024-09-25Auto merge of #130803 - cuviper:file-buffered, r=joshtriplettbors-2/+3
Add `File` constructors that return files wrapped with a buffer In addition to the light convenience, these are intended to raise visibility that buffering is something you should consider when opening a file, since unbuffered I/O is a common performance footgun to Rust newcomers. ACP: https://github.com/rust-lang/libs-team/issues/446 Tracking Issue: #130804
2024-09-24Dogfood `feature(file_buffered)`Josh Stone-2/+3
2024-09-24be even more precise about "cast" vs "coercion"Lukas Markeffsky-33/+48
2024-09-24replace "cast" with "coercion" where applicableLukas Markeffsky-13/+20
This changes the remaining span for the cast, because the new `Cast` category has a higher priority (lower `Ord`) than the old `Coercion` category, so we no longer report the region error for the "unsizing" coercion from `*const Trait` to itself.
2024-09-24unify dyn* coercions with other pointer coercionsLukas Markeffsky-1/+1
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-162/+149
2024-09-18Begin experimental support for pin reborrowingEric Holk-1/+1
This commit adds basic support for reborrowing `Pin` types in argument position. At the moment it only supports reborrowing `Pin<&mut T>` as `Pin<&mut T>` by inserting a call to `Pin::as_mut()`, and only in argument position (not as the receiver in a method call).
2024-09-14Rollup merge of #130294 - nnethercote:more-lifetimes, r=lcnrLeón Orell Valerian Liehr-73/+73
Lifetime cleanups The last commit is very opinionated, let's see how we go. r? `@oli-obk`
2024-09-13Rollup merge of #130297 - nnethercote:dataflow-cleanups, r=cjgillotMatthias Krüger-98/+96
Dataflow cleanups r? `@cjgillot`
2024-09-13Rename `FlowState` as `Domain`.Nicholas Nethercote-98/+96
Because that's what it is; no point having a different name for it.
2024-09-13Rename and reorder lots of lifetimes.Nicholas Nethercote-67/+67
- Replace non-standard names like 's, 'p, 'rg, 'ck, 'parent, 'this, and 'me with vanilla 'a. These are cases where the original name isn't really any more informative than 'a. - Replace names like 'cx, 'mir, and 'body with vanilla 'a when the lifetime applies to multiple fields and so the original lifetime name isn't really accurate. - Put 'tcx last in lifetime lists, and 'a before 'b.
2024-09-13Rename some lifetimes.Nicholas Nethercote-6/+6
Giving them more typical names.
2024-09-13Auto merge of #107251 - dingxiangfei2009:let-chain-rescope, r=jieyouxubors-17/+122
Rescope temp lifetime in if-let into IfElse with migration lint Tracking issue #124085 This PR shortens the temporary lifetime to cover only the pattern matching and consequent branch of a `if let`. At the expression location, means that the lifetime is shortened from previously the deepest enclosing block or statement in Edition 2021. This warrants an Edition change. Coming with the Edition change, this patch also implements an edition lint to warn about the change and a safe rewrite suggestion to preserve the 2021 semantics in most cases. Related to #103108. Related crater runs: https://github.com/rust-lang/rust/pull/129466.
2024-09-12Rollup merge of #130235 - compiler-errors:nested-if, r=michaelwoeristerStuart Cook-43/+36
Simplify some nested `if` statements Applies some but not all instances of `clippy::collapsible_if`. Some ended up looking worse afterwards, though, so I left those out. Also applies instances of `clippy::collapsible_else_if` Review with whitespace disabled please.
2024-09-11Rollup merge of #130114 - eduardosm:needless-returns, r=compiler-errorsJubilee-2/+2
Remove needless returns detected by clippy in the compiler
2024-09-11Also fix if in elseMichael Goulet-8/+4
2024-09-11Simplify some nested if statementsMichael Goulet-35/+32
2024-09-11downgrade borrowck suggestion level due to possible span conflictDing Xiang Fei-14/+29
2024-09-11rescope temp lifetime in let-chain into IfElseDing Xiang Fei-17/+107
apply rules by span edition
2024-09-09Remove needless returns detected by clippy in the compilerEduardo Sánchez Muñoz-2/+2
2024-09-09Rename some lifetimes.Nicholas Nethercote-5/+5
Give them the names used in most places.
2024-09-09Remove unnecessary lifetimes in dataflow structs.Nicholas Nethercote-111/+101
There are four related dataflow structs: `MaybeInitializedPlaces`, `MaybeUninitializedPlaces`, and `EverInitializedPlaces`, `DefinitelyInitializedPlaces`. They all have a `&Body` and a `&MoveData<'tcx>` field. The first three use different lifetimes for the two fields, but the last one uses the same lifetime for both. This commit changes the first three to use the same lifetime, removing the need for one of the lifetimes. Other structs that also lose a lifetime as a result of this are `LivenessContext`, `LivenessResults`, `InitializationData`. It then does similar things in various other structs.
2024-09-06Rollup merge of #129969 - GrigorenkoPV:boxed-ty, r=compiler-errorsMatthias Krüger-3/+4
Make `Ty::boxed_ty` return an `Option` Looks like a good place to use Rust's type system. --- Most of https://github.com/rust-lang/rust/blob/4ac7bcbaad8d6fd7a51bdf1b696cbc3ba4c796cf/compiler/rustc_middle/src/ty/sty.rs#L971-L1963 looks like it could be moved to `TyKind` (then I guess `Ty` should be made to deref to `TyKind`).
2024-09-06Rollup merge of #129021 - compiler-errors:ptr-cast-outlives, r=lcnrMatthias Krüger-7/+64
Check WF of source type's signature on fn pointer cast This PR patches the implied bounds holes slightly for #129005, #25860. Like most implied bounds related unsoundness fixes, this isn't complete w.r.t. higher-ranked function signatures, but I believe it implements a pretty good heuristic for now. ### What does this do? This PR makes a partial patch for a soundness hole in a `FnDef` -> `FnPtr` "reifying" pointer cast where we were never checking that the signature we are casting *from* is actually well-formed. Because of this, and because `FnDef` doesn't require its signature to be well-formed (just its predicates must hold), we are essentially allowed to "cast away" implied bounds that are assumed within the body of the `FnDef`: ``` fn foo<'a, 'b, T>(_: &'a &'b (), v: &'b T) -> &'a T { v } fn bad<'short, T>(x: &'short T) -> &'static T { let f: fn(_, &'short T) -> &'static T = foo; f(&&(), x) } ``` In this example, subtyping ends up casting the `_` type (which should be `&'static &'short ()`) to some other type that no longer serves as a "witness" to the lifetime relationship `'short: 'static` which would otherwise be required for this call to be WF. This happens regardless of if `foo`'s lifetimes are early- or late-bound. This PR implements two checks: 1. We check that the signature of the `FnDef` is well-formed *before* casting it. This ensures that there is at least one point in the MIR where we ensure that the `FnDef`'s implied bounds are actually satisfied by the caller. 2. Implements a special case where if we're casting from a higher-ranked `FnDef` to a non-higher-ranked, we instantiate the binder of the `FnDef` with *infer vars* and ensure that it is a supertype of the target of the cast. The (2.) is necessary to validate that these pointer casts are valid for higher-ranked `FnDef`. Otherwise, the example above would still pass even if `help`'s `'a` lifetime were late-bound. ### Further work The WF checks for function calls are scattered all over the MIR. We check the WF of args in call terminators, we check the WF of `FnDef` when we create a `const` operand referencing it, and we check the WF of the return type in #115538, to name a few. One way to make this a bit cleaner is to simply extend #115538 to always check that the signature is WF for `FnDef` types. I may do this as a follow-up, but I wanted to keep this simple since this leads to some pretty bad NLL diagnostics regressions, and AFAICT this solution is *complete enough*. ### Crater triage Done here: https://github.com/rust-lang/rust/pull/129021#issuecomment-2297702647 r? lcnr
2024-09-06Make `Ty::boxed_ty` return an `Option`Pavel Grigorenko-3/+4
2024-09-05Check unnormalized signature on pointer castMichael Goulet-7/+64
2024-09-04fix ICE when `asm_const` and `const_refs_to_static` are combinedFolkert de Vries-2/+12
2024-09-04propagate `tainted_by_errors` in `MirBorrowckCtxt::emit_errors`Folkert de Vries-1/+1
2024-09-02chore: Fix typos in 'compiler' (batch 1)Alexander Cyon-2/+2
2024-08-31Rollup merge of #129767 - nnethercote:rm-extern-crate-tracing-4, r=jieyouxuMatthias Krüger-3/+38
Remove `#[macro_use] extern crate tracing`, round 4 Because explicit importing of macros via use items is nicer (more standard and readable) than implicit importing via #[macro_use]. Continuing the work from #124511, #124914, and #125434. After this PR no `rustc_*` crates use `#[macro_use] extern crate tracing` except for `rustc_codegen_gcc` which is a special case and I will do separately. r? ```@jieyouxu```
2024-08-30Remove `#[macro_use] extern crate tracing` from `rustc_borrowck`.Nicholas Nethercote-3/+38
2024-08-30add borrows to NLL MIR dumpsRémy Rakic-1/+14
explicitly disable `-Zmir-include-spans` in mir-opt tests This will override the NLL default of true, and keep the blessed dumps easier to work with.
2024-08-30refactor NLL MIR dump entry pointRémy Rakic-15/+23
2024-08-30enable extra comments in NLL MIR dumpsRémy Rakic-21/+40
2024-08-27Rollup merge of #129340 - stephen-lazaro:u/slazaro/issue-129274, ↵Matthias Krüger-2/+3
r=compiler-errors Remove Duplicate E0381 Label Aims to resolve https://github.com/rust-lang/rust/issues/129274, and adds a test for the case. Essentially, we are duplicating this span for some reason. For now, I'm just using a set to collect the spans rather than the vec. I imagine there's probably no real reason to inspect duplicates in this area, but if I'm wrong I can adjust to collect "seen spans" in just the point where this label is applied. I'm not sure why it's producing duplicate spans. Looks like this has been this way for a while? I think it gives the duplicate label on 1.75.0 for example.
2024-08-27Rollup merge of #126013 - nnethercote:unreachable_pub, r=UrgauMatthias Krüger-68/+74
Add `#[warn(unreachable_pub)]` to a bunch of compiler crates By default `unreachable_pub` identifies things that need not be `pub` and tells you to make them `pub(crate)`. But sometimes those things don't need any kind of visibility. So they way I did these was to remove the visibility entirely for each thing the lint identifies, and then add `pub(crate)` back in everywhere the compiler said it was necessary. (Or occasionally `pub(super)` when context suggested that was appropriate.) Tedious, but results in more `pub` removal. There are plenty more crates to do but this seems like enough for a first PR. r? `@compiler-errors`
2024-08-26Rollup merge of #129590 - compiler-errors:ref-tykind, r=fmeaseMatthias Krüger-2/+2
Avoid taking reference of &TyKind It's already a ref anyways. Just a tiny cleanup here.
2024-08-25Avoid taking reference of &TyKindMichael Goulet-2/+2
2024-08-22Deduplicate Spans in Uninitialized CheckStephen Lazaro-2/+3
Prevents reporting labels or diagnostics on spans that are produced multiple times.
2024-08-19Use subtyping for UnsafeFnPointer coercion, tooMichael Goulet-2/+2