rust/compiler/rustc_borrowck/src
bors 6bf600bc98 Auto merge of #120019 - lcnr:fn-wf, r=BoxyUwU
fix fn/const items implied bounds and wf check (rebase)

A rebase of #104098, see that PR for discussion. This is pretty much entirely the work of `@aliemjay.` I received his permission for this rebase.

---

These are two distinct changes (edit: actually three, see below):
1. Wf-check all fn item args. This is a soundness fix.
Fixes #104005

2. Use implied bounds from impl header in borrowck of associated functions/consts. This strictly accepts more code and helps to mitigate the impact of other breaking changes.
Fixes #98852
Fixes #102611

The first is a breaking change and will likely have a big impact without the the second one. See the first commit for how it breaks libstd.

Landing the second one without the first will allow more incorrect code to pass. For example an exploit of #104005 would be as simple as:
```rust
use core::fmt::Display;

trait ExtendLt<Witness> {
    fn extend(self) -> Box<dyn Display>;
}

impl<T: Display> ExtendLt<&'static T> for T {
    fn extend(self) -> Box<dyn Display> {
        Box::new(self)
    }
}

fn main() {
    let val = (&String::new()).extend();
    println!("{val}");
}
```

The third change is to to check WF of user type annotations before normalizing them (fixes #104764, fixes #104763). It is mutually dependent on the second change above: an attempt to land it separately in #104746 caused several crater regressions that can all be mitigated by using the implied from the impl header. It is also necessary for the soundness of associated consts that use the implied bounds of impl header. See #104763 and how the third commit fixes the soundness issue in `tests/ui/wf/wf-associated-const.rs` that was introduces by the previous commit.

r? types
2024-01-17 02:35:06 +00:00
..
constraints Replace no_ord_impl with orderable. 2023-11-22 18:38:17 +11:00
diagnostics Auto merge of #116520 - Enselic:large-copy-into-fn, r=oli-obk 2024-01-16 19:33:14 +00:00
polonius compiler: Lower fn call arg spans down to MIR 2024-01-15 19:07:11 +01:00
region_infer Rename consuming chaining methods on DiagnosticBuilder. 2024-01-10 07:40:00 +11:00
type_check Auto merge of #120019 - lcnr:fn-wf, r=BoxyUwU 2024-01-17 02:35:06 +00:00
util Move some utils out of rustc_const_eval 2023-04-16 12:05:54 +02:00
borrow_set.rs Fix clippy::needless_borrow in the compiler 2023-11-21 20:13:40 +01:00
borrowck_errors.rs Rename consuming chaining methods on DiagnosticBuilder. 2024-01-10 07:40:00 +11:00
consumers.rs Fix redundant explicit link in rustc_borrowck 2023-08-19 02:22:13 +08:00
dataflow.rs remove redundant imports 2023-12-10 10:56:22 +08:00
def_use.rs rename BorrowKind::Shallow to Fake 2023-11-08 22:55:28 +01:00
facts.rs introduce Polonius enum for -Zpolonius 2023-10-04 16:16:12 +00:00
lib.rs compiler: Lower fn call arg spans down to MIR 2024-01-15 19:07:11 +01:00
location.rs Replace no_ord_impl with orderable. 2023-11-22 18:38:17 +11:00
member_constraints.rs remove unused muts 2023-04-28 20:19:48 +02:00
nll.rs Remove Session methods that duplicate DiagCtxt methods. 2023-12-24 08:05:28 +11:00
path_utils.rs Remove Upvar duplication 2023-11-26 13:19:10 -05:00
place_ext.rs use PlaceRef abstractions more consistently 2023-06-25 20:38:01 -04:00
places_conflict.rs rename BorrowKind::Shallow to Fake 2023-11-08 22:55:28 +01:00
prefixes.rs Add docs, remove code, change subtyper code 2023-10-02 23:39:44 +03:00
renumber.rs add fixme to RegionCtxt 2023-11-13 14:13:54 +00:00
session_diagnostics.rs s/generator/coroutine/ 2023-10-20 21:14:01 +00:00
universal_regions.rs Simplify closure_env_ty and closure_env_param 2024-01-14 19:15:46 +00:00
used_muts.rs Fix clippy::needless_borrow in the compiler 2023-11-21 20:13:40 +01:00