Skip to content

Commit 96204ee

Browse files
committed
add tests
1 parent a7a8b5b commit 96204ee

File tree

7 files changed

+154
-2
lines changed

7 files changed

+154
-2
lines changed

Diff for: compiler/rustc_infer/src/infer/generalize.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,9 @@ where
343343
self.for_universe.can_name(visitor.max_universe())
344344
&& !t.has_escaping_bound_vars();
345345
if !infer_replacement_is_complete {
346-
warn!("incomplete generalization of an alias type: {t:?}");
346+
warn!(
347+
"may incompletely handle alias type: {t:?}"
348+
);
347349
}
348350

349351
debug!("generalization failure in alias");

Diff for: compiler/rustc_trait_selection/src/traits/coherence.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,13 @@ impl<'a, 'tcx> ProofTreeVisitor<'tcx> for AmbiguityCausesVisitor<'a> {
930930
let trait_ref = match predicate.kind().no_bound_vars() {
931931
Some(ty::PredicateKind::Clause(ty::ClauseKind::Trait(tr))) => tr.trait_ref,
932932
Some(ty::PredicateKind::Clause(ty::ClauseKind::Projection(proj))) => {
933-
proj.projection_ty.trait_ref(infcx.tcx)
933+
match proj.projection_ty.kind(infcx.tcx) {
934+
ty::AliasKind::Projection => proj.projection_ty.trait_ref(infcx.tcx),
935+
ty::AliasKind::Inherent | ty::AliasKind::Opaque | ty::AliasKind::Weak => {
936+
// No intercrate ambiguity causes here.
937+
return ControlFlow::Continue(());
938+
}
939+
}
934940
}
935941
_ => return ControlFlow::Continue(()),
936942
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
WARN rustc_infer::infer::generalize may incompletely handle alias type: Alias(Projection, AliasTy { args: [*const ?1t, ReLateBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1), 'a) })], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit) })
2+
WARN rustc_infer::infer::generalize may incompletely handle alias type: Alias(Projection, AliasTy { args: [*const ?1t, RePlaceholder(!2_BoundRegion { var: 0, kind: BrNamed(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1), 'a) })], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit) })
3+
WARN rustc_infer::infer::generalize may incompletely handle alias type: Alias(Projection, AliasTy { args: [*const ?1t, ReLateBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1), 'a) })], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit) })
4+
WARN rustc_infer::infer::generalize may incompletely handle alias type: Alias(Projection, AliasTy { args: [*const ?1t, RePlaceholder(!2_BoundRegion { var: 0, kind: BrNamed(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1), 'a) })], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit) })
5+
WARN rustc_infer::infer::generalize may incompletely handle alias type: Alias(Projection, AliasTy { args: [*const ?1t, ReLateBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1), 'a) })], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit) })
6+
WARN rustc_infer::infer::generalize may incompletely handle alias type: Alias(Projection, AliasTy { args: [*const ?1t, RePlaceholder(!2_BoundRegion { var: 0, kind: BrNamed(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1), 'a) })], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit) })
7+
WARN rustc_infer::infer::generalize may incompletely handle alias type: Alias(Projection, AliasTy { args: [*const ?1t, ReLateBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1), 'a) })], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit) })
8+
WARN rustc_infer::infer::generalize may incompletely handle alias type: Alias(Projection, AliasTy { args: [*const ?1t, RePlaceholder(!2_BoundRegion { var: 0, kind: BrNamed(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1), 'a) })], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit) })
9+
error[E0119]: conflicting implementations of trait `Overlap<for<'a> fn(&'a (), ())>` for type `for<'a> fn(&'a (), ())`
10+
--> $DIR/associated-type.rs:31:1
11+
|
12+
LL | impl<T> Overlap<T> for T {
13+
| ------------------------ first implementation here
14+
...
15+
LL | / impl<T> Overlap<for<'a> fn(&'a (), Assoc<'a, T>)> for T
16+
LL | |
17+
LL | | where
18+
LL | | for<'a> *const T: ToUnit<'a>,
19+
| |_________________________________^ conflicting implementation for `for<'a> fn(&'a (), ())`
20+
|
21+
= note: this behavior recently changed as a result of a bug fix; see rust-lang/rust#56105 for details
22+
23+
error: aborting due to previous error
24+
25+
For more information about this error, try `rustc --explain E0119`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
WARN rustc_infer::infer::generalize may incompletely handle alias type: Alias(Projection, AliasTy { args: [*const ?1t, ReLateBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1), 'a) })], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit) })
2+
WARN rustc_infer::infer::generalize may incompletely handle alias type: Alias(Projection, AliasTy { args: [*const ?1t, RePlaceholder(!3_BoundRegion { var: 0, kind: BrNamed(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1), 'a) })], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit) })
3+
WARN rustc_infer::infer::generalize may incompletely handle alias type: Alias(Projection, AliasTy { args: [*const ?1t, ReLateBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1), 'a) })], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit) })
4+
WARN rustc_infer::infer::generalize may incompletely handle alias type: Alias(Projection, AliasTy { args: [*const ?1t, RePlaceholder(!3_BoundRegion { var: 0, kind: BrNamed(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1), 'a) })], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit) })
5+
WARN rustc_infer::infer::generalize may incompletely handle alias type: Alias(Projection, AliasTy { args: [*const ?1t, ReLateBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1), 'a) })], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit) })
6+
WARN rustc_infer::infer::generalize may incompletely handle alias type: Alias(Projection, AliasTy { args: [*const ?1t, RePlaceholder(!3_BoundRegion { var: 0, kind: BrNamed(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1), 'a) })], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit) })
7+
WARN rustc_infer::infer::generalize may incompletely handle alias type: Alias(Projection, AliasTy { args: [*const ?1t, ReLateBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1), 'a) })], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit) })
8+
WARN rustc_infer::infer::generalize may incompletely handle alias type: Alias(Projection, AliasTy { args: [*const ?1t, RePlaceholder(!3_BoundRegion { var: 0, kind: BrNamed(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1), 'a) })], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit) })
9+
error[E0119]: conflicting implementations of trait `Overlap<for<'a> fn(&'a (), _)>` for type `for<'a> fn(&'a (), _)`
10+
--> $DIR/associated-type.rs:31:1
11+
|
12+
LL | impl<T> Overlap<T> for T {
13+
| ------------------------ first implementation here
14+
...
15+
LL | / impl<T> Overlap<for<'a> fn(&'a (), Assoc<'a, T>)> for T
16+
LL | |
17+
LL | | where
18+
LL | | for<'a> *const T: ToUnit<'a>,
19+
| |_________________________________^ conflicting implementation for `for<'a> fn(&'a (), _)`
20+
|
21+
= note: this behavior recently changed as a result of a bug fix; see rust-lang/rust#56105 for details
22+
23+
error: aborting due to previous error
24+
25+
For more information about this error, try `rustc --explain E0119`.

Diff for: tests/ui/coherence/occurs-check/associated-type.rs

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// revisions: old next
2+
//[next] compile-flags: -Ztrait-solver=next
3+
4+
// A regression test for #105787
5+
6+
// Using the higher ranked projection hack to prevent us from replacing the projection
7+
// with an inference variable.
8+
trait ToUnit<'a> {
9+
type Unit;
10+
}
11+
12+
struct LocalTy;
13+
impl<'a> ToUnit<'a> for *const LocalTy {
14+
type Unit = ();
15+
}
16+
17+
impl<'a, T: Copy + ?Sized> ToUnit<'a> for *const T {
18+
type Unit = ();
19+
}
20+
21+
trait Overlap<T> {
22+
type Assoc;
23+
}
24+
25+
type Assoc<'a, T> = <*const T as ToUnit<'a>>::Unit;
26+
27+
impl<T> Overlap<T> for T {
28+
type Assoc = usize;
29+
}
30+
31+
impl<T> Overlap<for<'a> fn(&'a (), Assoc<'a, T>)> for T
32+
//~^ ERROR conflicting implementations of trait
33+
where
34+
for<'a> *const T: ToUnit<'a>,
35+
{
36+
type Assoc = Box<usize>;
37+
}
38+
39+
fn foo<T: Overlap<U>, U>(x: T::Assoc) -> T::Assoc {
40+
x
41+
}
42+
43+
fn main() {
44+
foo::<for<'a> fn(&'a (), ()), for<'a> fn(&'a (), ())>(3usize);
45+
}

Diff for: tests/ui/coherence/occurs-check/opaques.next.stderr

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0119]: conflicting implementations of trait `Trait<Alias<_>>` for type `Alias<_>`
2+
--> $DIR/opaques.rs:29:1
3+
|
4+
LL | impl<T> Trait<T> for T {
5+
| ---------------------- first implementation here
6+
...
7+
LL | impl<T> Trait<T> for defining_scope::Alias<T> {
8+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `Alias<_>`
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0119`.

Diff for: tests/ui/coherence/occurs-check/opaques.rs

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//revisions: old next
2+
//[next] compile-flags: -Ztrait-solver=next
3+
4+
// A regression test for #105787
5+
6+
//[old] known-bug: #105787
7+
//[old] check-pass
8+
#![feature(type_alias_impl_trait)]
9+
mod defining_scope {
10+
use super::*;
11+
pub type Alias<T> = impl Sized;
12+
13+
pub fn cast<T>(x: Container<Alias<T>, T>) -> Container<T, T> {
14+
x
15+
}
16+
}
17+
18+
struct Container<T: Trait<U>, U> {
19+
x: <T as Trait<U>>::Assoc,
20+
}
21+
22+
trait Trait<T> {
23+
type Assoc;
24+
}
25+
26+
impl<T> Trait<T> for T {
27+
type Assoc = Box<u32>;
28+
}
29+
impl<T> Trait<T> for defining_scope::Alias<T> {
30+
//[next]~^ ERROR conflicting implementations of trait
31+
type Assoc = usize;
32+
}
33+
34+
fn main() {
35+
let x: Box<u32> = defining_scope::cast::<()>(Container { x: 0 }).x;
36+
println!("{}", *x);
37+
}

0 commit comments

Comments
 (0)