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
4 changes: 2 additions & 2 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1267,9 +1267,9 @@ dependencies = [

[[package]]
name = "ena"
version = "0.14.4"
version = "0.14.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eabffdaee24bd1bf95c5ef7cec31260444317e72ea56c4c91750e8b7ee58d5f1"
checksum = "3d248bdd43ce613d87415282f69b9bb99d947d290b10962dd6c56233312c2ad5"
dependencies = [
"log",
]
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_data_structures/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ arrayvec = { version = "0.7", default-features = false }
bitflags = "2.4.1"
either = "1.0"
elsa = "1.11.0"
ena = "0.14.4"
ena = "0.14.3"
indexmap = "2.12.1"
jobserver_crate = { version = "0.1.28", package = "jobserver" }
measureme = "12.0.1"
Expand Down
5 changes: 5 additions & 0 deletions compiler/rustc_hir_typeck/src/fallback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,11 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
VecGraph::new(num_ty_vars, coercion_edges)
}

/// If `ty` is an unresolved type variable, returns its root vid.
fn root_vid(&self, ty: Ty<'tcx>) -> Option<ty::TyVid> {
Some(self.root_var(self.shallow_resolve(ty).ty_vid()?))
}

/// Given a set of diverging vids and coercions, walk the HIR to gather a
/// set of suggestions which can be applied to preserve fallback to unit.
fn try_to_suggest_annotations(
Expand Down
59 changes: 13 additions & 46 deletions compiler/rustc_infer/src/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1099,45 +1099,22 @@ impl<'tcx> InferCtxt<'tcx> {
//
// Note: if these two lines are combined into one we get
// dynamic borrow errors on `self.inner`.
let (root_vid, value) =
self.inner.borrow_mut().type_variables().probe_with_root_vid(v);
value.known().map_or_else(
|| if root_vid == v { ty } else { Ty::new_var(self.tcx, root_vid) },
|t| self.shallow_resolve(t),
)
let known = self.inner.borrow_mut().type_variables().probe(v).known();
known.map_or(ty, |t| self.shallow_resolve(t))
}

ty::IntVar(v) => {
let (root, value) =
self.inner.borrow_mut().int_unification_table().inlined_probe_key_value(v);
match value {
match self.inner.borrow_mut().int_unification_table().probe_value(v) {
ty::IntVarValue::IntType(ty) => Ty::new_int(self.tcx, ty),
ty::IntVarValue::UintType(ty) => Ty::new_uint(self.tcx, ty),
ty::IntVarValue::Unknown => {
if root == v {
ty
} else {
Ty::new_int_var(self.tcx, root)
}
}
ty::IntVarValue::Unknown => ty,
}
}

ty::FloatVar(v) => {
let (root, value) = self
.inner
.borrow_mut()
.float_unification_table()
.inlined_probe_key_value(v);
match value {
match self.inner.borrow_mut().float_unification_table().probe_value(v) {
ty::FloatVarValue::Known(ty) => Ty::new_float(self.tcx, ty),
ty::FloatVarValue::Unknown => {
if root == v {
ty
} else {
Ty::new_float_var(self.tcx, root)
}
}
ty::FloatVarValue::Unknown => ty,
}
}

Expand All @@ -1151,16 +1128,13 @@ impl<'tcx> InferCtxt<'tcx> {
pub fn shallow_resolve_const(&self, ct: ty::Const<'tcx>) -> ty::Const<'tcx> {
match ct.kind() {
ty::ConstKind::Infer(infer_ct) => match infer_ct {
InferConst::Var(vid) => {
let (root, value) = self
.inner
.borrow_mut()
.const_unification_table()
.inlined_probe_key_value(vid);
value.known().unwrap_or_else(|| {
if root.vid == vid { ct } else { ty::Const::new_var(self.tcx, root.vid) }
})
}
InferConst::Var(vid) => self
.inner
.borrow_mut()
.const_unification_table()
.probe_value(vid)
.known()
.unwrap_or(ct),
InferConst::Fresh(_) => ct,
},
ty::ConstKind::Param(_)
Expand All @@ -1184,13 +1158,6 @@ impl<'tcx> InferCtxt<'tcx> {
self.inner.borrow_mut().type_variables().root_var(var)
}

/// If `ty` is an unresolved type variable, returns its root vid.
pub fn root_vid(&self, ty: Ty<'tcx>) -> Option<ty::TyVid> {
let (root, value) =
self.inner.borrow_mut().type_variables().inlined_probe_with_vid(ty.ty_vid()?);
value.is_unknown().then_some(root)
}

pub fn sub_unify_ty_vids_raw(&self, a: ty::TyVid, b: ty::TyVid) {
self.inner.borrow_mut().type_variables().sub_unify(a, b);
}
Expand Down
19 changes: 0 additions & 19 deletions compiler/rustc_infer/src/infer/type_variable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,25 +258,6 @@ impl<'tcx> TypeVariableTable<'_, 'tcx> {
self.eq_relations().inlined_probe_value(vid)
}

/// Retrieves the type to which `vid` has been instantiated, if
/// any, along with the root `vid`.
pub(crate) fn probe_with_root_vid(
&mut self,
vid: ty::TyVid,
) -> (ty::TyVid, TypeVariableValue<'tcx>) {
self.inlined_probe_with_vid(vid)
}

/// An always-inlined variant of `probe_with_root_vid`, for very hot call sites.
#[inline(always)]
pub(crate) fn inlined_probe_with_vid(
&mut self,
vid: ty::TyVid,
) -> (ty::TyVid, TypeVariableValue<'tcx>) {
let (id, value) = self.eq_relations().inlined_probe_key_value(vid);
(id.vid, value)
}

#[inline]
fn eq_relations(&mut self) -> super::UnificationTable<'_, 'tcx, TyVidEqKey<'tcx>> {
self.storage.eq_relations.with_log(self.undo_log)
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_type_ir/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2024"
arrayvec = { version = "0.7", default-features = false }
bitflags = "2.4.1"
derive-where = "1.2.7"
ena = "0.14.4"
ena = "0.14.3"
indexmap = "2.0.0"
rustc-hash = "2.0.0"
rustc_ast_ir = { path = "../rustc_ast_ir", default-features = false }
Expand Down
2 changes: 2 additions & 0 deletions tests/incremental/const-generics/issue-64087.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ fn combinator<T, const S: usize>() -> [T; S] {}
fn main() {
combinator().into_iter();
//[cfail1]~^ ERROR type annotations needed
//[cfail1]~| ERROR type annotations needed
//[cfail1]~| ERROR type annotations needed
}
2 changes: 1 addition & 1 deletion tests/ui/associated-inherent-types/inference-fail.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0282]: type annotations needed
--> $DIR/inference-fail.rs:10:12
|
LL | let _: S<_>::P = ();
| ^^^^^^^ cannot infer type
| ^^^^^^^ cannot infer type for type parameter `T`

error: aborting due to 1 previous error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::cmp::Ordering;
use std::marker::PhantomData;

#[derive(PartialEq, Default)]
//~^ ERROR conflicting implementations of trait `PartialEq` for type `Interval<_>`
//~^ ERROR conflicting implementations of trait `PartialEq<Interval<_>>` for type `Interval<_>`
pub(crate) struct Interval<T>(PhantomData<T>);

// This impl overlaps with the `derive` unless we reject the nested
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0119]: conflicting implementations of trait `PartialEq` for type `Interval<_>`
error[E0119]: conflicting implementations of trait `PartialEq<Interval<_>>` for type `Interval<_>`
--> $DIR/warn-when-cycle-is-error-in-coherence.rs:5:10
|
LL | #[derive(PartialEq, Default)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ fn use_dyn<const N: usize>(v: &dyn Foo<N>) where [u8; N + 1]: Sized {
fn main() {
use_dyn(&());
//~^ ERROR type annotations needed
//~| ERROR type annotations needed
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,27 @@ help: consider specifying the generic argument
LL | use_dyn::<N>(&());
| +++++

error: aborting due to 1 previous error
error[E0284]: type annotations needed
--> $DIR/dyn-compatibility-ok-infer-err.rs:19:5
|
LL | use_dyn(&());
| ^^^^^^^ --- type must be known at this point
| |
| cannot infer the value of the const parameter `N` declared on the function `use_dyn`
|
note: required for `()` to implement `Foo<_>`
--> $DIR/dyn-compatibility-ok-infer-err.rs:8:22
|
LL | impl<const N: usize> Foo<N> for () {
| -------------- ^^^^^^ ^^
| |
| unsatisfied trait bound introduced here
= note: required for the cast from `&()` to `&dyn Foo<_>`
help: consider specifying the generic argument
|
LL | use_dyn::<N>(&());
| +++++

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0284`.
1 change: 1 addition & 0 deletions tests/ui/const-generics/infer/issue-77092.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ fn main() {
for i in 1..4 {
println!("{:?}", take_array_from_mut(&mut arr, i));
//~^ ERROR type annotations needed
//~| ERROR type annotations needed
}
}
20 changes: 19 additions & 1 deletion tests/ui/const-generics/infer/issue-77092.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,24 @@ help: consider specifying the generic arguments
LL | println!("{:?}", take_array_from_mut::<i32, N>(&mut arr, i));
| ++++++++++

error: aborting due to 1 previous error
error[E0284]: type annotations needed
--> $DIR/issue-77092.rs:11:26
|
LL | println!("{:?}", take_array_from_mut(&mut arr, i));
| ---- ^^^^^^^^^^^^^^^^^^^ cannot infer the value of the const parameter `N` declared on the function `take_array_from_mut`
| |
| required by this formatting parameter
|
= note: required for `[i32; _]` to implement `Debug`
= note: 1 redundant requirement hidden
= note: required for `&mut [i32; _]` to implement `Debug`
note: required by a bound in `core::fmt::rt::Argument::<'_>::new_debug`
--> $SRC_DIR/core/src/fmt/rt.rs:LL:COL
help: consider specifying the generic arguments
|
LL | println!("{:?}", take_array_from_mut::<i32, N>(&mut arr, i));
| ++++++++++

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0284`.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use std::convert::TryFrom;
pub fn test_usage(p: ()) {
SmallCString::try_from(p).map(|cstr| cstr);
//~^ ERROR: type annotations needed
//~| ERROR: type annotations needed
//~| ERROR: type annotations needed
}

pub struct SmallCString<const N: usize> {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ LL | SmallCString::try_from(p).map(|cstr| cstr);
| type must be known at this point
|
note: required by a const generic parameter in `SmallCString`
--> $DIR/try-from-with-const-genericsrs-98299.rs:9:25
--> $DIR/try-from-with-const-genericsrs-98299.rs:11:25
|
LL | pub struct SmallCString<const N: usize> {}
| ^^^^^^^^^^^^^^ required by this const generic parameter in `SmallCString`
Expand All @@ -16,6 +16,46 @@ help: consider giving this closure parameter an explicit type, where the value o
LL | SmallCString::try_from(p).map(|cstr: SmallCString<N>| cstr);
| +++++++++++++++++

error: aborting due to 1 previous error
error[E0284]: type annotations needed for `SmallCString<_>`
--> $DIR/try-from-with-const-genericsrs-98299.rs:5:36
|
LL | SmallCString::try_from(p).map(|cstr| cstr);
| ------------ ^^^^
| |
| type must be known at this point
|
note: required for `SmallCString<_>` to implement `TryFrom<()>`
--> $DIR/try-from-with-const-genericsrs-98299.rs:13:22
|
LL | impl<const N: usize> TryFrom<()> for SmallCString<N> {
| -------------- ^^^^^^^^^^^ ^^^^^^^^^^^^^^^
| |
| unsatisfied trait bound introduced here
help: consider giving this closure parameter an explicit type, where the value of const parameter `N` is specified
|
LL | SmallCString::try_from(p).map(|cstr: SmallCString<N>| cstr);
| +++++++++++++++++

error[E0284]: type annotations needed for `SmallCString<_>`
--> $DIR/try-from-with-const-genericsrs-98299.rs:5:36
|
LL | SmallCString::try_from(p).map(|cstr| cstr);
| ------------------------- ^^^^
| |
| type must be known at this point
|
note: required for `SmallCString<_>` to implement `TryFrom<()>`
--> $DIR/try-from-with-const-genericsrs-98299.rs:13:22
|
LL | impl<const N: usize> TryFrom<()> for SmallCString<N> {
| -------------- ^^^^^^^^^^^ ^^^^^^^^^^^^^^^
| |
| unsatisfied trait bound introduced here
help: consider giving this closure parameter an explicit type, where the value of const parameter `N` is specified
|
LL | SmallCString::try_from(p).map(|cstr: SmallCString<N>| cstr);
| +++++++++++++++++

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0284`.
Loading
Loading