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
This commit is contained in:
commit
db79625326
@ -973,6 +973,9 @@ fn assemble_extension_candidates_for_trait(
|
|||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
debug_assert!(self.tcx.is_trait(trait_def_id));
|
debug_assert!(self.tcx.is_trait(trait_def_id));
|
||||||
|
if self.tcx.trait_is_auto(trait_def_id) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
for item in self.impl_or_trait_item(trait_def_id) {
|
for item in self.impl_or_trait_item(trait_def_id) {
|
||||||
// Check whether `trait_def_id` defines a method with suitable name.
|
// Check whether `trait_def_id` defines a method with suitable name.
|
||||||
if !self.has_applicable_self(&item) {
|
if !self.has_applicable_self(&item) {
|
||||||
|
@ -2306,6 +2306,7 @@ fn suggest_traits_to_import(
|
|||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}) && (type_is_local || info.def_id.is_local())
|
}) && (type_is_local || info.def_id.is_local())
|
||||||
|
&& !self.tcx.trait_is_auto(info.def_id)
|
||||||
&& self
|
&& self
|
||||||
.associated_value(info.def_id, item_name)
|
.associated_value(info.def_id, item_name)
|
||||||
.filter(|item| {
|
.filter(|item| {
|
||||||
|
@ -491,17 +491,6 @@ fn recover_intersection_pat(&mut self, lhs: P<Pat>) -> PResult<'a, P<Pat>> {
|
|||||||
|
|
||||||
if let PatKind::Ident(_, _, sub @ None) = &mut rhs.kind {
|
if let PatKind::Ident(_, _, sub @ None) = &mut rhs.kind {
|
||||||
// The user inverted the order, so help them fix that.
|
// The user inverted the order, so help them fix that.
|
||||||
let mut applicability = Applicability::MachineApplicable;
|
|
||||||
// FIXME(bindings_after_at): Remove this code when stabilizing the feature.
|
|
||||||
lhs.walk(&mut |p| match p.kind {
|
|
||||||
// `check_match` is unhappy if the subpattern has a binding anywhere.
|
|
||||||
PatKind::Ident(..) => {
|
|
||||||
applicability = Applicability::MaybeIncorrect;
|
|
||||||
false // Short-circuit.
|
|
||||||
}
|
|
||||||
_ => true,
|
|
||||||
});
|
|
||||||
|
|
||||||
let lhs_span = lhs.span;
|
let lhs_span = lhs.span;
|
||||||
// Move the LHS into the RHS as a subpattern.
|
// Move the LHS into the RHS as a subpattern.
|
||||||
// The RHS is now the full pattern.
|
// The RHS is now the full pattern.
|
||||||
@ -510,7 +499,12 @@ fn recover_intersection_pat(&mut self, lhs: P<Pat>) -> PResult<'a, P<Pat>> {
|
|||||||
self.struct_span_err(sp, "pattern on wrong side of `@`")
|
self.struct_span_err(sp, "pattern on wrong side of `@`")
|
||||||
.span_label(lhs_span, "pattern on the left, should be on the right")
|
.span_label(lhs_span, "pattern on the left, should be on the right")
|
||||||
.span_label(rhs.span, "binding on the right, should be on the left")
|
.span_label(rhs.span, "binding on the right, should be on the left")
|
||||||
.span_suggestion(sp, "switch the order", pprust::pat_to_string(&rhs), applicability)
|
.span_suggestion(
|
||||||
|
sp,
|
||||||
|
"switch the order",
|
||||||
|
pprust::pat_to_string(&rhs),
|
||||||
|
Applicability::MachineApplicable,
|
||||||
|
)
|
||||||
.emit();
|
.emit();
|
||||||
} else {
|
} else {
|
||||||
// The special case above doesn't apply so we may have e.g. `A(x) @ B(y)`.
|
// The special case above doesn't apply so we may have e.g. `A(x) @ B(y)`.
|
||||||
|
@ -0,0 +1,15 @@
|
|||||||
|
// edition:2018
|
||||||
|
// run-pass
|
||||||
|
|
||||||
|
#![allow(incomplete_features)]
|
||||||
|
#![feature(generic_const_exprs)]
|
||||||
|
|
||||||
|
#[allow(unused)]
|
||||||
|
async fn foo<'a>() {
|
||||||
|
let _data = &mut [0u8; { 1 + 4 }];
|
||||||
|
bar().await
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn bar() {}
|
||||||
|
|
||||||
|
fn main() {}
|
@ -6,7 +6,8 @@
|
|||||||
|
|
||||||
trait Bar {
|
trait Bar {
|
||||||
fn f(&self) {
|
fn f(&self) {
|
||||||
self.g(); //~ ERROR the method `g` exists for reference `&Self`, but its trait bounds were not satisfied
|
// issue #105788
|
||||||
|
self.g(); //~ ERROR no method named `g` found for reference `&Self` in the current scope
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,21 +6,11 @@ LL | auto trait Foo {
|
|||||||
LL | fn g(&self);
|
LL | fn g(&self);
|
||||||
| ---^-------- help: remove these associated items
|
| ---^-------- help: remove these associated items
|
||||||
|
|
||||||
error[E0599]: the method `g` exists for reference `&Self`, but its trait bounds were not satisfied
|
error[E0599]: no method named `g` found for reference `&Self` in the current scope
|
||||||
--> $DIR/issue-105732.rs:9:14
|
--> $DIR/issue-105732.rs:10:14
|
||||||
|
|
|
|
||||||
LL | self.g();
|
LL | self.g();
|
||||||
| ^
|
| ^ help: there is a method with a similar name: `f`
|
||||||
|
|
|
||||||
= note: the following trait bounds were not satisfied:
|
|
||||||
`Self: Foo`
|
|
||||||
which is required by `&Self: Foo`
|
|
||||||
`&Self: Foo`
|
|
||||||
= help: items from traits can only be used if the type parameter is bounded by the trait
|
|
||||||
help: the following trait defines an item `g`, perhaps you need to add a supertrait for it:
|
|
||||||
|
|
|
||||||
LL | trait Bar: Foo {
|
|
||||||
| +++++
|
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
|
35
src/test/ui/parser/intersection-patterns-1.fixed
Normal file
35
src/test/ui/parser/intersection-patterns-1.fixed
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
// This tests the parser recovery in `recover_intersection_pat`
|
||||||
|
// and serves as a regression test for the diagnostics issue #65400.
|
||||||
|
//
|
||||||
|
// The general idea is that for `$pat_lhs @ $pat_rhs` where
|
||||||
|
// `$pat_lhs` is not generated by `ref? mut? $ident` we want
|
||||||
|
// to suggest either switching the order or note that intersection
|
||||||
|
// patterns are not allowed.
|
||||||
|
|
||||||
|
// run-rustfix
|
||||||
|
|
||||||
|
#![allow(unused_variables)]
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let s: Option<u8> = None;
|
||||||
|
|
||||||
|
match s {
|
||||||
|
y @ Some(x) => {}
|
||||||
|
//~^ ERROR pattern on wrong side of `@`
|
||||||
|
//~| pattern on the left, should be on the right
|
||||||
|
//~| binding on the right, should be on the left
|
||||||
|
//~| HELP switch the order
|
||||||
|
//~| SUGGESTION y @ Some(x)
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
|
||||||
|
match 2 {
|
||||||
|
e @ 1..=5 => {}
|
||||||
|
//~^ ERROR pattern on wrong side of `@`
|
||||||
|
//~| pattern on the left, should be on the right
|
||||||
|
//~| binding on the right, should be on the left
|
||||||
|
//~| HELP switch the order
|
||||||
|
//~| SUGGESTION e @ 1..=5
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
@ -6,6 +6,10 @@
|
|||||||
// to suggest either switching the order or note that intersection
|
// to suggest either switching the order or note that intersection
|
||||||
// patterns are not allowed.
|
// patterns are not allowed.
|
||||||
|
|
||||||
|
// run-rustfix
|
||||||
|
|
||||||
|
#![allow(unused_variables)]
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let s: Option<u8> = None;
|
let s: Option<u8> = None;
|
||||||
|
|
||||||
@ -19,15 +23,6 @@ fn main() {
|
|||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
match s {
|
|
||||||
Some(x) @ Some(y) => {}
|
|
||||||
//~^ ERROR left-hand side of `@` must be a binding
|
|
||||||
//~| interpreted as a pattern, not a binding
|
|
||||||
//~| also a pattern
|
|
||||||
//~| NOTE bindings are `x`, `mut x`, `ref x`, and `ref mut x`
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
|
|
||||||
match 2 {
|
match 2 {
|
||||||
1 ..= 5 @ e => {}
|
1 ..= 5 @ e => {}
|
||||||
//~^ ERROR pattern on wrong side of `@`
|
//~^ ERROR pattern on wrong side of `@`
|
@ -1,5 +1,5 @@
|
|||||||
error: pattern on wrong side of `@`
|
error: pattern on wrong side of `@`
|
||||||
--> $DIR/intersection-patterns.rs:13:9
|
--> $DIR/intersection-patterns-1.rs:17:9
|
||||||
|
|
|
|
||||||
LL | Some(x) @ y => {}
|
LL | Some(x) @ y => {}
|
||||||
| -------^^^-
|
| -------^^^-
|
||||||
@ -8,19 +8,8 @@ LL | Some(x) @ y => {}
|
|||||||
| pattern on the left, should be on the right
|
| pattern on the left, should be on the right
|
||||||
| help: switch the order: `y @ Some(x)`
|
| help: switch the order: `y @ Some(x)`
|
||||||
|
|
||||||
error: left-hand side of `@` must be a binding
|
|
||||||
--> $DIR/intersection-patterns.rs:23:9
|
|
||||||
|
|
|
||||||
LL | Some(x) @ Some(y) => {}
|
|
||||||
| -------^^^-------
|
|
||||||
| | |
|
|
||||||
| | also a pattern
|
|
||||||
| interpreted as a pattern, not a binding
|
|
||||||
|
|
|
||||||
= note: bindings are `x`, `mut x`, `ref x`, and `ref mut x`
|
|
||||||
|
|
||||||
error: pattern on wrong side of `@`
|
error: pattern on wrong side of `@`
|
||||||
--> $DIR/intersection-patterns.rs:32:9
|
--> $DIR/intersection-patterns-1.rs:27:9
|
||||||
|
|
|
|
||||||
LL | 1 ..= 5 @ e => {}
|
LL | 1 ..= 5 @ e => {}
|
||||||
| -------^^^-
|
| -------^^^-
|
||||||
@ -29,5 +18,5 @@ LL | 1 ..= 5 @ e => {}
|
|||||||
| pattern on the left, should be on the right
|
| pattern on the left, should be on the right
|
||||||
| help: switch the order: `e @ 1..=5`
|
| help: switch the order: `e @ 1..=5`
|
||||||
|
|
||||||
error: aborting due to 3 previous errors
|
error: aborting due to 2 previous errors
|
||||||
|
|
20
src/test/ui/parser/intersection-patterns-2.rs
Normal file
20
src/test/ui/parser/intersection-patterns-2.rs
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
// This tests the parser recovery in `recover_intersection_pat`
|
||||||
|
// and serves as a regression test for the diagnostics issue #65400.
|
||||||
|
//
|
||||||
|
// The general idea is that for `$pat_lhs @ $pat_rhs` where
|
||||||
|
// `$pat_lhs` is not generated by `ref? mut? $ident` we want
|
||||||
|
// to suggest either switching the order or note that intersection
|
||||||
|
// patterns are not allowed.
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let s: Option<u8> = None;
|
||||||
|
|
||||||
|
match s {
|
||||||
|
Some(x) @ Some(y) => {}
|
||||||
|
//~^ ERROR left-hand side of `@` must be a binding
|
||||||
|
//~| interpreted as a pattern, not a binding
|
||||||
|
//~| also a pattern
|
||||||
|
//~| NOTE bindings are `x`, `mut x`, `ref x`, and `ref mut x`
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
13
src/test/ui/parser/intersection-patterns-2.stderr
Normal file
13
src/test/ui/parser/intersection-patterns-2.stderr
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
error: left-hand side of `@` must be a binding
|
||||||
|
--> $DIR/intersection-patterns-2.rs:13:9
|
||||||
|
|
|
||||||
|
LL | Some(x) @ Some(y) => {}
|
||||||
|
| -------^^^-------
|
||||||
|
| | |
|
||||||
|
| | also a pattern
|
||||||
|
| interpreted as a pattern, not a binding
|
||||||
|
|
|
||||||
|
= note: bindings are `x`, `mut x`, `ref x`, and `ref mut x`
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
Loading…
Reference in New Issue
Block a user