Skip to content

Commit f2d8af1

Browse files
Do not mention private Self types from other crates
1 parent a51fb2b commit f2d8af1

File tree

5 files changed

+67
-3
lines changed

5 files changed

+67
-3
lines changed

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

+20-2
Original file line numberDiff line numberDiff line change
@@ -1805,8 +1805,26 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
18051805
|| self.tcx.is_builtin_derive(def_id)
18061806
})
18071807
.filter_map(|def_id| self.tcx.impl_trait_ref(def_id))
1808-
// Avoid mentioning type parameters.
1809-
.filter(|trait_ref| !matches!(trait_ref.self_ty().kind(), ty::Param(_)))
1808+
.filter(|trait_ref| {
1809+
let self_ty = trait_ref.self_ty();
1810+
// Avoid mentioning type parameters.
1811+
if let ty::Param(_) = self_ty.kind() {
1812+
false
1813+
}
1814+
// Avoid mentioning types that are private to another crate
1815+
else if let ty::Adt(def, _) = self_ty.peel_refs().kind() {
1816+
// FIXME(compiler-errors): This could be generalized, both to
1817+
// be more granular, and probably look past other `#[fundamental]`
1818+
// types, too.
1819+
match self.tcx.visibility(def.did()) {
1820+
ty::Visibility::Public => true,
1821+
ty::Visibility::Restricted(def_id) => def_id.is_local(),
1822+
ty::Visibility::Invisible => false,
1823+
}
1824+
} else {
1825+
true
1826+
}
1827+
})
18101828
.collect();
18111829
return report(normalized_impl_candidates, err);
18121830
}
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
pub trait Meow {
2+
fn meow(&self) {}
3+
}
4+
5+
pub struct GlobalMeow;
6+
7+
impl Meow for GlobalMeow {}
8+
9+
pub(crate) struct PrivateMeow;
10+
11+
impl Meow for PrivateMeow {}
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// aux-build:meow.rs
2+
3+
extern crate meow;
4+
5+
use meow::Meow;
6+
7+
fn needs_meow<T: Meow>(t: T) {}
8+
9+
fn main() {
10+
needs_meow(1usize);
11+
//~^ ERROR the trait bound `usize: Meow` is not satisfied
12+
}
13+
14+
struct LocalMeow;
15+
16+
impl Meow for LocalMeow {}
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error[E0277]: the trait bound `usize: Meow` is not satisfied
2+
--> $DIR/issue-99080.rs:10:16
3+
|
4+
LL | needs_meow(1usize);
5+
| ---------- ^^^^^^ the trait `Meow` is not implemented for `usize`
6+
| |
7+
| required by a bound introduced by this call
8+
|
9+
= help: the following other types implement trait `Meow`:
10+
GlobalMeow
11+
LocalMeow
12+
note: required by a bound in `needs_meow`
13+
--> $DIR/issue-99080.rs:7:18
14+
|
15+
LL | fn needs_meow<T: Meow>(t: T) {}
16+
| ^^^^ required by this bound in `needs_meow`
17+
18+
error: aborting due to previous error
19+
20+
For more information about this error, try `rustc --explain E0277`.

src/test/ui/traits/bound/assoc-fn-bound-root-obligation.stderr

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ LL | s.strip_suffix(b'\n').unwrap_or(s)
1515
&'c &'b str
1616
[char; N]
1717
char
18-
pattern::MultiCharEqPattern<C>
1918
= note: required because of the requirements on the impl of `Pattern<'_>` for `u8`
2019

2120
error: aborting due to previous error

0 commit comments

Comments
 (0)