Skip to content

Commit eca9c01

Browse files
authored
2 parents e31ebae + e449daa commit eca9c01

File tree

7 files changed

+30
-13
lines changed

7 files changed

+30
-13
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::FnCtxt;
22
use rustc_hir as hir;
33
use rustc_hir::def::Res;
44
use rustc_hir::def_id::DefId;
5-
use rustc_infer::traits::ObligationCauseCode;
5+
use rustc_infer::{infer::type_variable::TypeVariableOriginKind, traits::ObligationCauseCode};
66
use rustc_middle::ty::{self, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitor};
77
use rustc_span::{self, symbol::kw, Span};
88
use rustc_trait_selection::traits;
@@ -267,8 +267,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
267267
type BreakTy = ty::GenericArg<'tcx>;
268268
fn visit_ty(&mut self, ty: Ty<'tcx>) -> std::ops::ControlFlow<Self::BreakTy> {
269269
if let Some(origin) = self.0.type_var_origin(ty)
270-
&& let rustc_infer::infer::type_variable::TypeVariableOriginKind::TypeParameterDefinition(_, def_id) =
271-
origin.kind
270+
&& let TypeVariableOriginKind::TypeParameterDefinition(_, def_id) = origin.kind
272271
&& let generics = self.0.tcx.generics_of(self.1)
273272
&& let Some(index) = generics.param_def_id_to_index(self.0.tcx, def_id)
274273
&& let Some(subst) = ty::GenericArgs::identity_for_item(self.0.tcx, self.1)

compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ fn fmt_printer<'a, 'tcx>(infcx: &'a InferCtxt<'tcx>, ns: Namespace) -> FmtPrinte
163163
let ty_vars = infcx_inner.type_variables();
164164
let var_origin = ty_vars.var_origin(ty_vid);
165165
if let TypeVariableOriginKind::TypeParameterDefinition(name, def_id) = var_origin.kind
166-
&& !var_origin.span.from_expansion()
166+
&& name != kw::SelfUpper && !var_origin.span.from_expansion()
167167
{
168168
let generics = infcx.tcx.generics_of(infcx.tcx.parent(def_id));
169169
let idx = generics.param_def_id_to_index(infcx.tcx, def_id).unwrap();

compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -2388,14 +2388,11 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
23882388
// If there is only one implementation of the trait, suggest using it.
23892389
// Otherwise, use a placeholder comment for the implementation.
23902390
let (message, impl_suggestion) = if non_blanket_impl_count == 1 {(
2391-
"use the fully-qualified path to the only available implementation".to_string(),
2391+
"use the fully-qualified path to the only available implementation",
23922392
format!("<{} as ", self.tcx.type_of(impl_def_id).instantiate_identity())
2393-
)} else {(
2394-
format!(
2395-
"use a fully-qualified path to a specific available implementation ({} found)",
2396-
non_blanket_impl_count
2397-
),
2398-
"</* self type */ as ".to_string()
2393+
)} else {
2394+
("use a fully-qualified path to a specific available implementation",
2395+
"</* self type */ as ".to_string()
23992396
)};
24002397
let mut suggestions = vec![(
24012398
path.span.shrink_to_lo(),

tests/ui/error-codes/E0283.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | fn create() -> u32;
77
LL | let cont: u32 = Generator::create();
88
| ^^^^^^^^^^^^^^^^^ cannot call associated function of trait
99
|
10-
help: use a fully-qualified path to a specific available implementation (2 found)
10+
help: use a fully-qualified path to a specific available implementation
1111
|
1212
LL | let cont: u32 = </* self type */ as Generator>::create();
1313
| +++++++++++++++++++ +

tests/ui/error-codes/E0790.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ LL | fn my_fn();
6363
LL | MyTrait2::my_fn();
6464
| ^^^^^^^^^^^^^^^ cannot call associated function of trait
6565
|
66-
help: use a fully-qualified path to a specific available implementation (2 found)
66+
help: use a fully-qualified path to a specific available implementation
6767
|
6868
LL | </* self type */ as MyTrait2>::my_fn();
6969
| +++++++++++++++++++ +
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Regression test for #113610 where we ICEd when trying to print
2+
// inference variables created by instantiating the self type parameter.
3+
4+
fn main() {
5+
let _ = (Default::default(),);
6+
//~^ ERROR cannot call associated function on trait
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0790]: cannot call associated function on trait without specifying the corresponding `impl` type
2+
--> $DIR/infer-var-for-self-param.rs:5:14
3+
|
4+
LL | let _ = (Default::default(),);
5+
| ^^^^^^^^^^^^^^^^ cannot call associated function of trait
6+
|
7+
help: use a fully-qualified path to a specific available implementation
8+
|
9+
LL | let _ = (</* self type */ as Default>::default(),);
10+
| +++++++++++++++++++ +
11+
12+
error: aborting due to previous error
13+
14+
For more information about this error, try `rustc --explain E0790`.

0 commit comments

Comments
 (0)