Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve and lower parenthesized types #3328

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
19 changes: 19 additions & 0 deletions gcc/rust/hir/rust-ast-lower-type.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "rust-ast-lower-type.h"
#include "rust-hir-map.h"
#include "rust-hir-path.h"
#include "rust-hir-type.h"
#include "rust-path.h"
#include "rust-pattern.h"

Expand Down Expand Up @@ -471,6 +472,24 @@ ASTLoweringType::visit (AST::TraitObjectType &type)
type.get_locus (), type.is_dyn ());
}

void
ASTLoweringType::visit (AST::ParenthesisedType &type)
{
auto *inner = ASTLoweringType::translate (*type.get_type_in_parens (),
default_to_static_lifetime);

auto crate_num = mappings.get_current_crate ();
Analysis::NodeMapping mapping (crate_num, type.get_node_id (),
mappings.get_next_hir_id (crate_num),
mappings.get_next_localdef_id (crate_num));

// FIXME: Do we actually need to know if a type is parenthesized in the HIR?
// or can we just use the type in parens?
translated
= new HIR::ParenthesisedType (mapping, std::unique_ptr<HIR::Type> (inner),
type.get_locus ());
}

HIR::GenericParam *
ASTLowerGenericParam::translate (AST::GenericParam &param)
{
Expand Down
2 changes: 2 additions & 0 deletions gcc/rust/hir/rust-ast-lower-type.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "rust-ast-lower-base.h"
#include "rust-ast-lower-expr.h"
#include "rust-hir-path.h"
#include "rust-type.h"

namespace Rust {
namespace HIR {
Expand Down Expand Up @@ -83,6 +84,7 @@ class ASTLoweringType : public ASTLoweringBase
void visit (AST::NeverType &type) override;
void visit (AST::TraitObjectTypeOneBound &type) override;
void visit (AST::TraitObjectType &type) override;
void visit (AST::ParenthesisedType &type) override;

private:
ASTLoweringType (bool default_to_static_lifetime)
Expand Down
6 changes: 6 additions & 0 deletions gcc/rust/resolve/rust-ast-resolve-type.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ ResolveType::visit (AST::TraitObjectType &type)
}
}

void
ResolveType::visit (AST::ParenthesisedType &type)
{
resolved_node = ResolveType::go(*type.get_type_in_parens());
}

void
ResolveType::visit (AST::ReferenceType &type)
{
Expand Down
3 changes: 3 additions & 0 deletions gcc/rust/resolve/rust-ast-resolve-type.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#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 {
Expand Down Expand Up @@ -143,6 +144,8 @@ class ResolveType : public ResolverBase

void visit (AST::TraitObjectType &type) override;

void visit (AST::ParenthesisedType &type) override;

void visit (AST::SliceType &type) override;

private:
Expand Down
6 changes: 6 additions & 0 deletions gcc/rust/typecheck/rust-hir-type-check-type.cc
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,12 @@ TypeCheckType::visit (HIR::TraitObjectType &type)
std::move (specified_bounds));
}

void
TypeCheckType::visit (HIR::ParenthesisedType &type)
{
translated = TypeCheckType::Resolve (type.get_type_in_parens ());
}

void
TypeCheckType::visit (HIR::ArrayType &type)
{
Expand Down
4 changes: 1 addition & 3 deletions gcc/rust/typecheck/rust-hir-type-check-type.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class TypeCheckType : public TypeCheckBase, public HIR::HIRTypeVisitor
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 */
Expand All @@ -69,9 +70,6 @@ class TypeCheckType : public TypeCheckBase, public HIR::HIRTypeVisitor
void visit (HIR::ImplTraitType &type) override
{ /* TODO */
}
void visit (HIR::ParenthesisedType &type) override
{ /* TODO */
}
void visit (HIR::ImplTraitTypeOneBound &type) override
{ /* TODO */
}
Expand Down
27 changes: 27 additions & 0 deletions gcc/testsuite/rust/compile/auto_traits1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// { dg-additional-options "-frust-compile-until=typecheck" }

Check failure on line 1 in gcc/testsuite/rust/compile/auto_traits1.rs

View workflow job for this annotation

GitHub Actions / build-and-check-ubuntu-64bit

Test failure (FAIL)

(test for excess errors)

Check failure on line 1 in gcc/testsuite/rust/compile/auto_traits1.rs

View workflow job for this annotation

GitHub Actions / build-and-check-ubuntu-32bit

Test failure (FAIL)

(test for excess errors)

Check failure on line 1 in gcc/testsuite/rust/compile/auto_traits1.rs

View workflow job for this annotation

GitHub Actions / build-and-check-ubuntu-64bit-glibcxx

Test failure (FAIL)

(test for excess errors)

Check failure on line 1 in gcc/testsuite/rust/compile/auto_traits1.rs

View workflow job for this annotation

GitHub Actions / build-and-check-asan

Test failure (FAIL)

(test for excess errors)

Check failure on line 1 in gcc/testsuite/rust/compile/auto_traits1.rs

View workflow job for this annotation

GitHub Actions / build-alpine-32bit-and-check-alpine-32bit

Test failure (FAIL)

(test for excess errors)

#![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);
}
26 changes: 26 additions & 0 deletions gcc/testsuite/rust/compile/auto_traits2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#![feature(optin_builtin_traits)]

Check failure on line 1 in gcc/testsuite/rust/compile/auto_traits2.rs

View workflow job for this annotation

GitHub Actions / build-and-check-ubuntu-64bit

Test failure (FAIL)

(test for excess errors)

Check failure on line 1 in gcc/testsuite/rust/compile/auto_traits2.rs

View workflow job for this annotation

GitHub Actions / build-and-check-ubuntu-32bit

Test failure (FAIL)

(test for excess errors)

Check failure on line 1 in gcc/testsuite/rust/compile/auto_traits2.rs

View workflow job for this annotation

GitHub Actions / build-and-check-ubuntu-64bit-glibcxx

Test failure (FAIL)

(test for excess errors)

Check failure on line 1 in gcc/testsuite/rust/compile/auto_traits2.rs

View workflow job for this annotation

GitHub Actions / build-and-check-asan

Test failure (FAIL)

(test for excess errors)

Check failure on line 1 in gcc/testsuite/rust/compile/auto_traits2.rs

View workflow job for this annotation

GitHub Actions / build-alpine-32bit-and-check-alpine-32bit

Test failure (FAIL)

(test for excess errors)

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)) { // { dg-error "bounds not satisfied" }

Check failure on line 11 in gcc/testsuite/rust/compile/auto_traits2.rs

View workflow job for this annotation

GitHub Actions / build-and-check-ubuntu-64bit

Test failure (FAIL)

(test for errors, line 11)

Check failure on line 11 in gcc/testsuite/rust/compile/auto_traits2.rs

View workflow job for this annotation

GitHub Actions / build-and-check-ubuntu-32bit

Test failure (FAIL)

(test for errors, line 11)

Check failure on line 11 in gcc/testsuite/rust/compile/auto_traits2.rs

View workflow job for this annotation

GitHub Actions / build-and-check-ubuntu-64bit-glibcxx

Test failure (FAIL)

(test for errors, line 11)

Check failure on line 11 in gcc/testsuite/rust/compile/auto_traits2.rs

View workflow job for this annotation

GitHub Actions / build-and-check-asan

Test failure (FAIL)

(test for errors, line 11)

Check failure on line 11 in gcc/testsuite/rust/compile/auto_traits2.rs

View workflow job for this annotation

GitHub Actions / build-alpine-32bit-and-check-alpine-32bit

Test failure (FAIL)

(test for errors, line 11)
// { dg-error "mismatched type" "" { target *-*-* } .-1 }

Check failure on line 12 in gcc/testsuite/rust/compile/auto_traits2.rs

View workflow job for this annotation

GitHub Actions / build-and-check-ubuntu-64bit

Test failure (FAIL)

at line 12 (test for errors, line 11)

Check failure on line 12 in gcc/testsuite/rust/compile/auto_traits2.rs

View workflow job for this annotation

GitHub Actions / build-and-check-ubuntu-32bit

Test failure (FAIL)

at line 12 (test for errors, line 11)

Check failure on line 12 in gcc/testsuite/rust/compile/auto_traits2.rs

View workflow job for this annotation

GitHub Actions / build-and-check-ubuntu-64bit-glibcxx

Test failure (FAIL)

at line 12 (test for errors, line 11)

Check failure on line 12 in gcc/testsuite/rust/compile/auto_traits2.rs

View workflow job for this annotation

GitHub Actions / build-and-check-asan

Test failure (FAIL)

at line 12 (test for errors, line 11)

Check failure on line 12 in gcc/testsuite/rust/compile/auto_traits2.rs

View workflow job for this annotation

GitHub Actions / build-alpine-32bit-and-check-alpine-32bit

Test failure (FAIL)

at line 12 (test for errors, line 11)
a.a_method();
}

struct S;

impl A for S {
fn a_method(&self) {}
}

fn main() {
let s = S;

foo(&s);
}
34 changes: 34 additions & 0 deletions gcc/testsuite/rust/compile/auto_traits3.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#![feature(optin_builtin_traits)]

Check failure on line 1 in gcc/testsuite/rust/compile/auto_traits3.rs

View workflow job for this annotation

GitHub Actions / build-and-check-ubuntu-64bit

Test failure (FAIL)

(test for excess errors)

Check failure on line 1 in gcc/testsuite/rust/compile/auto_traits3.rs

View workflow job for this annotation

GitHub Actions / build-and-check-ubuntu-32bit

Test failure (FAIL)

(test for excess errors)

Check failure on line 1 in gcc/testsuite/rust/compile/auto_traits3.rs

View workflow job for this annotation

GitHub Actions / build-and-check-ubuntu-64bit-glibcxx

Test failure (FAIL)

(test for excess errors)

Check failure on line 1 in gcc/testsuite/rust/compile/auto_traits3.rs

View workflow job for this annotation

GitHub Actions / build-and-check-asan

Test failure (FAIL)

(test for excess errors)

Check failure on line 1 in gcc/testsuite/rust/compile/auto_traits3.rs

View workflow job for this annotation

GitHub Actions / build-alpine-32bit-and-check-alpine-32bit

Test failure (FAIL)

(test for excess errors)

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" }

Check failure on line 18 in gcc/testsuite/rust/compile/auto_traits3.rs

View workflow job for this annotation

GitHub Actions / build-and-check-ubuntu-64bit

Test failure (FAIL)

(test for warnings, line 18)

Check failure on line 18 in gcc/testsuite/rust/compile/auto_traits3.rs

View workflow job for this annotation

GitHub Actions / build-and-check-ubuntu-32bit

Test failure (FAIL)

(test for warnings, line 18)

Check failure on line 18 in gcc/testsuite/rust/compile/auto_traits3.rs

View workflow job for this annotation

GitHub Actions / build-and-check-ubuntu-64bit-glibcxx

Test failure (FAIL)

(test for warnings, line 18)

Check failure on line 18 in gcc/testsuite/rust/compile/auto_traits3.rs

View workflow job for this annotation

GitHub Actions / build-and-check-asan

Test failure (FAIL)

(test for warnings, line 18)

Check failure on line 18 in gcc/testsuite/rust/compile/auto_traits3.rs

View workflow job for this annotation

GitHub Actions / build-alpine-32bit-and-check-alpine-32bit

Test failure (FAIL)

(test for warnings, line 18)
}

// 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);
}
Loading