forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#121982 - GuillaumeGomez:rollup-kh0w7jd, r=Gui…
…llaumeGomez Rollup of 9 pull requests Successful merges: - rust-lang#120976 (constify a couple thread_local statics) - rust-lang#121576 (Convert the rest of the visitors to use `VisitorResult`) - rust-lang#121826 (Use root obligation on E0277 for some cases) - rust-lang#121928 (Extract an arguments struct for `Builder::then_else_break`) - rust-lang#121958 (Fix redundant import errors for preload extern crate) - rust-lang#121959 (Removing absolute path in proc-macro) - rust-lang#121968 (Don't run test_get_os_named_thread on win7) - rust-lang#121977 (Doc: Fix incorrect reference to integer in Atomic{Ptr,Bool}::as_ptr.) - rust-lang#121978 (Fix duplicated path in the "not found dylib" error) r? `@ghost` `@rustbot` modify labels: rollup
- Loading branch information
Showing
149 changed files
with
913 additions
and
839 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
use core::ops::ControlFlow; | ||
|
||
/// Similar to the `Try` trait, but also implemented for `()`. | ||
pub trait VisitorResult { | ||
type Residual; | ||
fn output() -> Self; | ||
fn from_residual(residual: Self::Residual) -> Self; | ||
fn from_branch(b: ControlFlow<Self::Residual>) -> Self; | ||
fn branch(self) -> ControlFlow<Self::Residual>; | ||
} | ||
|
||
impl VisitorResult for () { | ||
#[cfg(feature = "nightly")] | ||
type Residual = !; | ||
|
||
#[cfg(not(feature = "nightly"))] | ||
type Residual = core::ops::Infallible; | ||
|
||
fn output() -> Self {} | ||
fn from_residual(_: Self::Residual) -> Self {} | ||
fn from_branch(_: ControlFlow<Self::Residual>) -> Self {} | ||
fn branch(self) -> ControlFlow<Self::Residual> { | ||
ControlFlow::Continue(()) | ||
} | ||
} | ||
|
||
impl<T> VisitorResult for ControlFlow<T> { | ||
type Residual = T; | ||
|
||
fn output() -> Self { | ||
ControlFlow::Continue(()) | ||
} | ||
fn from_residual(residual: Self::Residual) -> Self { | ||
ControlFlow::Break(residual) | ||
} | ||
fn from_branch(b: Self) -> Self { | ||
b | ||
} | ||
fn branch(self) -> Self { | ||
self | ||
} | ||
} | ||
|
||
#[macro_export] | ||
macro_rules! try_visit { | ||
($e:expr) => { | ||
match $crate::visit::VisitorResult::branch($e) { | ||
core::ops::ControlFlow::Continue(()) => (), | ||
#[allow(unreachable_code)] | ||
core::ops::ControlFlow::Break(r) => { | ||
return $crate::visit::VisitorResult::from_residual(r); | ||
} | ||
} | ||
}; | ||
} | ||
|
||
#[macro_export] | ||
macro_rules! visit_opt { | ||
($visitor: expr, $method: ident, $opt: expr $(, $($extra_args: expr),* )?) => { | ||
if let Some(x) = $opt { | ||
$crate::try_visit!($visitor.$method(x $(, $($extra_args,)* )?)); | ||
} | ||
} | ||
} | ||
|
||
#[macro_export] | ||
macro_rules! walk_list { | ||
($visitor: expr, $method: ident, $list: expr $(, $($extra_args: expr),* )?) => { | ||
for elem in $list { | ||
$crate::try_visit!($visitor.$method(elem $(, $($extra_args,)* )?)); | ||
} | ||
} | ||
} | ||
|
||
#[macro_export] | ||
macro_rules! walk_visitable_list { | ||
($visitor: expr, $list: expr $(, $($extra_args: expr),* )?) => { | ||
for elem in $list { | ||
$crate::try_visit!(elem.visit_with($visitor $(, $($extra_args,)* )?)); | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.