Commit Graph

2465 Commits

Author SHA1 Message Date
Matthias Krüger
920092531f
Rollup merge of #133218 - compiler-errors:const-opaque, r=fee1-dead
Implement `~const` item bounds in RPIT

an RPIT in a `const fn` is allowed to be conditionally const itself :)

r? fee1-dead or reroll
2024-11-21 07:56:13 +01:00
Matthias Krüger
b1008d1370
Rollup merge of #132207 - compiler-errors:tweak-res-mod-segment, r=petrochenkov
Store resolution for self and crate root module segments

Let's make sure to record the segment resolution for `self::`, `crate::` and `$crate::`.

I'm actually somewhat surprised that the only diagnostic that uses this is the one that errors on invalid generics on a module segment... but seems strictly more correct regardless, and there may be other diagnostics using these segments resolutions that just haven't been tested for `self`. Also includes a drive-by on `report_prohibit_generics_error`.
2024-11-21 07:56:12 +01:00
bors
2d0ea7956c Auto merge of #133261 - matthiaskrgr:rollup-ekui4we, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #129838 (uefi: process: Add args support)
 - #130800 (Mark `get_mut` and `set_position` in `std::io::Cursor` as const.)
 - #132708 (Point at `const` definition when used instead of a binding in a `let` statement)
 - #133226 (Make `PointerLike` opt-in instead of built-in)
 - #133244 (Account for `wasm32v1-none` when exporting TLS symbols)
 - #133257 (Add `UnordMap::clear` method)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-11-20 21:58:38 +00:00
Michael Goulet
b33a0d3292 we should not be reporting generic error if there is not a segment to deny 2024-11-20 18:57:02 +00:00
Michael Goulet
228068bc6e Make PointerLike opt-in as a trait 2024-11-20 16:36:12 +00:00
Ding Xiang Fei
297b618944
reduce false positives of tail-expr-drop-order from consumed values
take 2

open up coroutines

tweak the wordings

the lint works up until 2021

We were missing one case, for ADTs, which was
causing `Result` to yield incorrect results.

only include field spans with significant types

deduplicate and eliminate field spans

switch to emit spans to impl Drops

Co-authored-by: Niko Matsakis <nikomat@amazon.com>

collect drops instead of taking liveness diff

apply some suggestions and add explantory notes

small fix on the cache

let the query recurse through coroutine

new suggestion format with extracted variable name

fine-tune the drop span and messages

bugfix on runtime borrows

tweak message wording

filter out ecosystem types earlier

apply suggestions

clippy

check lint level at session level

further restrict applicability of the lint

translate bid into nop for stable mir

detect cycle in type structure
2024-11-20 20:53:11 +08:00
bors
70e814bd9e Auto merge of #133212 - lcnr:questionable-uwu, r=compiler-errors
continue `ParamEnv` to `TypingEnv` transition

cc #132279

r? `@compiler-errors`
2024-11-20 06:22:01 +00:00
lcnr
002efeb72a additional TypingEnv cleanups 2024-11-19 21:36:23 +01:00
lcnr
7a90e84f4d InterpCx store TypingEnv instead of a ParamEnv 2024-11-19 21:36:23 +01:00
Michael Goulet
5eeaf2ec33 Implement ~const opaques 2024-11-19 20:31:05 +00:00
Michael Goulet
588c4c45d5 Rename implied_const_bounds to explicit_implied_const_bounds 2024-11-19 20:30:58 +00:00
lcnr
948cec0fad move fn is_item_raw to TypingEnv 2024-11-19 18:06:20 +01:00
Boxy
473b5d5290 Fix broken intra-doc link 2024-11-19 06:06:47 +00:00
Noah Lev
59e339f766 Introduce min_generic_const_args and directly represent paths
Co-authored-by: Boxy UwU <rust@boxyuwu.dev>
Co-authored-by: León Orell Valerian Liehr <me@fmease.dev>
2024-11-19 05:07:43 +00:00
lcnr
2e087d2eaa review 2024-11-18 10:50:14 +01:00
lcnr
9cba14b95b use TypingEnv when no infcx is available
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-18 10:38:56 +01:00
Jacob Pratt
e2993cd06e
Rollup merge of #132795 - compiler-errors:refine-rpitit, r=lcnr
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 22:30:47 -05:00
Michael Goulet
32d2340dbd Check use<..> in RPITIT for refinement 2024-11-18 00:27:44 +00:00
bors
3fb7e441ae Auto merge of #120370 - x17jiri:likely_unlikely_fix, r=saethlin
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-17 23:57:53 +00:00
Jiri Bobek
777003ae9f Likely unlikely fix 2024-11-17 21:49:10 +01:00
Matthias Krüger
a1c98ca160
Rollup merge of #132832 - compiler-errors:late-ty, r=cjgillot
Deny capturing late-bound ty/const params in nested opaques

First, this reverts a7f609504c. I can't exactly remember why I approved this specific bit of https://github.com/rust-lang/rust/pull/132466; specifically, I don't know that the purpose of that commit is, and afaict we will never have an opaque that captures late-bound params through a const because opaques can't be used inside of anon consts. Am I missing something `@cjgillot?` Since I can't see a case where this matters, and no tests seem to fail.

The second commit adds a `deny_late_regions: bool` to distinguish `Scope::LateBoundary` which should deny *any* late-bound params or just ty/consts. Then, when resolving opaques we wrap ourselves in a `Scope::LateBoundary { deny_late_regions: false }` so that we deny late-bound ty/const, which fixes a bunch of ICEs that all vaguely look like `impl for<T> Trait<Assoc = impl OtherTrait<T>>`.

I guess this could be achieved other ways; for example, with a different scope kind, or maybe we could just reuse `Scope::Opaque`. But this seems a bit more verbose. I'm open to feedback anyways.

Fixes #131535
Fixes #131637
Fixes #132530

I opted to remove those crashes tests ^ without adding them as regular tests, since they're basically triggering uninteresting late-bound ICEs far off in the trait solver, and the reason that existing tests such as `tests/ui/type-alias-impl-trait/non-lifetime-binder-in-constraint.rs` don't ICE are kinda just coincidental (i.e. due to a missing impl block). I don't really feel motivated to add random permutations to tests just to exercise non-lifetime binders.

r? cjgillot
2024-11-16 21:05:46 +01:00
León Orell Valerian Liehr
d0ddba3d5b
Simplify some places that deal with generic parameter defaults 2024-11-11 21:29:18 +01:00
Michael Goulet
8d871b7687 Deny capturing late-bound ty/ct params in nested opaques 2024-11-10 04:30:33 +00:00
Michael Goulet
58abbaf077 Revert "Skip late-bound lifetimes when crossing an AnonConst."
This reverts commit a7f609504c.
2024-11-10 04:30:33 +00:00
Jubilee
7a4970476e
Rollup merge of #132757 - compiler-errors:yeet-check-wf, r=lcnr
Get rid of `check_opaque_type_well_formed`

Instead, replicate it by improving the span of the opaque in `check_opaque_meets_bounds`.

This has two consequences:
1. We now prefer "concrete type differs" errors, since we'll hit those first before we check the opaque is WF.
2. Spans have gotten slightly worse.

Specifically, (2.) could be improved by adding a new obligation cause that explains that the definition's environment has stronger assumptions than the declaration.

r? lcnr
2024-11-08 20:46:12 -08:00
Ralf Jung
e3010e84db remove support for rustc_safe_intrinsic attribute; use rustc_intrinsic functions instead 2024-11-08 09:16:00 +01:00
Michael Goulet
97dfe8b871 Manually register some bounds for a better span 2024-11-08 04:56:08 +00:00
Michael Goulet
e4c1a0016c Get rid of check_opaque_type_well_formed 2024-11-08 03:46:27 +00:00
Matthias Krüger
fd41a373f3
Rollup merge of #132734 - RalfJung:platform-intrinsic, r=compiler-errors
remove 'platform-intrinsic' ABI leftovers

This was removed a while ago, but some parts haven't been fully cleaned up.
2024-11-07 18:19:38 +01:00
Ralf Jung
fa0b97268a remove 'platform-intrinsic' ABI leftovers 2024-11-07 17:42:49 +01:00
clubby789
b480f0f224 Remove unused intercrate dependencies 2024-11-07 14:17:16 +00:00
Eric Huss
c7d29cd56d Remove unused errs.rs file
This module was removed in #124895, but the actual file was not removed.
2024-11-05 11:10:12 -08:00
bors
096277e989 Auto merge of #132580 - compiler-errors:globs, r=Noratrieb
Remove unnecessary pub enum glob-imports from `rustc_middle::ty`

We used to have an idiom in the compiler where we'd prefix or suffix all the variants of an enum, for example `BoundRegionKind`, with something like `Br`, and then *glob-import* that enum variant directly.

`@noratrieb` brought this up, and I think that it's easier to read when we just use the normal style `EnumName::Variant`.

This PR is a bit large, but it's just naming.

The only somewhat opinionated change that this PR does is rename `BorrowKind::Imm` to `BorrowKind::Immutable` and same for the other variants. I think these enums are used sparingly enough that the extra length is fine.

r? `@noratrieb` or reassign
2024-11-05 08:30:56 +00:00
Matthias Krüger
909574e411
Rollup merge of #132559 - bvanjoi:fix-132534, r=compiler-errors
find the generic container rather than simply looking up for the assoc with const arg

Fixes #132534

This issue is caused by mismatched generic parameters. Previously, it tried to find `T` in `trait X`, but after this change, it will find `T` in `fn a`.

r? `@compiler-errors`  as this assertion was introduced by you.
2024-11-04 18:12:47 +01:00
Matthias Krüger
b9db639ea5
Rollup merge of #132544 - dianne:unstable-library-feature-backticks, r=compiler-errors
Use backticks instead of single quotes for library feature names in diagnostics

This PR changes the text of library feature errors for using unstable or body-unstable items. Displaying library feature names in backticks is consistent with other diagnostics (e.g. those from `rustc_passes`) and with the `reason`s on unstable attributes in the library. Additionally, this simplifies diagnostics when supporting multiple unstable attributes on items (see #131824) since `DiagSymbolList` also displays symbols using backticks.
2024-11-04 18:12:46 +01:00
Michael Goulet
d458f850aa ty::BrK -> ty::BoundRegionKind::K 2024-11-04 04:45:52 +00:00
Michael Goulet
be4b0261c2 ty::KContainer -> ty::AssocItemContainer::K 2024-11-04 04:45:52 +00:00
bohan
6026a0f6c9 find the generic container rather than simply looking up for the assoc with const arg 2024-11-04 12:17:44 +08:00
Jubilee
72df7780dd
Rollup merge of #132574 - workingjubilee:abi-in-compiler, r=compiler-errors
compiler: Directly use rustc_abi almost everywhere

Use rustc_abi instead of rustc_target where applicable. This is mostly described by the following substitutions:
```rust
match path_substring {
    rustc_target::spec::abi::Abi => rustc_abi::ExternAbi,
    rustc_target::abi::call => rustc_target::callconv,
    rustc_target::abi => rustc_abi,
}
```

A number of spot-fixes make that not quite the whole story.

The main exception is in 33edc68 where I get a lot more persnickety about how things are imported, especially in `rustc_middle::ty::layout`, not just from where. This includes putting an end to a reexport of `rustc_middle::ty::ReprOptions`, for the same reason that the rest of this change is happening: reexports mostly confound things.

This notably omits rustc_passes and the ast crates, as I'm still examining a question I have about how they do stability checking of `extern "Abi"` strings and if I can simplify their logic. The rustc_abi and rustc_target crates also go untouched because they will be entangled in that cleanup.

r? compiler-errors
2024-11-03 15:25:00 -08:00
dianne
d7d6238b23 use backticks instead of single quotes when reporting "use of unstable library feature"
This is consistent with all other diagnostics I could find containing
features and enables the use of `DiagSymbolList` for generalizing
diagnostics for unstable library features to multiple features.
2024-11-03 13:55:52 -08:00
Jubilee Young
89ec8c2cfe compiler: Directly use rustc_abi in hir_{analysis,typeck} 2024-11-03 13:38:47 -08:00
Michael Goulet
6b96103bf3 Rename the FIXMEs, remove a few that dont matter anymore 2024-11-03 18:59:41 +00:00
Matthias Krüger
020b63aebc
Rollup merge of #132466 - cjgillot:opaque-late, r=compiler-errors
Account for late-bound depth when capturing all opaque lifetimes.

Fixes https://github.com/rust-lang/rust/issues/132429

r? ````@compiler-errors````
2024-11-02 08:33:14 +01:00
Camille GILLOT
a7f609504c Skip late-bound lifetimes when crossing an AnonConst. 2024-11-01 17:42:14 +00:00
Camille GILLOT
45d4465028 Account for late-bound depth when capturing all opaque lifetimes. 2024-11-01 17:03:17 +00:00
bors
5ca0e9fa9b Auto merge of #132196 - compiler-errors:probe_ty_param_bounds, r=petrochenkov
Some where clause lowering simplifications

Rename `PredicateFilter::SelfThatDefines` to `PredicateFilter::SelfTraitThatDefines` to make it clear that it's only concerned with converting *traits*, and make it do a bit less work when converting bounds.

Also, make the predicate filter matching in `probe_ty_param_bounds_in_generics` explicit, and simply the args it receives a bit.
2024-11-01 15:40:13 +00:00
Jubilee
e31988cfc9
Rollup merge of #132209 - compiler-errors:modifiers, r=fmease
Fix validation when lowering `?` trait bounds

Pass the unlowered (`rustc_hir`) polarity to `lower_poly_trait_ref`.

This allows us to actually *validate* that generic args are actually valid on `?Trait` paths. This actually regressed in #113671 because that PR changed the behavior where we were inadvertently re-lowering paths as `BoundPolarity::Positive`, which was also coincidentally the only place we were enforcing the generics on `?Trait` paths were correct.
2024-10-31 17:50:40 -07:00
Michael Goulet
81dba0755e Double check the lowered predicates in type_param_predicates 2024-10-31 04:31:59 +00:00
Michael Goulet
697eda5f9a Make SelfTraitThatDefines a tighter filter 2024-10-31 04:31:37 +00:00
Michael Goulet
ac67d295b9 Make predicate filter in probe_ty_param_bounds_in_generics more explicit 2024-10-31 04:31:37 +00:00