Skip to content

Rollup of 9 pull requests #113700

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 154 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
154 commits
Select commit Hold shift + click to select a range
c5a9adc
new lint: `type_id_on_box`
y21 Jun 18, 2023
9ab1e8e
that was definitely not the right version
y21 Jun 18, 2023
26ac76c
add it to the methods lint pass
y21 Jun 18, 2023
b0dfecd
add a few more test cases
y21 Jun 18, 2023
1b6738b
s/is_dyn_trait/is_dyn_any
y21 Jun 20, 2023
7bd8ab7
Make simd_shuffle_indices use valtrees
oli-obk Jun 16, 2023
d69c4f5
Add `SPEEDTEST`
blyxyas Jun 10, 2023
0cd8bbc
Fix dogfood
blyxyas Jun 10, 2023
57923c3
Finally fix dogfood
blyxyas Jun 28, 2023
4340a8a
Use depinfo to discover UI test dependencies
Alexendoo Jun 28, 2023
86391ab
Don't lint manual_let_else in cases where the question mark operator …
est31 Jun 11, 2023
c6be621
Fix the now stricter lint in manual_rem_euclid.rs
est31 Jun 11, 2023
20dfaba
Put into one pass
est31 Jun 30, 2023
2f7f139
Use `cargo build --tests` in CI
Alexendoo Jun 30, 2023
420f3d1
"try this" -> "try"
smoelius Jul 1, 2023
bb33e03
Auto merge of #112718 - oli-obk:SIMD-destructure_mir_const, r=cjgillot
bors Jul 2, 2023
885a182
Fix typos
Centri3 Jul 2, 2023
1990b72
Auto merge of #11058 - Centri3:typos, r=xFrednet
bors Jul 2, 2023
17a48c2
Auto merge of #11053 - Alexendoo:ci-build-tests, r=flip1995
bors Jul 2, 2023
cb3ecf7
Merge commit '37f4c1725d3fd7e9c3ffd8783246bc5589debc53' into clippyup
flip1995 Jul 2, 2023
ba1ffec
Fix valtree changes
flip1995 Jul 2, 2023
4aa4fec
Fix compile-test tests to work with the new ui_test crate
flip1995 Jul 2, 2023
e29a5ac
let_and_return: lint 'static lifetimes, don't lint borrows in closures
Alexendoo Jul 2, 2023
83d0682
Auto merge of #11061 - Alexendoo:let-and-return-closures, r=llogiq
bors Jul 2, 2023
ea4ca22
Auto merge of #10920 - blyxyas:speedtest, r=llogiq
bors Jul 2, 2023
555ceb8
[`missing_fields_in_debug`]: make sure `self` is an adt
y21 Jul 2, 2023
4752466
Auto merge of #11069 - y21:issue11063, r=Alexendoo
bors Jul 2, 2023
c46ddeb
Auto merge of #10987 - y21:type_id_on_box, r=llogiq
bors Jul 3, 2023
6990eaa
Don't suppress manual_let_else if question_mark is allowed
est31 Jul 2, 2023
d80581c
Move pat_and_expr_can_be_question_mark into clippy_utils
est31 Jul 3, 2023
75c339c
[`arc_with_non_send_sync`]: look for nested type parameters
y21 Jul 3, 2023
2b03bb0
Auto merge of #11077 - y21:issue11076, r=Manishearth
bors Jul 3, 2023
9a58107
Fix FP [`needless_raw_string_hashes`]
Centri3 Jul 3, 2023
1f77f8c
[`useless_vec`]: use the source span
y21 Jul 3, 2023
a959061
Auto merge of #11081 - y21:issue11075, r=Manishearth
bors Jul 3, 2023
3f17c5c
Auto merge of #10924 - est31:manual_let_else_question_mark, r=Centri3…
bors Jul 3, 2023
ba3bd8f
Auto merge of #11078 - Centri3:11068, r=llogiq
bors Jul 3, 2023
b4549c5
[`useless_vec`]: add more tests for macro combinations
y21 Jul 3, 2023
b41fc67
Add needless_pass_by_ref lint
GuillaumeGomez Jun 6, 2023
a43bea1
Add UI test for `needless_pass_by_ref_mut`
GuillaumeGomez Jun 6, 2023
c62c7fa
Update UI tests with new `needless_pass_by_ref_mut` lint
GuillaumeGomez Jun 15, 2023
dd3e00f
Fix warnings of `needless_pass_by_ref_mut` in clippy
GuillaumeGomez Jun 15, 2023
33adfcd
Add warning for `NEEDLESS_PASS_BY_REF_MUT` lint about the fact that i…
GuillaumeGomez Jul 3, 2023
8fad54e
new lint: `read_line_without_trim`
y21 Jun 16, 2023
85f535b
add test cases for u32, f32, bool, String
y21 Jul 3, 2023
3f4e599
Auto merge of #11094 - y21:issue11084, r=Alexendoo
bors Jul 3, 2023
f048f73
Add warning about semver compatibility if it's a public function
GuillaumeGomez Jul 4, 2023
1e656d8
Auto merge of #10970 - y21:read_line_without_trim, r=giraffate
bors Jul 5, 2023
4062418
Deal with fallout
BoxyUwU Jul 4, 2023
6868c0a
[`unnecessary_literal_unwrap`]: don't lint if binding initializer is …
y21 Jul 5, 2023
a4f9914
Patch clippy
oli-obk Jul 5, 2023
f945351
Fix regex lints for regex 1.9.0
Alexendoo Jul 5, 2023
cbe4682
Move `TyCtxt::mk_x` to `Ty::new_x` where applicable
BoxyUwU Jul 5, 2023
8aca068
Auto merge of #113291 - oli-obk:pretty_print_mir_const, r=RalfJung
bors Jul 6, 2023
8c70e52
Auto merge of #113377 - BoxyUwU:move_ty_ctors_to_ty, r=compiler-errors
bors Jul 6, 2023
dd8e44c
Auto merge of #11111 - Alexendoo:regex-def-paths, r=giraffate
bors Jul 6, 2023
f12edfd
`manual_float_methods`
Centri3 Jun 30, 2023
5949f76
Make suggestion give multiple alternatives
Centri3 Jul 2, 2023
4939a71
arc_with_non_send_sync: reword and move to suspicious
Alexendoo Jul 4, 2023
26edd5a
Auto merge of #11104 - Alexendoo:arc-with-non-send-sync, r=Centri3
bors Jul 7, 2023
2865526
Fix changelog PR listings, create them automatically in `fetch_prs_be…
Alexendoo Jul 6, 2023
5cc0c04
[`manual_range_patterns`]: lint negative values
y21 Jul 3, 2023
c927912
[`manual_range_patterns`]: document what range we don't lint
y21 Jul 6, 2023
b5ac726
Rename `adjustment::PointerCast` and variants using it to `PointerCoe…
Noratrieb Jul 5, 2023
87373d7
Fix failing clippy tests
Alexendoo Jul 7, 2023
5df1f66
Pass correct substs to `implements_trait` in `incorrect_impls`
Noratrieb Jul 7, 2023
2eff2f2
Auto merge of #11122 - Nilstrieb:SUBSTITUTION-INITIATED, r=flip1995
bors Jul 7, 2023
3a1fc26
Auto merge of #11114 - Alexendoo:changelog-prs-fetch, r=xFrednet
bors Jul 7, 2023
1816caa
Auto merge of #113376 - Nilstrieb:pointer-coercions-are-not-casts-bec…
bors Jul 8, 2023
31d50a6
Delete `to_string_in_format_args_incremental.rs`
Noratrieb Jul 8, 2023
b485e4f
Auto merge of #113450 - Nilstrieb:src/bootstrap/test.rs, r=flip1995
bors Jul 8, 2023
2a1fd22
implement `manual_partial_ord_impl`
Centri3 May 15, 2023
004e89d
rename to `manual_partial_ord_and_ord_impl`
Centri3 May 15, 2023
844afbf
use `other` instead of `self`
Centri3 Jun 15, 2023
a5dfb68
refactor
Centri3 Jun 30, 2023
41438c2
Refactor, remove `Constant::to_bits`
Centri3 Jul 4, 2023
e5db198
Auto merge of #10788 - Centri3:duplicate_manual_partial_ord_impl, r=x…
bors Jul 8, 2023
8e261c0
Auto merge of #11049 - Centri3:manual_is_infinite, r=blyxyas,xFrednet
bors Jul 8, 2023
2be695b
[significant_drop_tightening] Fix #11128
c410-f3r Jul 8, 2023
6384221
Dogfood
c410-f3r Jul 8, 2023
6ae065f
Auto merge of #11129 - c410-f3r:lock-1, r=Manishearth
bors Jul 8, 2023
b4738a6
Add test for #10535
smoelius Jul 8, 2023
3bf2138
Fix #10535
smoelius Jul 8, 2023
757fe49
Auto merge of #11130 - smoelius:fix-10535, r=Jarcho
bors Jul 9, 2023
b46033e
Auto merge of #10900 - GuillaumeGomez:needless-pass-by-ref, r=llogiq
bors Jul 9, 2023
ebd8d31
Auto merge of #11055 - smoelius:try-this, r=dswij
bors Jul 9, 2023
507d1c2
Auto merge of #11110 - y21:unnecessary_literal_unwrap_ignore_expn, r=…
bors Jul 9, 2023
9058b04
Auto merge of #11096 - y21:issue11091, r=giraffate
bors Jul 10, 2023
d1575d1
changelog: Fix typo in `needless_pass_by_ref_mut` lint description
GuillaumeGomez Jul 9, 2023
23ac723
adjust applicability and suggest making binding mutable
y21 Jun 23, 2023
9ab7137
Auto merge of #11133 - GuillaumeGomez:fix-description-typo, r=Manishe…
bors Jul 10, 2023
3be3fb7
Auto merge of #11016 - y21:issue10029, r=blyxyas,dswij
bors Jul 10, 2023
103949b
Drop uplifted `clippy::fn_null_check`
Urgau May 17, 2023
cd1c853
[`unnecessary_literal_unwrap`]: lint `unwrap_unchecked`
y21 Jul 3, 2023
0b5dac0
[`unnecessary_literal_unwrap`]: also handle unwrap_err_unchecked
y21 Jul 3, 2023
a8939e5
Auto merge of #111717 - Urgau:uplift_fn_null_check, r=oli-obk
bors Jul 11, 2023
31397b4
Update version attribute for 1.71 lints
xFrednet Jul 11, 2023
5ea622c
Changelog for Rust 1.71 :crown:
xFrednet Jul 11, 2023
7624d33
Preparing for merge from rustc
RalfJung Jul 12, 2023
4481569
Merge from rustc
RalfJung Jul 12, 2023
58433bf
fmt
RalfJung Jul 12, 2023
7a3756a
Changelog: Add disclaimer about the new format
xFrednet Jul 12, 2023
660ef4f
Ignore flaky clippy tests.
ehuss Jul 12, 2023
c49c177
[`panic_in_result_fn`] remove `todo!`, `unimplemented!`, `unreachable!`
panosfol Jul 7, 2023
d1e1f76
fix tag GC deleting protected tags
RalfJung Jul 12, 2023
53d2938
Auto merge of #11045 - Alexendoo:extern-flags, r=flip1995
bors Jul 12, 2023
5085fe3
Auto merge of #2977 - RalfJung:rustup, r=RalfJung
bors Jul 12, 2023
3b43b1e
Auto merge of #11098 - y21:issue11093, r=giraffate
bors Jul 12, 2023
c5fc61c
[`arithmetic_side_effect`]: allow different rhs type
y21 Jul 12, 2023
4102a30
[`tuple_array_conversions`]: move from `complexity` to `nursery`
MingweiSamuel Jul 12, 2023
d398e59
Auto merge of #11138 - xFrednet:changelog-1-71, r=flip1995
bors Jul 12, 2023
df92b52
Auto merge of #11123 - panosfol:master, r=giraffate
bors Jul 12, 2023
050b714
Add "Known problems" section to `needless_borrow` documentation
smoelius Jul 13, 2023
b10a0aa
Auto merge of #11148 - smoelius:nb-known-problems, r=Jarcho
bors Jul 13, 2023
477ef41
Preparing for merge from rustc
Jul 13, 2023
461baf2
Merge from rustc
Jul 13, 2023
ad9b7b5
Auto merge of #2979 - rust-lang:rustup2023-07-13, r=RalfJung
bors Jul 13, 2023
631faa1
Auto merge of #11146 - hydro-project:tuple-array-conversions, r=Centr…
bors Jul 13, 2023
a0e8257
Auto merge of #11147 - y21:issue11145, r=Alexendoo
bors Jul 13, 2023
2811eff
Add `imports_granularity = "Module"` to rustfmt.toml
Alexendoo Jul 3, 2023
7ccf5d4
Auto merge of #11095 - Alexendoo:rustfmt-imports, r=Manishearth
bors Jul 13, 2023
ea36a9d
Set `unnecessary_cast` suggestion to `MaybeIncorrect` for pointer casts
Alexendoo Jul 13, 2023
c0a105b
Rename VecDeque's rotate_left and rotate_right parameters
pedroclobo Jul 13, 2023
30a029e
Fix VecDeque's rotate_left and rotate_right panic tests
pedroclobo Jul 13, 2023
36279f1
Trigger a rebuild when CLIPPY_CONF_DIR changes
Alexendoo Jul 13, 2023
4b355d8
Auto merge of #11154 - Alexendoo:track-clippy-conf-dir, r=flip1995
bors Jul 13, 2023
3ddf6f7
use maybe_body_owned_by for closure
chenyukang Jul 11, 2023
bdd04a6
fix the issue of shorthand in suggest_cloning
chenyukang Jul 13, 2023
04dbc7d
rustdoc-json: Add test for private supertrait.
aDotInTheVoid Jul 14, 2023
bafde54
Auto merge of #11152 - Alexendoo:unnecessary-cast-applicability, r=Ma…
bors Jul 14, 2023
c0156d1
also apply to nested modules of `solve`
lcnr Jul 14, 2023
40cef61
work around custom_mir span
RalfJung Jul 14, 2023
01c842a
Auto merge of #2980 - RalfJung:span, r=RalfJung
bors Jul 14, 2023
415fdb2
Merge remote-tracking branch 'upstream/master' into rustup
flip1995 Jul 14, 2023
faa07d3
Bump Clippy version -> 0.1.73
flip1995 Jul 14, 2023
753c30f
Bump nightly version -> 2023-07-14
flip1995 Jul 14, 2023
1d33469
Auto merge of #11157 - flip1995:rustup, r=flip1995
bors Jul 14, 2023
c6c29cb
Merge commit '1d334696587ac22b3a9e651e7ac684ac9e0697b2' into clippyup
flip1995 Jul 14, 2023
3bd9da2
Update Cargo.lock/toml
flip1995 Jul 14, 2023
6ddf912
llvm-wrapper: update for LLVM API change
krasimirgg Jul 14, 2023
b88bcda
remove compile-flags that are no longer needed
RalfJung Jul 11, 2023
21b05e7
Auto merge of #2975 - RalfJung:flags, r=RalfJung
bors Jul 14, 2023
18305ea
Print artifact sizes in `opt-dist`
Kobzol Jul 14, 2023
d7922fb
Structurally normalize in selection
compiler-errors Jul 7, 2023
8e2fcde
Another fix for incorrect_impls
flip1995 Jul 14, 2023
9027e40
Rollup merge of #113599 - chenyukang:yukang-fix-use-maybe_body_owned_…
matthiaskrgr Jul 14, 2023
b0ee988
Rollup merge of #113625 - compiler-errors:structurally-norm-in-select…
matthiaskrgr Jul 14, 2023
1161c1d
Rollup merge of #113662 - pedroclobo:vec-deque-rotate, r=thomcc
matthiaskrgr Jul 14, 2023
76e478b
Rollup merge of #113681 - aDotInTheVoid:rdj-priv-supertrait, r=Guilla…
matthiaskrgr Jul 14, 2023
d5d19f5
Rollup merge of #113682 - lcnr:toml-file, r=Mark-Simulacrum
matthiaskrgr Jul 14, 2023
f021136
Rollup merge of #113685 - Kobzol:opt-dist-binary-sizes, r=Mark-Simula…
matthiaskrgr Jul 14, 2023
43807a2
Rollup merge of #113686 - flip1995:clippyup, r=Manishearth
matthiaskrgr Jul 14, 2023
d398650
Rollup merge of #113688 - krasimirgg:llvm-17-small-string, r=nikic
matthiaskrgr Jul 14, 2023
b5687c5
Rollup merge of #113699 - RalfJung:miri, r=RalfJung
matthiaskrgr Jul 14, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
35 changes: 13 additions & 22 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -513,16 +513,25 @@ checksum = "2da6da31387c7e4ef160ffab6d5e7f00c42626fe39aea70a7b0f1773f7dd6c1b"

[[package]]
name = "clippy"
version = "0.1.72"
version = "0.1.73"
dependencies = [
"clippy_lints",
"clippy_utils",
"derive-new",
"filetime",
"futures",
"if_chain",
"itertools",
"parking_lot 0.12.1",
"quote",
"regex",
"rustc_tools_util",
"serde",
"syn 2.0.8",
"tempfile",
"termize",
"tester",
"tokio",
"toml 0.7.5",
"ui_test",
"walkdir",
Expand All @@ -543,7 +552,7 @@ dependencies = [

[[package]]
name = "clippy_lints"
version = "0.1.72"
version = "0.1.73"
dependencies = [
"arrayvec",
"cargo_metadata",
Expand All @@ -566,27 +575,9 @@ dependencies = [
"url",
]

[[package]]
name = "clippy_test_deps"
version = "0.1.0"
dependencies = [
"clippy_lints",
"clippy_utils",
"derive-new",
"futures",
"if_chain",
"itertools",
"parking_lot 0.12.1",
"quote",
"regex",
"serde",
"syn 2.0.8",
"tokio",
]

[[package]]
name = "clippy_utils"
version = "0.1.72"
version = "0.1.73"
dependencies = [
"arrayvec",
"if_chain",
Expand Down Expand Up @@ -847,7 +838,7 @@ checksum = "a0afaad2b26fa326569eb264b1363e8ae3357618c43982b3f285f0774ce76b69"

[[package]]
name = "declare_clippy_lint"
version = "0.1.72"
version = "0.1.73"
dependencies = [
"itertools",
"quote",
Expand Down
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ members = [
"src/tools/cargotest",
"src/tools/clippy",
"src/tools/clippy/clippy_dev",
"src/tools/clippy/clippy_test_deps",
"src/tools/compiletest",
"src/tools/error_index_generator",
"src/tools/linkchecker",
Expand Down
37 changes: 20 additions & 17 deletions compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,21 +363,12 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
}
}
let hir = self.infcx.tcx.hir();
if let Some(hir::Node::Item(hir::Item {
kind: hir::ItemKind::Fn(_, _, body_id),
..
})) = hir.find(self.mir_hir_id())
&& let Some(hir::Node::Expr(expr)) = hir.find(body_id.hir_id)
{
if let Some(body_id) = hir.maybe_body_owned_by(self.mir_def_id()) {
let expr = hir.body(body_id).value;
let place = &self.move_data.move_paths[mpi].place;
let span = place.as_local()
.map(|local| self.body.local_decls[local].source_info.span);
let mut finder = ExpressionFinder {
expr_span: move_span,
expr: None,
pat: None,
parent_pat: None,
};
let span = place.as_local().map(|local| self.body.local_decls[local].source_info.span);
let mut finder =
ExpressionFinder { expr_span: move_span, expr: None, pat: None, parent_pat: None };
finder.visit_expr(expr);
if let Some(span) = span && let Some(expr) = finder.expr {
for (_, expr) in hir.parent_iter(expr.hir_id) {
Expand Down Expand Up @@ -461,7 +452,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
} = move_spans {
// We already suggest cloning for these cases in `explain_captures`.
} else {
self.suggest_cloning(err, ty, move_span);
self.suggest_cloning(err, ty, expr, move_span);
}
}
}
Expand Down Expand Up @@ -736,9 +727,21 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
true
}

fn suggest_cloning(&self, err: &mut Diagnostic, ty: Ty<'tcx>, span: Span) {
fn suggest_cloning(
&self,
err: &mut Diagnostic,
ty: Ty<'tcx>,
expr: &hir::Expr<'_>,
span: Span,
) {
let tcx = self.infcx.tcx;
// Try to find predicates on *generic params* that would allow copying `ty`
let suggestion =
if let Some(symbol) = tcx.hir().maybe_get_struct_pattern_shorthand_field(expr) {
format!(": {}.clone()", symbol)
} else {
".clone()".to_owned()
};
if let Some(clone_trait_def) = tcx.lang_items().clone_trait()
&& self.infcx
.type_implements_trait(
Expand All @@ -751,7 +754,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
err.span_suggestion_verbose(
span.shrink_to_hi(),
"consider cloning the value if the performance cost is acceptable",
".clone()",
suggestion,
Applicability::MachineApplicable,
);
}
Expand Down
101 changes: 41 additions & 60 deletions compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed
use rustc_hir as hir;
use rustc_hir::intravisit::Visitor;
use rustc_hir::Node;
use rustc_middle::hir::map::Map;
use rustc_middle::mir::{Mutability, Place, PlaceRef, ProjectionElem};
use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_middle::{
Expand Down Expand Up @@ -646,14 +645,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
}
let hir_map = self.infcx.tcx.hir();
let def_id = self.body.source.def_id();
let hir_id = hir_map.local_def_id_to_hir_id(def_id.as_local().unwrap());
let node = hir_map.find(hir_id);
let Some(hir::Node::Item(item)) = node else {
return;
};
let hir::ItemKind::Fn(.., body_id) = item.kind else {
return;
};
let Some(local_def_id) = def_id.as_local() else { return };
let Some(body_id) = hir_map.maybe_body_owned_by(local_def_id) else { return };
let body = self.infcx.tcx.hir().body(body_id);

let mut v = V { assign_span: span, err, ty, suggested: false };
Expand Down Expand Up @@ -790,23 +783,12 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
// In the future, attempt in all path but initially for RHS of for_loop
fn suggest_similar_mut_method_for_for_loop(&self, err: &mut Diagnostic) {
use hir::{
BodyId, Expr,
Expr,
ExprKind::{Block, Call, DropTemps, Match, MethodCall},
HirId, ImplItem, ImplItemKind, Item, ItemKind,
};

fn maybe_body_id_of_fn(hir_map: Map<'_>, id: HirId) -> Option<BodyId> {
match hir_map.find(id) {
Some(Node::Item(Item { kind: ItemKind::Fn(_, _, body_id), .. }))
| Some(Node::ImplItem(ImplItem { kind: ImplItemKind::Fn(_, body_id), .. })) => {
Some(*body_id)
}
_ => None,
}
}
let hir_map = self.infcx.tcx.hir();
let mir_body_hir_id = self.mir_hir_id();
if let Some(fn_body_id) = maybe_body_id_of_fn(hir_map, mir_body_hir_id) {
if let Some(body_id) = hir_map.maybe_body_owned_by(self.mir_def_id()) {
if let Block(
hir::Block {
expr:
Expand Down Expand Up @@ -840,7 +822,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
..
},
_,
) = hir_map.body(fn_body_id).value.kind
) = hir_map.body(body_id).value.kind
{
let opt_suggestions = self
.infcx
Expand Down Expand Up @@ -1102,46 +1084,45 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
}
let hir_map = self.infcx.tcx.hir();
let def_id = self.body.source.def_id();
let hir_id = hir_map.local_def_id_to_hir_id(def_id.expect_local());
let node = hir_map.find(hir_id);
let hir_id = if let Some(hir::Node::Item(item)) = node
&& let hir::ItemKind::Fn(.., body_id) = item.kind
{
let body = hir_map.body(body_id);
let mut v = BindingFinder {
span: err_label_span,
hir_id: None,
let hir_id = if let Some(local_def_id) = def_id.as_local() &&
let Some(body_id) = hir_map.maybe_body_owned_by(local_def_id)
{
let body = hir_map.body(body_id);
let mut v = BindingFinder {
span: err_label_span,
hir_id: None,
};
v.visit_body(body);
v.hir_id
} else {
None
};
v.visit_body(body);
v.hir_id
} else {
None
};

if let Some(hir_id) = hir_id
&& let Some(hir::Node::Local(local)) = hir_map.find(hir_id)
{
let (changing, span, sugg) = match local.ty {
Some(ty) => ("changing", ty.span, message),
None => (
"specifying",
local.pat.span.shrink_to_hi(),
format!(": {message}"),
),
};
err.span_suggestion_verbose(
span,
format!("consider {changing} this binding's type"),
sugg,
Applicability::HasPlaceholders,
);
} else {
err.span_label(
err_label_span,
format!(
"consider changing this binding's type to be: `{message}`"
),
);
}
{
let (changing, span, sugg) = match local.ty {
Some(ty) => ("changing", ty.span, message),
None => (
"specifying",
local.pat.span.shrink_to_hi(),
format!(": {message}"),
),
};
err.span_suggestion_verbose(
span,
format!("consider {changing} this binding's type"),
sugg,
Applicability::HasPlaceholders,
);
} else {
err.span_label(
err_label_span,
format!(
"consider changing this binding's type to be: `{message}`"
),
);
}
}
None => {}
}
Expand Down
41 changes: 4 additions & 37 deletions compiler/rustc_hir_typeck/src/demand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use rustc_middle::ty::error::{ExpectedFound, TypeError};
use rustc_middle::ty::fold::BottomUpFolder;
use rustc_middle::ty::print::with_no_trimmed_paths;
use rustc_middle::ty::{self, Article, AssocItem, Ty, TypeAndMut, TypeFoldable};
use rustc_span::symbol::{sym, Symbol};
use rustc_span::symbol::sym;
use rustc_span::{BytePos, Span, DUMMY_SP};
use rustc_trait_selection::infer::InferCtxtExt as _;
use rustc_trait_selection::traits::ObligationCause;
Expand Down Expand Up @@ -997,7 +997,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.collect();

let suggestions_for = |variant: &_, ctor_kind, field_name| {
let prefix = match self.maybe_get_struct_pattern_shorthand_field(expr) {
let prefix = match self.tcx.hir().maybe_get_struct_pattern_shorthand_field(expr) {
Some(ident) => format!("{ident}: "),
None => String::new(),
};
Expand Down Expand Up @@ -1240,39 +1240,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
}

pub(crate) fn maybe_get_struct_pattern_shorthand_field(
&self,
expr: &hir::Expr<'_>,
) -> Option<Symbol> {
let hir = self.tcx.hir();
let local = match expr {
hir::Expr {
kind:
hir::ExprKind::Path(hir::QPath::Resolved(
None,
hir::Path {
res: hir::def::Res::Local(_),
segments: [hir::PathSegment { ident, .. }],
..
},
)),
..
} => Some(ident),
_ => None,
}?;

match hir.find_parent(expr.hir_id)? {
Node::ExprField(field) => {
if field.ident.name == local.name && field.is_shorthand {
return Some(local.name);
}
}
_ => {}
}

None
}

/// If the given `HirId` corresponds to a block with a trailing expression, return that expression
pub(crate) fn maybe_get_block_expr(
&self,
Expand Down Expand Up @@ -1467,7 +1434,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
));
}

let prefix = match self.maybe_get_struct_pattern_shorthand_field(expr) {
let prefix = match self.tcx.hir().maybe_get_struct_pattern_shorthand_field(expr) {
Some(ident) => format!("{ident}: "),
None => String::new(),
};
Expand Down Expand Up @@ -1661,7 +1628,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
)
};

let prefix = match self.maybe_get_struct_pattern_shorthand_field(expr) {
let prefix = match self.tcx.hir().maybe_get_struct_pattern_shorthand_field(expr) {
Some(ident) => format!("{ident}: "),
None => String::new(),
};
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
vec![(expr.span.shrink_to_hi(), format!(".{}()", conversion_method.name))]
};
let struct_pat_shorthand_field =
self.maybe_get_struct_pattern_shorthand_field(expr);
self.tcx.hir().maybe_get_struct_pattern_shorthand_field(expr);
if let Some(name) = struct_pat_shorthand_field {
sugg.insert(0, (expr.span.shrink_to_lo(), format!("{}: ", name)));
}
Expand Down Expand Up @@ -1069,7 +1069,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
)
.must_apply_modulo_regions()
{
let suggestion = match self.maybe_get_struct_pattern_shorthand_field(expr) {
let suggestion = match self.tcx.hir().maybe_get_struct_pattern_shorthand_field(expr) {
Some(ident) => format!(": {}.clone()", ident),
None => ".clone()".to_string()
};
Expand Down Expand Up @@ -1247,7 +1247,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
return false;
}

let suggestion = match self.maybe_get_struct_pattern_shorthand_field(expr) {
let suggestion = match self.tcx.hir().maybe_get_struct_pattern_shorthand_field(expr) {
Some(ident) => format!(": {}.is_some()", ident),
None => ".is_some()".to_string(),
};
Expand Down
Loading