Skip to content

Commit 8f36866

Browse files
author
Yuki Okushi
authored
Rollup merge of #105181 - bhbs:skip-note, r=estebank
Don't add a note for implementing a trait if its inner type is erroneous Fix #105138
2 parents 019795b + 715d4a8 commit 8f36866

File tree

3 files changed

+64
-15
lines changed

3 files changed

+64
-15
lines changed

compiler/rustc_trait_selection/src/traits/select/mod.rs

+20-15
Original file line numberDiff line numberDiff line change
@@ -371,23 +371,28 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
371371

372372
if !candidate_set.ambiguous && no_candidates_apply {
373373
let trait_ref = stack.obligation.predicate.skip_binder().trait_ref;
374-
let self_ty = trait_ref.self_ty();
375-
let (trait_desc, self_desc) = with_no_trimmed_paths!({
376-
let trait_desc = trait_ref.print_only_trait_path().to_string();
377-
let self_desc = if self_ty.has_concrete_skeleton() {
378-
Some(self_ty.to_string())
374+
if !trait_ref.references_error() {
375+
let self_ty = trait_ref.self_ty();
376+
let (trait_desc, self_desc) = with_no_trimmed_paths!({
377+
let trait_desc = trait_ref.print_only_trait_path().to_string();
378+
let self_desc = if self_ty.has_concrete_skeleton() {
379+
Some(self_ty.to_string())
380+
} else {
381+
None
382+
};
383+
(trait_desc, self_desc)
384+
});
385+
let cause = if let Conflict::Upstream = conflict {
386+
IntercrateAmbiguityCause::UpstreamCrateUpdate {
387+
trait_desc,
388+
self_desc,
389+
}
379390
} else {
380-
None
391+
IntercrateAmbiguityCause::DownstreamCrate { trait_desc, self_desc }
381392
};
382-
(trait_desc, self_desc)
383-
});
384-
let cause = if let Conflict::Upstream = conflict {
385-
IntercrateAmbiguityCause::UpstreamCrateUpdate { trait_desc, self_desc }
386-
} else {
387-
IntercrateAmbiguityCause::DownstreamCrate { trait_desc, self_desc }
388-
};
389-
debug!(?cause, "evaluate_stack: pushing cause");
390-
self.intercrate_ambiguity_causes.as_mut().unwrap().insert(cause);
393+
debug!(?cause, "evaluate_stack: pushing cause");
394+
self.intercrate_ambiguity_causes.as_mut().unwrap().insert(cause);
395+
}
391396
}
392397
}
393398
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Regression test for #105138.
2+
// This test ensures that the compiler does not add note
3+
// for implementation of trait whose inner type is erroneous.
4+
5+
pub enum LabelText {
6+
Plain,
7+
}
8+
9+
impl<T> From<T> for LabelText
10+
//~^ ERROR conflicting implementations of trait `From<LabelText>` for type `LabelText` [E0119]
11+
where
12+
T: Into<Cow<'static, str>>,
13+
//~^ ERROR cannot find type `Cow` in this scope [E0412]
14+
{
15+
fn from(text: T) -> Self {
16+
LabelText::Plain(text.into())
17+
}
18+
}
19+
20+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
error[E0412]: cannot find type `Cow` in this scope
2+
--> $DIR/impl-bound-with-references-error.rs:12:13
3+
|
4+
LL | T: Into<Cow<'static, str>>,
5+
| ^^^ not found in this scope
6+
|
7+
help: consider importing this enum
8+
|
9+
LL | use std::borrow::Cow;
10+
|
11+
12+
error[E0119]: conflicting implementations of trait `From<LabelText>` for type `LabelText`
13+
--> $DIR/impl-bound-with-references-error.rs:9:1
14+
|
15+
LL | impl<T> From<T> for LabelText
16+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17+
|
18+
= note: conflicting implementation in crate `core`:
19+
- impl<T> From<T> for T;
20+
21+
error: aborting due to 2 previous errors
22+
23+
Some errors have detailed explanations: E0119, E0412.
24+
For more information about an error, try `rustc --explain E0119`.

0 commit comments

Comments
 (0)