1 |
From 476732995c2f5dc08e20eb8f9f03c628a48f5f41 Mon Sep 17 00:00:00 2001 |
2 |
From: Oliver Scherer <github35764891676564198441@oli-obk.de> |
3 |
Date: Thu, 23 May 2019 17:05:48 +0200 |
4 |
Subject: [PATCH 1/3] WIP |
5 |
|
6 |
--- |
7 |
src/librustc_typeck/check/mod.rs | 22 +++++++++++----------- |
8 |
src/test/run-pass/issue-60989.rs | 4 ++++ |
9 |
2 files changed, 15 insertions(+), 11 deletions(-) |
10 |
create mode 100644 src/test/run-pass/issue-60989.rs |
11 |
|
12 |
diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs |
13 |
index 313ed19b945d..088729f12b1e 100644 |
14 |
--- a/src/librustc_typeck/check/mod.rs |
15 |
+++ b/src/librustc_typeck/check/mod.rs |
16 |
@@ -5396,17 +5396,6 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { |
17 |
|
18 |
let tcx = self.tcx; |
19 |
|
20 |
- match def { |
21 |
- Def::Local(nid) | Def::Upvar(nid, ..) => { |
22 |
- let hid = self.tcx.hir().node_to_hir_id(nid); |
23 |
- let ty = self.local_ty(span, hid).decl_ty; |
24 |
- let ty = self.normalize_associated_types_in(span, &ty); |
25 |
- self.write_ty(hir_id, ty); |
26 |
- return (ty, def); |
27 |
- } |
28 |
- _ => {} |
29 |
- } |
30 |
- |
31 |
let (def, def_id, ty) = self.rewrite_self_ctor(def, span); |
32 |
let path_segs = AstConv::def_ids_for_path_segments(self, segments, self_ty, def); |
33 |
|
34 |
@@ -5469,6 +5458,17 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { |
35 |
user_self_ty = None; |
36 |
} |
37 |
|
38 |
+ match def { |
39 |
+ Def::Local(nid) | Def::Upvar(nid, ..) => { |
40 |
+ let hid = self.tcx.hir().node_to_hir_id(nid); |
41 |
+ let ty = self.local_ty(span, hid).decl_ty; |
42 |
+ let ty = self.normalize_associated_types_in(span, &ty); |
43 |
+ self.write_ty(hir_id, ty); |
44 |
+ return (ty, def); |
45 |
+ } |
46 |
+ _ => {} |
47 |
+ } |
48 |
+ |
49 |
// Now we have to compare the types that the user *actually* |
50 |
// provided against the types that were *expected*. If the user |
51 |
// did not provide any types, then we want to substitute inference |
52 |
diff --git a/src/test/run-pass/issue-60989.rs b/src/test/run-pass/issue-60989.rs |
53 |
new file mode 100644 |
54 |
index 000000000000..efaa74da3baa |
55 |
--- /dev/null |
56 |
+++ b/src/test/run-pass/issue-60989.rs |
57 |
@@ -0,0 +1,4 @@ |
58 |
+fn main() { |
59 |
+ let c1 = (); |
60 |
+ c1::<()>; |
61 |
+} |
62 |
-- |
63 |
2.21.0 |
64 |
|
65 |
|
66 |
From 97f204e6ae43bfe0fed64221d709a194bef728a4 Mon Sep 17 00:00:00 2001 |
67 |
From: Oliver Scherer <github35764891676564198441@oli-obk.de> |
68 |
Date: Thu, 23 May 2019 17:21:32 +0200 |
69 |
Subject: [PATCH 2/3] Make regression test a compile-fail test |
70 |
|
71 |
--- |
72 |
src/test/{run-pass => compile-fail}/issue-60989.rs | 0 |
73 |
1 file changed, 0 insertions(+), 0 deletions(-) |
74 |
rename src/test/{run-pass => compile-fail}/issue-60989.rs (100%) |
75 |
|
76 |
diff --git a/src/test/run-pass/issue-60989.rs b/src/test/compile-fail/issue-60989.rs |
77 |
similarity index 100% |
78 |
rename from src/test/run-pass/issue-60989.rs |
79 |
rename to src/test/compile-fail/issue-60989.rs |
80 |
-- |
81 |
2.21.0 |
82 |
|
83 |
|
84 |
From 6e81f8205a6d47648d086d26e96bf05e962e3715 Mon Sep 17 00:00:00 2001 |
85 |
From: Eduard-Mihai Burtescu <edy.burt@gmail.com> |
86 |
Date: Thu, 23 May 2019 19:23:00 +0300 |
87 |
Subject: [PATCH 3/3] rustc_typeck: don't produce a `DefId` or `Ty` from |
88 |
`rewrite_self_ctor`, only a `Def`. |
89 |
|
90 |
--- |
91 |
src/librustc_typeck/check/mod.rs | 30 ++++++++++++++++++---------- |
92 |
src/test/compile-fail/issue-60989.rs | 4 ---- |
93 |
src/test/ui/issue-60989.rs | 18 +++++++++++++++++ |
94 |
src/test/ui/issue-60989.stderr | 15 ++++++++++++++ |
95 |
4 files changed, 52 insertions(+), 15 deletions(-) |
96 |
delete mode 100644 src/test/compile-fail/issue-60989.rs |
97 |
create mode 100644 src/test/ui/issue-60989.rs |
98 |
create mode 100644 src/test/ui/issue-60989.stderr |
99 |
|
100 |
diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs |
101 |
index 088729f12b1e..b6adcdbf35e9 100644 |
102 |
--- a/src/librustc_typeck/check/mod.rs |
103 |
+++ b/src/librustc_typeck/check/mod.rs |
104 |
@@ -5330,7 +5330,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { |
105 |
} |
106 |
|
107 |
// Rewrite `SelfCtor` to `Ctor` |
108 |
- pub fn rewrite_self_ctor(&self, def: Def, span: Span) -> (Def, DefId, Ty<'tcx>) { |
109 |
+ pub fn rewrite_self_ctor(&self, def: Def, span: Span) -> Def { |
110 |
let tcx = self.tcx; |
111 |
if let Def::SelfCtor(impl_def_id) = def { |
112 |
let ty = self.impl_self_ty(span, impl_def_id).ty; |
113 |
@@ -5340,8 +5340,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { |
114 |
Some(adt_def) if adt_def.has_ctor() => { |
115 |
let variant = adt_def.non_enum_variant(); |
116 |
let ctor_def_id = variant.ctor_def_id.unwrap(); |
117 |
- let def = Def::Ctor(ctor_def_id, CtorOf::Struct, variant.ctor_kind); |
118 |
- (def, ctor_def_id, tcx.type_of(ctor_def_id)) |
119 |
+ Def::Ctor(ctor_def_id, CtorOf::Struct, variant.ctor_kind) |
120 |
} |
121 |
_ => { |
122 |
let mut err = tcx.sess.struct_span_err(span, |
123 |
@@ -5364,16 +5363,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { |
124 |
} |
125 |
err.emit(); |
126 |
|
127 |
- (def, impl_def_id, tcx.types.err) |
128 |
+ def |
129 |
} |
130 |
} |
131 |
} else { |
132 |
- let def_id = def.def_id(); |
133 |
- |
134 |
- // The things we are substituting into the type should not contain |
135 |
- // escaping late-bound regions, and nor should the base type scheme. |
136 |
- let ty = tcx.type_of(def_id); |
137 |
- (def, def_id, ty) |
138 |
+ def |
139 |
} |
140 |
} |
141 |
|
142 |
@@ -5396,7 +5390,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { |
143 |
|
144 |
let tcx = self.tcx; |
145 |
|
146 |
- let (def, def_id, ty) = self.rewrite_self_ctor(def, span); |
147 |
+ let def = self.rewrite_self_ctor(def, span); |
148 |
let path_segs = AstConv::def_ids_for_path_segments(self, segments, self_ty, def); |
149 |
|
150 |
let mut user_self_ty = None; |
151 |
@@ -5501,6 +5495,20 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { |
152 |
tcx.generics_of(*def_id).has_self |
153 |
}).unwrap_or(false); |
154 |
|
155 |
+ let (def_id, ty) = if let Def::SelfCtor(impl_def_id) = def { |
156 |
+ // NOTE(eddyb) an error has already been emitted by `rewrite_self_ctor`, |
157 |
+ // avoid using the wrong type here. This isn't in `rewrite_self_ctor` |
158 |
+ // itself because that runs too early (see #60989). |
159 |
+ (impl_def_id, tcx.types.err) |
160 |
+ } else { |
161 |
+ let def_id = def.def_id(); |
162 |
+ |
163 |
+ // The things we are substituting into the type should not contain |
164 |
+ // escaping late-bound regions, and nor should the base type scheme. |
165 |
+ let ty = tcx.type_of(def_id); |
166 |
+ (def_id, ty) |
167 |
+ }; |
168 |
+ |
169 |
let substs = AstConv::create_substs_for_generic_args( |
170 |
tcx, |
171 |
def_id, |
172 |
diff --git a/src/test/compile-fail/issue-60989.rs b/src/test/compile-fail/issue-60989.rs |
173 |
deleted file mode 100644 |
174 |
index efaa74da3baa..000000000000 |
175 |
--- a/src/test/compile-fail/issue-60989.rs |
176 |
+++ /dev/null |
177 |
@@ -1,4 +0,0 @@ |
178 |
-fn main() { |
179 |
- let c1 = (); |
180 |
- c1::<()>; |
181 |
-} |
182 |
diff --git a/src/test/ui/issue-60989.rs b/src/test/ui/issue-60989.rs |
183 |
new file mode 100644 |
184 |
index 000000000000..930e98bedce8 |
185 |
--- /dev/null |
186 |
+++ b/src/test/ui/issue-60989.rs |
187 |
@@ -0,0 +1,18 @@ |
188 |
+struct A {} |
189 |
+struct B {} |
190 |
+ |
191 |
+impl From<A> for B { |
192 |
+ fn from(a: A) -> B { |
193 |
+ B{} |
194 |
+ } |
195 |
+} |
196 |
+ |
197 |
+fn main() { |
198 |
+ let c1 = (); |
199 |
+ c1::<()>; |
200 |
+ //~^ ERROR type arguments are not allowed for this type |
201 |
+ |
202 |
+ let c1 = A {}; |
203 |
+ c1::<Into<B>>; |
204 |
+ //~^ ERROR type arguments are not allowed for this type |
205 |
+} |
206 |
diff --git a/src/test/ui/issue-60989.stderr b/src/test/ui/issue-60989.stderr |
207 |
new file mode 100644 |
208 |
index 000000000000..55a0b9626df7 |
209 |
--- /dev/null |
210 |
+++ b/src/test/ui/issue-60989.stderr |
211 |
@@ -0,0 +1,15 @@ |
212 |
+error[E0109]: type arguments are not allowed for this type |
213 |
+ --> $DIR/issue-60989.rs:12:10 |
214 |
+ | |
215 |
+LL | c1::<()>; |
216 |
+ | ^^ type argument not allowed |
217 |
+ |
218 |
+error[E0109]: type arguments are not allowed for this type |
219 |
+ --> $DIR/issue-60989.rs:16:10 |
220 |
+ | |
221 |
+LL | c1::<Into<B>>; |
222 |
+ | ^^^^^^^ type argument not allowed |
223 |
+ |
224 |
+error: aborting due to 2 previous errors |
225 |
+ |
226 |
+For more information about this error, try `rustc --explain E0109`. |
227 |
-- |
228 |
2.21.0 |
229 |
|