parent
2ea468e386
commit
f8e73ede83
5 changed files with 93 additions and 6 deletions
|
@ -2,6 +2,7 @@ use crate::infer::type_variable::TypeVariableOriginKind;
|
|||
use crate::infer::InferCtxt;
|
||||
use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder, ErrorGuaranteed};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::Res;
|
||||
use rustc_hir::def::{CtorOf, DefKind, Namespace};
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_hir::intravisit::{self, Visitor};
|
||||
|
@ -853,12 +854,20 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
|
|||
hir::TyKind::Path(hir::QPath::Resolved(_self_ty, path)),
|
||||
) => {
|
||||
if tcx.res_generics_def_id(path.res) != Some(def.did()) {
|
||||
bug!(
|
||||
match path.res {
|
||||
Res::Def(DefKind::TyAlias, _) => {
|
||||
// FIXME: Ideally we should support this. For that
|
||||
// we have to map back from the self type to the
|
||||
// type alias though. That's difficult.
|
||||
//
|
||||
// See the `need_type_info/type-alias.rs` test for
|
||||
// some examples.
|
||||
}
|
||||
_ => warn!(
|
||||
"unexpected path: def={:?} substs={:?} path={:?}",
|
||||
def,
|
||||
substs,
|
||||
path,
|
||||
);
|
||||
def, substs, path,
|
||||
),
|
||||
}
|
||||
} else {
|
||||
return Box::new(
|
||||
self.resolved_path_inferred_subst_iter(path, substs)
|
||||
|
|
18
src/test/ui/inference/need_type_info/type-alias-indirect.rs
Normal file
18
src/test/ui/inference/need_type_info/type-alias-indirect.rs
Normal file
|
@ -0,0 +1,18 @@
|
|||
// An addition to the `type-alias.rs` test,
|
||||
// see the FIXME in that file for why this test
|
||||
// exists.
|
||||
//
|
||||
// If there is none, feel free to remove this test
|
||||
// again.
|
||||
struct Ty<T>(T);
|
||||
impl<T> Ty<T> {
|
||||
fn new() {}
|
||||
}
|
||||
|
||||
type IndirectAlias<T> = Ty<Box<T>>;
|
||||
fn indirect_alias() {
|
||||
IndirectAlias::new();
|
||||
//~^ ERROR type annotations needed
|
||||
}
|
||||
|
||||
fn main() {}
|
|
@ -0,0 +1,9 @@
|
|||
error[E0282]: type annotations needed
|
||||
--> $DIR/type-alias-indirect.rs:14:5
|
||||
|
|
||||
LL | IndirectAlias::new();
|
||||
| ^^^^^^^^^^^^^ cannot infer type for type parameter `T` declared on the type alias `IndirectAlias`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0282`.
|
36
src/test/ui/inference/need_type_info/type-alias.rs
Normal file
36
src/test/ui/inference/need_type_info/type-alias.rs
Normal file
|
@ -0,0 +1,36 @@
|
|||
// Test the inference errors in case the relevant path
|
||||
// uses a type alias.
|
||||
//
|
||||
// Regression test for #97698.
|
||||
struct Ty<T>(T);
|
||||
impl<T> Ty<T> {
|
||||
fn new() {}
|
||||
}
|
||||
|
||||
type DirectAlias<T> = Ty<T>;
|
||||
fn direct_alias() {
|
||||
DirectAlias::new()
|
||||
//~^ ERROR type annotations needed
|
||||
}
|
||||
|
||||
type IndirectAlias<T> = Ty<Box<T>>;
|
||||
fn indirect_alias() {
|
||||
IndirectAlias::new();
|
||||
// FIXME: This should also emit an error.
|
||||
//
|
||||
// Added it separately as `type-alias-indirect.rs`
|
||||
// where it does error.
|
||||
}
|
||||
|
||||
struct TyDefault<T, U = u32>(T, U);
|
||||
impl<T> TyDefault<T> {
|
||||
fn new() {}
|
||||
}
|
||||
|
||||
type DirectButWithDefaultAlias<T> = TyDefault<T>;
|
||||
fn direct_but_with_default_alias() {
|
||||
DirectButWithDefaultAlias::new();
|
||||
//~^ ERROR type annotations needed
|
||||
}
|
||||
|
||||
fn main() {}
|
15
src/test/ui/inference/need_type_info/type-alias.stderr
Normal file
15
src/test/ui/inference/need_type_info/type-alias.stderr
Normal file
|
@ -0,0 +1,15 @@
|
|||
error[E0282]: type annotations needed
|
||||
--> $DIR/type-alias.rs:12:5
|
||||
|
|
||||
LL | DirectAlias::new()
|
||||
| ^^^^^^^^^^^^^^^^ cannot infer type for type parameter `T`
|
||||
|
||||
error[E0282]: type annotations needed
|
||||
--> $DIR/type-alias.rs:32:5
|
||||
|
|
||||
LL | DirectButWithDefaultAlias::new();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for type parameter `T`
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0282`.
|
Loading…
Add table
Add a link
Reference in a new issue