mirror of
https://github.com/rust-lang/rust.git
synced 2024-10-30 22:12:15 +00:00
Auto merge of #114811 - estebank:impl-ambiguity, r=wesleywiser
Show more information when multiple `impl`s apply - When there are `impl`s without type params, show only those (to avoid showing overly generic `impl`s). ``` error[E0283]: type annotations needed --> $DIR/multiple-impl-apply.rs:34:9 | LL | let y = x.into(); | ^ ---- type must be known at this point | note: multiple `impl`s satisfying `_: From<Baz>` found --> $DIR/multiple-impl-apply.rs:14:1 | LL | impl From<Baz> for Bar { | ^^^^^^^^^^^^^^^^^^^^^^ ... LL | impl From<Baz> for Foo { | ^^^^^^^^^^^^^^^^^^^^^^ = note: required for `Baz` to implement `Into<_>` help: consider giving `y` an explicit type | LL | let y: /* Type */ = x.into(); | ++++++++++++ ``` - Lower the importance of `T: Sized`, `T: WellFormed` and coercion errors, to prioritize more relevant errors. The pre-existing deduplication logic deals with hiding redundant errors better that way, and we show errors with more metadata that is useful to the user. - Show `<SelfTy as Trait>::assoc_fn` suggestion in more cases. ``` error[E0790]: cannot call associated function on trait without specifying the corresponding `impl` type --> $DIR/cross-return-site-inference.rs:38:16 | LL | return Err(From::from("foo")); | ^^^^^^^^^^ cannot call associated function of trait | help: use a fully-qualified path to a specific available implementation | LL | return Err(</* self type */ as From>::from("foo")); | +++++++++++++++++++ + ``` Fix #88284.
This commit is contained in:
commit
94bc9c737e
@ -368,7 +368,7 @@ fn check_opaque_type_well_formed<'tcx>(
|
||||
if errors.is_empty() {
|
||||
Ok(definition_ty)
|
||||
} else {
|
||||
Err(infcx.err_ctxt().report_fulfillment_errors(&errors))
|
||||
Err(infcx.err_ctxt().report_fulfillment_errors(errors))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -743,7 +743,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
|
||||
|
||||
let errors = ocx.select_all_or_error();
|
||||
if !errors.is_empty() {
|
||||
infcx.err_ctxt().report_fulfillment_errors(&errors);
|
||||
infcx.err_ctxt().report_fulfillment_errors(errors);
|
||||
}
|
||||
|
||||
// Attempting to call a trait method?
|
||||
|
@ -3,7 +3,7 @@ The compiler could not infer a type and asked for a type annotation.
|
||||
Erroneous code example:
|
||||
|
||||
```compile_fail,E0282
|
||||
let x = "hello".chars().rev().collect();
|
||||
let x = Vec::new();
|
||||
```
|
||||
|
||||
This error indicates that type inference did not result in one unique possible
|
||||
@ -11,21 +11,24 @@ type, and extra information is required. In most cases this can be provided
|
||||
by adding a type annotation. Sometimes you need to specify a generic type
|
||||
parameter manually.
|
||||
|
||||
A common example is the `collect` method on `Iterator`. It has a generic type
|
||||
parameter with a `FromIterator` bound, which for a `char` iterator is
|
||||
implemented by `Vec` and `String` among others. Consider the following snippet
|
||||
that reverses the characters of a string:
|
||||
In the example above, type `Vec` has a type parameter `T`. When calling
|
||||
`Vec::new`, barring any other later usage of the variable `x` that allows the
|
||||
compiler to infer what type `T` is, the compiler needs to be told what it is.
|
||||
|
||||
In the first code example, the compiler cannot infer what the type of `x` should
|
||||
be: `Vec<char>` and `String` are both suitable candidates. To specify which type
|
||||
to use, you can use a type annotation on `x`:
|
||||
The type can be specified on the variable:
|
||||
|
||||
```
|
||||
let x: Vec<char> = "hello".chars().rev().collect();
|
||||
let x: Vec<i32> = Vec::new();
|
||||
```
|
||||
|
||||
It is not necessary to annotate the full type. Once the ambiguity is resolved,
|
||||
the compiler can infer the rest:
|
||||
The type can also be specified in the path of the expression:
|
||||
|
||||
```
|
||||
let x = Vec::<i32>::new();
|
||||
```
|
||||
|
||||
In cases with more complex types, it is not necessary to annotate the full
|
||||
type. Once the ambiguity is resolved, the compiler can infer the rest:
|
||||
|
||||
```
|
||||
let x: Vec<_> = "hello".chars().rev().collect();
|
||||
|
@ -1,7 +1,51 @@
|
||||
An implementation cannot be chosen unambiguously because of lack of information.
|
||||
The compiler could not infer a type and asked for a type annotation.
|
||||
|
||||
Erroneous code example:
|
||||
|
||||
```compile_fail,E0283
|
||||
let x = "hello".chars().rev().collect();
|
||||
```
|
||||
|
||||
This error indicates that type inference did not result in one unique possible
|
||||
type, and extra information is required. In most cases this can be provided
|
||||
by adding a type annotation. Sometimes you need to specify a generic type
|
||||
parameter manually.
|
||||
|
||||
A common example is the `collect` method on `Iterator`. It has a generic type
|
||||
parameter with a `FromIterator` bound, which for a `char` iterator is
|
||||
implemented by `Vec` and `String` among others. Consider the following snippet
|
||||
that reverses the characters of a string:
|
||||
|
||||
In the first code example, the compiler cannot infer what the type of `x` should
|
||||
be: `Vec<char>` and `String` are both suitable candidates. To specify which type
|
||||
to use, you can use a type annotation on `x`:
|
||||
|
||||
```
|
||||
let x: Vec<char> = "hello".chars().rev().collect();
|
||||
```
|
||||
|
||||
It is not necessary to annotate the full type. Once the ambiguity is resolved,
|
||||
the compiler can infer the rest:
|
||||
|
||||
```
|
||||
let x: Vec<_> = "hello".chars().rev().collect();
|
||||
```
|
||||
|
||||
Another way to provide the compiler with enough information, is to specify the
|
||||
generic type parameter:
|
||||
|
||||
```
|
||||
let x = "hello".chars().rev().collect::<Vec<char>>();
|
||||
```
|
||||
|
||||
Again, you need not specify the full type if the compiler can infer it:
|
||||
|
||||
```
|
||||
let x = "hello".chars().rev().collect::<Vec<_>>();
|
||||
```
|
||||
|
||||
We can see a self-contained example below:
|
||||
|
||||
```compile_fail,E0283
|
||||
struct Foo;
|
||||
|
||||
|
@ -327,7 +327,7 @@ fn check_opaque_meets_bounds<'tcx>(
|
||||
// version.
|
||||
let errors = ocx.select_all_or_error();
|
||||
if !errors.is_empty() {
|
||||
let guar = infcx.err_ctxt().report_fulfillment_errors(&errors);
|
||||
let guar = infcx.err_ctxt().report_fulfillment_errors(errors);
|
||||
return Err(guar);
|
||||
}
|
||||
match origin {
|
||||
@ -1512,6 +1512,6 @@ pub(super) fn check_generator_obligations(tcx: TyCtxt<'_>, def_id: LocalDefId) {
|
||||
let errors = fulfillment_cx.select_all_or_error(&infcx);
|
||||
debug!(?errors);
|
||||
if !errors.is_empty() {
|
||||
infcx.err_ctxt().report_fulfillment_errors(&errors);
|
||||
infcx.err_ctxt().report_fulfillment_errors(errors);
|
||||
}
|
||||
}
|
||||
|
@ -323,7 +323,7 @@ fn compare_method_predicate_entailment<'tcx>(
|
||||
// FIXME(-Ztrait-solver=next): Not needed when the hack below is removed.
|
||||
let errors = ocx.select_where_possible();
|
||||
if !errors.is_empty() {
|
||||
let reported = infcx.err_ctxt().report_fulfillment_errors(&errors);
|
||||
let reported = infcx.err_ctxt().report_fulfillment_errors(errors);
|
||||
return Err(reported);
|
||||
}
|
||||
|
||||
@ -394,7 +394,7 @@ fn compare_method_predicate_entailment<'tcx>(
|
||||
});
|
||||
}
|
||||
CheckImpliedWfMode::Skip => {
|
||||
let reported = infcx.err_ctxt().report_fulfillment_errors(&errors);
|
||||
let reported = infcx.err_ctxt().report_fulfillment_errors(errors);
|
||||
return Err(reported);
|
||||
}
|
||||
}
|
||||
@ -874,7 +874,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
|
||||
// RPITs.
|
||||
let errors = ocx.select_all_or_error();
|
||||
if !errors.is_empty() {
|
||||
let reported = infcx.err_ctxt().report_fulfillment_errors(&errors);
|
||||
let reported = infcx.err_ctxt().report_fulfillment_errors(errors);
|
||||
return Err(reported);
|
||||
}
|
||||
|
||||
@ -2050,7 +2050,7 @@ fn compare_const_predicate_entailment<'tcx>(
|
||||
// version.
|
||||
let errors = ocx.select_all_or_error();
|
||||
if !errors.is_empty() {
|
||||
return Err(infcx.err_ctxt().report_fulfillment_errors(&errors));
|
||||
return Err(infcx.err_ctxt().report_fulfillment_errors(errors));
|
||||
}
|
||||
|
||||
let outlives_env = OutlivesEnvironment::new(param_env);
|
||||
@ -2143,7 +2143,7 @@ fn compare_type_predicate_entailment<'tcx>(
|
||||
// version.
|
||||
let errors = ocx.select_all_or_error();
|
||||
if !errors.is_empty() {
|
||||
let reported = infcx.err_ctxt().report_fulfillment_errors(&errors);
|
||||
let reported = infcx.err_ctxt().report_fulfillment_errors(errors);
|
||||
return Err(reported);
|
||||
}
|
||||
|
||||
@ -2358,7 +2358,7 @@ pub(super) fn check_type_bounds<'tcx>(
|
||||
// version.
|
||||
let errors = ocx.select_all_or_error();
|
||||
if !errors.is_empty() {
|
||||
let reported = infcx.err_ctxt().report_fulfillment_errors(&errors);
|
||||
let reported = infcx.err_ctxt().report_fulfillment_errors(errors);
|
||||
return Err(reported);
|
||||
}
|
||||
|
||||
|
@ -158,7 +158,7 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
|
||||
ocx.register_bound(cause, param_env, norm_return_ty, term_did);
|
||||
let errors = ocx.select_all_or_error();
|
||||
if !errors.is_empty() {
|
||||
infcx.err_ctxt().report_fulfillment_errors(&errors);
|
||||
infcx.err_ctxt().report_fulfillment_errors(errors);
|
||||
error = true;
|
||||
}
|
||||
// now we can take the return type of the given main function
|
||||
|
@ -588,7 +588,7 @@ pub fn check_function_signature<'tcx>(
|
||||
Ok(()) => {
|
||||
let errors = ocx.select_all_or_error();
|
||||
if !errors.is_empty() {
|
||||
infcx.err_ctxt().report_fulfillment_errors(&errors);
|
||||
infcx.err_ctxt().report_fulfillment_errors(errors);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -116,7 +116,7 @@ pub(super) fn enter_wf_checking_ctxt<'tcx, F>(
|
||||
|
||||
let errors = wfcx.select_all_or_error();
|
||||
if !errors.is_empty() {
|
||||
infcx.err_ctxt().report_fulfillment_errors(&errors);
|
||||
infcx.err_ctxt().report_fulfillment_errors(errors);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -261,7 +261,7 @@ fn visit_implementation_of_dispatch_from_dyn(tcx: TyCtxt<'_>, impl_did: LocalDef
|
||||
}
|
||||
let errors = ocx.select_all_or_error();
|
||||
if !errors.is_empty() {
|
||||
infcx.err_ctxt().report_fulfillment_errors(&errors);
|
||||
infcx.err_ctxt().report_fulfillment_errors(errors);
|
||||
}
|
||||
|
||||
// Finally, resolve all regions.
|
||||
@ -470,7 +470,7 @@ pub fn coerce_unsized_info<'tcx>(tcx: TyCtxt<'tcx>, impl_did: LocalDefId) -> Coe
|
||||
ocx.register_obligation(obligation);
|
||||
let errors = ocx.select_all_or_error();
|
||||
if !errors.is_empty() {
|
||||
infcx.err_ctxt().report_fulfillment_errors(&errors);
|
||||
infcx.err_ctxt().report_fulfillment_errors(errors);
|
||||
}
|
||||
|
||||
// Finally, resolve all regions.
|
||||
|
@ -196,7 +196,7 @@ fn get_impl_args(
|
||||
|
||||
let errors = ocx.select_all_or_error();
|
||||
if !errors.is_empty() {
|
||||
let guar = ocx.infcx.err_ctxt().report_fulfillment_errors(&errors);
|
||||
let guar = ocx.infcx.err_ctxt().report_fulfillment_errors(errors);
|
||||
return Err(guar);
|
||||
}
|
||||
|
||||
|
@ -2958,7 +2958,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
// There should be at least one error reported. If not, we
|
||||
// will still delay a span bug in `report_fulfillment_errors`.
|
||||
Ok::<_, NoSolution>((
|
||||
self.err_ctxt().report_fulfillment_errors(&errors),
|
||||
self.err_ctxt().report_fulfillment_errors(errors),
|
||||
impl_trait_ref.args.type_at(1),
|
||||
element_ty,
|
||||
))
|
||||
|
@ -564,7 +564,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
|
||||
if !errors.is_empty() {
|
||||
self.adjust_fulfillment_errors_for_expr_obligation(&mut errors);
|
||||
self.err_ctxt().report_fulfillment_errors(&errors);
|
||||
self.err_ctxt().report_fulfillment_errors(errors);
|
||||
}
|
||||
}
|
||||
|
||||
@ -577,7 +577,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
if !result.is_empty() {
|
||||
mutate_fulfillment_errors(&mut result);
|
||||
self.adjust_fulfillment_errors_for_expr_obligation(&mut result);
|
||||
self.err_ctxt().report_fulfillment_errors(&result);
|
||||
self.err_ctxt().report_fulfillment_errors(result);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1477,7 +1477,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
{
|
||||
Ok(normalized_ty) => normalized_ty,
|
||||
Err(errors) => {
|
||||
let guar = self.err_ctxt().report_fulfillment_errors(&errors);
|
||||
let guar = self.err_ctxt().report_fulfillment_errors(errors);
|
||||
return Ty::new_error(self.tcx,guar);
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ use std::iter;
|
||||
|
||||
pub enum TypeAnnotationNeeded {
|
||||
/// ```compile_fail,E0282
|
||||
/// let x = "hello".chars().rev().collect();
|
||||
/// let x;
|
||||
/// ```
|
||||
E0282,
|
||||
/// An implementation cannot be chosen unambiguously because of lack of information.
|
||||
|
@ -2373,7 +2373,7 @@ impl CheckAttrVisitor<'_> {
|
||||
|
||||
let errors = ocx.select_all_or_error();
|
||||
if !errors.is_empty() {
|
||||
infcx.err_ctxt().report_fulfillment_errors(&errors);
|
||||
infcx.err_ctxt().report_fulfillment_errors(errors);
|
||||
self.abort.set(true);
|
||||
}
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ pub fn ensure_wf<'tcx>(
|
||||
ocx.register_obligation(obligation);
|
||||
let errors = ocx.select_all_or_error();
|
||||
if !errors.is_empty() {
|
||||
infcx.err_ctxt().report_fulfillment_errors(&errors);
|
||||
infcx.err_ctxt().report_fulfillment_errors(errors);
|
||||
false
|
||||
} else {
|
||||
// looks WF!
|
||||
|
@ -218,7 +218,7 @@ impl<'a, 'tcx> ObligationCtxt<'a, 'tcx> {
|
||||
def_id: LocalDefId,
|
||||
) -> Result<FxIndexSet<Ty<'tcx>>, ErrorGuaranteed> {
|
||||
self.assumed_wf_types(param_env, def_id)
|
||||
.map_err(|errors| self.infcx.err_ctxt().report_fulfillment_errors(&errors))
|
||||
.map_err(|errors| self.infcx.err_ctxt().report_fulfillment_errors(errors))
|
||||
}
|
||||
|
||||
pub fn assumed_wf_types(
|
||||
|
@ -0,0 +1,275 @@
|
||||
use crate::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
|
||||
use crate::infer::InferCtxt;
|
||||
use crate::traits::{Obligation, ObligationCause, ObligationCtxt};
|
||||
use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder, ErrorGuaranteed};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::Node;
|
||||
use rustc_middle::ty::{self, Ty};
|
||||
use rustc_span::{Span, DUMMY_SP};
|
||||
|
||||
use super::ArgKind;
|
||||
|
||||
pub use rustc_infer::traits::error_reporting::*;
|
||||
|
||||
pub trait InferCtxtExt<'tcx> {
|
||||
/// Given some node representing a fn-like thing in the HIR map,
|
||||
/// returns a span and `ArgKind` information that describes the
|
||||
/// arguments it expects. This can be supplied to
|
||||
/// `report_arg_count_mismatch`.
|
||||
fn get_fn_like_arguments(&self, node: Node<'_>) -> Option<(Span, Option<Span>, Vec<ArgKind>)>;
|
||||
|
||||
/// Reports an error when the number of arguments needed by a
|
||||
/// trait match doesn't match the number that the expression
|
||||
/// provides.
|
||||
fn report_arg_count_mismatch(
|
||||
&self,
|
||||
span: Span,
|
||||
found_span: Option<Span>,
|
||||
expected_args: Vec<ArgKind>,
|
||||
found_args: Vec<ArgKind>,
|
||||
is_closure: bool,
|
||||
closure_pipe_span: Option<Span>,
|
||||
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed>;
|
||||
|
||||
/// Checks if the type implements one of `Fn`, `FnMut`, or `FnOnce`
|
||||
/// in that order, and returns the generic type corresponding to the
|
||||
/// argument of that trait (corresponding to the closure arguments).
|
||||
fn type_implements_fn_trait(
|
||||
&self,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
ty: ty::Binder<'tcx, Ty<'tcx>>,
|
||||
polarity: ty::ImplPolarity,
|
||||
) -> Result<(ty::ClosureKind, ty::Binder<'tcx, Ty<'tcx>>), ()>;
|
||||
}
|
||||
|
||||
impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
|
||||
/// Given some node representing a fn-like thing in the HIR map,
|
||||
/// returns a span and `ArgKind` information that describes the
|
||||
/// arguments it expects. This can be supplied to
|
||||
/// `report_arg_count_mismatch`.
|
||||
fn get_fn_like_arguments(&self, node: Node<'_>) -> Option<(Span, Option<Span>, Vec<ArgKind>)> {
|
||||
let sm = self.tcx.sess.source_map();
|
||||
let hir = self.tcx.hir();
|
||||
Some(match node {
|
||||
Node::Expr(&hir::Expr {
|
||||
kind: hir::ExprKind::Closure(&hir::Closure { body, fn_decl_span, fn_arg_span, .. }),
|
||||
..
|
||||
}) => (
|
||||
fn_decl_span,
|
||||
fn_arg_span,
|
||||
hir.body(body)
|
||||
.params
|
||||
.iter()
|
||||
.map(|arg| {
|
||||
if let hir::Pat { kind: hir::PatKind::Tuple(ref args, _), span, .. } =
|
||||
*arg.pat
|
||||
{
|
||||
Some(ArgKind::Tuple(
|
||||
Some(span),
|
||||
args.iter()
|
||||
.map(|pat| {
|
||||
sm.span_to_snippet(pat.span)
|
||||
.ok()
|
||||
.map(|snippet| (snippet, "_".to_owned()))
|
||||
})
|
||||
.collect::<Option<Vec<_>>>()?,
|
||||
))
|
||||
} else {
|
||||
let name = sm.span_to_snippet(arg.pat.span).ok()?;
|
||||
Some(ArgKind::Arg(name, "_".to_owned()))
|
||||
}
|
||||
})
|
||||
.collect::<Option<Vec<ArgKind>>>()?,
|
||||
),
|
||||
Node::Item(&hir::Item { kind: hir::ItemKind::Fn(ref sig, ..), .. })
|
||||
| Node::ImplItem(&hir::ImplItem { kind: hir::ImplItemKind::Fn(ref sig, _), .. })
|
||||
| Node::TraitItem(&hir::TraitItem {
|
||||
kind: hir::TraitItemKind::Fn(ref sig, _), ..
|
||||
}) => (
|
||||
sig.span,
|
||||
None,
|
||||
sig.decl
|
||||
.inputs
|
||||
.iter()
|
||||
.map(|arg| match arg.kind {
|
||||
hir::TyKind::Tup(ref tys) => ArgKind::Tuple(
|
||||
Some(arg.span),
|
||||
vec![("_".to_owned(), "_".to_owned()); tys.len()],
|
||||
),
|
||||
_ => ArgKind::empty(),
|
||||
})
|
||||
.collect::<Vec<ArgKind>>(),
|
||||
),
|
||||
Node::Ctor(ref variant_data) => {
|
||||
let span = variant_data.ctor_hir_id().map_or(DUMMY_SP, |id| hir.span(id));
|
||||
(span, None, vec![ArgKind::empty(); variant_data.fields().len()])
|
||||
}
|
||||
_ => panic!("non-FnLike node found: {node:?}"),
|
||||
})
|
||||
}
|
||||
|
||||
/// Reports an error when the number of arguments needed by a
|
||||
/// trait match doesn't match the number that the expression
|
||||
/// provides.
|
||||
fn report_arg_count_mismatch(
|
||||
&self,
|
||||
span: Span,
|
||||
found_span: Option<Span>,
|
||||
expected_args: Vec<ArgKind>,
|
||||
found_args: Vec<ArgKind>,
|
||||
is_closure: bool,
|
||||
closure_arg_span: Option<Span>,
|
||||
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
|
||||
let kind = if is_closure { "closure" } else { "function" };
|
||||
|
||||
let args_str = |arguments: &[ArgKind], other: &[ArgKind]| {
|
||||
let arg_length = arguments.len();
|
||||
let distinct = matches!(other, &[ArgKind::Tuple(..)]);
|
||||
match (arg_length, arguments.get(0)) {
|
||||
(1, Some(ArgKind::Tuple(_, fields))) => {
|
||||
format!("a single {}-tuple as argument", fields.len())
|
||||
}
|
||||
_ => format!(
|
||||
"{} {}argument{}",
|
||||
arg_length,
|
||||
if distinct && arg_length > 1 { "distinct " } else { "" },
|
||||
pluralize!(arg_length)
|
||||
),
|
||||
}
|
||||
};
|
||||
|
||||
let expected_str = args_str(&expected_args, &found_args);
|
||||
let found_str = args_str(&found_args, &expected_args);
|
||||
|
||||
let mut err = struct_span_err!(
|
||||
self.tcx.sess,
|
||||
span,
|
||||
E0593,
|
||||
"{} is expected to take {}, but it takes {}",
|
||||
kind,
|
||||
expected_str,
|
||||
found_str,
|
||||
);
|
||||
|
||||
err.span_label(span, format!("expected {kind} that takes {expected_str}"));
|
||||
|
||||
if let Some(found_span) = found_span {
|
||||
err.span_label(found_span, format!("takes {found_str}"));
|
||||
|
||||
// Suggest to take and ignore the arguments with expected_args_length `_`s if
|
||||
// found arguments is empty (assume the user just wants to ignore args in this case).
|
||||
// For example, if `expected_args_length` is 2, suggest `|_, _|`.
|
||||
if found_args.is_empty() && is_closure {
|
||||
let underscores = vec!["_"; expected_args.len()].join(", ");
|
||||
err.span_suggestion_verbose(
|
||||
closure_arg_span.unwrap_or(found_span),
|
||||
format!(
|
||||
"consider changing the closure to take and ignore the expected argument{}",
|
||||
pluralize!(expected_args.len())
|
||||
),
|
||||
format!("|{underscores}|"),
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
}
|
||||
|
||||
if let &[ArgKind::Tuple(_, ref fields)] = &found_args[..] {
|
||||
if fields.len() == expected_args.len() {
|
||||
let sugg = fields
|
||||
.iter()
|
||||
.map(|(name, _)| name.to_owned())
|
||||
.collect::<Vec<String>>()
|
||||
.join(", ");
|
||||
err.span_suggestion_verbose(
|
||||
found_span,
|
||||
"change the closure to take multiple arguments instead of a single tuple",
|
||||
format!("|{sugg}|"),
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
}
|
||||
}
|
||||
if let &[ArgKind::Tuple(_, ref fields)] = &expected_args[..]
|
||||
&& fields.len() == found_args.len()
|
||||
&& is_closure
|
||||
{
|
||||
let sugg = format!(
|
||||
"|({}){}|",
|
||||
found_args
|
||||
.iter()
|
||||
.map(|arg| match arg {
|
||||
ArgKind::Arg(name, _) => name.to_owned(),
|
||||
_ => "_".to_owned(),
|
||||
})
|
||||
.collect::<Vec<String>>()
|
||||
.join(", "),
|
||||
// add type annotations if available
|
||||
if found_args.iter().any(|arg| match arg {
|
||||
ArgKind::Arg(_, ty) => ty != "_",
|
||||
_ => false,
|
||||
}) {
|
||||
format!(
|
||||
": ({})",
|
||||
fields
|
||||
.iter()
|
||||
.map(|(_, ty)| ty.to_owned())
|
||||
.collect::<Vec<String>>()
|
||||
.join(", ")
|
||||
)
|
||||
} else {
|
||||
String::new()
|
||||
},
|
||||
);
|
||||
err.span_suggestion_verbose(
|
||||
found_span,
|
||||
"change the closure to accept a tuple instead of individual arguments",
|
||||
sugg,
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
err
|
||||
}
|
||||
|
||||
fn type_implements_fn_trait(
|
||||
&self,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
ty: ty::Binder<'tcx, Ty<'tcx>>,
|
||||
polarity: ty::ImplPolarity,
|
||||
) -> Result<(ty::ClosureKind, ty::Binder<'tcx, Ty<'tcx>>), ()> {
|
||||
self.commit_if_ok(|_| {
|
||||
for trait_def_id in [
|
||||
self.tcx.lang_items().fn_trait(),
|
||||
self.tcx.lang_items().fn_mut_trait(),
|
||||
self.tcx.lang_items().fn_once_trait(),
|
||||
] {
|
||||
let Some(trait_def_id) = trait_def_id else { continue };
|
||||
// Make a fresh inference variable so we can determine what the substitutions
|
||||
// of the trait are.
|
||||
let var = self.next_ty_var(TypeVariableOrigin {
|
||||
span: DUMMY_SP,
|
||||
kind: TypeVariableOriginKind::MiscVariable,
|
||||
});
|
||||
// FIXME(effects)
|
||||
let trait_ref = ty::TraitRef::new(self.tcx, trait_def_id, [ty.skip_binder(), var]);
|
||||
let obligation = Obligation::new(
|
||||
self.tcx,
|
||||
ObligationCause::dummy(),
|
||||
param_env,
|
||||
ty.rebind(ty::TraitPredicate { trait_ref, polarity }),
|
||||
);
|
||||
let ocx = ObligationCtxt::new(self);
|
||||
ocx.register_obligation(obligation);
|
||||
if ocx.select_all_or_error().is_empty() {
|
||||
return Ok((
|
||||
self.tcx
|
||||
.fn_trait_kind_from_def_id(trait_def_id)
|
||||
.expect("expected to map DefId to ClosureKind"),
|
||||
ty.rebind(self.resolve_vars_if_possible(var)),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
Err(())
|
||||
})
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -18,7 +18,7 @@ use crate::errors::{
|
||||
EmptyOnClauseInOnUnimplemented, InvalidOnClauseInOnUnimplemented, NoValueInOnUnimplemented,
|
||||
};
|
||||
|
||||
use super::InferCtxtPrivExt;
|
||||
use crate::traits::error_reporting::type_err_ctxt_ext::InferCtxtPrivExt;
|
||||
|
||||
pub trait TypeErrCtxtExt<'tcx> {
|
||||
/*private*/
|
||||
|
@ -41,8 +41,8 @@ use rustc_target::spec::abi;
|
||||
use std::borrow::Cow;
|
||||
use std::iter;
|
||||
|
||||
use super::InferCtxtPrivExt;
|
||||
use crate::infer::InferCtxtExt as _;
|
||||
use crate::traits::error_reporting::type_err_ctxt_ext::InferCtxtPrivExt;
|
||||
use crate::traits::query::evaluate_obligation::InferCtxtExt as _;
|
||||
use rustc_middle::ty::print::{with_forced_trimmed_paths, with_no_trimmed_paths};
|
||||
|
||||
@ -4254,6 +4254,39 @@ impl<'a, 'hir> hir::intravisit::Visitor<'hir> for ReplaceImplTraitVisitor<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn get_explanation_based_on_obligation<'tcx>(
|
||||
obligation: &PredicateObligation<'tcx>,
|
||||
trait_ref: ty::PolyTraitRef<'tcx>,
|
||||
trait_predicate: &ty::PolyTraitPredicate<'tcx>,
|
||||
pre_message: String,
|
||||
) -> String {
|
||||
if let ObligationCauseCode::MainFunctionType = obligation.cause.code() {
|
||||
"consider using `()`, or a `Result`".to_owned()
|
||||
} else {
|
||||
let ty_desc = match trait_ref.skip_binder().self_ty().kind() {
|
||||
ty::FnDef(_, _) => Some("fn item"),
|
||||
ty::Closure(_, _) => Some("closure"),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
match ty_desc {
|
||||
Some(desc) => format!(
|
||||
"{}the trait `{}` is not implemented for {} `{}`",
|
||||
pre_message,
|
||||
trait_predicate.print_modifiers_and_trait_path(),
|
||||
desc,
|
||||
trait_ref.skip_binder().self_ty(),
|
||||
),
|
||||
None => format!(
|
||||
"{}the trait `{}` is not implemented for `{}`",
|
||||
pre_message,
|
||||
trait_predicate.print_modifiers_and_trait_path(),
|
||||
trait_ref.skip_binder().self_ty(),
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Replace `param` with `replace_ty`
|
||||
struct ReplaceImplTraitFolder<'tcx> {
|
||||
tcx: TyCtxt<'tcx>,
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -204,7 +204,7 @@ fn do_normalize_predicates<'tcx>(
|
||||
let predicates = match fully_normalize(&infcx, cause, elaborated_env, predicates) {
|
||||
Ok(predicates) => predicates,
|
||||
Err(errors) => {
|
||||
let reported = infcx.err_ctxt().report_fulfillment_errors(&errors);
|
||||
let reported = infcx.err_ctxt().report_fulfillment_errors(errors);
|
||||
return Err(reported);
|
||||
}
|
||||
};
|
||||
|
@ -2,7 +2,7 @@ error[E0282]: type annotations needed for `Vec<T>`
|
||||
--> $DIR/vector-no-ann.rs:2:9
|
||||
|
|
||||
LL | let _foo = Vec::new();
|
||||
| ^^^^
|
||||
| ^^^^ ---------- type must be known at this point
|
||||
|
|
||||
help: consider giving `_foo` an explicit type, where the type for type parameter `T` is specified
|
||||
|
|
||||
|
@ -1,3 +1,11 @@
|
||||
error: unconstrained generic constant
|
||||
--> $DIR/const-argument-if-length.rs:17:10
|
||||
|
|
||||
LL | pad: [u8; is_zst::<T>()],
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: try adding a `where` bound using this expression: `where [(); is_zst::<T>()]:`
|
||||
|
||||
error[E0277]: the size for values of type `T` cannot be known at compilation time
|
||||
--> $DIR/const-argument-if-length.rs:15:12
|
||||
|
|
||||
@ -22,14 +30,6 @@ help: the `Box` type always has a statically known size and allocates its conten
|
||||
LL | value: Box<T>,
|
||||
| ++++ +
|
||||
|
||||
error: unconstrained generic constant
|
||||
--> $DIR/const-argument-if-length.rs:17:10
|
||||
|
|
||||
LL | pad: [u8; is_zst::<T>()],
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: try adding a `where` bound using this expression: `where [(); is_zst::<T>()]:`
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0277`.
|
||||
|
@ -1,9 +1,18 @@
|
||||
error[E0282]: type annotations needed
|
||||
error[E0283]: type annotations needed
|
||||
--> $DIR/issue-83249.rs:19:9
|
||||
|
|
||||
LL | let _ = foo([0; 1]);
|
||||
| ^
|
||||
| ^ --- ------ type must be known at this point
|
||||
| |
|
||||
| required by a bound introduced by this call
|
||||
|
|
||||
= note: cannot satisfy `_: Foo`
|
||||
= help: the trait `Foo` is implemented for `u8`
|
||||
note: required by a bound in `foo`
|
||||
--> $DIR/issue-83249.rs:12:11
|
||||
|
|
||||
LL | fn foo<T: Foo>(_: [u8; T::N]) -> T {
|
||||
| ^^^ required by this bound in `foo`
|
||||
help: consider giving this pattern a type
|
||||
|
|
||||
LL | let _: /* Type */ = foo([0; 1]);
|
||||
@ -11,4 +20,4 @@ LL | let _: /* Type */ = foo([0; 1]);
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0282`.
|
||||
For more information about this error, try `rustc --explain E0283`.
|
||||
|
@ -1,4 +1,4 @@
|
||||
fn main() {
|
||||
let x = "hello".chars().rev().collect();
|
||||
let x;
|
||||
//~^ ERROR E0282
|
||||
}
|
||||
|
@ -1,13 +1,13 @@
|
||||
error[E0282]: type annotations needed
|
||||
--> $DIR/E0282.rs:2:9
|
||||
|
|
||||
LL | let x = "hello".chars().rev().collect();
|
||||
LL | let x;
|
||||
| ^
|
||||
|
|
||||
help: consider giving `x` an explicit type
|
||||
|
|
||||
LL | let x: Vec<_> = "hello".chars().rev().collect();
|
||||
| ++++++++
|
||||
LL | let x: /* Type */;
|
||||
| ++++++++++++
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -32,12 +32,18 @@ LL | fn helper(sel: &Self) -> u8 {
|
||||
| use of generic parameter from outer item
|
||||
| refer to the type directly here instead
|
||||
|
||||
error[E0282]: type annotations needed
|
||||
error[E0283]: type annotations needed
|
||||
--> $DIR/E0401.rs:11:5
|
||||
|
|
||||
LL | bfnr(x);
|
||||
| ^^^^ cannot infer type of the type parameter `U` declared on the function `bfnr`
|
||||
| ^^^^ cannot infer type of the type parameter `V` declared on the function `bfnr`
|
||||
|
|
||||
= note: cannot satisfy `_: Baz<_>`
|
||||
note: required by a bound in `bfnr`
|
||||
--> $DIR/E0401.rs:4:19
|
||||
|
|
||||
LL | fn bfnr<U, V: Baz<U>, W: Fn()>(y: T) {
|
||||
| ^^^^^^ required by this bound in `bfnr`
|
||||
help: consider specifying the generic arguments
|
||||
|
|
||||
LL | bfnr::<U, V, W>(x);
|
||||
@ -66,5 +72,5 @@ LL | bfnr::<U, V, W>(x);
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0282, E0283, E0401.
|
||||
For more information about an error, try `rustc --explain E0282`.
|
||||
Some errors have detailed explanations: E0283, E0401.
|
||||
For more information about an error, try `rustc --explain E0283`.
|
||||
|
@ -44,12 +44,6 @@ LL | for item in *things { *item = 0 }
|
||||
= note: all local variables must have a statically known size
|
||||
= help: unsized locals are gated as an unstable feature
|
||||
|
||||
error: the type `Option<<<dyn Iterator<Item = &'a mut u8> as IntoIterator>::IntoIter as Iterator>::Item>` is not well-formed
|
||||
--> $DIR/issue-20605.rs:5:17
|
||||
|
|
||||
LL | for item in *things { *item = 0 }
|
||||
| ^^^^^^^
|
||||
|
||||
error[E0277]: the size for values of type `<<dyn Iterator<Item = &'a mut u8> as IntoIterator>::IntoIter as Iterator>::Item` cannot be known at compilation time
|
||||
--> $DIR/issue-20605.rs:5:5
|
||||
|
|
||||
@ -60,6 +54,12 @@ LL | for item in *things { *item = 0 }
|
||||
note: required by a bound in `None`
|
||||
--> $SRC_DIR/core/src/option.rs:LL:COL
|
||||
|
||||
error: the type `Option<<<dyn Iterator<Item = &'a mut u8> as IntoIterator>::IntoIter as Iterator>::Item>` is not well-formed
|
||||
--> $DIR/issue-20605.rs:5:17
|
||||
|
|
||||
LL | for item in *things { *item = 0 }
|
||||
| ^^^^^^^
|
||||
|
||||
error[E0614]: type `<<dyn Iterator<Item = &'a mut u8> as IntoIterator>::IntoIter as Iterator>::Item` cannot be dereferenced
|
||||
--> $DIR/issue-20605.rs:5:27
|
||||
|
|
||||
|
@ -1,9 +1,10 @@
|
||||
error[E0282]: type annotations needed
|
||||
error[E0284]: type annotations needed
|
||||
--> $DIR/issue-91762.rs:24:15
|
||||
|
|
||||
LL | ret = <Self::Base as Functor>::fmap(arg);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type of the type parameter `T` declared on the associated function `fmap`
|
||||
|
|
||||
= note: cannot satisfy `<<Self as FunctorExt<T>>::Base as Functor>::With<_> == Self`
|
||||
help: consider specifying the generic arguments
|
||||
|
|
||||
LL | ret = <Self::Base as Functor>::fmap::<T, U>(arg);
|
||||
@ -11,4 +12,4 @@ LL | ret = <Self::Base as Functor>::fmap::<T, U>(arg);
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0282`.
|
||||
For more information about this error, try `rustc --explain E0284`.
|
||||
|
@ -2,7 +2,7 @@ error[E0282]: type annotations needed for `Option<T>`
|
||||
--> $DIR/inference-failure.rs:8:9
|
||||
|
|
||||
LL | let _ = NONE;
|
||||
| ^
|
||||
| ^ ---- type must be known at this point
|
||||
|
|
||||
help: consider giving this pattern a type, where the type for type parameter `T` is specified
|
||||
|
|
||||
|
@ -36,13 +36,13 @@ fn muh() -> Result<(), impl std::fmt::Debug> {
|
||||
|
||||
fn muh2() -> Result<(), impl std::fmt::Debug> {
|
||||
return Err(From::from("foo"));
|
||||
//~^ ERROR type annotations needed
|
||||
//~^ ERROR cannot call associated function on trait
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn muh3() -> Result<(), impl std::fmt::Debug> {
|
||||
Err(From::from("foo"))
|
||||
//~^ ERROR type annotations needed
|
||||
//~^ ERROR cannot call associated function on trait
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
@ -9,28 +9,29 @@ help: consider specifying the generic arguments
|
||||
LL | Ok::<(), E>(())
|
||||
| +++++++++
|
||||
|
||||
error[E0282]: type annotations needed
|
||||
--> $DIR/cross-return-site-inference.rs:38:12
|
||||
error[E0790]: cannot call associated function on trait without specifying the corresponding `impl` type
|
||||
--> $DIR/cross-return-site-inference.rs:38:16
|
||||
|
|
||||
LL | return Err(From::from("foo"));
|
||||
| ^^^ cannot infer type of the type parameter `E` declared on the enum `Result`
|
||||
| ^^^^^^^^^^ cannot call associated function of trait
|
||||
|
|
||||
help: consider specifying the generic arguments
|
||||
help: use a fully-qualified path to a specific available implementation
|
||||
|
|
||||
LL | return Err::<(), E>(From::from("foo"));
|
||||
| +++++++++
|
||||
LL | return Err(</* self type */ as From>::from("foo"));
|
||||
| +++++++++++++++++++ +
|
||||
|
||||
error[E0282]: type annotations needed
|
||||
--> $DIR/cross-return-site-inference.rs:44:5
|
||||
error[E0790]: cannot call associated function on trait without specifying the corresponding `impl` type
|
||||
--> $DIR/cross-return-site-inference.rs:44:9
|
||||
|
|
||||
LL | Err(From::from("foo"))
|
||||
| ^^^ cannot infer type of the type parameter `E` declared on the enum `Result`
|
||||
| ^^^^^^^^^^ cannot call associated function of trait
|
||||
|
|
||||
help: consider specifying the generic arguments
|
||||
help: use a fully-qualified path to a specific available implementation
|
||||
|
|
||||
LL | Err::<(), E>(From::from("foo"))
|
||||
| +++++++++
|
||||
LL | Err(</* self type */ as From>::from("foo"))
|
||||
| +++++++++++++++++++ +
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0282`.
|
||||
Some errors have detailed explanations: E0282, E0790.
|
||||
For more information about an error, try `rustc --explain E0282`.
|
||||
|
@ -2,7 +2,7 @@ error[E0282]: type annotations needed for `RaceBuilder<T, Never<T>>`
|
||||
--> $DIR/issue-84073.rs:32:16
|
||||
|
|
||||
LL | Race::new(|race| race.when());
|
||||
| ^^^^
|
||||
| ^^^^ ---- type must be known at this point
|
||||
|
|
||||
help: consider giving this closure parameter an explicit type, where the type for type parameter `T` is specified
|
||||
|
|
||||
|
@ -1,9 +1,11 @@
|
||||
error[E0282]: type annotations needed
|
||||
error[E0283]: type annotations needed
|
||||
--> $DIR/opaque-cast-field-access-in-future.rs:22:17
|
||||
|
|
||||
LL | fn run() -> Foo<impl Future<Output = ()>> {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type
|
||||
|
|
||||
= note: cannot satisfy `_: Future`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0282`.
|
||||
For more information about this error, try `rustc --explain E0283`.
|
||||
|
@ -1,9 +1,11 @@
|
||||
error[E0282]: type annotations needed
|
||||
error[E0283]: type annotations needed
|
||||
--> $DIR/where-allowed-2.rs:3:30
|
||||
|
|
||||
LL | fn in_adt_in_return() -> Vec<impl Debug> { panic!() }
|
||||
| ^^^^^^^^^^ cannot infer type
|
||||
|
|
||||
= note: cannot satisfy `_: Debug`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0282`.
|
||||
For more information about this error, try `rustc --explain E0283`.
|
||||
|
@ -3,6 +3,9 @@ error[E0282]: type annotations needed for `Result<(), E>`
|
||||
|
|
||||
LL | let x = |r| {
|
||||
| ^
|
||||
LL | let v = r?;
|
||||
LL | Ok(v)
|
||||
| ----- type must be known at this point
|
||||
|
|
||||
help: consider giving this closure parameter an explicit type, where the type for type parameter `E` is specified
|
||||
|
|
||||
|
@ -2,7 +2,7 @@ error[E0282]: type annotations needed for `A<std::result::Result<std::result::Re
|
||||
--> $DIR/issue-104649.rs:24:9
|
||||
|
|
||||
LL | let a = A(Result::Ok(Result::Ok(())));
|
||||
| ^
|
||||
| ^ -------------- type must be known at this point
|
||||
|
|
||||
help: consider giving `a` an explicit type, where the type for type parameter `E` is specified
|
||||
|
|
||||
|
@ -1,3 +1,4 @@
|
||||
// ignore-windows different list of satisfying impls
|
||||
fn main() {
|
||||
let n: u32 = 1;
|
||||
let mut d: u64 = 2;
|
||||
|
@ -1,5 +1,5 @@
|
||||
error[E0284]: type annotations needed
|
||||
--> $DIR/issue-71584.rs:4:15
|
||||
--> $DIR/issue-71584.rs:5:15
|
||||
|
|
||||
LL | d = d % n.into();
|
||||
| - ^^^^
|
||||
|
@ -24,16 +24,15 @@ help: try using a fully qualified path to specify the expected types
|
||||
LL | String::from(<str as AsRef<T>>::as_ref("x"));
|
||||
| ++++++++++++++++++++++++++ ~
|
||||
|
||||
error[E0282]: type annotations needed
|
||||
--> $DIR/issue-72690.rs:12:6
|
||||
error[E0283]: type annotations needed
|
||||
--> $DIR/issue-72690.rs:12:9
|
||||
|
|
||||
LL | |x| String::from("x".as_ref());
|
||||
| ^
|
||||
| ^^^^^^ cannot infer type for reference `&_`
|
||||
|
|
||||
help: consider giving this closure parameter an explicit type
|
||||
|
|
||||
LL | |x: /* Type */| String::from("x".as_ref());
|
||||
| ++++++++++++
|
||||
= note: multiple `impl`s satisfying `String: From<&_>` found in the `alloc` crate:
|
||||
- impl From<&String> for String;
|
||||
- impl From<&str> for String;
|
||||
|
||||
error[E0283]: type annotations needed
|
||||
--> $DIR/issue-72690.rs:12:26
|
||||
@ -225,5 +224,4 @@ LL | String::from(<str as AsRef<T>>::as_ref("x"));
|
||||
|
||||
error: aborting due to 17 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0282, E0283.
|
||||
For more information about an error, try `rustc --explain E0282`.
|
||||
For more information about this error, try `rustc --explain E0283`.
|
||||
|
48
tests/ui/inference/multiple-impl-apply.rs
Normal file
48
tests/ui/inference/multiple-impl-apply.rs
Normal file
@ -0,0 +1,48 @@
|
||||
struct Foo {
|
||||
inner: u32,
|
||||
}
|
||||
|
||||
struct Bar {
|
||||
inner: u32,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
struct Baz {
|
||||
inner: u32,
|
||||
}
|
||||
|
||||
impl From<Baz> for Bar {
|
||||
fn from(other: Baz) -> Self {
|
||||
Self {
|
||||
inner: other.inner,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Baz> for Foo {
|
||||
fn from(other: Baz) -> Self {
|
||||
Self {
|
||||
inner: other.inner,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let x: Baz = Baz { inner: 42 };
|
||||
|
||||
// DOESN'T Compile: Multiple options!
|
||||
let y = x.into(); //~ ERROR E0283
|
||||
|
||||
let y_1: Foo = x.into();
|
||||
let y_2: Bar = x.into();
|
||||
|
||||
let z_1 = Foo::from(y_1);
|
||||
let z_2 = Bar::from(y_2);
|
||||
|
||||
// No type annotations needed, the compiler KNOWS the type must be `Foo`!
|
||||
let m = magic_foo(x);
|
||||
}
|
||||
|
||||
fn magic_foo(arg: Baz) -> Foo {
|
||||
arg.into()
|
||||
}
|
23
tests/ui/inference/multiple-impl-apply.stderr
Normal file
23
tests/ui/inference/multiple-impl-apply.stderr
Normal file
@ -0,0 +1,23 @@
|
||||
error[E0283]: type annotations needed
|
||||
--> $DIR/multiple-impl-apply.rs:34:9
|
||||
|
|
||||
LL | let y = x.into();
|
||||
| ^ ---- type must be known at this point
|
||||
|
|
||||
note: multiple `impl`s satisfying `_: From<Baz>` found
|
||||
--> $DIR/multiple-impl-apply.rs:14:1
|
||||
|
|
||||
LL | impl From<Baz> for Bar {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
...
|
||||
LL | impl From<Baz> for Foo {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
= note: required for `Baz` to implement `Into<_>`
|
||||
help: consider giving `y` an explicit type
|
||||
|
|
||||
LL | let y: /* Type */ = x.into();
|
||||
| ++++++++++++
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0283`.
|
@ -14,6 +14,4 @@ fn main() {
|
||||
<Struct as Ambiguous<_>>::method();
|
||||
//~^ ERROR type annotations needed
|
||||
//~| NOTE cannot infer type of the type parameter `A`
|
||||
//~| ERROR type annotations needed
|
||||
//~| NOTE infer type of the type parameter `A`
|
||||
}
|
||||
|
@ -1,9 +1,3 @@
|
||||
error[E0282]: type annotations needed
|
||||
--> $DIR/concrete-impl.rs:14:5
|
||||
|
|
||||
LL | <Struct as Ambiguous<_>>::method();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type of the type parameter `A` declared on the trait `Ambiguous`
|
||||
|
||||
error[E0283]: type annotations needed
|
||||
--> $DIR/concrete-impl.rs:14:5
|
||||
|
|
||||
@ -19,7 +13,6 @@ LL |
|
||||
LL | impl Ambiguous<Two> for Struct {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
error: aborting due to previous error
|
||||
|
||||
Some errors have detailed explanations: E0282, E0283.
|
||||
For more information about an error, try `rustc --explain E0282`.
|
||||
For more information about this error, try `rustc --explain E0283`.
|
||||
|
@ -1,9 +1,17 @@
|
||||
error[E0282]: type annotations needed
|
||||
error[E0283]: type annotations needed
|
||||
--> $DIR/issue-113264-incorrect-impl-trait-in-path-suggestion.rs:10:16
|
||||
|
|
||||
LL | (S {}).owo(None)
|
||||
| ^^^^ cannot infer type of the type parameter `T` declared on the enum `Option`
|
||||
| --- ^^^^ cannot infer type of the type parameter `T` declared on the enum `Option`
|
||||
| |
|
||||
| required by a bound introduced by this call
|
||||
|
|
||||
= note: cannot satisfy `_: T`
|
||||
note: required by a bound in `S::owo`
|
||||
--> $DIR/issue-113264-incorrect-impl-trait-in-path-suggestion.rs:6:35
|
||||
|
|
||||
LL | fn owo(&self, _: Option<&impl T>) {}
|
||||
| ^ required by this bound in `S::owo`
|
||||
help: consider specifying the generic argument
|
||||
|
|
||||
LL | (S {}).owo(None::<&_>)
|
||||
@ -11,4 +19,4 @@ LL | (S {}).owo(None::<&_>)
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0282`.
|
||||
For more information about this error, try `rustc --explain E0283`.
|
||||
|
@ -1,9 +1,12 @@
|
||||
error[E0282]: type annotations needed
|
||||
error[E0283]: type annotations needed
|
||||
--> $DIR/question-mark-type-infer.rs:10:21
|
||||
|
|
||||
LL | l.iter().map(f).collect()?
|
||||
| ^^^^^^^ cannot infer type of the type parameter `B` declared on the method `collect`
|
||||
|
|
||||
= note: cannot satisfy `_: FromIterator<Result<i32, ()>>`
|
||||
note: required by a bound in `collect`
|
||||
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
|
||||
help: consider specifying the generic argument
|
||||
|
|
||||
LL | l.iter().map(f).collect::<Vec<_>>()?
|
||||
@ -11,4 +14,4 @@ LL | l.iter().map(f).collect::<Vec<_>>()?
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0282`.
|
||||
For more information about this error, try `rustc --explain E0283`.
|
||||
|
@ -2,9 +2,9 @@ error[E0282]: type annotations needed for `&T`
|
||||
--> $DIR/issue-12187-1.rs:6:9
|
||||
|
|
||||
LL | let &v = new();
|
||||
| ^^
|
||||
| ^^ ----- type must be known at this point
|
||||
|
|
||||
help: consider giving this pattern a type, where the placeholders `_` are specified
|
||||
help: consider giving this pattern a type, where the type for type parameter `T` is specified
|
||||
|
|
||||
LL | let &v: &T = new();
|
||||
| ++++
|
||||
|
@ -2,9 +2,9 @@ error[E0282]: type annotations needed for `&T`
|
||||
--> $DIR/issue-12187-2.rs:6:9
|
||||
|
|
||||
LL | let &v = new();
|
||||
| ^^
|
||||
| ^^ ----- type must be known at this point
|
||||
|
|
||||
help: consider giving this pattern a type, where the placeholders `_` are specified
|
||||
help: consider giving this pattern a type, where the type for type parameter `T` is specified
|
||||
|
|
||||
LL | let &v: &T = new();
|
||||
| ++++
|
||||
|
@ -1,9 +1,16 @@
|
||||
error[E0282]: type annotations needed
|
||||
error[E0283]: type annotations needed
|
||||
--> $DIR/issue-16966.rs:2:12
|
||||
|
|
||||
LL | panic!(std::default::Default::default());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type
|
||||
| -------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
|
||||
| | |
|
||||
| | cannot infer type
|
||||
| required by a bound introduced by this call
|
||||
|
|
||||
= note: cannot satisfy `_: Any`
|
||||
note: required by a bound in `begin_panic`
|
||||
--> $SRC_DIR/std/src/panicking.rs:LL:COL
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0282`.
|
||||
For more information about this error, try `rustc --explain E0283`.
|
||||
|
@ -2,7 +2,7 @@ error[E0282]: type annotations needed for `B<T>`
|
||||
--> $DIR/issue-17551.rs:6:9
|
||||
|
|
||||
LL | let foo = B(marker::PhantomData);
|
||||
| ^^^
|
||||
| ^^^ ------------------- type must be known at this point
|
||||
|
|
||||
help: consider giving `foo` an explicit type, where the type for type parameter `T` is specified
|
||||
|
|
||||
|
@ -11,12 +11,13 @@ LL | x = |c| c + 1;
|
||||
= note: no two closures, even if identical, have the same type
|
||||
= help: consider boxing your closure and/or using it as a trait object
|
||||
|
||||
error[E0282]: type annotations needed
|
||||
error[E0284]: type annotations needed
|
||||
--> $DIR/issue-24036.rs:9:15
|
||||
|
|
||||
LL | 1 => |c| c + 1,
|
||||
| ^
|
||||
| ^ - type must be known at this point
|
||||
|
|
||||
= note: cannot satisfy `<_ as Add<i32>>::Output == _`
|
||||
help: consider giving this closure parameter an explicit type
|
||||
|
|
||||
LL | 1 => |c: /* Type */| c + 1,
|
||||
@ -24,5 +25,5 @@ LL | 1 => |c: /* Type */| c + 1,
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0282, E0308.
|
||||
For more information about an error, try `rustc --explain E0282`.
|
||||
Some errors have detailed explanations: E0284, E0308.
|
||||
For more information about an error, try `rustc --explain E0284`.
|
||||
|
@ -1,11 +1,3 @@
|
||||
error[E0277]: the size for values of type `(dyn Fn() -> u32 + 'static)` cannot be known at compilation time
|
||||
--> $DIR/issue-24446.rs:2:17
|
||||
|
|
||||
LL | static foo: dyn Fn() -> u32 = || -> u32 {
|
||||
| ^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
||||
|
|
||||
= help: the trait `Sized` is not implemented for `(dyn Fn() -> u32 + 'static)`
|
||||
|
||||
error[E0277]: `(dyn Fn() -> u32 + 'static)` cannot be shared between threads safely
|
||||
--> $DIR/issue-24446.rs:2:17
|
||||
|
|
||||
@ -15,6 +7,14 @@ LL | static foo: dyn Fn() -> u32 = || -> u32 {
|
||||
= help: the trait `Sync` is not implemented for `(dyn Fn() -> u32 + 'static)`
|
||||
= note: shared static variables must have a type that implements `Sync`
|
||||
|
||||
error[E0277]: the size for values of type `(dyn Fn() -> u32 + 'static)` cannot be known at compilation time
|
||||
--> $DIR/issue-24446.rs:2:17
|
||||
|
|
||||
LL | static foo: dyn Fn() -> u32 = || -> u32 {
|
||||
| ^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
||||
|
|
||||
= help: the trait `Sized` is not implemented for `(dyn Fn() -> u32 + 'static)`
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0277`.
|
||||
|
@ -1,3 +1,13 @@
|
||||
error[E0277]: a slice of type `[i32]` cannot be built since `[i32]` has no definite size
|
||||
--> $DIR/collect-into-slice.rs:6:38
|
||||
|
|
||||
LL | let some_generated_vec = (0..10).collect();
|
||||
| ^^^^^^^ try explicitly collecting into a `Vec<{integer}>`
|
||||
|
|
||||
= help: the trait `FromIterator<{integer}>` is not implemented for `[i32]`
|
||||
note: required by a bound in `collect`
|
||||
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
|
||||
|
||||
error[E0277]: the size for values of type `[i32]` cannot be known at compilation time
|
||||
--> $DIR/collect-into-slice.rs:6:9
|
||||
|
|
||||
@ -18,16 +28,6 @@ LL | let some_generated_vec = (0..10).collect();
|
||||
note: required by a bound in `collect`
|
||||
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
|
||||
|
||||
error[E0277]: a slice of type `[i32]` cannot be built since `[i32]` has no definite size
|
||||
--> $DIR/collect-into-slice.rs:6:38
|
||||
|
|
||||
LL | let some_generated_vec = (0..10).collect();
|
||||
| ^^^^^^^ try explicitly collecting into a `Vec<{integer}>`
|
||||
|
|
||||
= help: the trait `FromIterator<{integer}>` is not implemented for `[i32]`
|
||||
note: required by a bound in `collect`
|
||||
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
|
||||
|
||||
error[E0277]: a slice of type `&[i32]` cannot be built since we need to store the elements somewhere
|
||||
--> $DIR/collect-into-slice.rs:18:38
|
||||
|
|
||||
|
@ -2,7 +2,7 @@ error[E0282]: type annotations needed for `Vec<T>`
|
||||
--> $DIR/method-ambig-one-trait-unknown-int-type.rs:24:9
|
||||
|
|
||||
LL | let mut x = Vec::new();
|
||||
| ^^^^^
|
||||
| ^^^^^ ---------- type must be known at this point
|
||||
|
|
||||
help: consider giving `x` an explicit type, where the type for type parameter `T` is specified
|
||||
|
|
||||
|
@ -3,6 +3,9 @@ error[E0282]: type annotations needed for `[_; 3]`
|
||||
|
|
||||
LL | let b;
|
||||
| ^
|
||||
LL |
|
||||
LL | [a, b] = Default::default();
|
||||
| - type must be known at this point
|
||||
|
|
||||
help: consider giving `b` an explicit type, where the placeholders `_` are specified
|
||||
|
|
||||
|
@ -1,18 +1,3 @@
|
||||
error[E0277]: the size for values of type `[i32]` cannot be known at compilation time
|
||||
--> $DIR/slice-issue-87994.rs:3:12
|
||||
|
|
||||
LL | for _ in v[1..] {
|
||||
| ^^^^^^ the trait `IntoIterator` is not implemented for `[i32]`
|
||||
|
|
||||
= note: the trait bound `[i32]: IntoIterator` is not satisfied
|
||||
= note: required for `[i32]` to implement `IntoIterator`
|
||||
help: consider borrowing here
|
||||
|
|
||||
LL | for _ in &v[1..] {
|
||||
| +
|
||||
LL | for _ in &mut v[1..] {
|
||||
| ++++
|
||||
|
||||
error[E0277]: `[i32]` is not an iterator
|
||||
--> $DIR/slice-issue-87994.rs:3:12
|
||||
|
|
||||
@ -28,7 +13,22 @@ LL | for _ in &v[1..] {
|
||||
LL | for _ in &mut v[1..] {
|
||||
| ++++
|
||||
|
||||
error[E0277]: the size for values of type `[K]` cannot be known at compilation time
|
||||
error[E0277]: the size for values of type `[i32]` cannot be known at compilation time
|
||||
--> $DIR/slice-issue-87994.rs:3:12
|
||||
|
|
||||
LL | for _ in v[1..] {
|
||||
| ^^^^^^ the trait `IntoIterator` is not implemented for `[i32]`
|
||||
|
|
||||
= note: the trait bound `[i32]: IntoIterator` is not satisfied
|
||||
= note: required for `[i32]` to implement `IntoIterator`
|
||||
help: consider borrowing here
|
||||
|
|
||||
LL | for _ in &v[1..] {
|
||||
| +
|
||||
LL | for _ in &mut v[1..] {
|
||||
| ++++
|
||||
|
||||
error[E0277]: `[K]` is not an iterator
|
||||
--> $DIR/slice-issue-87994.rs:11:13
|
||||
|
|
||||
LL | for i2 in v2[1..] {
|
||||
@ -43,7 +43,7 @@ LL | for i2 in &v2[1..] {
|
||||
LL | for i2 in &mut v2[1..] {
|
||||
| ++++
|
||||
|
||||
error[E0277]: `[K]` is not an iterator
|
||||
error[E0277]: the size for values of type `[K]` cannot be known at compilation time
|
||||
--> $DIR/slice-issue-87994.rs:11:13
|
||||
|
|
||||
LL | for i2 in v2[1..] {
|
||||
|
@ -2,7 +2,7 @@ error[E0282]: type annotations needed for `Option<T>`
|
||||
--> $DIR/copy-guessing.rs:20:9
|
||||
|
|
||||
LL | let n = None;
|
||||
| ^
|
||||
| ^ ---- type must be known at this point
|
||||
|
|
||||
help: consider giving `n` an explicit type, where the type for type parameter `T` is specified
|
||||
|
|
||||
|
@ -14,7 +14,5 @@ impl<X> Method<u32> for Thing<X> {
|
||||
|
||||
fn main() {
|
||||
let thing = Thing(true);
|
||||
thing.method(42);
|
||||
//~^ ERROR type annotations needed
|
||||
//~| ERROR type annotations needed
|
||||
thing.method(42); //~ ERROR type annotations needed
|
||||
}
|
||||
|
@ -1,14 +1,3 @@
|
||||
error[E0282]: type annotations needed
|
||||
--> $DIR/do-not-mention-type-params-by-name-in-suggestion-issue-96292.rs:17:11
|
||||
|
|
||||
LL | thing.method(42);
|
||||
| ^^^^^^
|
||||
|
|
||||
help: try using a fully qualified path to specify the expected types
|
||||
|
|
||||
LL | <Thing<bool> as Method<T>>::method(thing, 42);
|
||||
| +++++++++++++++++++++++++++++++++++ ~
|
||||
|
||||
error[E0283]: type annotations needed
|
||||
--> $DIR/do-not-mention-type-params-by-name-in-suggestion-issue-96292.rs:17:11
|
||||
|
|
||||
@ -28,7 +17,6 @@ help: try using a fully qualified path to specify the expected types
|
||||
LL | <Thing<bool> as Method<T>>::method(thing, 42);
|
||||
| +++++++++++++++++++++++++++++++++++ ~
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
error: aborting due to previous error
|
||||
|
||||
Some errors have detailed explanations: E0282, E0283.
|
||||
For more information about an error, try `rustc --explain E0282`.
|
||||
For more information about this error, try `rustc --explain E0283`.
|
||||
|
@ -1,3 +1,4 @@
|
||||
// ignore-windows different list of satisfying impls
|
||||
use std::collections::HashMap;
|
||||
|
||||
fn what() {
|
||||
|
@ -1,5 +1,5 @@
|
||||
error[E0283]: type annotations needed
|
||||
--> $DIR/issue-77982.rs:8:10
|
||||
--> $DIR/issue-77982.rs:9:10
|
||||
|
|
||||
LL | opts.get(opt.as_ref());
|
||||
| ^^^ ------------ type must be known at this point
|
||||
@ -18,7 +18,7 @@ LL | opts.get::<Q>(opt.as_ref());
|
||||
| +++++
|
||||
|
||||
error[E0283]: type annotations needed
|
||||
--> $DIR/issue-77982.rs:8:10
|
||||
--> $DIR/issue-77982.rs:9:10
|
||||
|
|
||||
LL | opts.get(opt.as_ref());
|
||||
| ^^^ ------ type must be known at this point
|
||||
@ -35,25 +35,34 @@ help: consider specifying the generic argument
|
||||
LL | opts.get::<Q>(opt.as_ref());
|
||||
| +++++
|
||||
|
||||
error[E0282]: type annotations needed
|
||||
--> $DIR/issue-77982.rs:13:59
|
||||
error[E0283]: type annotations needed
|
||||
--> $DIR/issue-77982.rs:14:59
|
||||
|
|
||||
LL | let ips: Vec<_> = (0..100_000).map(|_| u32::from(0u32.into())).collect();
|
||||
| ^^^^
|
||||
| --- ^^^^
|
||||
| |
|
||||
| type must be known at this point
|
||||
|
|
||||
= note: multiple `impl`s satisfying `u32: From<_>` found in the `core` crate:
|
||||
- impl From<Ipv4Addr> for u32;
|
||||
- impl From<NonZeroU32> for u32;
|
||||
- impl From<bool> for u32;
|
||||
- impl From<char> for u32;
|
||||
- impl From<u16> for u32;
|
||||
- impl From<u8> for u32;
|
||||
help: try using a fully qualified path to specify the expected types
|
||||
|
|
||||
LL | let ips: Vec<_> = (0..100_000).map(|_| u32::from(<u32 as Into<T>>::into(0u32))).collect();
|
||||
| +++++++++++++++++++++++ ~
|
||||
|
||||
error[E0283]: type annotations needed for `Box<T>`
|
||||
--> $DIR/issue-77982.rs:36:9
|
||||
--> $DIR/issue-77982.rs:37:9
|
||||
|
|
||||
LL | let _ = ().foo();
|
||||
| ^ --- type must be known at this point
|
||||
|
|
||||
note: multiple `impl`s satisfying `(): Foo<'_, _>` found
|
||||
--> $DIR/issue-77982.rs:29:1
|
||||
--> $DIR/issue-77982.rs:30:1
|
||||
|
|
||||
LL | impl Foo<'static, u32> for () {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
@ -65,13 +74,13 @@ LL | let _: Box<T> = ().foo();
|
||||
| ++++++++
|
||||
|
||||
error[E0283]: type annotations needed for `Box<T>`
|
||||
--> $DIR/issue-77982.rs:40:9
|
||||
--> $DIR/issue-77982.rs:41:9
|
||||
|
|
||||
LL | let _ = (&()).bar();
|
||||
| ^ --- type must be known at this point
|
||||
|
|
||||
note: multiple `impl`s satisfying `&(): Bar<'_, _>` found
|
||||
--> $DIR/issue-77982.rs:32:1
|
||||
--> $DIR/issue-77982.rs:33:1
|
||||
|
|
||||
LL | impl<'a> Bar<'static, u32> for &'a () {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
@ -84,5 +93,4 @@ LL | let _: Box<T> = (&()).bar();
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0282, E0283.
|
||||
For more information about an error, try `rustc --explain E0282`.
|
||||
For more information about this error, try `rustc --explain E0283`.
|
||||
|
@ -25,7 +25,6 @@ where T : Convert<U>
|
||||
fn a() {
|
||||
test(22, std::default::Default::default());
|
||||
//~^ ERROR type annotations needed
|
||||
//~| ERROR type annotations needed
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
@ -1,14 +1,3 @@
|
||||
error[E0282]: type annotations needed
|
||||
--> $DIR/multidispatch-convert-ambig-dest.rs:26:5
|
||||
|
|
||||
LL | test(22, std::default::Default::default());
|
||||
| ^^^^ cannot infer type of the type parameter `U` declared on the function `test`
|
||||
|
|
||||
help: consider specifying the generic arguments
|
||||
|
|
||||
LL | test::<i32, U>(22, std::default::Default::default());
|
||||
| ++++++++++
|
||||
|
||||
error[E0283]: type annotations needed
|
||||
--> $DIR/multidispatch-convert-ambig-dest.rs:26:5
|
||||
|
|
||||
@ -37,7 +26,6 @@ help: consider specifying the generic arguments
|
||||
LL | test::<i32, U>(22, std::default::Default::default());
|
||||
| ++++++++++
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
error: aborting due to previous error
|
||||
|
||||
Some errors have detailed explanations: E0282, E0283.
|
||||
For more information about an error, try `rustc --explain E0282`.
|
||||
For more information about this error, try `rustc --explain E0283`.
|
||||
|
@ -27,6 +27,5 @@ fn main() {
|
||||
//~| ERROR overflow evaluating the requirement `<() as Foo>::Item well-formed`
|
||||
//~| ERROR overflow evaluating the requirement `String <: <() as Foo>::Item`
|
||||
//~| ERROR overflow evaluating the requirement `&<() as Foo>::Item well-formed`
|
||||
//~| ERROR type annotations needed
|
||||
println!("{x}");
|
||||
}
|
||||
|
@ -11,25 +11,6 @@ note: required by a bound in `Foo::Item`
|
||||
LL | type Item: Copy
|
||||
| ^^^^ required by this bound in `Foo::Item`
|
||||
|
||||
error[E0282]: type annotations needed
|
||||
--> $DIR/alias-bound-unsound.rs:24:5
|
||||
|
|
||||
LL | drop(<() as Foo>::copy_me(&x));
|
||||
| ^^^^ cannot infer type of the type parameter `T` declared on the function `drop`
|
||||
|
|
||||
help: consider specifying the generic argument
|
||||
|
|
||||
LL | drop::<T>(<() as Foo>::copy_me(&x));
|
||||
| +++++
|
||||
|
||||
error[E0275]: overflow evaluating the requirement `&<() as Foo>::Item well-formed`
|
||||
--> $DIR/alias-bound-unsound.rs:24:31
|
||||
|
|
||||
LL | drop(<() as Foo>::copy_me(&x));
|
||||
| ^^
|
||||
|
|
||||
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`alias_bound_unsound`)
|
||||
|
||||
error[E0275]: overflow evaluating the requirement `String <: <() as Foo>::Item`
|
||||
--> $DIR/alias-bound-unsound.rs:24:31
|
||||
|
|
||||
@ -38,14 +19,6 @@ LL | drop(<() as Foo>::copy_me(&x));
|
||||
|
|
||||
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`alias_bound_unsound`)
|
||||
|
||||
error[E0275]: overflow evaluating the requirement `<() as Foo>::Item well-formed`
|
||||
--> $DIR/alias-bound-unsound.rs:24:10
|
||||
|
|
||||
LL | drop(<() as Foo>::copy_me(&x));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`alias_bound_unsound`)
|
||||
|
||||
error[E0275]: overflow evaluating the requirement `<() as Foo>::Item == _`
|
||||
--> $DIR/alias-bound-unsound.rs:24:10
|
||||
|
|
||||
@ -63,7 +36,22 @@ LL | drop(<() as Foo>::copy_me(&x));
|
||||
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`alias_bound_unsound`)
|
||||
= note: the return type of a function must have a statically known size
|
||||
|
||||
error: aborting due to 7 previous errors
|
||||
error[E0275]: overflow evaluating the requirement `&<() as Foo>::Item well-formed`
|
||||
--> $DIR/alias-bound-unsound.rs:24:31
|
||||
|
|
||||
LL | drop(<() as Foo>::copy_me(&x));
|
||||
| ^^
|
||||
|
|
||||
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`alias_bound_unsound`)
|
||||
|
||||
Some errors have detailed explanations: E0275, E0282.
|
||||
For more information about an error, try `rustc --explain E0275`.
|
||||
error[E0275]: overflow evaluating the requirement `<() as Foo>::Item well-formed`
|
||||
--> $DIR/alias-bound-unsound.rs:24:10
|
||||
|
|
||||
LL | drop(<() as Foo>::copy_me(&x));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`alias_bound_unsound`)
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0275`.
|
||||
|
@ -1,9 +1,16 @@
|
||||
error[E0282]: type annotations needed
|
||||
error[E0283]: type annotations needed
|
||||
--> $DIR/runaway-impl-candidate-selection.rs:13:22
|
||||
|
|
||||
LL | println!("{:?}", iter::<_>());
|
||||
| ^^^^^^^^^ cannot infer type of the type parameter `T` declared on the function `iter`
|
||||
|
|
||||
= note: cannot satisfy `_: Iterator`
|
||||
note: required by a bound in `iter`
|
||||
--> $DIR/runaway-impl-candidate-selection.rs:8:12
|
||||
|
|
||||
LL | fn iter<T: Iterator>() -> <T as Iterator>::Item {
|
||||
| ^^^^^^^^ required by this bound in `iter`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0282`.
|
||||
For more information about this error, try `rustc --explain E0283`.
|
||||
|
@ -27,6 +27,5 @@ fn impls<T: Trait>() {}
|
||||
|
||||
fn main() {
|
||||
impls::<W<_>>();
|
||||
//~^ ERROR type annotations needed
|
||||
//~| ERROR overflow evaluating the requirement
|
||||
//~^ ERROR overflow evaluating the requirement
|
||||
}
|
||||
|
@ -1,9 +1,3 @@
|
||||
error[E0282]: type annotations needed
|
||||
--> $DIR/fixpoint-exponential-growth.rs:29:5
|
||||
|
|
||||
LL | impls::<W<_>>();
|
||||
| ^^^^^^^^^^^^^ cannot infer type of the type parameter `T` declared on the function `impls`
|
||||
|
||||
error[E0275]: overflow evaluating the requirement `W<_>: Trait`
|
||||
--> $DIR/fixpoint-exponential-growth.rs:29:13
|
||||
|
|
||||
@ -17,7 +11,6 @@ note: required by a bound in `impls`
|
||||
LL | fn impls<T: Trait>() {}
|
||||
| ^^^^^ required by this bound in `impls`
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
error: aborting due to previous error
|
||||
|
||||
Some errors have detailed explanations: E0275, E0282.
|
||||
For more information about an error, try `rustc --explain E0275`.
|
||||
For more information about this error, try `rustc --explain E0275`.
|
||||
|
@ -1,9 +1,18 @@
|
||||
error[E0282]: type annotations needed
|
||||
error[E0284]: type annotations needed: cannot satisfy `<<Leaf as WithAssoc<_>>::Assoc as Id>::Assoc == <<Leaf as WithAssoc<_>>::Assoc as Id>::Assoc`
|
||||
--> $DIR/generalize-proj-new-universe-index-2.rs:74:5
|
||||
|
|
||||
LL | bound::<<Rigid as IdHigherRankedBound>::Assoc, <Wrapper<Leaf> as Id>::Assoc, _>()
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type of the type parameter `V` declared on the function `bound`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot satisfy `<<Leaf as WithAssoc<_>>::Assoc as Id>::Assoc == <<Leaf as WithAssoc<_>>::Assoc as Id>::Assoc`
|
||||
|
|
||||
note: required by a bound in `bound`
|
||||
--> $DIR/generalize-proj-new-universe-index-2.rs:69:21
|
||||
|
|
||||
LL | fn bound<T: ?Sized, U: ?Sized, V: ?Sized>()
|
||||
| ----- required by a bound in this function
|
||||
LL | where
|
||||
LL | T: WithAssoc<U, Assoc = V>,
|
||||
| ^^^^^^^^^ required by this bound in `bound`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0282`.
|
||||
For more information about this error, try `rustc --explain E0284`.
|
||||
|
@ -1,9 +1,17 @@
|
||||
error[E0282]: type annotations needed
|
||||
error[E0283]: type annotations needed
|
||||
--> $DIR/normalizes_to_ignores_unnormalizable_candidate.rs:36:5
|
||||
|
|
||||
LL | foo(unconstrained())
|
||||
| ^^^ cannot infer type of the type parameter `T` declared on the function `foo`
|
||||
| ^^^ --------------- type must be known at this point
|
||||
| |
|
||||
| cannot infer type of the type parameter `T` declared on the function `foo`
|
||||
|
|
||||
= note: cannot satisfy `_: Trait`
|
||||
note: required by a bound in `foo`
|
||||
--> $DIR/normalizes_to_ignores_unnormalizable_candidate.rs:19:11
|
||||
|
|
||||
LL | fn foo<T: Trait<Assoc = u8>>(x: T) {}
|
||||
| ^^^^^^^^^^^^^^^^^ required by this bound in `foo`
|
||||
help: consider specifying the generic argument
|
||||
|
|
||||
LL | foo::<T>(unconstrained())
|
||||
@ -11,4 +19,4 @@ LL | foo::<T>(unconstrained())
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0282`.
|
||||
For more information about this error, try `rustc --explain E0283`.
|
||||
|
@ -15,6 +15,5 @@ fn impls<T: Trait>() {}
|
||||
|
||||
fn main() {
|
||||
impls::<W<_>>();
|
||||
//~^ ERROR type annotations needed
|
||||
//~| ERROR overflow evaluating the requirement `W<_>: Trait`
|
||||
//~^ ERROR overflow evaluating the requirement `W<_>: Trait`
|
||||
}
|
||||
|
@ -1,9 +1,3 @@
|
||||
error[E0282]: type annotations needed
|
||||
--> $DIR/exponential-trait-goals.rs:17:5
|
||||
|
|
||||
LL | impls::<W<_>>();
|
||||
| ^^^^^^^^^^^^^ cannot infer type of the type parameter `T` declared on the function `impls`
|
||||
|
||||
error[E0275]: overflow evaluating the requirement `W<_>: Trait`
|
||||
--> $DIR/exponential-trait-goals.rs:17:13
|
||||
|
|
||||
@ -17,7 +11,6 @@ note: required by a bound in `impls`
|
||||
LL | fn impls<T: Trait>() {}
|
||||
| ^^^^^ required by this bound in `impls`
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
error: aborting due to previous error
|
||||
|
||||
Some errors have detailed explanations: E0275, E0282.
|
||||
For more information about an error, try `rustc --explain E0275`.
|
||||
For more information about this error, try `rustc --explain E0275`.
|
||||
|
@ -23,23 +23,6 @@ LL | where
|
||||
LL | for<V> V: Sized,
|
||||
| ^^^^^ required by this bound in `foo`
|
||||
|
||||
error[E0277]: the size for values of type `V` cannot be known at compilation time
|
||||
--> $DIR/bad-sized-cond.rs:20:5
|
||||
|
|
||||
LL | bar();
|
||||
| ^^^ doesn't have a size known at compile-time
|
||||
|
|
||||
= help: the trait `Sized` is not implemented for `V`
|
||||
= note: required for `V` to implement `IntoIterator`
|
||||
note: required by a bound in `bar`
|
||||
--> $DIR/bad-sized-cond.rs:12:15
|
||||
|
|
||||
LL | pub fn bar()
|
||||
| --- required by a bound in this function
|
||||
LL | where
|
||||
LL | for<V> V: IntoIterator,
|
||||
| ^^^^^^^^^^^^ required by this bound in `bar`
|
||||
|
||||
error[E0277]: `V` is not an iterator
|
||||
--> $DIR/bad-sized-cond.rs:20:5
|
||||
|
|
||||
@ -57,6 +40,23 @@ LL | where
|
||||
LL | for<V> V: IntoIterator,
|
||||
| ^^^^^^^^^^^^ required by this bound in `bar`
|
||||
|
||||
error[E0277]: the size for values of type `V` cannot be known at compilation time
|
||||
--> $DIR/bad-sized-cond.rs:20:5
|
||||
|
|
||||
LL | bar();
|
||||
| ^^^ doesn't have a size known at compile-time
|
||||
|
|
||||
= help: the trait `Sized` is not implemented for `V`
|
||||
= note: required for `V` to implement `IntoIterator`
|
||||
note: required by a bound in `bar`
|
||||
--> $DIR/bad-sized-cond.rs:12:15
|
||||
|
|
||||
LL | pub fn bar()
|
||||
| --- required by a bound in this function
|
||||
LL | where
|
||||
LL | for<V> V: IntoIterator,
|
||||
| ^^^^^^^^^^^^ required by this bound in `bar`
|
||||
|
||||
error: aborting due to 3 previous errors; 1 warning emitted
|
||||
|
||||
For more information about this error, try `rustc --explain E0277`.
|
||||
|
@ -18,7 +18,5 @@ where
|
||||
|
||||
fn main() {
|
||||
let a = A(B);
|
||||
a.method();
|
||||
//~^ ERROR type annotations needed
|
||||
//~| ERROR type annotations needed
|
||||
a.method(); //~ ERROR type annotations needed
|
||||
}
|
||||
|
@ -1,14 +1,3 @@
|
||||
error[E0282]: type annotations needed
|
||||
--> $DIR/not-suggest-non-existing-fully-qualified-path.rs:21:7
|
||||
|
|
||||
LL | a.method();
|
||||
| ^^^^^^
|
||||
|
|
||||
help: try using a fully qualified path to specify the expected types
|
||||
|
|
||||
LL | <A<B> as V<U>>::method(a);
|
||||
| +++++++++++++++++++++++ ~
|
||||
|
||||
error[E0283]: type annotations needed
|
||||
--> $DIR/not-suggest-non-existing-fully-qualified-path.rs:21:7
|
||||
|
|
||||
@ -35,7 +24,6 @@ help: try using a fully qualified path to specify the expected types
|
||||
LL | <A<B> as V<U>>::method(a);
|
||||
| +++++++++++++++++++++++ ~
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
error: aborting due to previous error
|
||||
|
||||
Some errors have detailed explanations: E0282, E0283.
|
||||
For more information about an error, try `rustc --explain E0282`.
|
||||
For more information about this error, try `rustc --explain E0283`.
|
||||
|
@ -1,14 +1,3 @@
|
||||
error[E0282]: type annotations needed
|
||||
--> $DIR/suggest-fully-qualified-closure.rs:23:7
|
||||
|
|
||||
LL | q.lol(||());
|
||||
| ^^^
|
||||
|
|
||||
help: try using a fully qualified path to specify the expected types
|
||||
|
|
||||
LL | <Qqq as MyTrait<T>>::lol::<{closure@}>(&q, ||());
|
||||
| +++ ~
|
||||
|
||||
error[E0283]: type annotations needed
|
||||
--> $DIR/suggest-fully-qualified-closure.rs:23:7
|
||||
|
|
||||
@ -28,7 +17,6 @@ help: try using a fully qualified path to specify the expected types
|
||||
LL | <Qqq as MyTrait<T>>::lol::<{closure@}>(&q, ||());
|
||||
| +++ ~
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
error: aborting due to previous error
|
||||
|
||||
Some errors have detailed explanations: E0282, E0283.
|
||||
For more information about an error, try `rustc --explain E0282`.
|
||||
For more information about this error, try `rustc --explain E0283`.
|
||||
|
@ -42,9 +42,7 @@ impl<T> DerefMut for DerefsTo<T> {
|
||||
|
||||
fn main() {
|
||||
let mut thing = Thing;
|
||||
thing.method();
|
||||
//~^ ERROR type annotations needed
|
||||
//~| ERROR type annotations needed
|
||||
thing.method(); //~ ERROR type annotations needed
|
||||
thing.mut_method(); //~ ERROR type annotations needed
|
||||
thing.by_self(); //~ ERROR type annotations needed
|
||||
|
||||
|
@ -1,14 +1,3 @@
|
||||
error[E0282]: type annotations needed
|
||||
--> $DIR/suggest-fully-qualified-path-with-adjustment.rs:45:11
|
||||
|
|
||||
LL | thing.method();
|
||||
| ^^^^^^
|
||||
|
|
||||
help: try using a fully qualified path to specify the expected types
|
||||
|
|
||||
LL | <Thing as Method<T>>::method(&thing);
|
||||
| ++++++++++++++++++++++++++++++ ~
|
||||
|
||||
error[E0283]: type annotations needed
|
||||
--> $DIR/suggest-fully-qualified-path-with-adjustment.rs:45:11
|
||||
|
|
||||
@ -29,7 +18,7 @@ LL | <Thing as Method<T>>::method(&thing);
|
||||
| ++++++++++++++++++++++++++++++ ~
|
||||
|
||||
error[E0283]: type annotations needed
|
||||
--> $DIR/suggest-fully-qualified-path-with-adjustment.rs:48:11
|
||||
--> $DIR/suggest-fully-qualified-path-with-adjustment.rs:46:11
|
||||
|
|
||||
LL | thing.mut_method();
|
||||
| ^^^^^^^^^^
|
||||
@ -48,7 +37,7 @@ LL | <Thing as Method<T>>::mut_method(&mut thing);
|
||||
| +++++++++++++++++++++++++++++++++++++ ~
|
||||
|
||||
error[E0283]: type annotations needed
|
||||
--> $DIR/suggest-fully-qualified-path-with-adjustment.rs:49:11
|
||||
--> $DIR/suggest-fully-qualified-path-with-adjustment.rs:47:11
|
||||
|
|
||||
LL | thing.by_self();
|
||||
| ^^^^^^^
|
||||
@ -67,7 +56,7 @@ LL | <&Thing as MethodRef<T>>::by_self(&thing);
|
||||
| +++++++++++++++++++++++++++++++++++ ~
|
||||
|
||||
error[E0283]: type annotations needed
|
||||
--> $DIR/suggest-fully-qualified-path-with-adjustment.rs:52:14
|
||||
--> $DIR/suggest-fully-qualified-path-with-adjustment.rs:50:14
|
||||
|
|
||||
LL | deref_to.method();
|
||||
| ^^^^^^
|
||||
@ -86,7 +75,7 @@ LL | <Thing as Method<T>>::method(&deref_to);
|
||||
| ++++++++++++++++++++++++++++++ ~
|
||||
|
||||
error[E0283]: type annotations needed
|
||||
--> $DIR/suggest-fully-qualified-path-with-adjustment.rs:53:14
|
||||
--> $DIR/suggest-fully-qualified-path-with-adjustment.rs:51:14
|
||||
|
|
||||
LL | deref_to.mut_method();
|
||||
| ^^^^^^^^^^
|
||||
@ -105,7 +94,7 @@ LL | <Thing as Method<T>>::mut_method(&mut deref_to);
|
||||
| +++++++++++++++++++++++++++++++++++++ ~
|
||||
|
||||
error[E0283]: type annotations needed
|
||||
--> $DIR/suggest-fully-qualified-path-with-adjustment.rs:54:14
|
||||
--> $DIR/suggest-fully-qualified-path-with-adjustment.rs:52:14
|
||||
|
|
||||
LL | deref_to.by_self();
|
||||
| ^^^^^^^
|
||||
@ -124,7 +113,7 @@ LL | <&Thing as MethodRef<T>>::by_self(&deref_to);
|
||||
| +++++++++++++++++++++++++++++++++++ ~
|
||||
|
||||
error[E0283]: type annotations needed
|
||||
--> $DIR/suggest-fully-qualified-path-with-adjustment.rs:57:20
|
||||
--> $DIR/suggest-fully-qualified-path-with-adjustment.rs:55:20
|
||||
|
|
||||
LL | deref_deref_to.method();
|
||||
| ^^^^^^
|
||||
@ -143,7 +132,7 @@ LL | <Thing as Method<T>>::method(&deref_deref_to);
|
||||
| ++++++++++++++++++++++++++++++ ~
|
||||
|
||||
error[E0283]: type annotations needed
|
||||
--> $DIR/suggest-fully-qualified-path-with-adjustment.rs:58:20
|
||||
--> $DIR/suggest-fully-qualified-path-with-adjustment.rs:56:20
|
||||
|
|
||||
LL | deref_deref_to.mut_method();
|
||||
| ^^^^^^^^^^
|
||||
@ -162,7 +151,7 @@ LL | <Thing as Method<T>>::mut_method(&mut deref_deref_to);
|
||||
| +++++++++++++++++++++++++++++++++++++ ~
|
||||
|
||||
error[E0283]: type annotations needed
|
||||
--> $DIR/suggest-fully-qualified-path-with-adjustment.rs:59:20
|
||||
--> $DIR/suggest-fully-qualified-path-with-adjustment.rs:57:20
|
||||
|
|
||||
LL | deref_deref_to.by_self();
|
||||
| ^^^^^^^
|
||||
@ -180,7 +169,6 @@ help: try using a fully qualified path to specify the expected types
|
||||
LL | <&Thing as MethodRef<T>>::by_self(&deref_deref_to);
|
||||
| +++++++++++++++++++++++++++++++++++ ~
|
||||
|
||||
error: aborting due to 10 previous errors
|
||||
error: aborting due to 9 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0282, E0283.
|
||||
For more information about an error, try `rustc --explain E0282`.
|
||||
For more information about this error, try `rustc --explain E0283`.
|
||||
|
@ -42,9 +42,7 @@ impl<T> DerefMut for DerefsTo<T> {
|
||||
|
||||
fn main() {
|
||||
let mut ref_thing = &Thing;
|
||||
ref_thing.method();
|
||||
//~^ ERROR type annotations needed
|
||||
//~| ERROR type annotations needed
|
||||
ref_thing.method(); //~ ERROR type annotations needed
|
||||
ref_thing.by_self(); //~ ERROR type annotations needed
|
||||
|
||||
let mut mut_thing = &mut Thing;
|
||||
|
@ -1,14 +1,3 @@
|
||||
error[E0282]: type annotations needed
|
||||
--> $DIR/suggest-fully-qualified-path-without-adjustment.rs:45:15
|
||||
|
|
||||
LL | ref_thing.method();
|
||||
| ^^^^^^
|
||||
|
|
||||
help: try using a fully qualified path to specify the expected types
|
||||
|
|
||||
LL | <Thing as Method<T>>::method(ref_thing);
|
||||
| +++++++++++++++++++++++++++++ ~
|
||||
|
||||
error[E0283]: type annotations needed
|
||||
--> $DIR/suggest-fully-qualified-path-without-adjustment.rs:45:15
|
||||
|
|
||||
@ -29,7 +18,7 @@ LL | <Thing as Method<T>>::method(ref_thing);
|
||||
| +++++++++++++++++++++++++++++ ~
|
||||
|
||||
error[E0283]: type annotations needed
|
||||
--> $DIR/suggest-fully-qualified-path-without-adjustment.rs:48:15
|
||||
--> $DIR/suggest-fully-qualified-path-without-adjustment.rs:46:15
|
||||
|
|
||||
LL | ref_thing.by_self();
|
||||
| ^^^^^^^
|
||||
@ -48,7 +37,7 @@ LL | <&Thing as MethodRef<T>>::by_self(ref_thing);
|
||||
| ++++++++++++++++++++++++++++++++++ ~
|
||||
|
||||
error[E0283]: type annotations needed
|
||||
--> $DIR/suggest-fully-qualified-path-without-adjustment.rs:51:15
|
||||
--> $DIR/suggest-fully-qualified-path-without-adjustment.rs:49:15
|
||||
|
|
||||
LL | mut_thing.method();
|
||||
| ^^^^^^
|
||||
@ -67,7 +56,7 @@ LL | <Thing as Method<T>>::method(mut_thing);
|
||||
| +++++++++++++++++++++++++++++ ~
|
||||
|
||||
error[E0283]: type annotations needed
|
||||
--> $DIR/suggest-fully-qualified-path-without-adjustment.rs:52:15
|
||||
--> $DIR/suggest-fully-qualified-path-without-adjustment.rs:50:15
|
||||
|
|
||||
LL | mut_thing.mut_method();
|
||||
| ^^^^^^^^^^
|
||||
@ -86,7 +75,7 @@ LL | <Thing as Method<T>>::mut_method(mut_thing);
|
||||
| +++++++++++++++++++++++++++++++++ ~
|
||||
|
||||
error[E0283]: type annotations needed
|
||||
--> $DIR/suggest-fully-qualified-path-without-adjustment.rs:53:15
|
||||
--> $DIR/suggest-fully-qualified-path-without-adjustment.rs:51:15
|
||||
|
|
||||
LL | mut_thing.by_self();
|
||||
| ^^^^^^^
|
||||
@ -105,7 +94,7 @@ LL | <&Thing as MethodRef<T>>::by_self(mut_thing);
|
||||
| ++++++++++++++++++++++++++++++++++ ~
|
||||
|
||||
error[E0283]: type annotations needed
|
||||
--> $DIR/suggest-fully-qualified-path-without-adjustment.rs:56:14
|
||||
--> $DIR/suggest-fully-qualified-path-without-adjustment.rs:54:14
|
||||
|
|
||||
LL | deref_to.method();
|
||||
| ^^^^^^
|
||||
@ -124,7 +113,7 @@ LL | <Thing as Method<T>>::method(deref_to);
|
||||
| +++++++++++++++++++++++++++++ ~
|
||||
|
||||
error[E0283]: type annotations needed
|
||||
--> $DIR/suggest-fully-qualified-path-without-adjustment.rs:57:14
|
||||
--> $DIR/suggest-fully-qualified-path-without-adjustment.rs:55:14
|
||||
|
|
||||
LL | deref_to.mut_method();
|
||||
| ^^^^^^^^^^
|
||||
@ -143,7 +132,7 @@ LL | <Thing as Method<T>>::mut_method(deref_to);
|
||||
| +++++++++++++++++++++++++++++++++ ~
|
||||
|
||||
error[E0283]: type annotations needed
|
||||
--> $DIR/suggest-fully-qualified-path-without-adjustment.rs:58:14
|
||||
--> $DIR/suggest-fully-qualified-path-without-adjustment.rs:56:14
|
||||
|
|
||||
LL | deref_to.by_self();
|
||||
| ^^^^^^^
|
||||
@ -162,7 +151,7 @@ LL | <&Thing as MethodRef<T>>::by_self(deref_to);
|
||||
| ++++++++++++++++++++++++++++++++++ ~
|
||||
|
||||
error[E0283]: type annotations needed
|
||||
--> $DIR/suggest-fully-qualified-path-without-adjustment.rs:61:20
|
||||
--> $DIR/suggest-fully-qualified-path-without-adjustment.rs:59:20
|
||||
|
|
||||
LL | deref_deref_to.method();
|
||||
| ^^^^^^
|
||||
@ -181,7 +170,7 @@ LL | <Thing as Method<T>>::method(deref_deref_to);
|
||||
| +++++++++++++++++++++++++++++ ~
|
||||
|
||||
error[E0283]: type annotations needed
|
||||
--> $DIR/suggest-fully-qualified-path-without-adjustment.rs:62:20
|
||||
--> $DIR/suggest-fully-qualified-path-without-adjustment.rs:60:20
|
||||
|
|
||||
LL | deref_deref_to.mut_method();
|
||||
| ^^^^^^^^^^
|
||||
@ -200,7 +189,7 @@ LL | <Thing as Method<T>>::mut_method(deref_deref_to);
|
||||
| +++++++++++++++++++++++++++++++++ ~
|
||||
|
||||
error[E0283]: type annotations needed
|
||||
--> $DIR/suggest-fully-qualified-path-without-adjustment.rs:63:20
|
||||
--> $DIR/suggest-fully-qualified-path-without-adjustment.rs:61:20
|
||||
|
|
||||
LL | deref_deref_to.by_self();
|
||||
| ^^^^^^^
|
||||
@ -218,7 +207,6 @@ help: try using a fully qualified path to specify the expected types
|
||||
LL | <&Thing as MethodRef<T>>::by_self(deref_deref_to);
|
||||
| ++++++++++++++++++++++++++++++++++ ~
|
||||
|
||||
error: aborting due to 12 previous errors
|
||||
error: aborting due to 11 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0282, E0283.
|
||||
For more information about an error, try `rustc --explain E0282`.
|
||||
For more information about this error, try `rustc --explain E0283`.
|
||||
|
@ -1,9 +1,14 @@
|
||||
error[E0282]: type annotations needed
|
||||
error[E0283]: type annotations needed
|
||||
--> $DIR/sort_by_key.rs:3:40
|
||||
|
|
||||
LL | lst.sort_by_key(|&(v, _)| v.iter().sum());
|
||||
| ^^^ cannot infer type of the type parameter `S` declared on the method `sum`
|
||||
| ----------- ^^^ cannot infer type of the type parameter `S` declared on the method `sum`
|
||||
| |
|
||||
| type must be known at this point
|
||||
|
|
||||
= note: cannot satisfy `_: Ord`
|
||||
note: required by a bound in `slice::<impl [T]>::sort_by_key`
|
||||
--> $SRC_DIR/alloc/src/slice.rs:LL:COL
|
||||
help: consider specifying the generic argument
|
||||
|
|
||||
LL | lst.sort_by_key(|&(v, _)| v.iter().sum::<S>());
|
||||
@ -11,4 +16,4 @@ LL | lst.sort_by_key(|&(v, _)| v.iter().sum::<S>());
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0282`.
|
||||
For more information about this error, try `rustc --explain E0283`.
|
||||
|
@ -2,7 +2,7 @@ error[E0282]: type annotations needed for `Vec<_>`
|
||||
--> $DIR/cannot_infer_local_or_vec.rs:2:9
|
||||
|
|
||||
LL | let x = vec![];
|
||||
| ^
|
||||
| ^ ------ type must be known at this point
|
||||
|
|
||||
help: consider giving `x` an explicit type, where the placeholders `_` are specified
|
||||
|
|
||||
|
@ -14,6 +14,15 @@ help: consider further restricting type parameter `U`
|
||||
LL | fn foo<T,U>() where T: ExtraCopy<U>, U: std::marker::Copy
|
||||
| ++++++++++++++++++++++
|
||||
|
||||
error[E0038]: the trait `Copy` cannot be made into an object
|
||||
--> $DIR/wf-fn-where-clause.rs:12:16
|
||||
|
|
||||
LL | fn bar() where Vec<dyn Copy>:, {}
|
||||
| ^^^^^^^^^^^^^ `Copy` cannot be made into an object
|
||||
|
|
||||
= note: the trait cannot be made into an object because it requires `Self: Sized`
|
||||
= note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
|
||||
|
||||
error[E0277]: the size for values of type `(dyn Copy + 'static)` cannot be known at compilation time
|
||||
--> $DIR/wf-fn-where-clause.rs:12:16
|
||||
|
|
||||
@ -34,15 +43,6 @@ LL | struct Vec<T> {
|
||||
LL | t: T,
|
||||
| - ...if indirection were used here: `Box<T>`
|
||||
|
||||
error[E0038]: the trait `Copy` cannot be made into an object
|
||||
--> $DIR/wf-fn-where-clause.rs:12:16
|
||||
|
|
||||
LL | fn bar() where Vec<dyn Copy>:, {}
|
||||
| ^^^^^^^^^^^^^ `Copy` cannot be made into an object
|
||||
|
|
||||
= note: the trait cannot be made into an object because it requires `Self: Sized`
|
||||
= note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0038, E0277.
|
||||
|
Loading…
Reference in New Issue
Block a user