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
Trait environment #1515
Merged
Merged
Trait environment #1515
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
638100d
Refactor a bit & introduce Environment struct
flodiebold b1b1207
Start handling environment in trait resolution
flodiebold 15862fc
Use environment for associated type normalization as well
flodiebold 9afbf2d
Unify `normalize` and `implements` to simplify code
flodiebold File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -2950,6 +2950,85 @@ fn test(o: O<S>) { | |
assert_eq!(t, "&str"); | ||
} | ||
|
||
#[test] | ||
fn generic_param_env_1() { | ||
let t = type_at( | ||
r#" | ||
//- /main.rs | ||
trait Clone {} | ||
trait Trait { fn foo(self) -> u128; } | ||
struct S; | ||
impl Clone for S {} | ||
impl<T> Trait for T where T: Clone {} | ||
fn test<T: Clone>(t: T) { t.foo()<|>; } | ||
"#, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool! This test doesn't work in IntelliJ Rust 😜 |
||
); | ||
assert_eq!(t, "u128"); | ||
} | ||
|
||
#[test] | ||
fn generic_param_env_1_not_met() { | ||
let t = type_at( | ||
r#" | ||
//- /main.rs | ||
trait Clone {} | ||
trait Trait { fn foo(self) -> u128; } | ||
struct S; | ||
impl Clone for S {} | ||
impl<T> Trait for T where T: Clone {} | ||
fn test<T>(t: T) { t.foo()<|>; } | ||
"#, | ||
); | ||
assert_eq!(t, "{unknown}"); | ||
} | ||
|
||
#[test] | ||
fn generic_param_env_2() { | ||
let t = type_at( | ||
r#" | ||
//- /main.rs | ||
trait Trait { fn foo(self) -> u128; } | ||
struct S; | ||
impl Trait for S {} | ||
fn test<T: Trait>(t: T) { t.foo()<|>; } | ||
"#, | ||
); | ||
assert_eq!(t, "u128"); | ||
} | ||
|
||
#[test] | ||
fn generic_param_env_2_not_met() { | ||
let t = type_at( | ||
r#" | ||
//- /main.rs | ||
trait Trait { fn foo(self) -> u128; } | ||
struct S; | ||
impl Trait for S {} | ||
fn test<T>(t: T) { t.foo()<|>; } | ||
"#, | ||
); | ||
assert_eq!(t, "{unknown}"); | ||
} | ||
|
||
#[test] | ||
fn generic_param_env_deref() { | ||
let t = type_at( | ||
r#" | ||
//- /main.rs | ||
#[lang = "deref"] | ||
trait Deref { | ||
type Target; | ||
} | ||
trait Trait {} | ||
impl<T> Deref for T where T: Trait { | ||
type Target = i128; | ||
} | ||
fn test<T: Trait>(t: T) { (*t)<|>; } | ||
"#, | ||
); | ||
assert_eq!(t, "i128"); | ||
} | ||
|
||
fn type_at_pos(db: &MockDatabase, pos: FilePosition) -> String { | ||
let file = db.parse(pos.file_id).ok().unwrap(); | ||
let expr = algo::find_node_at_offset::<ast::Expr>(file.syntax(), pos.offset).unwrap(); | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Micro nit about naming: perhaps this should be something like
chalk_solve
ortrait_solve
?Solve is fine within chalk itself, but, in larger context, it is a bit too ambiguous.