Skip to content

Commit 7624ac7

Browse files
authored
Rollup merge of #72621 - Aaron1011:fix/trait-select-error, r=nikomatsakis
Don't bail out of trait selection when predicate references an error Fixes #72590 With PR #70551, observing a `ty::Error` guarantees that compilation is going to fail. Therefore, there are no soundness impliciations to continuing on when we encounter a `ty::Error` - we can only affect whether or not additional error messags are emitted. By not bailing out, we avoid incorrectly determining that types are `!Sized` when a type error is present, which allows us to avoid emitting additional spurious error messages. The original comment mentioned this code being shared by coherence - howver, this change resulted in no diagnostic changes in any of the existing tests.
2 parents a5fb7fc + 1c30c9e commit 7624ac7

File tree

3 files changed

+50
-11
lines changed

3 files changed

+50
-11
lines changed

src/librustc_trait_selection/traits/select.rs

-11
Original file line numberDiff line numberDiff line change
@@ -1040,17 +1040,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
10401040
&mut self,
10411041
stack: &TraitObligationStack<'o, 'tcx>,
10421042
) -> SelectionResult<'tcx, SelectionCandidate<'tcx>> {
1043-
if stack.obligation.predicate.references_error() {
1044-
// If we encounter a `Error`, we generally prefer the
1045-
// most "optimistic" result in response -- that is, the
1046-
// one least likely to report downstream errors. But
1047-
// because this routine is shared by coherence and by
1048-
// trait selection, there isn't an obvious "right" choice
1049-
// here in that respect, so we opt to just return
1050-
// ambiguity and let the upstream clients sort it out.
1051-
return Ok(None);
1052-
}
1053-
10541043
if let Some(conflict) = self.is_knowable(stack) {
10551044
debug!("coherence stage: not knowable");
10561045
if self.intercrate_ambiguity_causes.is_some() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Regression test for issue #72590
2+
// Tests that we don't emit a spurious "size cannot be statically determined" error
3+
// edition:2018
4+
5+
struct Foo {
6+
foo: Nonexistent, //~ ERROR cannot find
7+
other: str
8+
}
9+
10+
struct Bar {
11+
test: Missing //~ ERROR cannot find
12+
}
13+
14+
impl Foo {
15+
async fn frob(self) {} //~ ERROR the size
16+
}
17+
18+
impl Bar {
19+
async fn myfn(self) {}
20+
}
21+
22+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
error[E0412]: cannot find type `Nonexistent` in this scope
2+
--> $DIR/issue-72590-type-error-sized.rs:6:10
3+
|
4+
LL | foo: Nonexistent,
5+
| ^^^^^^^^^^^ not found in this scope
6+
7+
error[E0412]: cannot find type `Missing` in this scope
8+
--> $DIR/issue-72590-type-error-sized.rs:11:11
9+
|
10+
LL | test: Missing
11+
| ^^^^^^^ not found in this scope
12+
13+
error[E0277]: the size for values of type `str` cannot be known at compilation time
14+
--> $DIR/issue-72590-type-error-sized.rs:15:19
15+
|
16+
LL | async fn frob(self) {}
17+
| ^^^^ doesn't have a size known at compile-time
18+
|
19+
= help: within `Foo`, the trait `std::marker::Sized` is not implemented for `str`
20+
= note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
21+
= note: required because it appears within the type `Foo`
22+
= note: all local variables must have a statically known size
23+
= help: unsized locals are gated as an unstable feature
24+
25+
error: aborting due to 3 previous errors
26+
27+
Some errors have detailed explanations: E0277, E0412.
28+
For more information about an error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)