about summary refs log tree commit diff
path: root/compiler
AgeCommit message (Collapse)AuthorLines
2023-12-05rustc_interface: Address all `rustc::potential_query_instability` lintsMartin Nordholts-1/+7
Instead of allowing `rustc::potential_query_instability` on the whole crate we go over each lint and allow it individually if it is safe to do. Turns out all instances were safe to allow in this crate.
2023-12-05Factor out some repeated code.Nicholas Nethercote-14/+10
2023-12-05rustc_driver_impl: Address all `rustc::potential_query_instability` lintsMartin Nordholts-1/+0
Instead of allowing `rustc::potential_query_instability` on the whole crate we go over each lint and allow it individually if it is safe to do. Turns out there were no instances of this lint in this crate.
2023-12-05Auto merge of #118066 - estebank:structured-use-suggestion, r=b-naberbors-1/+86
Structured `use` suggestion on privacy error When encoutering a privacy error on an item through a re-export that is accessible in an alternative path, provide a structured suggestion with that path. ``` error[E0603]: module import `mem` is private --> $DIR/private-std-reexport-suggest-public.rs:4:14 | LL | use foo::mem; | ^^^ private module import | note: the module import `mem` is defined here... --> $DIR/private-std-reexport-suggest-public.rs:8:9 | LL | use std::mem; | ^^^^^^^^ note: ...and refers to the module `mem` which is defined here --> $SRC_DIR/std/src/lib.rs:LL:COL | = note: you could import this help: import `mem` through the re-export | LL | use std::mem; | ~~~~~~~~ ``` Fix #42909.
2023-12-04Add FieldDef to StableMIR and methods to get typeCelina G. Val-5/+95
2023-12-05Auto merge of #118230 - nnethercote:streamline-dataflow-cursors, r=cjgillotbors-243/+113
Streamline MIR dataflow cursors `rustc_mir_dataflow` has two kinds of results (`Results` and `ResultsCloned`) and three kinds of results cursor (`ResultsCursor`, `ResultsClonedCursor`, `ResultsRefCursor`). I found this quite confusing. This PR removes `ResultsCloned`, `ResultsClonedCursor`, and `ResultsRefCursor`, leaving just `Results` and `ResultsCursor`. This makes the relevant code shorter and easier to read, and there is no performance penalty. r? `@cjgillot`
2023-12-05Remove `#[rustc_host]`, use internal desugaringDeadbeef-76/+42
2023-12-05Auto merge of #117088 - lcnr:generalize-alias, r=compiler-errorsbors-26/+131
generalize: handle occurs check failure in aliases mostly fixes #105787, except for the `for<'a> fn(<<?x as OtherTrait>::Assoc as Trait<'a>>::Assoc) eq ?x` case in https://github.com/rust-lang/trait-system-refactor-initiative/issues/8. r? `@compiler-errors`
2023-12-05Consider only `#[no_mangle]` as builtin functionsDianQK-2/+3
2023-12-04Address code review feedbackEric Holk-21/+28
2023-12-04Structured `use` suggestion on privacy errorEsteban Küber-1/+86
When encoutering a privacy error on an item through a re-export that is accessible in an alternative path, provide a structured suggestion with that path. ``` error[E0603]: module import `mem` is private --> $DIR/private-std-reexport-suggest-public.rs:4:14 | LL | use foo::mem; | ^^^ private module import | note: the module import `mem` is defined here... --> $DIR/private-std-reexport-suggest-public.rs:8:9 | LL | use std::mem; | ^^^^^^^^ note: ...and refers to the module `mem` which is defined here --> $SRC_DIR/std/src/lib.rs:LL:COL | = note: you could import this help: import `mem` through the re-export | LL | use std::mem; | ~~~~~~~~ ``` Fix #42909.
2023-12-04Provide more suggestions for cloning immutable bindingsEsteban Küber-1/+101
When encountering multiple mutable borrows, suggest cloning and adding derive annotations as needed. ``` error[E0596]: cannot borrow `sm.x` as mutable, as it is behind a `&` reference --> $DIR/accidentally-cloning-ref-borrow-error.rs:32:9 | LL | foo(&mut sm.x); | ^^^^^^^^^ `sm` is a `&` reference, so the data it refers to cannot be borrowed as mutable | help: `Str` doesn't implement `Clone`, so this call clones the reference `&Str` --> $DIR/accidentally-cloning-ref-borrow-error.rs:31:21 | LL | let mut sm = sr.clone(); | ^^^^^^^ help: consider annotating `Str` with `#[derive(Clone)]` | LL + #[derive(Clone)] LL | struct Str { | help: consider specifying this binding's type | LL | let mut sm: &mut Str = sr.clone(); | ++++++++++ ``` ``` error[E0596]: cannot borrow `*inner` as mutable, as it is behind a `&` reference --> $DIR/issue-91206.rs:14:5 | LL | inner.clear(); | ^^^^^ `inner` is a `&` reference, so the data it refers to cannot be borrowed as mutable | help: you can `clone` the `Vec<usize>` value and consume it, but this might not be your desired behavior --> $DIR/issue-91206.rs:11:17 | LL | let inner = client.get_inner_ref(); | ^^^^^^^^^^^^^^^^^^^^^^ help: consider specifying this binding's type | LL | let inner: &mut Vec<usize> = client.get_inner_ref(); | +++++++++++++++++ ```
2023-12-04Deduplicate some logicEsteban Küber-181/+161
2023-12-04On "this .clone() is on the reference", provide more infoEsteban Küber-1/+74
When encountering a case where `let x: T = (val: &T).clone();` and `T: !Clone`, already mention that the reference is being cloned. We now also suggest `#[derive(Clone)]` not only on `T` but also on type parameters to satisfy blanket implementations. ``` error[E0308]: mismatched types --> $DIR/assignment-of-clone-call-on-ref-due-to-missing-bound.rs:17:39 | LL | let mut x: HashSet<Day> = v.clone(); | ------------ ^^^^^^^^^ expected `HashSet<Day>`, found `&HashSet<Day>` | | | expected due to this | = note: expected struct `HashSet<Day>` found reference `&HashSet<Day>` note: `HashSet<Day>` does not implement `Clone`, so `&HashSet<Day>` was cloned instead --> $DIR/assignment-of-clone-call-on-ref-due-to-missing-bound.rs:17:39 | LL | let mut x: HashSet<Day> = v.clone(); | ^ = help: `Clone` is not implemented because the trait bound `Day: Clone` is not satisfied help: consider annotating `Day` with `#[derive(Clone)]` | LL + #[derive(Clone)] LL | enum Day { | ``` Case taken from # #41825.
2023-12-04Tweak output on specific caseEsteban Küber-1/+21
2023-12-04Suggest cloning and point out obligation errors on move errorEsteban Küber-48/+124
When encountering a move error, look for implementations of `Clone` for the moved type. If there is one, check if all its obligations are met. If they are, we suggest cloning without caveats. If they aren't, we suggest cloning while mentioning the unmet obligations, potentially suggesting `#[derive(Clone)]` when appropriate. ``` error[E0507]: cannot move out of a shared reference --> $DIR/suggest-clone-when-some-obligation-is-unmet.rs:20:28 | LL | let mut copy: Vec<U> = map.clone().into_values().collect(); | ^^^^^^^^^^^ ------------- value moved due to this method call | | | move occurs because value has type `HashMap<T, U, Hash128_1>`, which does not implement the `Copy` trait | note: `HashMap::<K, V, S>::into_values` takes ownership of the receiver `self`, which moves value --> $SRC_DIR/std/src/collections/hash/map.rs:LL:COL help: you could `clone` the value and consume it, if the `Hash128_1: Clone` trait bound could be satisfied | LL | let mut copy: Vec<U> = <HashMap<T, U, Hash128_1> as Clone>::clone(&map.clone()).into_values().collect(); | ++++++++++++++++++++++++++++++++++++++++++++ + help: consider annotating `Hash128_1` with `#[derive(Clone)]` | LL + #[derive(Clone)] LL | pub struct Hash128_1; | ``` Fix #109429.
2023-12-04Tweak `.clone()` suggestion to work in more casesEsteban Küber-3/+17
When going through auto-deref, the `<T as Clone>` impl sometimes needs to be specified for rustc to actually clone the value and not the reference. ``` error[E0507]: cannot move out of dereference of `S` --> $DIR/needs-clone-through-deref.rs:15:18 | LL | for _ in self.clone().into_iter() {} | ^^^^^^^^^^^^ ----------- value moved due to this method call | | | move occurs because value has type `Vec<usize>`, which does not implement the `Copy` trait | note: `into_iter` takes ownership of the receiver `self`, which moves value --> $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL help: you can `clone` the value and consume it, but this might not be your desired behavior | LL | for _ in <Vec<usize> as Clone>::clone(&self.clone()).into_iter() {} | ++++++++++++++++++++++++++++++ + ``` CC #109429.
2023-12-04Fix some broken testsEric Holk-1/+1
2023-12-04Option<CoroutineKind>Eric Holk-112/+93
2023-12-04Merge Async and Gen into CoroutineKindEric Holk-218/+212
2023-12-04Rollup merge of #118565 - RalfJung:numeric_intrinsic, r=davidtwcoGuillaume Gomez-46/+36
interpret: make numeric_intrinsic accessible from Miri This will let us share the code of the cttz and simd_cttz intrinsics (and same for ctlz).
2023-12-04Make async gen fn an errorEric Holk-0/+15
2023-12-04gate gen fn behind gen_blocksEric Holk-0/+4
2023-12-04Lower return types for gen fn to impl IteratorEric Holk-80/+167
2023-12-04Add genness to FnHeaderEric Holk-5/+26
2023-12-04Finish implementing `RustcInternal` for `TyKind`Celina G. Val-13/+186
This will allow us to provide methods to create `Ty` inside the stable MIR, which can be helpful while handling pointers and other stuff.
2023-12-04Add Variant and a few more APIs to stable_mirCelina G. Val-39/+153
2023-12-04Fix parser ICE when recovering `dyn`/`impl` after `for<...>`sjwang05-10/+12
2023-12-04Don't include destruction scopes in THIRMatthew Jasper-162/+72
They are not used by anyone, and add memory/performance overhead.
2023-12-04Use default params until effects in desugaringDeadbeef-0/+25
2023-12-04Avoid adding compiler-used functions to `symbols.o`DianQK-2/+18
2023-12-04Rollup merge of #118573 - petrochenkov:pathdatakind, r=TaKO8KiTakayuki Maeda-132/+133
rustc: Harmonize `DefKind` and `DefPathData` Follow up to https://github.com/rust-lang/rust/pull/118188. `DefPathData::(ClosureExpr,ImplTrait)` are renamed to match `DefKind::(Closure,OpaqueTy)`. `DefPathData::ImplTraitAssocTy` is replaced with `DefPathData::TypeNS(kw::Empty)` because both correspond to `DefKind::AssocTy`. It's possible that introducing `(DefKind,DefPathData)::AssocOpaqueTy` instead could be a better solution, but that would be a much more invasive change. Const generic parameters introduced for effects are moved from `DefPathData::TypeNS` to `DefPathData::ValueNS`, because constants are values. `DefPathData` is no longer passed to `create_def` functions to avoid redundancy.
2023-12-04Rollup merge of #118551 - RalfJung:extern-types-bugs, r=compiler-errorsTakayuki Maeda-0/+22
more targeted errors when extern types end up in places they should not Cc https://github.com/rust-lang/rust/issues/115709 -- this does not fix that bug but it makes the panics less obscure and makes it more clear that this is a deeper issue than just a little codegen oversight. (In https://github.com/rust-lang/rust/pull/116115 we decided we'd stick to causing ICEs here for now, rather than nicer errors. We can't currently show any errors pre-mono and probably we don't want post-mono checks when this gets stabilized anyway.)
2023-12-04Rollup merge of #118540 - RalfJung:unsized-packed-offset, r=TaKO8KiTakayuki Maeda-11/+23
codegen, miri: fix computing the offset of an unsized field in a packed struct `#[repr(packed)]` strikes again. Fixes https://github.com/rust-lang/rust/issues/118537 Fixes https://github.com/rust-lang/miri/issues/3200 `@bjorn3` I assume cranelift needs the same fix.
2023-12-04Rollup merge of #118495 - weiznich:more_tests_for_on_unimplemented, ↵Takayuki Maeda-52/+98
r=compiler-errors Restrict what symbols can be used in `#[diagnostic::on_unimplemented]` format strings This commit restricts what symbols can be used in a format string for any option of the `diagnostic::on_unimplemented` attribute. We previously allowed all the ad-hoc options supported by the internal `#[rustc_on_unimplemented]` attribute. For the stable attribute we only want to support generic parameter names and `{Self}` as parameters. For any other parameter an warning is emitted and the parameter is replaced by the literal parameter string, so for example `{integer}` turns into `{integer}`. This follows the general design of attributes in the `#[diagnostic]` attribute namespace, that any syntax "error" is treated as warning and subsequently ignored. r? `@compiler-errors`
2023-12-04Remove the `precise_pointer_size_matching` feature gateNadrieril-21/+9
2023-12-04cleanup and commentslcnr-26/+34
2023-12-04generalize: handle occurs check failure in aliaseslcnr-23/+120
2023-12-04do not fetch variance info during generalizationlcnr-1/+1
2023-12-04Restrict what symbols can be used in `#[diagnostic::on_unimplemented]` ↵Georg Semmler-52/+98
format strings This commit restricts what symbols can be used in a format string for any option of the `diagnostic::on_unimplemented` attribute. We previously allowed all the ad-hoc options supported by the internal `#[rustc_on_unimplemented]` attribute. For the stable attribute we only want to support generic parameter names and `{Self}` as parameters. For any other parameter an warning is emitted and the parameter is replaced by the literal parameter string, so for example `{integer}` turns into `{integer}`. This follows the general design of attributes in the `#[diagnostic]` attribute namespace, that any syntax "error" is treated as warning and subsequently ignored.
2023-12-04Inline and remove `fatal_no_raise`.Nicholas Nethercote-10/+3
This makes `Handler::fatal` more like `Handler::{err,warn,bug,note}`.
2023-12-04Make `Handler::{err,bug}` more like `Handler::{warn,note}`.Nicholas Nethercote-10/+3
2023-12-04Remove `HandlerInner::emit`.Nicholas Nethercote-12/+12
This is weird: `HandlerInner::emit` calls `HandlerInner::emit_diagnostic`, but only after doing a `treat-err-as-bug` check. Which is fine, *except* that there are multiple others paths for an `Error` or `Fatal` diagnostic to be passed to `HandlerInner::emit_diagnostic` without going through `HandlerInner::emit`, e.g. `Handler::span_err` call `Handler::emit_diag_at_span`, which calls `emit_diagnostic`. So that suggests that the coverage for `treat-err-as-bug` is incomplete. This commit removes `HandlerInner::emit` and moves the `treat-err-as-bug` check to `HandlerInner::emit_diagnostic`, so it cannot by bypassed.
2023-12-04Move some `HandlerInner` functions to `Handler`.Nicholas Nethercote-212/+164
`Handler` is a wrapper around `HanderInner`. Some functions on on `Handler` just forward to the samed-named functions on `HandlerInner`. This commit removes as many of those as possible, implementing functions on `Handler` where possible, to avoid the boilerplate required for forwarding. The commit is moderately large but it's very mechanical.
2023-12-04Use `DiagnosticBuilder::new` more.Nicholas Nethercote-68/+36
By making it generic, instead of only for `EmissionGuarantee = ()`, we can use it everywhere.
2023-12-04De-genericize some `IntoDiagnostic` impls.Nicholas Nethercote-20/+20
These impls are all needed for just a single `IntoDiagnostic` type, not a family of them. Note that `ErrorGuaranteed` is the default type parameter for `IntoDiagnostic`.
2023-12-04Remove some unused code, and downgrade some `pub`s.Nicholas Nethercote-49/+6
2023-12-04Avoid `Diagnostic::new_with_code(..., None, ...)`.Nicholas Nethercote-5/+5
`Diagnostic::new` can be used instead.
2023-12-04Always use `G` for `EmissionGuarantee` type variables.Nicholas Nethercote-13/+13
That's what is mostly used. This commit changes a few `EM` and `E` and `T` type variables to `G`.
2023-12-04Rename some arguments.Nicholas Nethercote-10/+10
`sess` is a terribly misleading name for a `Handler`! This confused me for a bit.