-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1051 from sbillig/enum-tuple-ctor-fix
Fix cross-ingot inherent method resolution
- Loading branch information
Showing
16 changed files
with
193 additions
and
75 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
12 changes: 12 additions & 0 deletions
12
crates/hir-analysis/test_files/corelib/method_resolution.fe
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,12 @@ | ||
use core::{Option, panic} | ||
|
||
fn f() -> usize { | ||
let x = Option::Some(10) | ||
let y = Option::default() | ||
|
||
if y.is_some() { | ||
y.unwrap() | ||
} else { | ||
x.unwrap_or_default() | ||
} | ||
} |
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,35 @@ | ||
mod test_db; | ||
|
||
use camino::Utf8Path; | ||
use dir_test::{dir_test, Fixture}; | ||
use driver::DriverDataBase; | ||
|
||
#[test] | ||
fn analyze_corelib() { | ||
let mut db = DriverDataBase::default(); | ||
let (core, _) = db.static_core_ingot(); | ||
|
||
let core_diags = db.run_on_ingot(core); | ||
if !(core_diags.is_empty()) { | ||
core_diags.emit(&db); | ||
panic!("expected no diagnostics"); | ||
} | ||
} | ||
|
||
#[dir_test( | ||
dir: "$CARGO_MANIFEST_DIR/test_files/corelib", | ||
glob: "*.fe" | ||
)] | ||
fn corelib_standalone(fixture: Fixture<&str>) { | ||
let mut db = DriverDataBase::default(); | ||
let path = Utf8Path::new(fixture.path()); | ||
let file_name = path.file_name().unwrap(); | ||
let (core, _) = db.static_core_ingot(); | ||
let (ingot, _) = db.standalone(file_name.into(), fixture.content(), core); | ||
|
||
let local_diags = db.run_on_ingot(ingot); | ||
if !local_diags.is_empty() { | ||
local_diags.emit(&db); | ||
panic!("expected no diagnostics"); | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
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,9 @@ | ||
pub trait Default { | ||
fn default() -> Self | ||
} | ||
|
||
impl Default for usize { | ||
fn default() -> Self { | ||
0 | ||
} | ||
} |
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 |
---|---|---|
@@ -1,2 +1,7 @@ | ||
/// remove once useful code is added to core | ||
pub fn foo() { } | ||
pub use option::Option | ||
pub use default::Default | ||
|
||
extern { | ||
pub fn panic() -> ! | ||
pub fn todo() -> ! | ||
} |
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,49 @@ | ||
use ingot::Default | ||
use ingot::panic | ||
|
||
pub enum Option<T> { | ||
Some(T), | ||
None | ||
} | ||
|
||
impl<T> Option<T> { | ||
pub fn is_some(self) -> bool { | ||
match self { | ||
Self::Some(_) => true | ||
None => false | ||
} | ||
} | ||
|
||
pub fn is_none(self) -> bool { | ||
!self.is_some() | ||
} | ||
|
||
pub fn unwrap(self) -> T { | ||
match self { | ||
Self::Some(t) => t | ||
None => panic() | ||
} | ||
} | ||
|
||
pub fn unwrap_or(self, default: T) -> T { | ||
match self { | ||
Self::Some(x) => x | ||
Self::None => default | ||
} | ||
} | ||
} | ||
|
||
impl<T> Option<T> where T: Default { | ||
pub fn unwrap_or_default(self) -> T { | ||
match self { | ||
Self::Some(x) => x | ||
Self::None => T::default() | ||
} | ||
} | ||
} | ||
|
||
impl<T> Default for Option<T> { | ||
fn default() -> Self { | ||
Self::None | ||
} | ||
} |