diff options
author | Philip Herron <herron.philip@googlemail.com> | 2025-02-13 17:45:09 +0000 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2025-02-13 18:26:59 +0000 |
commit | 1eb46203ced28c5a3e44f6b63a23d4e91bd4f344 (patch) | |
tree | 74656405d93bea2ed19a3e46f2ef2b6f6de7cc5c /gcc | |
parent | 45fc433d0fa4c447df695aae4c2f63cb428ca6b5 (diff) | |
download | gcc-1eb46203ced28c5a3e44f6b63a23d4e91bd4f344.zip gcc-1eb46203ced28c5a3e44f6b63a23d4e91bd4f344.tar.gz gcc-1eb46203ced28c5a3e44f6b63a23d4e91bd4f344.tar.bz2 |
gccrs: self paths are patterns but we dont have mappings for it
With simple patterns we dont introduce any more inference varaibles as
they are already declared in a specific way. This would only lead to
more unconstrained inference varaibles than is required.
Fixes Rust-GCC#3022
gcc/rust/ChangeLog:
* hir/rust-ast-lower-base.cc (ASTLoweringBase::lower_self): add location mappings
* typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::resolve_root_path): check for self
gcc/testsuite/ChangeLog:
* rust/compile/issue-3022.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/hir/rust-ast-lower-base.cc | 1 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-hir-type-check-path.cc | 5 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/issue-3022.rs | 18 |
3 files changed, 23 insertions, 1 deletions
diff --git a/gcc/rust/hir/rust-ast-lower-base.cc b/gcc/rust/hir/rust-ast-lower-base.cc index 229f6e0..02fac9a 100644 --- a/gcc/rust/hir/rust-ast-lower-base.cc +++ b/gcc/rust/hir/rust-ast-lower-base.cc @@ -666,6 +666,7 @@ ASTLoweringBase::lower_self (AST::Param ¶m) Analysis::NodeMapping mapping (crate_num, self.get_node_id (), mappings.get_next_hir_id (crate_num), mappings.get_next_localdef_id (crate_num)); + mappings.insert_location (mapping.get_hirid (), param.get_locus ()); if (self.has_type ()) { diff --git a/gcc/rust/typecheck/rust-hir-type-check-path.cc b/gcc/rust/typecheck/rust-hir-type-check-path.cc index 73d9738..1904eba 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-path.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-path.cc @@ -312,6 +312,8 @@ TypeCheckExpr::resolve_root_path (HIR::PathInExpression &expr, size_t *offset, auto seg_is_module = mappings.lookup_module (ref).has_value (); auto seg_is_crate = mappings.is_local_hirid_crate (ref); auto seg_is_pattern = mappings.lookup_hir_pattern (ref).has_value (); + auto seg_is_self = is_root && !have_more_segments + && seg.get_segment ().as_string () == "self"; if (seg_is_module || seg_is_crate) { // A::B::C::this_is_a_module::D::E::F @@ -388,7 +390,8 @@ TypeCheckExpr::resolve_root_path (HIR::PathInExpression &expr, size_t *offset, if (lookup->get_kind () == TyTy::TypeKind::ERROR) return new TyTy::ErrorType (expr.get_mappings ().get_hirid ()); } - else if (lookup->needs_generic_substitutions () && !seg_is_pattern) + else if (lookup->needs_generic_substitutions () && !seg_is_pattern + && !seg_is_self) { lookup = SubstMapper::InferSubst (lookup, expr.get_locus ()); } diff --git a/gcc/testsuite/rust/compile/issue-3022.rs b/gcc/testsuite/rust/compile/issue-3022.rs new file mode 100644 index 0000000..b8b8e6f --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-3022.rs @@ -0,0 +1,18 @@ +#[lang = "sized"] +trait Sized {} + +trait Foo<T> { + fn foo(self) -> T; +} + +struct Bar<T, U> { + // { dg-warning "struct is never constructed" "" { target *-*-* } .-1 } + value: U, + valte: T, +} + +impl<T: Foo<U>, U> Foo<U> for Bar<T, U> { + fn foo(self) -> U { + self.value + } +} |