Skip to content

Commit

Permalink
small coherence cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
lcnr committed May 1, 2024
1 parent b2ac4e5 commit a0359c8
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 7 deletions.
7 changes: 2 additions & 5 deletions compiler/rustc_trait_selection/src/traits/coherence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -792,11 +792,8 @@ pub fn orphan_check_trait_ref<'tcx, E: Debug>(
in_crate: InCrate,
lazily_normalize_ty: impl FnMut(Ty<'tcx>) -> Result<Ty<'tcx>, E>,
) -> Result<Result<(), OrphanCheckErr<'tcx, Ty<'tcx>>>, E> {
if trait_ref.has_infer() && trait_ref.has_param() {
bug!(
"can't orphan check a trait ref with both params and inference variables {:?}",
trait_ref
);
if trait_ref.has_param() {
bug!("orphan check only expects inference variables: {trait_ref:?}");
}

let mut checker = OrphanChecker::new(in_crate, lazily_normalize_ty);
Expand Down
17 changes: 17 additions & 0 deletions tests/ui/traits/winnowing/global-non-global-env-1.current.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
error[E0308]: mismatched types
--> $DIR/global-non-global-env-1.rs:18:5
|
LL | fn foo<T>() -> u32
| - --- expected `u32` because of return type
| |
| found this type parameter
...
LL | impls_trait(())
| ^^^^^^^^^^^^^^^ expected `u32`, found type parameter `T`
|
= note: expected type `u32`
found type parameter `T`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0308`.
3 changes: 2 additions & 1 deletion tests/ui/traits/winnowing/global-non-global-env-1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//@ revisions: current next
//@ ignore-compare-mode-next-solver (explicit revisions)
//@[next] compile-flags: -Znext-solver
//@ check-pass
//@[next] check-pass

trait Trait<T> {}
impl<T> Trait<T> for () {}
Expand All @@ -16,6 +16,7 @@ where
(): Trait<T>,
{
impls_trait(())
//[current]~^ ERROR mismatched types
}

fn main() {}
17 changes: 17 additions & 0 deletions tests/ui/traits/winnowing/global-non-global-env-3.current.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
error[E0308]: mismatched types
--> $DIR/global-non-global-env-3.rs:20:5
|
LL | fn foo<T>() -> u32
| - --- expected `u32` because of return type
| |
| found this type parameter
...
LL | impls_trait(())
| ^^^^^^^^^^^^^^^ expected `u32`, found type parameter `T`
|
= note: expected type `u32`
found type parameter `T`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0308`.
3 changes: 2 additions & 1 deletion tests/ui/traits/winnowing/global-non-global-env-3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//@ revisions: current next
//@ ignore-compare-mode-next-solver (explicit revisions)
//@[next] compile-flags: -Znext-solver
//@ check-pass
//@[next] check-pass

trait Trait<T> {}
impl Trait<u32> for () {}
Expand All @@ -18,6 +18,7 @@ where
(): Trait<u32>,
{
impls_trait(())
//[current]~^ ERROR mismatched types
}

fn main() {}

0 comments on commit a0359c8

Please sign in to comment.