-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tychk: Add more support for additional trait bounds in functions
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.
- Loading branch information
1 parent
b15bae1
commit a8520d9
Showing
7 changed files
with
78 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#![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 } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#![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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters