Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f2b1278

Browse files
committedMay 29, 2024·
Delegation: partial generics support
1 parent f2e1a3a commit f2b1278

27 files changed

+1078
-252
lines changed
 

‎compiler/rustc_ast_lowering/src/delegation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
//! HIR ty lowering.
3434
//!
3535
//! Similarly generics, predicates and header are set to the "default" values.
36-
//! In case of discrepancy with callee function the `NotSupportedDelegation` error will
36+
//! In case of discrepancy with callee function the `UnsupportedDelegation` error will
3737
//! also be emitted during HIR ty lowering.
3838
3939
use crate::{ImplTraitPosition, ResolverAstLoweringExt};

‎compiler/rustc_hir_analysis/messages.ftl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,10 +309,6 @@ hir_analysis_must_implement_not_function_span_note = required by this annotation
309309
310310
hir_analysis_must_implement_one_of_attribute = the `#[rustc_must_implement_one_of]` attribute must be used with at least 2 args
311311
312-
hir_analysis_not_supported_delegation =
313-
{$descr} is not supported yet
314-
.label = callee defined here
315-
316312
hir_analysis_only_current_traits_adt = `{$name}` is not defined in the current crate
317313
318314
hir_analysis_only_current_traits_arbitrary = only traits defined in the current crate can be implemented for arbitrary types

‎compiler/rustc_hir_analysis/src/collect/generics_of.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
5151
};
5252
}
5353

54+
if tcx.hir().opt_delegation_sig_id(def_id).is_some()
55+
&& let Some(generics) = &tcx.lower_delegation_ty(def_id).generics
56+
{
57+
return generics.clone();
58+
}
59+
5460
let hir_id = tcx.local_def_id_to_hir_id(def_id);
5561

5662
let node = tcx.hir_node(hir_id);

‎compiler/rustc_hir_analysis/src/collect/predicates_of.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
111111
None => {}
112112
}
113113

114+
if tcx.hir().opt_delegation_sig_id(def_id).is_some()
115+
&& let Some(predicates) = tcx.lower_delegation_ty(def_id).predicates
116+
{
117+
return predicates;
118+
}
119+
114120
let hir_id = tcx.local_def_id_to_hir_id(def_id);
115121
let node = tcx.hir_node(hir_id);
116122

‎compiler/rustc_hir_analysis/src/errors.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1569,16 +1569,6 @@ pub enum RefOfMutStaticSugg {
15691569
},
15701570
}
15711571

1572-
#[derive(Diagnostic)]
1573-
#[diag(hir_analysis_not_supported_delegation)]
1574-
pub struct NotSupportedDelegation<'a> {
1575-
#[primary_span]
1576-
pub span: Span,
1577-
pub descr: &'a str,
1578-
#[label]
1579-
pub callee_span: Span,
1580-
}
1581-
15821572
#[derive(Diagnostic)]
15831573
#[diag(hir_analysis_method_should_return_future)]
15841574
pub struct MethodShouldReturnFuture {

‎compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

Lines changed: 5 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1939,94 +1939,11 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
19391939
self.lower_ty_common(hir_ty, false, true)
19401940
}
19411941

1942-
fn check_delegation_constraints(&self, sig_id: DefId, span: Span, emit: bool) -> bool {
1943-
let mut error_occured = false;
1944-
let sig_span = self.tcx().def_span(sig_id);
1945-
let mut try_emit = |descr| {
1946-
if emit {
1947-
self.tcx().dcx().emit_err(crate::errors::NotSupportedDelegation {
1948-
span,
1949-
descr,
1950-
callee_span: sig_span,
1951-
});
1952-
}
1953-
error_occured = true;
1954-
};
1955-
1956-
if let Some(node) = self.tcx().hir().get_if_local(sig_id)
1957-
&& let Some(decl) = node.fn_decl()
1958-
&& let hir::FnRetTy::Return(ty) = decl.output
1959-
&& let hir::TyKind::InferDelegation(_, _) = ty.kind
1960-
{
1961-
try_emit("recursive delegation");
1962-
}
1963-
1964-
let sig_generics = self.tcx().generics_of(sig_id);
1965-
let parent = self.tcx().parent(self.item_def_id());
1966-
let parent_generics = self.tcx().generics_of(parent);
1967-
1968-
let parent_is_trait = (self.tcx().def_kind(parent) == DefKind::Trait) as usize;
1969-
let sig_has_self = sig_generics.has_self as usize;
1970-
1971-
if sig_generics.count() > sig_has_self || parent_generics.count() > parent_is_trait {
1972-
try_emit("delegation with early bound generics");
1973-
}
1974-
1975-
// There is no way to instantiate `Self` param for caller if
1976-
// 1. callee is a trait method
1977-
// 2. delegation item isn't an associative item
1978-
if let DefKind::AssocFn = self.tcx().def_kind(sig_id)
1979-
&& let DefKind::Fn = self.tcx().def_kind(self.item_def_id())
1980-
&& self.tcx().associated_item(sig_id).container
1981-
== ty::AssocItemContainer::TraitContainer
1982-
{
1983-
try_emit("delegation to a trait method from a free function");
1984-
}
1985-
1986-
error_occured
1987-
}
1988-
1989-
fn lower_delegation_ty(
1990-
&self,
1991-
sig_id: DefId,
1992-
idx: hir::InferDelegationKind,
1993-
span: Span,
1994-
) -> Ty<'tcx> {
1995-
if self.check_delegation_constraints(sig_id, span, idx == hir::InferDelegationKind::Output)
1996-
{
1997-
let e = self.tcx().dcx().span_delayed_bug(span, "not supported delegation case");
1998-
self.set_tainted_by_errors(e);
1999-
return Ty::new_error(self.tcx(), e);
2000-
};
2001-
let sig = self.tcx().fn_sig(sig_id);
2002-
let sig_generics = self.tcx().generics_of(sig_id);
2003-
2004-
let parent = self.tcx().parent(self.item_def_id());
2005-
let parent_def_kind = self.tcx().def_kind(parent);
2006-
2007-
let sig = if let DefKind::Impl { .. } = parent_def_kind
2008-
&& sig_generics.has_self
2009-
{
2010-
// Generic params can't be here except the trait self type.
2011-
// They are not supported yet.
2012-
assert_eq!(sig_generics.count(), 1);
2013-
assert_eq!(self.tcx().generics_of(parent).count(), 0);
2014-
2015-
let self_ty = self.tcx().type_of(parent).instantiate_identity();
2016-
let generic_self_ty = ty::GenericArg::from(self_ty);
2017-
let args = self.tcx().mk_args_from_iter(std::iter::once(generic_self_ty));
2018-
sig.instantiate(self.tcx(), args)
2019-
} else {
2020-
sig.instantiate_identity()
2021-
};
2022-
2023-
// Bound vars are also inherited from `sig_id`.
2024-
// They will be rebound later in `lower_fn_ty`.
2025-
let sig = sig.skip_binder();
2026-
1942+
fn lower_delegation_ty(&self, idx: hir::InferDelegationKind) -> Ty<'tcx> {
1943+
let delegation_res = self.tcx().lower_delegation_ty(self.item_def_id().expect_local());
20271944
match idx {
2028-
hir::InferDelegationKind::Input(id) => sig.inputs()[id],
2029-
hir::InferDelegationKind::Output => sig.output(),
1945+
hir::InferDelegationKind::Input(idx) => delegation_res.inputs[idx],
1946+
hir::InferDelegationKind::Output => delegation_res.output,
20301947
}
20311948
}
20321949

@@ -2043,9 +1960,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
20431960
let tcx = self.tcx();
20441961

20451962
let result_ty = match &hir_ty.kind {
2046-
hir::TyKind::InferDelegation(sig_id, idx) => {
2047-
self.lower_delegation_ty(*sig_id, *idx, hir_ty.span)
2048-
}
1963+
hir::TyKind::InferDelegation(_, idx) => self.lower_delegation_ty(*idx),
20491964
hir::TyKind::Slice(ty) => Ty::new_slice(tcx, self.lower_ty(ty)),
20501965
hir::TyKind::Ptr(mt) => Ty::new_ptr(tcx, self.lower_ty(mt.ty), mt.mutbl),
20511966
hir::TyKind::Ref(region, mt) => {

‎compiler/rustc_hir_typeck/messages.ftl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ hir_typeck_no_associated_item = no {$item_kind} named `{$item_name}` found for {
111111
*[other] {" "}in the current scope
112112
}
113113
114+
hir_typeck_not_supported_delegation =
115+
{$descr}
116+
.label = callee defined here
117+
114118
hir_typeck_note_caller_chooses_ty_for_ty_param = the caller chooses a type for `{$ty_param_name}` which can be different from `{$found_ty}`
115119
116120
hir_typeck_note_edition_guide = for more on editions, read https://doc.rust-lang.org/edition-guide

‎compiler/rustc_hir_typeck/src/delegation.rs

Lines changed: 402 additions & 0 deletions
Large diffs are not rendered by default.

‎compiler/rustc_hir_typeck/src/errors.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,3 +679,13 @@ pub struct ReplaceWithName {
679679
pub span: Span,
680680
pub name: String,
681681
}
682+
683+
#[derive(Diagnostic)]
684+
#[diag(hir_typeck_not_supported_delegation)]
685+
pub struct UnsupportedDelegation<'a> {
686+
#[primary_span]
687+
pub span: Span,
688+
pub descr: &'a str,
689+
#[label]
690+
pub callee_span: Span,
691+
}

‎compiler/rustc_hir_typeck/src/lib.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub mod cast;
1818
mod check;
1919
mod closure;
2020
mod coercion;
21+
mod delegation;
2122
mod demand;
2223
mod diverges;
2324
mod errors;
@@ -39,6 +40,7 @@ mod upvar;
3940
mod writeback;
4041

4142
pub use coercion::can_coerce;
43+
use delegation::lower_delegation_ty;
4244
use fn_ctxt::FnCtxt;
4345
use typeck_root_ctxt::TypeckRootCtxt;
4446

@@ -415,5 +417,11 @@ fn fatally_break_rust(tcx: TyCtxt<'_>, span: Span) -> ! {
415417

416418
pub fn provide(providers: &mut Providers) {
417419
method::provide(providers);
418-
*providers = Providers { typeck, diagnostic_only_typeck, used_trait_imports, ..*providers };
420+
*providers = Providers {
421+
typeck,
422+
diagnostic_only_typeck,
423+
used_trait_imports,
424+
lower_delegation_ty,
425+
..*providers
426+
};
419427
}

‎compiler/rustc_hir_typeck/src/typeck_root_ctxt.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,16 @@ impl<'tcx> Deref for TypeckRootCtxt<'tcx> {
7676

7777
impl<'tcx> TypeckRootCtxt<'tcx> {
7878
pub fn new(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Self {
79-
let hir_owner = tcx.local_def_id_to_hir_id(def_id).owner;
80-
8179
let infcx = tcx.infer_ctxt().ignoring_regions().with_opaque_type_inference(def_id).build();
80+
Self::new_with_infcx(tcx, def_id, infcx)
81+
}
82+
83+
pub(super) fn new_with_infcx(
84+
tcx: TyCtxt<'tcx>,
85+
def_id: LocalDefId,
86+
infcx: InferCtxt<'tcx>,
87+
) -> Self {
88+
let hir_owner = tcx.local_def_id_to_hir_id(def_id).owner;
8289
let typeck_results = RefCell::new(ty::TypeckResults::new(hir_owner));
8390

8491
TypeckRootCtxt {

‎compiler/rustc_middle/src/hir/map/mod.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,21 @@ impl<'hir> Map<'hir> {
736736
}
737737
}
738738

739+
pub fn opt_delegation_sig_id(self, def_id: LocalDefId) -> Option<DefId> {
740+
if let Some(ret) = self.get_fn_output(def_id)
741+
&& let FnRetTy::Return(ty) = ret
742+
&& let TyKind::InferDelegation(sig_id, _) = ty.kind
743+
{
744+
return Some(sig_id);
745+
}
746+
None
747+
}
748+
749+
#[inline]
750+
pub fn delegation_sig_id(self, def_id: LocalDefId) -> DefId {
751+
self.opt_delegation_sig_id(def_id).unwrap()
752+
}
753+
739754
#[inline]
740755
fn opt_ident(self, id: HirId) -> Option<Ident> {
741756
match self.tcx.hir_node(id) {

‎compiler/rustc_middle/src/query/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1666,6 +1666,11 @@ rustc_queries! {
16661666
desc { |tcx| "getting the native library for `{}`", tcx.def_path_str(def_id) }
16671667
}
16681668

1669+
query lower_delegation_ty(_: LocalDefId) -> &'tcx ty::LoweredDelegation<'tcx> {
1670+
arena_cache
1671+
desc { "inheriting delegation type" }
1672+
}
1673+
16691674
/// Does lifetime resolution on items. Importantly, we can't resolve
16701675
/// lifetimes directly on things like trait methods, because of trait params.
16711676
/// See `rustc_resolve::late::lifetimes` for details.

‎compiler/rustc_middle/src/ty/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2130,6 +2130,14 @@ pub struct DestructuredConst<'tcx> {
21302130
pub fields: &'tcx [ty::Const<'tcx>],
21312131
}
21322132

2133+
#[derive(Clone, Debug, HashStable)]
2134+
pub struct LoweredDelegation<'tcx> {
2135+
pub inputs: &'tcx [Ty<'tcx>],
2136+
pub output: Ty<'tcx>,
2137+
pub generics: Option<Generics>,
2138+
pub predicates: Option<GenericPredicates<'tcx>>,
2139+
}
2140+
21332141
// Some types are used a lot. Make sure they don't unintentionally get bigger.
21342142
#[cfg(target_pointer_width = "64")]
21352143
mod size_asserts {

‎compiler/rustc_resolve/src/late.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3240,16 +3240,19 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
32403240
}
32413241

32423242
fn resolve_delegation(&mut self, delegation: &'ast Delegation) {
3243-
self.smart_resolve_path(
3244-
delegation.id,
3245-
&delegation.qself,
3246-
&delegation.path,
3247-
PathSource::Delegation,
3248-
);
3249-
if let Some(qself) = &delegation.qself {
3250-
self.visit_ty(&qself.ty);
3251-
}
3252-
self.visit_path(&delegation.path, delegation.id);
3243+
self.with_lifetime_rib(LifetimeRibKind::Elided(LifetimeRes::Infer), |this| {
3244+
this.smart_resolve_path(
3245+
delegation.id,
3246+
&delegation.qself,
3247+
&delegation.path,
3248+
PathSource::Delegation,
3249+
);
3250+
3251+
if let Some(qself) = &delegation.qself {
3252+
this.visit_ty(&qself.ty);
3253+
}
3254+
this.visit_path(&delegation.path, delegation.id);
3255+
});
32533256
if let Some(body) = &delegation.body {
32543257
// `PatBoundCtx` is not necessary in this context
32553258
let mut bindings = smallvec![(PatBoundCtx::Product, Default::default())];

‎tests/ui/delegation/explicit-paths.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ mod fn_to_other {
2222
use super::*;
2323

2424
reuse Trait::foo1;
25-
//~^ ERROR delegation to a trait method from a free function is not supported yet
2625
reuse <S as Trait>::foo2;
27-
//~^ ERROR delegation to a trait method from a free function is not supported yet
2826
reuse to_reuse::foo3;
2927
reuse S::foo4;
3028
//~^ ERROR cannot find function `foo4` in `S`
Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0407]: method `foo3` is not a member of trait `Trait`
2-
--> $DIR/explicit-paths.rs:51:9
2+
--> $DIR/explicit-paths.rs:49:9
33
|
44
LL | reuse to_reuse::foo3;
55
| ^^^^^^^^^^^^^^^^----^
@@ -8,7 +8,7 @@ LL | reuse to_reuse::foo3;
88
| not a member of trait `Trait`
99

1010
error[E0407]: method `foo4` is not a member of trait `Trait`
11-
--> $DIR/explicit-paths.rs:53:9
11+
--> $DIR/explicit-paths.rs:51:9
1212
|
1313
LL | reuse F::foo4 { &self.0 }
1414
| ^^^^^^^^^----^^^^^^^^^^^^
@@ -17,76 +17,58 @@ LL | reuse F::foo4 { &self.0 }
1717
| not a member of trait `Trait`
1818

1919
error[E0425]: cannot find function `foo4` in `S`
20-
--> $DIR/explicit-paths.rs:29:14
20+
--> $DIR/explicit-paths.rs:27:14
2121
|
2222
LL | reuse S::foo4;
2323
| ^^^^ not found in `S`
2424

2525
error[E0425]: cannot find function `foo4` in `F`
26-
--> $DIR/explicit-paths.rs:40:18
26+
--> $DIR/explicit-paths.rs:38:18
2727
|
2828
LL | reuse F::foo4 { &self.0 }
2929
| ^^^^ not found in `F`
3030
|
3131
note: function `fn_to_other::foo4` exists but is inaccessible
32-
--> $DIR/explicit-paths.rs:29:5
32+
--> $DIR/explicit-paths.rs:27:5
3333
|
3434
LL | reuse S::foo4;
3535
| ^^^^^^^^^^^^^^ not accessible
3636

3737
error[E0425]: cannot find function `foo4` in `F`
38-
--> $DIR/explicit-paths.rs:53:18
38+
--> $DIR/explicit-paths.rs:51:18
3939
|
4040
LL | reuse F::foo4 { &self.0 }
4141
| ^^^^ not found in `F`
4242
|
4343
note: function `fn_to_other::foo4` exists but is inaccessible
44-
--> $DIR/explicit-paths.rs:29:5
44+
--> $DIR/explicit-paths.rs:27:5
4545
|
4646
LL | reuse S::foo4;
4747
| ^^^^^^^^^^^^^^ not accessible
4848

4949
error[E0425]: cannot find function `foo4` in `F`
50-
--> $DIR/explicit-paths.rs:67:18
50+
--> $DIR/explicit-paths.rs:65:18
5151
|
5252
LL | reuse F::foo4 { &F }
5353
| ^^^^ not found in `F`
5454
|
5555
note: function `fn_to_other::foo4` exists but is inaccessible
56-
--> $DIR/explicit-paths.rs:29:5
56+
--> $DIR/explicit-paths.rs:27:5
5757
|
5858
LL | reuse S::foo4;
5959
| ^^^^^^^^^^^^^^ not accessible
6060

6161
error[E0119]: conflicting implementations of trait `Trait` for type `S`
62-
--> $DIR/explicit-paths.rs:76:5
62+
--> $DIR/explicit-paths.rs:74:5
6363
|
6464
LL | impl Trait for S {
6565
| ---------------- first implementation here
6666
...
6767
LL | impl Trait for S {
6868
| ^^^^^^^^^^^^^^^^ conflicting implementation for `S`
6969

70-
error: delegation to a trait method from a free function is not supported yet
71-
--> $DIR/explicit-paths.rs:24:18
72-
|
73-
LL | fn foo1(&self, x: i32) -> i32 { x }
74-
| ----------------------------- callee defined here
75-
...
76-
LL | reuse Trait::foo1;
77-
| ^^^^
78-
79-
error: delegation to a trait method from a free function is not supported yet
80-
--> $DIR/explicit-paths.rs:26:25
81-
|
82-
LL | fn foo2(x: i32) -> i32 { x }
83-
| ---------------------- callee defined here
84-
...
85-
LL | reuse <S as Trait>::foo2;
86-
| ^^^^
87-
8870
error[E0308]: mismatched types
89-
--> $DIR/explicit-paths.rs:63:36
71+
--> $DIR/explicit-paths.rs:61:36
9072
|
9173
LL | trait Trait2 : Trait {
9274
| -------------------- found this type parameter
@@ -97,7 +79,7 @@ LL | reuse <F as Trait>::foo1 { self }
9779
found reference `&Self`
9880

9981
error[E0277]: the trait bound `S2: Trait` is not satisfied
100-
--> $DIR/explicit-paths.rs:78:16
82+
--> $DIR/explicit-paths.rs:76:16
10183
|
10284
LL | reuse <S2 as Trait>::foo1;
10385
| ^^ the trait `Trait` is not implemented for `S2`
@@ -107,7 +89,7 @@ LL | reuse <S2 as Trait>::foo1;
10789
S
10890

10991
error[E0308]: mismatched types
110-
--> $DIR/explicit-paths.rs:78:30
92+
--> $DIR/explicit-paths.rs:76:30
11193
|
11294
LL | reuse <S2 as Trait>::foo1;
11395
| ---------------^^^^
@@ -123,7 +105,7 @@ note: method defined here
123105
LL | fn foo1(&self, x: i32) -> i32 { x }
124106
| ^^^^ -----
125107

126-
error: aborting due to 12 previous errors
108+
error: aborting due to 10 previous errors
127109

128110
Some errors have detailed explanations: E0119, E0277, E0308, E0407, E0425.
129111
For more information about an error, try `rustc --explain E0119`.
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
//@ run-pass
2+
#![feature(fn_delegation)]
3+
#![allow(incomplete_features)]
4+
5+
mod infer_types {
6+
mod to_reuse {
7+
pub fn foo<T, U>(x: T, y: U) -> (T, U) { (x, y) }
8+
pub fn bar<T>(x: T) -> T { x }
9+
}
10+
11+
pub fn check_shallow_inf_vars() {
12+
#[derive(PartialEq, Debug, Copy, Clone)]
13+
struct T;
14+
#[derive(PartialEq, Debug, Copy, Clone)]
15+
struct U;
16+
{
17+
reuse to_reuse::foo::<_, _>;
18+
assert_eq!(foo(T, U), (T, U));
19+
}
20+
{
21+
reuse to_reuse::foo;
22+
assert_eq!(foo(T, U), (T, U));
23+
}
24+
{
25+
reuse to_reuse::foo::<U, _>;
26+
assert_eq!(foo(U, 0), (U, 0));
27+
}
28+
}
29+
30+
pub fn check_deep_inf_vars() {
31+
#[derive(PartialEq, Debug, Copy, Clone)]
32+
struct Us;
33+
34+
#[derive(PartialEq, Debug, Copy, Clone)]
35+
struct Ss<A, B> {
36+
x: A,
37+
y: B,
38+
}
39+
let x = Ss::<u8, [i32; 1]> { x: 0, y: [1] };
40+
{
41+
reuse to_reuse::foo::<Ss<u8, _>, _>;
42+
let res = foo(x, Us);
43+
assert_eq!(res.1, Us);
44+
assert_eq!(res.0, x);
45+
}
46+
{
47+
reuse to_reuse::foo;
48+
let res = foo(x, Us);
49+
assert_eq!(res.1, Us);
50+
assert_eq!(res.0, x);
51+
}
52+
}
53+
54+
pub fn check_type_aliases() {
55+
trait Trait<T> {
56+
type Type;
57+
}
58+
59+
impl<T> Trait<T> for u8 {
60+
type Type = ();
61+
}
62+
63+
type Type = ();
64+
65+
{
66+
reuse to_reuse::bar::<<u8 as Trait<u8>>::Type>;
67+
assert_eq!(bar(()), ());
68+
}
69+
{
70+
reuse to_reuse::bar::<Type>;
71+
assert_eq!(bar(()), ());
72+
}
73+
}
74+
}
75+
76+
mod infer_late_bound_regions {
77+
mod to_reuse {
78+
pub fn foo<T>(x: &T) -> &T { x }
79+
}
80+
81+
pub fn check() {
82+
let x = 1;
83+
{
84+
reuse to_reuse::foo;
85+
assert_eq!(*foo(&x), 1);
86+
}
87+
}
88+
}
89+
90+
mod infer_early_bound_regions {
91+
mod to_reuse {
92+
pub fn foo<'a: 'a, T>(x: &'a T) -> &'a T { x }
93+
}
94+
95+
pub fn check_shallow_inf_vars() {
96+
let x = 1;
97+
{
98+
reuse to_reuse::foo::<'_, _>;
99+
assert_eq!(*foo(&x), 1);
100+
}
101+
{
102+
reuse to_reuse::foo;
103+
assert_eq!(*foo(&x), 1);
104+
}
105+
}
106+
107+
pub fn check_deep_inf_vars() {
108+
#[derive(PartialEq, Debug, Copy, Clone)]
109+
struct S<'a, U> {
110+
x: &'a U
111+
}
112+
let x = 0;
113+
let s = S { x: &x };
114+
{
115+
reuse to_reuse::foo::<'_, S<'_, i32>>;
116+
assert_eq!(*foo(&s), s);
117+
}
118+
{
119+
reuse to_reuse::foo;
120+
assert_eq!(*foo(&s), s);
121+
}
122+
}
123+
}
124+
125+
mod constants {
126+
mod to_reuse {
127+
pub fn foo1<const N: i32>() -> i32 { N }
128+
pub fn foo2<T>(x: T) -> T { x }
129+
}
130+
131+
pub fn check() {
132+
{
133+
reuse to_reuse::foo1::<42>;
134+
assert_eq!(foo1(), 42);
135+
}
136+
137+
#[derive(PartialEq, Debug)]
138+
struct S<const N: i32 = 1>;
139+
{
140+
reuse to_reuse::foo2::<S>;
141+
let s = S;
142+
assert_eq!(foo2(s), S::<1>);
143+
}
144+
{
145+
reuse to_reuse::foo2::<S::<2>>;
146+
let s = S;
147+
assert_eq!(foo2(s), S::<2>);
148+
}
149+
}
150+
}
151+
152+
fn main() {
153+
infer_types::check_shallow_inf_vars();
154+
infer_types::check_deep_inf_vars();
155+
infer_types::check_type_aliases();
156+
infer_late_bound_regions::check();
157+
infer_early_bound_regions::check_shallow_inf_vars();
158+
infer_early_bound_regions::check_deep_inf_vars();
159+
constants::check();
160+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#![feature(fn_delegation)]
2+
#![allow(incomplete_features)]
3+
4+
mod infer_types {
5+
trait Trait {}
6+
7+
mod to_reuse {
8+
use super::*;
9+
10+
pub fn foo<T, U>(x: T, y: U) -> (T, U) { (x, y) }
11+
pub fn foo2<T: Trait>(x: T) -> T { x }
12+
}
13+
14+
fn check() {
15+
{
16+
reuse to_reuse::foo::<_>;
17+
//~^ ERROR function takes 2 generic arguments but 1 generic argument was supplied
18+
//~| ERROR function takes 2 generic arguments but 1 generic argument was supplied
19+
}
20+
{
21+
reuse to_reuse::foo2::<u32>;
22+
//~^ ERROR the trait bound `u32: infer_types::Trait` is not satisfied
23+
}
24+
{
25+
reuse to_reuse::foo2<u32>;
26+
//~^ ERROR expected one of `::`, `;`, `as`, or `{`, found `<`
27+
}
28+
{
29+
reuse to_reuse::foo2::<T>;
30+
//~^ ERROR cannot find type `T` in this scope
31+
}
32+
}
33+
}
34+
35+
mod infer_late_bound_regions {
36+
mod to_reuse {
37+
pub fn foo<T>(x: &T) -> &T { x }
38+
}
39+
40+
fn check() {
41+
let x = 1;
42+
{
43+
reuse to_reuse::foo::<'_>;
44+
//~^ ERROR cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
45+
//~| ERROR cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
46+
assert_eq!(*foo(&x), 1);
47+
}
48+
}
49+
}
50+
51+
mod infer_early_bound_regions {
52+
mod to_reuse {
53+
pub fn foo<'a: 'a, T>(x: &'a T) -> &'a T { x }
54+
}
55+
56+
fn check() {
57+
let x = 1;
58+
{
59+
reuse to_reuse::foo::<'static, _>;
60+
assert_eq!(*foo(&x), 1);
61+
//~^ ERROR `x` does not live long enough
62+
}
63+
{
64+
fn bar<'a: 'a>(_: &'a i32) {
65+
reuse to_reuse::foo::<'a, _>;
66+
//~^ ERROR can't use generic parameters from outer item
67+
}
68+
69+
reuse to_reuse::foo::<'a, _>;
70+
//~^ ERROR use of undeclared lifetime name `'a`
71+
assert_eq!(*foo(&x), 1);
72+
}
73+
}
74+
}
75+
76+
fn main() {}
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
error: expected one of `::`, `;`, `as`, or `{`, found `<`
2+
--> $DIR/free-fn-to-free-fn.rs:25:33
3+
|
4+
LL | reuse to_reuse::foo2<u32>;
5+
| ^ expected one of `::`, `;`, `as`, or `{`
6+
7+
error[E0401]: can't use generic parameters from outer item
8+
--> $DIR/free-fn-to-free-fn.rs:65:39
9+
|
10+
LL | fn bar<'a: 'a>(_: &'a i32) {
11+
| -- lifetime parameter from outer item
12+
LL | reuse to_reuse::foo::<'a, _>;
13+
| - ^^ use of generic parameter from outer item
14+
| |
15+
| help: consider introducing lifetime `'a` here: `'a,`
16+
17+
error[E0261]: use of undeclared lifetime name `'a`
18+
--> $DIR/free-fn-to-free-fn.rs:69:35
19+
|
20+
LL | reuse to_reuse::foo::<'a, _>;
21+
| - ^^ undeclared lifetime
22+
| |
23+
| help: consider introducing lifetime `'a` here: `'a,`
24+
25+
error[E0412]: cannot find type `T` in this scope
26+
--> $DIR/free-fn-to-free-fn.rs:29:36
27+
|
28+
LL | reuse to_reuse::foo2::<T>;
29+
| ^ not found in this scope
30+
31+
error[E0107]: function takes 2 generic arguments but 1 generic argument was supplied
32+
--> $DIR/free-fn-to-free-fn.rs:16:29
33+
|
34+
LL | reuse to_reuse::foo::<_>;
35+
| ^^^ - supplied 1 generic argument
36+
| |
37+
| expected 2 generic arguments
38+
|
39+
note: function defined here, with 2 generic parameters: `T`, `U`
40+
--> $DIR/free-fn-to-free-fn.rs:10:16
41+
|
42+
LL | pub fn foo<T, U>(x: T, y: U) -> (T, U) { (x, y) }
43+
| ^^^ - -
44+
help: add missing generic argument
45+
|
46+
LL | reuse to_reuse::foo::<_, _>;
47+
| +++
48+
49+
error[E0277]: the trait bound `u32: infer_types::Trait` is not satisfied
50+
--> $DIR/free-fn-to-free-fn.rs:21:29
51+
|
52+
LL | reuse to_reuse::foo2::<u32>;
53+
| ^^^^ the trait `infer_types::Trait` is not implemented for `u32`
54+
|
55+
help: this trait has no implementations, consider adding one
56+
--> $DIR/free-fn-to-free-fn.rs:5:5
57+
|
58+
LL | trait Trait {}
59+
| ^^^^^^^^^^^
60+
= help: see issue #48214
61+
help: add `#![feature(trivial_bounds)]` to the crate attributes to enable
62+
|
63+
LL + #![feature(trivial_bounds)]
64+
|
65+
66+
error[E0794]: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
67+
--> $DIR/free-fn-to-free-fn.rs:43:35
68+
|
69+
LL | reuse to_reuse::foo::<'_>;
70+
| ^^
71+
|
72+
note: the late bound lifetime parameter is introduced here
73+
--> $DIR/free-fn-to-free-fn.rs:37:26
74+
|
75+
LL | pub fn foo<T>(x: &T) -> &T { x }
76+
| ^
77+
78+
error[E0107]: function takes 2 generic arguments but 1 generic argument was supplied
79+
--> $DIR/free-fn-to-free-fn.rs:16:29
80+
|
81+
LL | reuse to_reuse::foo::<_>;
82+
| ^^^ - supplied 1 generic argument
83+
| |
84+
| expected 2 generic arguments
85+
|
86+
note: function defined here, with 2 generic parameters: `T`, `U`
87+
--> $DIR/free-fn-to-free-fn.rs:10:16
88+
|
89+
LL | pub fn foo<T, U>(x: T, y: U) -> (T, U) { (x, y) }
90+
| ^^^ - -
91+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
92+
help: add missing generic argument
93+
|
94+
LL | reuse to_reuse::foo::<_, _>;
95+
| +++
96+
97+
error[E0794]: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
98+
--> $DIR/free-fn-to-free-fn.rs:43:35
99+
|
100+
LL | reuse to_reuse::foo::<'_>;
101+
| ^^
102+
|
103+
note: the late bound lifetime parameter is introduced here
104+
--> $DIR/free-fn-to-free-fn.rs:37:26
105+
|
106+
LL | pub fn foo<T>(x: &T) -> &T { x }
107+
| ^
108+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
109+
110+
error[E0597]: `x` does not live long enough
111+
--> $DIR/free-fn-to-free-fn.rs:60:29
112+
|
113+
LL | let x = 1;
114+
| - binding `x` declared here
115+
...
116+
LL | assert_eq!(*foo(&x), 1);
117+
| ----^^-
118+
| | |
119+
| | borrowed value does not live long enough
120+
| argument requires that `x` is borrowed for `'static`
121+
...
122+
LL | }
123+
| - `x` dropped here while still borrowed
124+
125+
error: aborting due to 10 previous errors
126+
127+
Some errors have detailed explanations: E0107, E0261, E0277, E0401, E0412, E0597, E0794.
128+
For more information about an error, try `rustc --explain E0107`.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//@ run-pass
2+
#![feature(fn_delegation)]
3+
#![allow(incomplete_features)]
4+
5+
#[derive(PartialEq, Debug, Copy, Clone)]
6+
struct S<'a, U> {
7+
x: &'a U
8+
}
9+
10+
trait Trait<T> {
11+
fn foo<U>(&self, x: U, y: T) -> (T, U) {(y, x)}
12+
}
13+
14+
impl<T> Trait<T> for u8 {}
15+
16+
fn check() {
17+
{
18+
reuse <u8 as Trait<_>>::foo;
19+
assert_eq!(foo(&2, "str", 1), (1, "str"));
20+
}
21+
{
22+
reuse <_ as Trait<_>>::foo::<_>;
23+
assert_eq!(foo(&2, "str", 1), (1, "str"));
24+
}
25+
}
26+
27+
fn check_deep_inf_vars() {
28+
let x = 0;
29+
let s = S { x: &x };
30+
reuse <_ as Trait<S<_>>>::foo;
31+
assert_eq!(foo(&2, "str", s), (s, "str"));
32+
}
33+
34+
fn main() {
35+
check();
36+
check_deep_inf_vars();
37+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#![feature(fn_delegation)]
2+
#![allow(incomplete_features)]
3+
4+
trait Marker {}
5+
6+
trait Trait<T: Marker> {
7+
fn foo<U>(&self, x: U, y: T) -> (T, U) {(y, x)}
8+
fn bar<U: Marker>(&self, x: U) {}
9+
}
10+
11+
impl<T: Marker> Trait<T> for u8 {}
12+
impl Marker for u8 {}
13+
14+
fn main() {
15+
{
16+
reuse <u16 as Trait<_>>::foo;
17+
foo(&2, "str", 1);
18+
//~^ ERROR the trait bound `u16: Trait<_>` is not satisfied
19+
}
20+
{
21+
reuse <u16 as Trait>::foo;
22+
//~^ ERROR missing generics for trait `Trait`
23+
//~| ERROR missing generics for trait `Trait`
24+
}
25+
{
26+
reuse Trait::<_>::bar::<u16>;
27+
//~^ ERROR the trait bound `u16: Marker` is not satisfied
28+
}
29+
{
30+
reuse <u8 as Trait<u16>>::bar;
31+
//~^ ERROR the trait bound `u16: Marker` is not satisfied
32+
}
33+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
error[E0107]: missing generics for trait `Trait`
2+
--> $DIR/free-fn-to-trait-methods.rs:21:23
3+
|
4+
LL | reuse <u16 as Trait>::foo;
5+
| ^^^^^ expected 1 generic argument
6+
|
7+
note: trait defined here, with 1 generic parameter: `T`
8+
--> $DIR/free-fn-to-trait-methods.rs:6:7
9+
|
10+
LL | trait Trait<T: Marker> {
11+
| ^^^^^ -
12+
help: add missing generic argument
13+
|
14+
LL | reuse <u16 as Trait<T>>::foo;
15+
| +++
16+
17+
error[E0277]: the trait bound `u16: Marker` is not satisfied
18+
--> $DIR/free-fn-to-trait-methods.rs:26:27
19+
|
20+
LL | reuse Trait::<_>::bar::<u16>;
21+
| ^^^ the trait `Marker` is not implemented for `u16`
22+
|
23+
= help: the trait `Marker` is implemented for `u8`
24+
= help: see issue #48214
25+
help: add `#![feature(trivial_bounds)]` to the crate attributes to enable
26+
|
27+
LL + #![feature(trivial_bounds)]
28+
|
29+
30+
error[E0277]: the trait bound `u16: Marker` is not satisfied
31+
--> $DIR/free-fn-to-trait-methods.rs:30:35
32+
|
33+
LL | reuse <u8 as Trait<u16>>::bar;
34+
| ^^^ the trait `Marker` is not implemented for `u16`
35+
|
36+
= help: the trait `Marker` is implemented for `u8`
37+
= help: see issue #48214
38+
help: add `#![feature(trivial_bounds)]` to the crate attributes to enable
39+
|
40+
LL + #![feature(trivial_bounds)]
41+
|
42+
43+
error[E0277]: the trait bound `u16: Trait<_>` is not satisfied
44+
--> $DIR/free-fn-to-trait-methods.rs:17:24
45+
|
46+
LL | foo(&2, "str", 1);
47+
| --- ^ the trait `Trait<_>` is not implemented for `u16`
48+
| |
49+
| required by a bound introduced by this call
50+
|
51+
= help: the trait `Trait<_>` is implemented for `u8`
52+
= help: for that trait implementation, expected `u8`, found `u16`
53+
note: required by a bound in `main::foo`
54+
--> $DIR/free-fn-to-trait-methods.rs:16:34
55+
|
56+
LL | reuse <u16 as Trait<_>>::foo;
57+
| ^^^ required by this bound in `foo`
58+
59+
error[E0107]: missing generics for trait `Trait`
60+
--> $DIR/free-fn-to-trait-methods.rs:21:23
61+
|
62+
LL | reuse <u16 as Trait>::foo;
63+
| ^^^^^ expected 1 generic argument
64+
|
65+
note: trait defined here, with 1 generic parameter: `T`
66+
--> $DIR/free-fn-to-trait-methods.rs:6:7
67+
|
68+
LL | trait Trait<T: Marker> {
69+
| ^^^^^ -
70+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
71+
help: add missing generic argument
72+
|
73+
LL | reuse <u16 as Trait<T>>::foo;
74+
| +++
75+
76+
error: aborting due to 5 previous errors
77+
78+
Some errors have detailed explanations: E0107, E0277.
79+
For more information about an error, try `rustc --explain E0107`.

‎tests/ui/delegation/not-supported.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ mod generics {
1414
fn foo3<'a: 'a>(_: &'a u32) {}
1515

1616
reuse GenericTrait::bar;
17-
//~^ ERROR delegation with early bound generics is not supported yet
17+
//~^ ERROR early bound generics are not supported for associated delegation items
1818
reuse GenericTrait::bar1;
19-
//~^ ERROR delegation with early bound generics is not supported yet
19+
//~^ ERROR early bound generics are not supported for associated delegation items
2020
}
2121

2222
struct F;
@@ -27,37 +27,37 @@ mod generics {
2727

2828
impl<T> GenericTrait<T> for S {
2929
reuse <F as GenericTrait<T>>::bar { &self.0 }
30-
//~^ ERROR delegation with early bound generics is not supported yet
30+
//~^ ERROR early bound generics are not supported for associated delegation items
3131
reuse GenericTrait::<T>::bar1;
32-
//~^ ERROR delegation with early bound generics is not supported yet
32+
//~^ ERROR early bound generics are not supported for associated delegation items
3333
}
3434

3535
impl GenericTrait<()> for () {
3636
reuse GenericTrait::bar { &F }
37-
//~^ ERROR delegation with early bound generics is not supported yet
37+
//~^ ERROR early bound generics are not supported for associated delegation items
3838
reuse GenericTrait::bar1;
39-
//~^ ERROR delegation with early bound generics is not supported yet
39+
//~^ ERROR early bound generics are not supported for associated delegation items
4040
}
4141

4242
impl Trait for &S {
4343
reuse Trait::foo;
44-
//~^ ERROR delegation with early bound generics is not supported yet
44+
//~^ ERROR early bound generics are not supported for associated delegation items
4545
}
4646

4747
impl Trait for S {
4848
reuse Trait::foo1 { &self.0 }
4949
reuse Trait::foo2 { &self.0 }
50-
//~^ ERROR delegation with early bound generics is not supported yet
50+
//~^ ERROR early bound generics are not supported for associated delegation items
5151
//~| ERROR method `foo2` has 0 type parameters but its trait declaration has 1 type parameter
5252
reuse <F as Trait>::foo3;
53-
//~^ ERROR delegation with early bound generics is not supported yet
53+
//~^ ERROR early bound generics are not supported for associated delegation items
5454
//~| ERROR lifetime parameters or bounds on method `foo3` do not match the trait declaration
5555
}
5656

5757
struct GenericS<T>(T);
5858
impl<T> Trait for GenericS<T> {
5959
reuse Trait::foo { &self.0 }
60-
//~^ ERROR delegation with early bound generics is not supported yet
60+
//~^ ERROR early bound generics are not supported for associated delegation items
6161
}
6262
}
6363

@@ -72,7 +72,6 @@ mod opaque {
7272
pub fn opaque_ret() -> impl Trait { unimplemented!() }
7373
}
7474
reuse to_reuse::opaque_arg;
75-
//~^ ERROR delegation with early bound generics is not supported yet
7675

7776
trait ToReuse {
7877
fn opaque_ret() -> impl Trait { unimplemented!() }
Lines changed: 40 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: delegation with early bound generics is not supported yet
1+
error: early bound generics are not supported for associated delegation items
22
--> $DIR/not-supported.rs:16:29
33
|
44
LL | fn bar(&self, x: T) -> T { x }
@@ -7,7 +7,7 @@ LL | fn bar(&self, x: T) -> T { x }
77
LL | reuse GenericTrait::bar;
88
| ^^^
99

10-
error: delegation with early bound generics is not supported yet
10+
error: early bound generics are not supported for associated delegation items
1111
--> $DIR/not-supported.rs:18:29
1212
|
1313
LL | fn bar1() {}
@@ -16,7 +16,7 @@ LL | fn bar1() {}
1616
LL | reuse GenericTrait::bar1;
1717
| ^^^^
1818

19-
error: delegation with early bound generics is not supported yet
19+
error: early bound generics are not supported for associated delegation items
2020
--> $DIR/not-supported.rs:29:39
2121
|
2222
LL | fn bar(&self, x: T) -> T { x }
@@ -25,7 +25,7 @@ LL | fn bar(&self, x: T) -> T { x }
2525
LL | reuse <F as GenericTrait<T>>::bar { &self.0 }
2626
| ^^^
2727

28-
error: delegation with early bound generics is not supported yet
28+
error: early bound generics are not supported for associated delegation items
2929
--> $DIR/not-supported.rs:31:34
3030
|
3131
LL | fn bar1() {}
@@ -34,7 +34,7 @@ LL | fn bar1() {}
3434
LL | reuse GenericTrait::<T>::bar1;
3535
| ^^^^
3636

37-
error: delegation with early bound generics is not supported yet
37+
error: early bound generics are not supported for associated delegation items
3838
--> $DIR/not-supported.rs:36:29
3939
|
4040
LL | fn bar(&self, x: T) -> T { x }
@@ -43,7 +43,7 @@ LL | fn bar(&self, x: T) -> T { x }
4343
LL | reuse GenericTrait::bar { &F }
4444
| ^^^
4545

46-
error: delegation with early bound generics is not supported yet
46+
error: early bound generics are not supported for associated delegation items
4747
--> $DIR/not-supported.rs:38:29
4848
|
4949
LL | fn bar1() {}
@@ -52,7 +52,7 @@ LL | fn bar1() {}
5252
LL | reuse GenericTrait::bar1;
5353
| ^^^^
5454

55-
error: delegation with early bound generics is not supported yet
55+
error: early bound generics are not supported for associated delegation items
5656
--> $DIR/not-supported.rs:43:22
5757
|
5858
LL | fn foo(&self, x: i32) -> i32 { x }
@@ -61,6 +61,15 @@ LL | fn foo(&self, x: i32) -> i32 { x }
6161
LL | reuse Trait::foo;
6262
| ^^^
6363

64+
error: early bound generics are not supported for associated delegation items
65+
--> $DIR/not-supported.rs:49:22
66+
|
67+
LL | fn foo2<T>(&self, x: T) -> T { x }
68+
| ---------------------------- callee defined here
69+
...
70+
LL | reuse Trait::foo2 { &self.0 }
71+
| ^^^^
72+
6473
error[E0049]: method `foo2` has 0 type parameters but its trait declaration has 1 type parameter
6574
--> $DIR/not-supported.rs:49:22
6675
|
@@ -70,7 +79,7 @@ LL | fn foo2<T>(&self, x: T) -> T { x }
7079
LL | reuse Trait::foo2 { &self.0 }
7180
| ^^^^ found 0 type parameters
7281

73-
error: delegation with early bound generics is not supported yet
82+
error: early bound generics are not supported for associated delegation items
7483
--> $DIR/not-supported.rs:52:29
7584
|
7685
LL | fn foo3<'a: 'a>(_: &'a u32) {}
@@ -88,81 +97,63 @@ LL | fn foo3<'a: 'a>(_: &'a u32) {}
8897
LL | reuse <F as Trait>::foo3;
8998
| ^^^^ lifetimes do not match method in trait
9099

91-
error: delegation with early bound generics is not supported yet
92-
--> $DIR/not-supported.rs:59:22
100+
error: recursive delegation is not supported yet
101+
--> $DIR/not-supported.rs:98:22
93102
|
94-
LL | fn foo(&self, x: i32) -> i32 { x }
95-
| ---------------------------- callee defined here
103+
LL | pub reuse to_reuse2::foo;
104+
| --- callee defined here
96105
...
97-
LL | reuse Trait::foo { &self.0 }
106+
LL | reuse to_reuse1::foo;
98107
| ^^^
99108

100-
error: delegation with early bound generics is not supported yet
101-
--> $DIR/not-supported.rs:49:22
109+
error: early bound generics are not supported for associated delegation items
110+
--> $DIR/not-supported.rs:59:22
102111
|
103-
LL | fn foo2<T>(&self, x: T) -> T { x }
112+
LL | fn foo(&self, x: i32) -> i32 { x }
104113
| ---------------------------- callee defined here
105114
...
106-
LL | reuse Trait::foo2 { &self.0 }
107-
| ^^^^
108-
109-
error: delegation with early bound generics is not supported yet
110-
--> $DIR/not-supported.rs:74:21
111-
|
112-
LL | pub fn opaque_arg(_: impl Trait) -> i32 { 0 }
113-
| --------------------------------------- callee defined here
114-
...
115-
LL | reuse to_reuse::opaque_arg;
116-
| ^^^^^^^^^^
115+
LL | reuse Trait::foo { &self.0 }
116+
| ^^^
117117

118-
error[E0391]: cycle detected when computing type of `opaque::<impl at $DIR/not-supported.rs:82:5: 82:24>::{synthetic#0}`
119-
--> $DIR/not-supported.rs:83:25
118+
error[E0391]: cycle detected when computing type of `opaque::<impl at $DIR/not-supported.rs:81:5: 81:24>::{synthetic#0}`
119+
--> $DIR/not-supported.rs:82:25
120120
|
121121
LL | reuse to_reuse::opaque_ret;
122122
| ^^^^^^^^^^
123123
|
124124
note: ...which requires comparing an impl and trait method signature, inferring any hidden `impl Trait` types in the process...
125-
--> $DIR/not-supported.rs:83:25
125+
--> $DIR/not-supported.rs:82:25
126126
|
127127
LL | reuse to_reuse::opaque_ret;
128128
| ^^^^^^^^^^
129-
= note: ...which again requires computing type of `opaque::<impl at $DIR/not-supported.rs:82:5: 82:24>::{synthetic#0}`, completing the cycle
130-
note: cycle used when checking that `opaque::<impl at $DIR/not-supported.rs:82:5: 82:24>` is well-formed
131-
--> $DIR/not-supported.rs:82:5
129+
= note: ...which again requires computing type of `opaque::<impl at $DIR/not-supported.rs:81:5: 81:24>::{synthetic#0}`, completing the cycle
130+
note: cycle used when checking that `opaque::<impl at $DIR/not-supported.rs:81:5: 81:24>` is well-formed
131+
--> $DIR/not-supported.rs:81:5
132132
|
133133
LL | impl ToReuse for u8 {
134134
| ^^^^^^^^^^^^^^^^^^^
135135
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
136136

137-
error[E0391]: cycle detected when computing type of `opaque::<impl at $DIR/not-supported.rs:85:5: 85:25>::{synthetic#0}`
138-
--> $DIR/not-supported.rs:86:24
137+
error[E0391]: cycle detected when computing type of `opaque::<impl at $DIR/not-supported.rs:84:5: 84:25>::{synthetic#0}`
138+
--> $DIR/not-supported.rs:85:24
139139
|
140140
LL | reuse ToReuse::opaque_ret;
141141
| ^^^^^^^^^^
142142
|
143143
note: ...which requires comparing an impl and trait method signature, inferring any hidden `impl Trait` types in the process...
144-
--> $DIR/not-supported.rs:86:24
144+
--> $DIR/not-supported.rs:85:24
145145
|
146146
LL | reuse ToReuse::opaque_ret;
147147
| ^^^^^^^^^^
148-
= note: ...which again requires computing type of `opaque::<impl at $DIR/not-supported.rs:85:5: 85:25>::{synthetic#0}`, completing the cycle
149-
note: cycle used when checking that `opaque::<impl at $DIR/not-supported.rs:85:5: 85:25>` is well-formed
150-
--> $DIR/not-supported.rs:85:5
148+
= note: ...which again requires computing type of `opaque::<impl at $DIR/not-supported.rs:84:5: 84:25>::{synthetic#0}`, completing the cycle
149+
note: cycle used when checking that `opaque::<impl at $DIR/not-supported.rs:84:5: 84:25>` is well-formed
150+
--> $DIR/not-supported.rs:84:5
151151
|
152152
LL | impl ToReuse for u16 {
153153
| ^^^^^^^^^^^^^^^^^^^^
154154
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
155155

156-
error: recursive delegation is not supported yet
157-
--> $DIR/not-supported.rs:99:22
158-
|
159-
LL | pub reuse to_reuse2::foo;
160-
| --- callee defined here
161-
...
162-
LL | reuse to_reuse1::foo;
163-
| ^^^
164-
165-
error: aborting due to 16 previous errors
156+
error: aborting due to 15 previous errors
166157

167158
Some errors have detailed explanations: E0049, E0195, E0391.
168159
For more information about an error, try `rustc --explain E0049`.

‎tests/ui/delegation/target-expr.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ fn foo(x: i32) -> i32 { x }
1414

1515
fn bar<T: Default>(_: T) {
1616
reuse Trait::static_method {
17-
//~^ ERROR delegation to a trait method from a free function is not supported yet
18-
//~| ERROR delegation with early bound generics is not supported yet
19-
//~| ERROR mismatched types
17+
//~^ ERROR mismatched types
2018
let _ = T::Default();
2119
//~^ ERROR can't use generic parameters from outer item
2220
}
@@ -25,7 +23,6 @@ fn bar<T: Default>(_: T) {
2523
fn main() {
2624
let y = 0;
2725
reuse <S as Trait>::static_method {
28-
//~^ ERROR delegation to a trait method from a free function is not supported yet
2926
let x = y;
3027
//~^ ERROR can't capture dynamic environment in a fn item
3128
foo(self);
Lines changed: 7 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
error[E0401]: can't use generic parameters from outer item
2-
--> $DIR/target-expr.rs:20:17
2+
--> $DIR/target-expr.rs:18:17
33
|
44
LL | fn bar<T: Default>(_: T) {
55
| - type parameter from outer item
66
LL | reuse Trait::static_method {
77
| - help: try introducing a local generic parameter here: `T,`
8-
...
8+
LL |
99
LL | let _ = T::Default();
1010
| ^^^^^^^^^^ use of generic parameter from outer item
1111

1212
error[E0434]: can't capture dynamic environment in a fn item
13-
--> $DIR/target-expr.rs:29:17
13+
--> $DIR/target-expr.rs:26:17
1414
|
1515
LL | let x = y;
1616
| ^
1717
|
1818
= help: use the `|| { ... }` closure form instead
1919

2020
error[E0424]: expected value, found module `self`
21-
--> $DIR/target-expr.rs:36:5
21+
--> $DIR/target-expr.rs:33:5
2222
|
2323
LL | fn main() {
2424
| ---- this function can't have a `self` parameter
@@ -27,58 +27,29 @@ LL | self.0;
2727
| ^^^^ `self` value is a keyword only available in methods with a `self` parameter
2828

2929
error[E0425]: cannot find value `x` in this scope
30-
--> $DIR/target-expr.rs:38:13
30+
--> $DIR/target-expr.rs:35:13
3131
|
3232
LL | let z = x;
3333
| ^
3434
|
3535
help: the binding `x` is available in a different scope in the same function
36-
--> $DIR/target-expr.rs:29:13
36+
--> $DIR/target-expr.rs:26:13
3737
|
3838
LL | let x = y;
3939
| ^
4040

41-
error: delegation with early bound generics is not supported yet
42-
--> $DIR/target-expr.rs:16:18
43-
|
44-
LL | fn static_method(x: i32) -> i32 { x }
45-
| ------------------------------- callee defined here
46-
...
47-
LL | reuse Trait::static_method {
48-
| ^^^^^^^^^^^^^
49-
50-
error: delegation to a trait method from a free function is not supported yet
51-
--> $DIR/target-expr.rs:16:18
52-
|
53-
LL | fn static_method(x: i32) -> i32 { x }
54-
| ------------------------------- callee defined here
55-
...
56-
LL | reuse Trait::static_method {
57-
| ^^^^^^^^^^^^^
58-
59-
error: delegation to a trait method from a free function is not supported yet
60-
--> $DIR/target-expr.rs:27:25
61-
|
62-
LL | fn static_method(x: i32) -> i32 { x }
63-
| ------------------------------- callee defined here
64-
...
65-
LL | reuse <S as Trait>::static_method {
66-
| ^^^^^^^^^^^^^
67-
6841
error[E0308]: mismatched types
6942
--> $DIR/target-expr.rs:16:32
7043
|
7144
LL | reuse Trait::static_method {
7245
| ________________________________^
7346
LL | |
74-
LL | |
75-
LL | |
7647
LL | | let _ = T::Default();
7748
LL | |
7849
LL | | }
7950
| |_____^ expected `i32`, found `()`
8051

81-
error: aborting due to 8 previous errors
52+
error: aborting due to 5 previous errors
8253

8354
Some errors have detailed explanations: E0308, E0401, E0424, E0425, E0434.
8455
For more information about an error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)
Please sign in to comment.