Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
328 changes: 195 additions & 133 deletions compiler/rustc_infer/src/infer/relate/generalize.rs

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions compiler/rustc_infer/src/infer/unify_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,13 @@ impl<'tcx> ConstVariableValue<'tcx> {
ConstVariableValue::Known { value } => Some(value),
}
}

pub(crate) fn is_unknown(&self) -> bool {
match *self {
ConstVariableValue::Unknown { .. } => true,
ConstVariableValue::Known { .. } => false,
}
}
}

#[derive(PartialEq, Copy, Clone, Debug)]
Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_middle/src/ty/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,13 @@ impl<'tcx> Const<'tcx> {
matches!(self.kind(), ty::ConstKind::Infer(_))
}

pub fn ct_vid(self) -> Option<ty::ConstVid> {
match self.kind() {
ConstKind::Infer(ty::InferConst::Var(vid)) => Some(vid),
_ => None,
}
}

/// Iterator that walks `self` and any types reachable from
/// `self`, in depth-first order. Note that just walks the types
/// that appear in `self`, it does not descend into the fields of
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/coherence/occurs-check/associated-type.next.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTy { args: [*const ?1t, '^0.Named(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1))], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit), .. }
WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTy { args: [*const ?1t, '^0.Named(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1))], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit), .. }
WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTerm { args: [*const ?1t, '^0.Named(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1))], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit), .. }
WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTerm { args: [*const ?1t, '^0.Named(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1))], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit), .. }
error[E0119]: conflicting implementations of trait `Overlap<for<'a> fn(&'a (), ())>` for type `for<'a> fn(&'a (), ())`
--> $DIR/associated-type.rs:32:1
|
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/coherence/occurs-check/associated-type.old.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTy { args: [*const ?1t, '^0.Named(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1))], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit), .. }
WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTy { args: [*const ?1t, '^0.Named(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1))], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit), .. }
WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTerm { args: [*const ?1t, '^0.Named(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1))], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit), .. }
WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTerm { args: [*const ?1t, '^0.Named(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1))], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit), .. }
error[E0119]: conflicting implementations of trait `Overlap<for<'a> fn(&'a (), ())>` for type `for<'a> fn(&'a (), ())`
--> $DIR/associated-type.rs:32:1
|
Expand Down
13 changes: 13 additions & 0 deletions tests/ui/const-generics/mgca/free-type-alias-recursive.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//! Regression test for <https://github.com/rust-lang/rust/issues/153831>
//@ check-fail
//@compile-flags: -Znext-solver=globally --emit=obj
#![feature(min_generic_const_args)]
#![expect(incomplete_features)]

type const A: () = A;
//~^ ERROR type mismatch resolving `A normalizes-to _`
//~| ERROR the constant `A` is not of type `()`

fn main() {
A;
}
15 changes: 15 additions & 0 deletions tests/ui/const-generics/mgca/free-type-alias-recursive.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
error[E0271]: type mismatch resolving `A normalizes-to _`
--> $DIR/free-type-alias-recursive.rs:7:1
|
LL | type const A: () = A;
| ^^^^^^^^^^^^^^^^ types differ

error: the constant `A` is not of type `()`
--> $DIR/free-type-alias-recursive.rs:7:1
|
LL | type const A: () = A;
| ^^^^^^^^^^^^^^^^ expected `()`, found a different `()`

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0271`.
7 changes: 3 additions & 4 deletions tests/ui/const-generics/ogca/coherence-ambiguous.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// FIXME(ogca): this should ERROR not pass!!
//@ check-pass
//@ check-fail

#![feature(generic_const_items, min_generic_const_args, opaque_generic_const_args)]
#![expect(incomplete_features)]
Expand All @@ -12,8 +11,8 @@ trait Trait {}

impl Trait for [(); FOO::<1>] {}
impl Trait for [(); BAR::<1>] {}
// FIXME(ogca): this should ERROR!
//~^ ERROR conflicting implementations of trait `Trait` for type `[(); FOO::<1>]`
impl Trait for [(); BAR::<2>] {}
// FIXME(ogca): this should ERROR!
//~^ ERROR conflicting implementations of trait `Trait` for type `[(); FOO::<1>]`

fn main() {}
20 changes: 20 additions & 0 deletions tests/ui/const-generics/ogca/coherence-ambiguous.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
error[E0119]: conflicting implementations of trait `Trait` for type `[(); FOO::<1>]`
--> $DIR/coherence-ambiguous.rs:13:1
|
LL | impl Trait for [(); FOO::<1>] {}
| ----------------------------- first implementation here
LL | impl Trait for [(); BAR::<1>] {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `[(); FOO::<1>]`

error[E0119]: conflicting implementations of trait `Trait` for type `[(); FOO::<1>]`
--> $DIR/coherence-ambiguous.rs:15:1
|
LL | impl Trait for [(); FOO::<1>] {}
| ----------------------------- first implementation here
...
LL | impl Trait for [(); BAR::<2>] {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `[(); FOO::<1>]`

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0119`.
2 changes: 1 addition & 1 deletion tests/ui/higher-ranked/structually-relate-aliases.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTy { args: [?1t, '^0.Named(DefId(0:15 ~ structually_relate_aliases[de75]::{impl#1}::'a))], def_id: DefId(0:5 ~ structually_relate_aliases[de75]::ToUnit::Unit), .. }
WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTerm { args: [?1t, '^0.Named(DefId(0:15 ~ structually_relate_aliases[de75]::{impl#1}::'a))], def_id: DefId(0:5 ~ structually_relate_aliases[de75]::ToUnit::Unit), .. }
error[E0277]: the trait bound `for<'a> T: ToUnit<'a>` is not satisfied
--> $DIR/structually-relate-aliases.rs:13:36
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ help: this trait has no implementations, consider adding one
LL | trait ToUnit<'a> {
| ^^^^^^^^^^^^^^^^

WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTy { args: ['^0.Named(DefId(0:15 ~ issue_118950_root_region[d54f]::{impl#1}::'a)), ?1t], def_id: DefId(0:8 ~ issue_118950_root_region[d54f]::Assoc), .. }
WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTerm { args: ['^0.Named(DefId(0:15 ~ issue_118950_root_region[d54f]::{impl#1}::'a)), ?1t], def_id: DefId(0:8 ~ issue_118950_root_region[d54f]::Assoc), .. }
error: aborting due to 2 previous errors

Some errors have detailed explanations: E0277, E0425.
Expand Down
Loading