rust/compiler/rustc_trait_selection/src
许杰友 Jieyou Xu (Joe) 4090d98b67
Rollup merge of #145537 - zachs18:metasized-negative-bound-fix, r=davidtwco
Do not consider a `T: !Sized` candidate to satisfy a `T: !MetaSized` obligation.

This example should fail to compile (and does under this PR, with the old and new solvers), but currently compiles successfully ([playground](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2024&gist=6e0e5d0ae0cdf0571dea97938fb4a86d)), because (IIUC) the old solver's `lazily_elaborate_sizedness_candidate`/callers and the new solver's `TraitPredicate::fast_reject_assumption`/`match_assumption` consider a `T: _ Sized` candidate to satisfy a `T: _ MetaSized` obligation, for either polarity `_`, when that should only hold for positive polarity.

```rs
#![feature(negative_bounds)]
#![feature(sized_hierarchy)]

use std::marker::MetaSized;

fn foo<T: !MetaSized>() {}

fn bar<T: !Sized + MetaSized>() {
    foo::<T>();
    //~^ ERROR the trait bound `T: !MetaSized` is not satisfied // error under this PR
}
```

Only observable with the internal-only `feature(negative_bounds)`, so might just be "wontfix".

This example is added as a test in this PR (as well as testing that `foo<()>` and `foo<str>` are disallowed for `fn foo<T: !MetaSized`).

cc `@davidtwco` for `feature(sized_hierarchy)`

Maybe similar to 91c53c9 from <https://github.com/rust-lang/rust/pull/143307>
2025-08-19 19:45:40 +08:00
..
error_reporting Auto merge of #145284 - nnethercote:type_name-print-regions, r=lcnr 2025-08-17 10:24:20 +00:00
errors Fix elided lifetimes in rustdoc 2025-07-04 18:26:09 +00:00
solve Auto merge of #144458 - compiler-errors:no-witness-mini, r=lcnr 2025-08-01 21:07:49 +00:00
traits Rollup merge of #145537 - zachs18:metasized-negative-bound-fix, r=davidtwco 2025-08-19 19:45:40 +08:00
errors.rs Use tcx.short_string() in more diagnostics 2025-08-07 21:18:00 +00:00
infer.rs Eagerly unify coroutine witness in old solver 2025-07-17 17:42:28 +00:00
lib.rs Remove all unused feature gates from the compiler 2025-06-08 14:50:42 +00:00
opaque_types.rs Rename unpack to kind 2025-05-27 11:14:45 +00:00
regions.rs Consider outlives assumptions when proving auto traits for coroutine interiors 2025-07-15 16:02:26 +00:00
solve.rs Eagerly unify coroutine witness in old solver 2025-07-17 17:42:28 +00:00