Skip to content

Commit a74fa7a

Browse files
Merge branch 'master' into 12015
2 parents 4bf9066 + 174a0d7 commit a74fa7a

File tree

66 files changed

+935
-190
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+935
-190
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5101,6 +5101,7 @@ Released 2018-09-13
51015101
[`duplicate_mod`]: https://rust-lang.github.io/rust-clippy/master/index.html#duplicate_mod
51025102
[`duplicate_underscore_argument`]: https://rust-lang.github.io/rust-clippy/master/index.html#duplicate_underscore_argument
51035103
[`duration_subsec`]: https://rust-lang.github.io/rust-clippy/master/index.html#duration_subsec
5104+
[`eager_transmute`]: https://rust-lang.github.io/rust-clippy/master/index.html#eager_transmute
51045105
[`else_if_without_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#else_if_without_else
51055106
[`empty_drop`]: https://rust-lang.github.io/rust-clippy/master/index.html#empty_drop
51065107
[`empty_enum`]: https://rust-lang.github.io/rust-clippy/master/index.html#empty_enum
@@ -5482,6 +5483,7 @@ Released 2018-09-13
54825483
[`ptr_eq`]: https://rust-lang.github.io/rust-clippy/master/index.html#ptr_eq
54835484
[`ptr_offset_with_cast`]: https://rust-lang.github.io/rust-clippy/master/index.html#ptr_offset_with_cast
54845485
[`pub_enum_variant_names`]: https://rust-lang.github.io/rust-clippy/master/index.html#pub_enum_variant_names
5486+
[`pub_underscore_fields`]: https://rust-lang.github.io/rust-clippy/master/index.html#pub_underscore_fields
54855487
[`pub_use`]: https://rust-lang.github.io/rust-clippy/master/index.html#pub_use
54865488
[`pub_with_shorthand`]: https://rust-lang.github.io/rust-clippy/master/index.html#pub_with_shorthand
54875489
[`pub_without_shorthand`]: https://rust-lang.github.io/rust-clippy/master/index.html#pub_without_shorthand
@@ -5810,4 +5812,5 @@ Released 2018-09-13
58105812
[`allowed-dotfiles`]: https://doc.rust-lang.org/clippy/lint_configuration.html#allowed-dotfiles
58115813
[`enforce-iter-loop-reborrow`]: https://doc.rust-lang.org/clippy/lint_configuration.html#enforce-iter-loop-reborrow
58125814
[`check-private-items`]: https://doc.rust-lang.org/clippy/lint_configuration.html#check-private-items
5815+
[`pub-underscore-fields-behavior`]: https://doc.rust-lang.org/clippy/lint_configuration.html#pub-underscore-fields-behavior
58135816
<!-- end autogenerated links to configuration documentation -->

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "clippy"
3-
version = "0.1.76"
3+
version = "0.1.77"
44
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
55
repository = "https://github.com/rust-lang/rust-clippy"
66
readme = "README.md"

book/src/lint_configuration.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,3 +805,13 @@ for _ in &mut *rmvec {}
805805
* [`missing_errors_doc`](https://rust-lang.github.io/rust-clippy/master/index.html#missing_errors_doc)
806806

807807

808+
## `pub-underscore-fields-behavior`
809+
810+
811+
**Default Value:** `"PublicallyExported"`
812+
813+
---
814+
**Affected lints:**
815+
* [`pub_underscore_fields`](https://rust-lang.github.io/rust-clippy/master/index.html#pub_underscore_fields)
816+
817+

clippy_config/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "clippy_config"
3-
version = "0.1.76"
3+
version = "0.1.77"
44
edition = "2021"
55

66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

clippy_config/src/conf.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::msrvs::Msrv;
2-
use crate::types::{DisallowedPath, MacroMatcher, MatchLintBehaviour, Rename};
2+
use crate::types::{DisallowedPath, MacroMatcher, MatchLintBehaviour, PubUnderscoreFieldsBehaviour, Rename};
33
use crate::ClippyConfiguration;
44
use rustc_data_structures::fx::FxHashSet;
55
use rustc_session::Session;
@@ -547,6 +547,11 @@ define_Conf! {
547547
///
548548
/// Whether to also run the listed lints on private items.
549549
(check_private_items: bool = false),
550+
/// Lint: PUB_UNDERSCORE_FIELDS
551+
///
552+
/// Lint "public" fields in a struct that are prefixed with an underscore based on their
553+
/// exported visibility; or whether they are marked as "pub".
554+
(pub_underscore_fields_behavior: PubUnderscoreFieldsBehaviour = PubUnderscoreFieldsBehaviour::PublicallyExported),
550555
}
551556

552557
/// Search for the configuration file.
@@ -636,11 +641,12 @@ impl Conf {
636641
match path {
637642
Ok((_, warnings)) => {
638643
for warning in warnings {
639-
sess.warn(warning.clone());
644+
sess.dcx().warn(warning.clone());
640645
}
641646
},
642647
Err(error) => {
643-
sess.err(format!("error finding Clippy's configuration file: {error}"));
648+
sess.dcx()
649+
.err(format!("error finding Clippy's configuration file: {error}"));
644650
},
645651
}
646652

@@ -652,7 +658,7 @@ impl Conf {
652658
Ok((Some(path), _)) => match sess.source_map().load_file(path) {
653659
Ok(file) => deserialize(&file),
654660
Err(error) => {
655-
sess.err(format!("failed to read `{}`: {error}", path.display()));
661+
sess.dcx().err(format!("failed to read `{}`: {error}", path.display()));
656662
TryConf::default()
657663
},
658664
},
@@ -663,14 +669,14 @@ impl Conf {
663669

664670
// all conf errors are non-fatal, we just use the default conf in case of error
665671
for error in errors {
666-
sess.span_err(
672+
sess.dcx().span_err(
667673
error.span,
668674
format!("error reading Clippy's configuration file: {}", error.message),
669675
);
670676
}
671677

672678
for warning in warnings {
673-
sess.span_warn(
679+
sess.dcx().span_warn(
674680
warning.span,
675681
format!("error reading Clippy's configuration file: {}", warning.message),
676682
);

clippy_config/src/msrvs.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ impl Msrv {
8484
(None, Some(cargo_msrv)) => self.stack = vec![cargo_msrv],
8585
(Some(clippy_msrv), Some(cargo_msrv)) => {
8686
if clippy_msrv != cargo_msrv {
87-
sess.warn(format!(
87+
sess.dcx().warn(format!(
8888
"the MSRV in `clippy.toml` and `Cargo.toml` differ; using `{clippy_msrv}` from `clippy.toml`"
8989
));
9090
}
@@ -107,7 +107,8 @@ impl Msrv {
107107

108108
if let Some(msrv_attr) = msrv_attrs.next() {
109109
if let Some(duplicate) = msrv_attrs.last() {
110-
sess.struct_span_err(duplicate.span, "`clippy::msrv` is defined multiple times")
110+
sess.dcx()
111+
.struct_span_err(duplicate.span, "`clippy::msrv` is defined multiple times")
111112
.span_note(msrv_attr.span, "first definition found here")
112113
.emit();
113114
}
@@ -117,9 +118,10 @@ impl Msrv {
117118
return Some(version);
118119
}
119120

120-
sess.span_err(msrv_attr.span, format!("`{msrv}` is not a valid Rust version"));
121+
sess.dcx()
122+
.span_err(msrv_attr.span, format!("`{msrv}` is not a valid Rust version"));
121123
} else {
122-
sess.span_err(msrv_attr.span, "bad clippy attribute");
124+
sess.dcx().span_err(msrv_attr.span, "bad clippy attribute");
123125
}
124126
}
125127

clippy_config/src/types.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,9 @@ unimplemented_serialize! {
126126
Rename,
127127
MacroMatcher,
128128
}
129+
130+
#[derive(Clone, Copy, Debug, PartialEq, Eq, Deserialize, Serialize)]
131+
pub enum PubUnderscoreFieldsBehaviour {
132+
PublicallyExported,
133+
AllPubFields,
134+
}

clippy_lints/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "clippy_lints"
3-
version = "0.1.76"
3+
version = "0.1.77"
44
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
55
repository = "https://github.com/rust-lang/rust-clippy"
66
readme = "README.md"

clippy_lints/src/async_yields_async.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_hir_and_then;
22
use clippy_utils::source::snippet;
33
use clippy_utils::ty::implements_trait;
44
use rustc_errors::Applicability;
5-
use rustc_hir::{Body, BodyId, CoroutineKind, CoroutineSource, ExprKind, QPath};
5+
use rustc_hir::{Closure, ClosureKind, CoroutineDesugaring, CoroutineKind, CoroutineSource, Expr, ExprKind, QPath};
66
use rustc_lint::{LateContext, LateLintPass};
77
use rustc_session::declare_lint_pass;
88

@@ -44,16 +44,22 @@ declare_clippy_lint! {
4444
declare_lint_pass!(AsyncYieldsAsync => [ASYNC_YIELDS_ASYNC]);
4545

4646
impl<'tcx> LateLintPass<'tcx> for AsyncYieldsAsync {
47-
fn check_body(&mut self, cx: &LateContext<'tcx>, body: &'tcx Body<'_>) {
48-
use CoroutineSource::{Block, Closure};
47+
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
4948
// For functions, with explicitly defined types, don't warn.
5049
// XXXkhuey maybe we should?
51-
if let Some(CoroutineKind::Async(Block | Closure)) = body.coroutine_kind {
50+
if let ExprKind::Closure(Closure {
51+
kind:
52+
ClosureKind::Coroutine(CoroutineKind::Desugared(
53+
CoroutineDesugaring::Async,
54+
CoroutineSource::Block | CoroutineSource::Closure,
55+
)),
56+
body: body_id,
57+
..
58+
}) = expr.kind
59+
{
5260
if let Some(future_trait_def_id) = cx.tcx.lang_items().future_trait() {
53-
let body_id = BodyId {
54-
hir_id: body.value.hir_id,
55-
};
56-
let typeck_results = cx.tcx.typeck_body(body_id);
61+
let typeck_results = cx.tcx.typeck_body(*body_id);
62+
let body = cx.tcx.hir().body(*body_id);
5763
let expr_ty = typeck_results.expr_ty(body.value);
5864

5965
if implements_trait(cx, expr_ty, future_trait_def_id, &[]) {

clippy_lints/src/await_holding_invalid.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use clippy_config::types::DisallowedPath;
22
use clippy_utils::diagnostics::span_lint_and_then;
33
use clippy_utils::{match_def_path, paths};
44
use rustc_data_structures::fx::FxHashMap;
5+
use rustc_hir as hir;
56
use rustc_hir::def_id::DefId;
6-
use rustc_hir::{Body, CoroutineKind, CoroutineSource};
77
use rustc_lint::{LateContext, LateLintPass};
88
use rustc_middle::mir::CoroutineLayout;
99
use rustc_session::impl_lint_pass;
@@ -183,8 +183,8 @@ impl AwaitHolding {
183183
}
184184
}
185185

186-
impl LateLintPass<'_> for AwaitHolding {
187-
fn check_crate(&mut self, cx: &LateContext<'_>) {
186+
impl<'tcx> LateLintPass<'tcx> for AwaitHolding {
187+
fn check_crate(&mut self, cx: &LateContext<'tcx>) {
188188
for conf in &self.conf_invalid_types {
189189
let segs: Vec<_> = conf.path().split("::").collect();
190190
for id in clippy_utils::def_path_def_ids(cx, &segs) {
@@ -193,11 +193,14 @@ impl LateLintPass<'_> for AwaitHolding {
193193
}
194194
}
195195

196-
fn check_body(&mut self, cx: &LateContext<'_>, body: &'_ Body<'_>) {
197-
use CoroutineSource::{Block, Closure, Fn};
198-
if let Some(CoroutineKind::Async(Block | Closure | Fn)) = body.coroutine_kind {
199-
let def_id = cx.tcx.hir().body_owner_def_id(body.id());
200-
if let Some(coroutine_layout) = cx.tcx.mir_coroutine_witnesses(def_id) {
196+
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'tcx>) {
197+
if let hir::ExprKind::Closure(hir::Closure {
198+
kind: hir::ClosureKind::Coroutine(hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Async, _)),
199+
def_id,
200+
..
201+
}) = expr.kind
202+
{
203+
if let Some(coroutine_layout) = cx.tcx.mir_coroutine_witnesses(*def_id) {
201204
self.check_interior_types(cx, coroutine_layout);
202205
}
203206
}

0 commit comments

Comments
 (0)