Skip to content

Commit db79625

Browse files
committed
Auto merge of #106183 - matthiaskrgr:rollup-ww6yzhi, r=matthiaskrgr
Rollup of 3 pull requests Successful merges: - #105817 (Remove unreasonable help message for auto trait) - #105994 (Add regression test for #99647) - #106066 (Always suggest as `MachineApplicable` in `recover_intersection_pat`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents b38a6d3 + b7657e9 commit db79625

File tree

12 files changed

+105
-49
lines changed

12 files changed

+105
-49
lines changed

compiler/rustc_hir_typeck/src/method/probe.rs

+3
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,9 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
973973
});
974974
} else {
975975
debug_assert!(self.tcx.is_trait(trait_def_id));
976+
if self.tcx.trait_is_auto(trait_def_id) {
977+
return;
978+
}
976979
for item in self.impl_or_trait_item(trait_def_id) {
977980
// Check whether `trait_def_id` defines a method with suitable name.
978981
if !self.has_applicable_self(&item) {

compiler/rustc_hir_typeck/src/method/suggest.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2306,6 +2306,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
23062306
_ => false,
23072307
}
23082308
}) && (type_is_local || info.def_id.is_local())
2309+
&& !self.tcx.trait_is_auto(info.def_id)
23092310
&& self
23102311
.associated_value(info.def_id, item_name)
23112312
.filter(|item| {

compiler/rustc_parse/src/parser/pat.rs

+6-12
Original file line numberDiff line numberDiff line change
@@ -491,17 +491,6 @@ impl<'a> Parser<'a> {
491491

492492
if let PatKind::Ident(_, _, sub @ None) = &mut rhs.kind {
493493
// The user inverted the order, so help them fix that.
494-
let mut applicability = Applicability::MachineApplicable;
495-
// FIXME(bindings_after_at): Remove this code when stabilizing the feature.
496-
lhs.walk(&mut |p| match p.kind {
497-
// `check_match` is unhappy if the subpattern has a binding anywhere.
498-
PatKind::Ident(..) => {
499-
applicability = Applicability::MaybeIncorrect;
500-
false // Short-circuit.
501-
}
502-
_ => true,
503-
});
504-
505494
let lhs_span = lhs.span;
506495
// Move the LHS into the RHS as a subpattern.
507496
// The RHS is now the full pattern.
@@ -510,7 +499,12 @@ impl<'a> Parser<'a> {
510499
self.struct_span_err(sp, "pattern on wrong side of `@`")
511500
.span_label(lhs_span, "pattern on the left, should be on the right")
512501
.span_label(rhs.span, "binding on the right, should be on the left")
513-
.span_suggestion(sp, "switch the order", pprust::pat_to_string(&rhs), applicability)
502+
.span_suggestion(
503+
sp,
504+
"switch the order",
505+
pprust::pat_to_string(&rhs),
506+
Applicability::MachineApplicable,
507+
)
514508
.emit();
515509
} else {
516510
// The special case above doesn't apply so we may have e.g. `A(x) @ B(y)`.
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// edition:2018
2+
// run-pass
3+
4+
#![allow(incomplete_features)]
5+
#![feature(generic_const_exprs)]
6+
7+
#[allow(unused)]
8+
async fn foo<'a>() {
9+
let _data = &mut [0u8; { 1 + 4 }];
10+
bar().await
11+
}
12+
13+
async fn bar() {}
14+
15+
fn main() {}

src/test/ui/methods/issues/issue-105732.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ auto trait Foo {
66

77
trait Bar {
88
fn f(&self) {
9-
self.g(); //~ ERROR the method `g` exists for reference `&Self`, but its trait bounds were not satisfied
9+
// issue #105788
10+
self.g(); //~ ERROR no method named `g` found for reference `&Self` in the current scope
1011
}
1112
}
1213

src/test/ui/methods/issues/issue-105732.stderr

+3-13
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,11 @@ LL | auto trait Foo {
66
LL | fn g(&self);
77
| ---^-------- help: remove these associated items
88

9-
error[E0599]: the method `g` exists for reference `&Self`, but its trait bounds were not satisfied
10-
--> $DIR/issue-105732.rs:9:14
9+
error[E0599]: no method named `g` found for reference `&Self` in the current scope
10+
--> $DIR/issue-105732.rs:10:14
1111
|
1212
LL | self.g();
13-
| ^
14-
|
15-
= note: the following trait bounds were not satisfied:
16-
`Self: Foo`
17-
which is required by `&Self: Foo`
18-
`&Self: Foo`
19-
= help: items from traits can only be used if the type parameter is bounded by the trait
20-
help: the following trait defines an item `g`, perhaps you need to add a supertrait for it:
21-
|
22-
LL | trait Bar: Foo {
23-
| +++++
13+
| ^ help: there is a method with a similar name: `f`
2414

2515
error: aborting due to 2 previous errors
2616

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// This tests the parser recovery in `recover_intersection_pat`
2+
// and serves as a regression test for the diagnostics issue #65400.
3+
//
4+
// The general idea is that for `$pat_lhs @ $pat_rhs` where
5+
// `$pat_lhs` is not generated by `ref? mut? $ident` we want
6+
// to suggest either switching the order or note that intersection
7+
// patterns are not allowed.
8+
9+
// run-rustfix
10+
11+
#![allow(unused_variables)]
12+
13+
fn main() {
14+
let s: Option<u8> = None;
15+
16+
match s {
17+
y @ Some(x) => {}
18+
//~^ ERROR pattern on wrong side of `@`
19+
//~| pattern on the left, should be on the right
20+
//~| binding on the right, should be on the left
21+
//~| HELP switch the order
22+
//~| SUGGESTION y @ Some(x)
23+
_ => {}
24+
}
25+
26+
match 2 {
27+
e @ 1..=5 => {}
28+
//~^ ERROR pattern on wrong side of `@`
29+
//~| pattern on the left, should be on the right
30+
//~| binding on the right, should be on the left
31+
//~| HELP switch the order
32+
//~| SUGGESTION e @ 1..=5
33+
_ => {}
34+
}
35+
}

src/test/ui/parser/intersection-patterns.rs renamed to src/test/ui/parser/intersection-patterns-1.rs

+4-9
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
// to suggest either switching the order or note that intersection
77
// patterns are not allowed.
88

9+
// run-rustfix
10+
11+
#![allow(unused_variables)]
12+
913
fn main() {
1014
let s: Option<u8> = None;
1115

@@ -19,15 +23,6 @@ fn main() {
1923
_ => {}
2024
}
2125

22-
match s {
23-
Some(x) @ Some(y) => {}
24-
//~^ ERROR left-hand side of `@` must be a binding
25-
//~| interpreted as a pattern, not a binding
26-
//~| also a pattern
27-
//~| NOTE bindings are `x`, `mut x`, `ref x`, and `ref mut x`
28-
_ => {}
29-
}
30-
3126
match 2 {
3227
1 ..= 5 @ e => {}
3328
//~^ ERROR pattern on wrong side of `@`
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: pattern on wrong side of `@`
2-
--> $DIR/intersection-patterns.rs:13:9
2+
--> $DIR/intersection-patterns-1.rs:17:9
33
|
44
LL | Some(x) @ y => {}
55
| -------^^^-
@@ -8,19 +8,8 @@ LL | Some(x) @ y => {}
88
| pattern on the left, should be on the right
99
| help: switch the order: `y @ Some(x)`
1010

11-
error: left-hand side of `@` must be a binding
12-
--> $DIR/intersection-patterns.rs:23:9
13-
|
14-
LL | Some(x) @ Some(y) => {}
15-
| -------^^^-------
16-
| | |
17-
| | also a pattern
18-
| interpreted as a pattern, not a binding
19-
|
20-
= note: bindings are `x`, `mut x`, `ref x`, and `ref mut x`
21-
2211
error: pattern on wrong side of `@`
23-
--> $DIR/intersection-patterns.rs:32:9
12+
--> $DIR/intersection-patterns-1.rs:27:9
2413
|
2514
LL | 1 ..= 5 @ e => {}
2615
| -------^^^-
@@ -29,5 +18,5 @@ LL | 1 ..= 5 @ e => {}
2918
| pattern on the left, should be on the right
3019
| help: switch the order: `e @ 1..=5`
3120

32-
error: aborting due to 3 previous errors
21+
error: aborting due to 2 previous errors
3322

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// This tests the parser recovery in `recover_intersection_pat`
2+
// and serves as a regression test for the diagnostics issue #65400.
3+
//
4+
// The general idea is that for `$pat_lhs @ $pat_rhs` where
5+
// `$pat_lhs` is not generated by `ref? mut? $ident` we want
6+
// to suggest either switching the order or note that intersection
7+
// patterns are not allowed.
8+
9+
fn main() {
10+
let s: Option<u8> = None;
11+
12+
match s {
13+
Some(x) @ Some(y) => {}
14+
//~^ ERROR left-hand side of `@` must be a binding
15+
//~| interpreted as a pattern, not a binding
16+
//~| also a pattern
17+
//~| NOTE bindings are `x`, `mut x`, `ref x`, and `ref mut x`
18+
_ => {}
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error: left-hand side of `@` must be a binding
2+
--> $DIR/intersection-patterns-2.rs:13:9
3+
|
4+
LL | Some(x) @ Some(y) => {}
5+
| -------^^^-------
6+
| | |
7+
| | also a pattern
8+
| interpreted as a pattern, not a binding
9+
|
10+
= note: bindings are `x`, `mut x`, `ref x`, and `ref mut x`
11+
12+
error: aborting due to previous error
13+

0 commit comments

Comments
 (0)