You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We get zero candidates after a probing for a trait function call
Reproducer
I tried this code:
#[lang = "sized"]traitSized{}enumResult{Ok(i32),Err(i32)}pubtraitFrom<T>:Sized{/// Performs the conversion.fnfrom(_:T) -> Self;}impl<T>From<T>forT{fnfrom(t:T) -> Self{ t }}pubtraitTry{/// The type of this value when viewed as successful.// #[unstable(feature = "try_trait", issue = "42327")]// type Ok;/// The type of this value when viewed as failed.// #[unstable(feature = "try_trait", issue = "42327")]// type Error;/// Applies the "?" operator. A return of `Ok(t)` means that the/// execution should continue normally, and the result of `?` is the/// value `t`. A return of `Err(e)` means that execution should branch/// to the innermost enclosing `catch`, or return from the function.////// If an `Err(e)` result is returned, the value `e` will be "wrapped"/// in the return type of the enclosing scope (which must itself implement/// `Try`). Specifically, the value `X::from_error(From::from(e))`/// is returned, where `X` is the return type of the enclosing function.fninto_result(self) -> Result;/// Wrap an error value to construct the composite result. For example,/// `Result::Err(x)` and `Result::from_error(x)` are equivalent.fnfrom_error(v:i32) -> Self;/// Wrap an OK value to construct the composite result. For example,/// `Result::Ok(x)` and `Result::from_ok(x)` are equivalent.fnfrom_ok(v:i32) -> Self;}implTryforResult{// type Ok = i32;// type Error = i32;fninto_result(self) -> Result{self}fnfrom_ok(v:i32) -> Self{Result::Ok(v)}fnfrom_error(v:i32) -> Self{Result::Err(v)}}fnprint(s:&str,value:i32){extern"C"{fnprintf(s:*consti8, ...);}unsafe{printf(s as*conststras*consti8, value);}}fnbar() -> Result{Result::Ok(15)}fnbaz() -> Result{Result::Err(15)}fnfoo() -> Result{let b = matchbaz(){Result::Ok(value) => value,Result::Err(err) => {returnTry::from_error(From::from(err));},};Result::Ok(15 + b)}fnmain(){foo();}
Does the code make use of any (1.49) nightly feature ?
auto candidates
= Resolver::PathProbeImplTrait::Probe (receiver, final_segment,
trait_ref);
if (candidates.size () == 0)
{
// this means we are defaulting back to the trait_item if// possible
Resolver::TraitItemReference *trait_item_ref = nullptr;
bool ok = trait_ref->lookup_hir_trait_item (*trait_item.value (),
&trait_item_ref);
rust_assert (ok); // foundrust_assert (trait_item_ref->is_optional ()); // has definition// ^ HERE
so since we didn't find any candidates, we assume that there must be a default implementation for the function in the trait definition itself - but we should actually typecheck this to the definition of from_error in the impl of Try by Result.
This doesn't cause any issues with rustc
Expected behavior
No error
GCC Version
latest master
The text was updated successfully, but these errors were encountered:
Summary
We get zero candidates after a probing for a trait function call
Reproducer
I tried this code:
Does the code make use of any (1.49) nightly feature ?
Godbolt link
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=66219ed4855ae9e6346c285e2f93f506
Actual behavior
The following assertion is triggered:
so since we didn't find any candidates, we assume that there must be a default implementation for the function in the trait definition itself - but we should actually typecheck this to the definition of
from_error
in the impl ofTry
byResult
.This doesn't cause any issues with rustc
Expected behavior
No error
GCC Version
latest master
The text was updated successfully, but these errors were encountered: