about summary refs log tree commit diff
path: root/compiler/rustc_lint/src/context.rs
AgeCommit message (Collapse)AuthorLines
2023-12-15Fix commentsMichael Goulet-9/+0
2023-12-15Don't pass lint back out of lint decoratorMichael Goulet-20/+10
2023-12-13Add more suggestion to unexpected cfg names and valuesUrgau-3/+48
2023-12-10Revert "Don't print host effect param in pretty path_generic_args"Deadbeef-1/+0
This reverts commit f1bf874fb13703d706fc8184407c6df12555d8e9.
2023-12-09Don't print host effect param in pretty path_generic_argsMichael Goulet-0/+1
2023-12-01vis note for no pub reexports glob importbohan-0/+4
2023-11-22rustc_session: implement latent TODOTamir Duberstein-1/+3
2023-11-22Auto merge of #118071 - Urgau:check-cfg-cargo-feature, r=petrochenkovbors-0/+2
Remove `feature` from the list of well known check-cfg name This PR removes `feature` from the list of well known check-cfg. This is done for multiple reasons: - Cargo is the source of truth, rustc shouldn't have any knowledge of it - It creates a conflict between Cargo and rustc when there are no features defined. In this case Cargo won't pass any `--check-cfg` for `feature` since no feature will ever be passed, but rustc by having in it's list adds a implicit `cfg(feature, values(any()))` which is completely wrong. Having any cfg `feature` is unexpected not allow any `feature` value. While doing this, I took the opportunity to specialise the diagnostic a bit for the case above. r? `@petrochenkov`
2023-11-21Fix `clippy::needless_borrow` in the compilerNilstrieb-10/+10
`x clippy compiler -Aclippy::all -Wclippy::needless_borrow --fix`. Then I had to remove a few unnecessary parens and muts that were exposed now.
2023-11-21Improve diagnostic for unexpected feature config name from CargoUrgau-0/+2
2023-11-17Rollup merge of #117549 - DaniPopes:more-copied, r=b-naberMatthias Krüger-1/+1
Use `copied` instead of manual `map`
2023-11-17Remove dead lint code.Nicholas Nethercote-27/+5
2023-11-04Remove support for compiler plugins.Nicholas Nethercote-10/+8
They've been deprecated for four years. This commit includes the following changes. - It eliminates the `rustc_plugin_impl` crate. - It changes the language used for lints in `compiler/rustc_driver_impl/src/lib.rs` and `compiler/rustc_lint/src/context.rs`. External lints are now called "loaded" lints, rather than "plugins" to avoid confusion with the old plugins. This only has a tiny effect on the output of `-W help`. - E0457 and E0498 are no longer used. - E0463 is narrowed, now only relating to unfound crates, not plugins. - The `plugin` feature was moved from "active" to "removed". - It removes the entire plugins chapter from the unstable book. - It removes quite a few tests, mostly all of those in `tests/ui-fulldeps/plugin/`. Closes #29597.
2023-11-03compiler: use `copied` instead of manual `map`DaniPopes-1/+1
2023-10-21Make `ty::print::Printer` take `&mut self` instead of `self`Nilstrieb-34/+33
This simplifies the code by removing all the `self` assignments and makes the flow of data clearer - always into the printer. Especially in v0 mangling, which already used `&mut self` in some places, it gets a lot more uniform.
2023-10-17Remove `Printer::Error`Nilstrieb-15/+13
It's always a `fmt::Error` except in some cases where it was `!`, but we're not really winning anything in that case.
2023-10-17Remove "subprinter" types from `Printer`Nilstrieb-31/+31
These are `Self` in almost all printers except one, which can just store the state as a field instead. This simplifies the printer and allows for further simplifications, for example using `&mut self` instead of passing around the printer.
2023-10-15Auto merge of #116688 - compiler-errors:rustfmt-up, r=WaffleLapkin,Nilstriebbors-4/+4
Format all the let-chains in compiler crates Since rust-lang/rustfmt#5910 has landed, soon we will have support for formatting let-chains (as soon as rustfmt syncs and beta gets bumped). This PR applies the changes [from master rustfmt to rust-lang/rust eagerly](https://rust-lang.zulipchat.com/#narrow/stream/122651-general/topic/out.20formatting.20of.20prs/near/374997516), so that the next beta bump does not have to deal with a 200+ file diff and can remain concerned with other things like `cfg(bootstrap)` -- #113637 was a pain to land, for example, because of let-else. I will also add this commit to the ignore list after it has landed. The commands that were run -- I'm not great at bash-foo, but this applies rustfmt to every compiler crate, and then reverts the two crates that should probably be formatted out-of-tree. ``` ~/rustfmt $ ls -1d ~/rust/compiler/* | xargs -I@ cargo run --bin rustfmt -- `@/src/lib.rs` --config-path ~/rust --edition=2021 # format all of the compiler crates ~/rust $ git checkout HEAD -- compiler/rustc_codegen_{gcc,cranelift} # revert changes to cg-gcc and cg-clif ``` cc `@rust-lang/rustfmt` r? `@WaffleLapkin` or `@Nilstrieb` who said they may be able to review this purely mechanical PR :> cc `@Mark-Simulacrum` and `@petrochenkov,` who had some thoughts on the order of operations with big formatting changes in https://github.com/rust-lang/rust/pull/95262#issue-1178993801. I think the situation has changed since then, given that let-chains support exists on master rustfmt now, and I'm fairly confident that this formatting PR should land even if *bootstrap* rustfmt doesn't yet format let-chains in order to lessen the burden of the next beta bump.
2023-10-13Format all the let chains in compilerMichael Goulet-4/+4
2023-10-12check-cfg: only print the list of expected names onceUrgau-1/+5
2023-10-12check-cfg: adjust expected names and values when usefulUrgau-1/+12
2023-09-27Fix ICE by introducing an expr_or_init variant for outside bodiesUrgau-1/+38
2023-09-18Add clippy like expr_or_init fn to rustc LateContextUrgau-0/+48
2023-08-30refactor(rustc_lint): inline `check_lint_name_cmdline`Weihang Lo-67/+0
2023-08-24refactor: use references to reduce unnecessary clonesWeihang Lo-8/+7
2023-08-24lint: translate `RenamedOrRemovedLint`Weihang Lo-16/+19
2023-08-20Warn on elided lifetimes in associated constantsMichael Goulet-0/+8
2023-08-11rustc: Move `features` from `Session` to `GlobalCtxt`Vadim Petrochenkov-0/+3
Removes two pieces of mutable state. Follow up to #114622.
2023-07-29fix(resolve): update the ambiguity glob binding as warning recursivelybohan-0/+3
2023-07-25inline format!() args from rustc_codegen_llvm to the end (4)Matthias Krüger-18/+16
r? @WaffleLapkin
2023-07-18Fix removal span calculation of unused_qualifications suggestion许杰友 Jieyou Xu (Joe)-4/+4
2023-07-14refactor(rustc_middle): Substs -> GenericArgMahdi Dibaiee-3/+3
2023-07-13Add machine-applicable suggestion for `unused_qualifications` lint许杰友 Jieyou Xu (Joe)-0/+8
2023-07-05Move `TyCtxt::mk_x` to `Ty::new_x` where applicableBoxy-1/+1
2023-06-10Adjust span labels for `HIDDEN_GLOB_REEXPORTS`许杰友 Jieyou Xu (Joe)-2/+2
2023-05-27Add warn-by-default lint for local binding shadowing exported glob re-export ↵许杰友 Jieyou Xu (Joe)-0/+4
item
2023-05-06introduce `DynSend` and `DynSync` auto traitSparrowLii-8/+8
2023-05-05Improve check-cfg diagnostics (part 2)Urgau-9/+45
2023-05-05Improve check-cfg diagnostics (part 1)Urgau-8/+8
2023-05-05Improve internal representation of check-cfgUrgau-6/+8
This is done to simplify to relationship between names() and values() but also make thing clearer (having an Any to represent that any values are allowed) but also to allow the (none) + values expected cases that wasn't possible before.
2023-05-03Restrict `From<S>` for `{D,Subd}iagnosticMessage`.Nicholas Nethercote-10/+10
Currently a `{D,Subd}iagnosticMessage` can be created from any type that impls `Into<String>`. That includes `&str`, `String`, and `Cow<'static, str>`, which are reasonable. It also includes `&String`, which is pretty weird, and results in many places making unnecessary allocations for patterns like this: ``` self.fatal(&format!(...)) ``` This creates a string with `format!`, takes a reference, passes the reference to `fatal`, which does an `into()`, which clones the reference, doing a second allocation. Two allocations for a single string, bleh. This commit changes the `From` impls so that you can only create a `{D,Subd}iagnosticMessage` from `&str`, `String`, or `Cow<'static, str>`. This requires changing all the places that currently create one from a `&String`. Most of these are of the `&format!(...)` form described above; each one removes an unnecessary static `&`, plus an allocation when executed. There are also a few places where the existing use of `&String` was more reasonable; these now just use `clone()` at the call site. As well as making the code nicer and more efficient, this is a step towards possibly using `Cow<'static, str>` in `{D,Subd}iagnosticMessage::{Str,Eager}`. That would require changing the `From<&'a str>` impls to `From<&'static str>`, which is doable, but I'm not yet sure if it's worthwhile.
2023-03-20Lint ambiguous glob re-exports许杰友 Jieyou Xu (Joe)-0/+4
2023-02-22Move the unused extern crate check back to the resolver.Camille GILLOT-0/+17
2023-02-19Make public API, docs algorithm-agnosticJacob Pratt-1/+1
2023-02-16Replace some `then`s with some `then_some`sMaybe Waffle-1/+1
2023-02-16`if $c:expr { Some($r:expr) } else { None }` =>> `$c.then(|| $r)`Maybe Waffle-6/+4
2023-02-14Fix #107998, avoid ICE when the generic_span is emptyyukang-1/+9
2023-01-30Allow more deriving on packed structs.Nicholas Nethercote-0/+3
Currently, deriving on packed structs has some non-trivial limitations, related to the fact that taking references on unaligned fields is UB. The current approach to field accesses in derived code: - Normal case: `&self.0` - In a packed struct that derives `Copy`: `&{self.0}` - In a packed struct that doesn't derive `Copy`: `&self.0` Plus, we disallow deriving any builtin traits other than `Default` for any packed generic type, because it's possible that there might be misaligned fields. This is a fairly broad restriction. Plus, we disallow deriving any builtin traits other than `Default` for most packed types that don't derive `Copy`. (The exceptions are those where the alignments inherently satisfy the packing, e.g. in a type with `repr(packed(N))` where all the fields have alignments of `N` or less anyway. Such types are pretty strange, because the `packed` attribute is not having any effect.) This commit introduces a new, simpler approach to field accesses: - Normal case: `&self.0` - In a packed struct: `&{self.0}` In the latter case, this requires that all fields impl `Copy`, which is a new restriction. This means that the following example compiles under the old approach and doesn't compile under the new approach. ``` #[derive(Debug)] struct NonCopy(u8); #[derive(Debug) #[repr(packed)] struct MyType(NonCopy); ``` (Note that the old approach's support for cases like this was brittle. Changing the `u8` to a `u16` would be enough to stop it working. So not much capability is lost here.) However, the other constraints from the old rules are removed. We can now derive builtin traits for packed generic structs like this: ``` trait Trait { type A; } #[derive(Hash)] #[repr(packed)] pub struct Foo<T: Trait>(T, T::A); ``` To allow this, we add a `T: Copy` bound in the derived impl and a `T::A: Copy` bound in where clauses. So `T` and `T::A` must impl `Copy`. We can now also derive builtin traits for packed structs that don't derive `Copy`, so long as the fields impl `Copy`: ``` #[derive(Hash)] #[repr(packed)] pub struct Foo(u32); ``` This includes types that hand-impl `Copy` rather than deriving it, such as the following, that show up in winapi-0.2: ``` #[derive(Clone)] #[repr(packed)] struct MyType(i32); impl Copy for MyType {} ``` The new approach is simpler to understand and implement, and it avoids the need for the `unsafe_derive_on_repr_packed` check. One exception is required for backwards-compatibility: we allow `[u8]` fields for now. There is a new lint for this, `byte_slice_in_packed_struct_with_derive`.
2023-01-16fix #104440Takayuki Maeda-21/+26
2023-01-09refactor: cleanupRejyr-2/+0