This commit correctly lowers and typechecks parenthesized types, which are used for trait objects with additional bounds.
gcc/rust/ChangeLog:
* resolve/rust-ast-resolve-type.cc (ResolveType::visit): New visitor to handle
ParenthesizedType.
* resolve/rust-ast-resolve-type.h: Likewise.
* typecheck/rust-hir-type-check-type.cc (TypeCheckType::visit): Likewise.
* typecheck/rust-hir-type-check-type.h: Likewise.
gcc/testsuite/ChangeLog:
* rust/compile/auto_traits2.rs: New test.
* rust/compile/auto_traits3.rs: New test.
* rust/compile/nr2/exclude: Add auto_traits2 test.
}
}
+void
+ResolveType::visit (AST::ParenthesisedType &type)
+{
+ resolved_node = ResolveType::go (*type.get_type_in_parens ());
+}
+
void
ResolveType::visit (AST::ReferenceType &type)
{
#include "rust-diagnostics.h"
#include "rust-hir-map.h"
#include "rust-path.h"
+#include "rust-type.h"
#include "util/rust-hir-map.h"
namespace Rust {
void visit (AST::TraitObjectType &type) override;
+ void visit (AST::ParenthesisedType &type) override;
+
void visit (AST::SliceType &type) override;
private:
std::move (specified_bounds));
}
+void
+TypeCheckType::visit (HIR::ParenthesisedType &type)
+{
+ translated = TypeCheckType::Resolve (type.get_type_in_parens ());
+}
+
void
TypeCheckType::visit (HIR::ArrayType &type)
{
void visit (HIR::InferredType &type) override;
void visit (HIR::NeverType &type) override;
void visit (HIR::TraitObjectType &type) override;
+ void visit (HIR::ParenthesisedType &type) override;
void visit (HIR::TypePathSegmentFunction &segment) override
{ /* TODO */
void visit (HIR::ImplTraitType &type) override
{ /* TODO */
}
- void visit (HIR::ParenthesisedType &type) override
- { /* TODO */
- }
void visit (HIR::ImplTraitTypeOneBound &type) override
{ /* TODO */
}
--- /dev/null
+#![feature(optin_builtin_traits)]
+
+pub unsafe auto trait Send {}
+#[lang = "sync"]
+pub unsafe auto trait Sync {}
+
+trait A {
+ fn a_method(&self) {}
+}
+
+fn foo(a: &(dyn A + Send + Sync)) {
+ a.a_method();
+}
+
+struct S;
+
+impl A for S {
+ fn a_method(&self) {}
+}
+
+fn main() {
+ let s = S;
+
+ foo(&s); // { dg-error "bounds not satisfied" }
+ // { dg-error "mismatched type" "" { target *-*-* } .-1 }
+}
--- /dev/null
+#![feature(optin_builtin_traits)]
+
+pub unsafe auto trait Send {}
+#[lang = "sync"]
+pub unsafe auto trait Sync {}
+
+trait A {
+ fn a_method(&self) {}
+}
+
+fn foo(a: &(dyn A + Send + Sync)) {
+ a.a_method();
+}
+
+struct S;
+
+impl A for S {
+ fn a_method(&self) {} // { dg-warning "unused" }
+}
+
+// These should not be necessary because they are both auto traits
+// They need to be removed once we figure out the proper implementation for each of them
+// However, it'd be silly to implement other traits in order to ensure the test is okay,
+// as these extra trait bounds are only allowed to use auto traits
+// FIXME: #3327
+// FIXME: #3326
+unsafe impl Send for S {}
+unsafe impl Sync for S {}
+
+fn main() {
+ let s = S;
+
+ foo(&s);
+}
issue-2423.rs
issue-266.rs
additional-trait-bounds2.rs
+auto_traits2.rs
+auto_traits3.rs
# please don't delete the trailing newline