Skip to content

Commit 4722744

Browse files
committed
Fix some remaining tests
1 parent 03c4628 commit 4722744

File tree

6 files changed

+39
-29
lines changed

6 files changed

+39
-29
lines changed

src/librustc_typeck/astconv.rs

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@ struct ConvertedBinding<'tcx> {
9292
span: Span,
9393
}
9494

95+
#[derive(PartialEq)]
96+
enum GenericArgPosition {
97+
Datatype,
98+
Function,
99+
Method,
100+
}
101+
95102
struct GenericArgMismatchErrorCode {
96103
lifetimes: (&'static str, &'static str),
97104
types: (&'static str, &'static str),
@@ -247,8 +254,11 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
247254
} else {
248255
&empty_args
249256
},
250-
false, // `is_declaration`
251-
is_method_call,
257+
if is_method_call {
258+
GenericArgPosition::Method
259+
} else {
260+
GenericArgPosition::Function
261+
},
252262
def.parent.is_none() && def.has_self, // `has_self`
253263
seg.infer_types || suppress_mismatch, // `infer_types`
254264
GenericArgMismatchErrorCode {
@@ -259,14 +269,13 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
259269
}
260270

261271
/// Check that the correct number of generic arguments have been provided.
262-
/// This is used both for type declarations and function calls.
272+
/// This is used both for datatypes and function calls.
263273
fn check_generic_arg_count(
264274
tcx: TyCtxt,
265275
span: Span,
266276
def: &ty::Generics,
267277
args: &hir::GenericArgs,
268-
is_declaration: bool,
269-
is_method_call: bool,
278+
position: GenericArgPosition,
270279
has_self: bool,
271280
infer_types: bool,
272281
error_codes: GenericArgMismatchErrorCode,
@@ -276,7 +285,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
276285
// arguments in order to validate them with respect to the generic parameters.
277286
let param_counts = def.own_counts();
278287
let arg_counts = args.own_counts();
279-
let infer_lifetimes = !is_declaration && arg_counts.lifetimes == 0;
288+
let infer_lifetimes = position != GenericArgPosition::Datatype && arg_counts.lifetimes == 0;
280289

281290
let mut defaults: ty::GenericParamCount = Default::default();
282291
for param in &def.params {
@@ -288,7 +297,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
288297
};
289298
}
290299

291-
if !is_declaration && !args.bindings.is_empty() {
300+
if position != GenericArgPosition::Datatype && !args.bindings.is_empty() {
292301
AstConv::prohibit_assoc_ty_binding(tcx, args.bindings[0].span);
293302
}
294303

@@ -299,7 +308,8 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
299308
if late bound lifetime parameters are present";
300309
let note = "the late bound lifetime parameter is introduced here";
301310
let span = args.args[0].span();
302-
if !is_method_call && arg_counts.lifetimes != param_counts.lifetimes {
311+
if position == GenericArgPosition::Function
312+
&& arg_counts.lifetimes != param_counts.lifetimes {
303313
let mut err = tcx.sess.struct_span_err(span, msg);
304314
err.span_note(span_late, note);
305315
err.emit();
@@ -328,15 +338,16 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
328338

329339
// Unfortunately lifetime and type parameter mismatches are typically styled
330340
// differently in diagnostics, which means we have a few cases to consider here.
331-
let (bound, quantifier, suppress_error) = if required != permitted {
341+
let (bound, quantifier) = if required != permitted {
332342
if provided < required {
333-
(required, "at least ", false)
343+
(required, "at least ")
334344
} else { // provided > permitted
335-
(permitted, "at most ", true)
345+
(permitted, "at most ")
336346
}
337347
} else {
338-
(required, "", false)
348+
(required, "")
339349
};
350+
340351
let label = if required == permitted && provided > permitted {
341352
let diff = provided - permitted;
342353
format!(
@@ -373,7 +384,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
373384
}.into())
374385
).span_label(span, label).emit();
375386

376-
suppress_error
387+
provided > required // `suppress_error`
377388
};
378389

379390
if !infer_lifetimes || arg_counts.lifetimes > param_counts.lifetimes {
@@ -572,8 +583,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
572583
span,
573584
&generic_params,
574585
&generic_args,
575-
true, // `is_declaration`
576-
false, // `is_method_call` (irrelevant here)
586+
GenericArgPosition::Datatype,
577587
has_self,
578588
infer_types,
579589
GenericArgMismatchErrorCode {

src/test/ui/bad/bad-mid-path-type-params.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,16 @@ impl Trait<isize> for S2 {
3838

3939
fn foo<'a>() {
4040
let _ = S::new::<isize,f64>(1, 1.0);
41-
//~^ ERROR too many type parameters provided
41+
//~^ ERROR wrong number of type arguments
4242

4343
let _ = S::<'a,isize>::new::<f64>(1, 1.0);
4444
//~^ ERROR wrong number of lifetime arguments
4545

4646
let _: S2 = Trait::new::<isize,f64>(1, 1.0);
47-
//~^ ERROR too many type parameters provided
47+
//~^ ERROR wrong number of type arguments
4848

4949
let _: S2 = Trait::<'a,isize>::new::<f64>(1, 1.0);
50-
//~^ ERROR too many lifetime parameters provided
50+
//~^ ERROR wrong number of lifetime arguments
5151
}
5252

5353
fn main() {}

src/test/ui/constructor-lifetime-args.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ enum E<'a, 'b> {
2525
fn main() {
2626
S(&0, &0); // OK
2727
S::<'static>(&0, &0);
28-
//~^ ERROR expected 2 lifetime parameters, found 1 lifetime parameter
28+
//~^ ERROR wrong number of lifetime arguments: expected 2, found 1
2929
S::<'static, 'static, 'static>(&0, &0);
30-
//~^ ERROR expected at most 2 lifetime parameters, found 3 lifetime parameters
30+
//~^ ERROR wrong number of lifetime arguments: expected 2, found 3
3131
E::V(&0); // OK
3232
E::V::<'static>(&0);
33-
//~^ ERROR expected 2 lifetime parameters, found 1 lifetime parameter
33+
//~^ ERROR wrong number of lifetime arguments: expected 2, found 1
3434
E::V::<'static, 'static, 'static>(&0);
35-
//~^ ERROR expected at most 2 lifetime parameters, found 3 lifetime parameters
35+
//~^ ERROR wrong number of lifetime arguments: expected 2, found 3
3636
}

src/test/ui/methods/method-call-lifetime-args-fail.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ impl S {
2424
fn method_call() {
2525
S.early(); // OK
2626
S.early::<'static>();
27-
//~^ ERROR expected 2 lifetime parameters, found 1 lifetime parameter
27+
//~^ ERROR wrong number of lifetime arguments: expected 2, found 1
2828
S.early::<'static, 'static, 'static>();
29-
//~^ ERROR expected at most 2 lifetime parameters, found 3 lifetime parameters
29+
//~^ ERROR wrong number of lifetime arguments: expected 2, found 3
3030
let _: &u8 = S.life_and_type::<'static>();
3131
S.life_and_type::<u8>();
3232
S.life_and_type::<'static, u8>();
@@ -71,9 +71,9 @@ fn ufcs() {
7171

7272
S::early(S); // OK
7373
S::early::<'static>(S);
74-
//~^ ERROR expected 2 lifetime parameters, found 1 lifetime parameter
74+
//~^ ERROR wrong number of lifetime arguments: expected 2, found 1
7575
S::early::<'static, 'static, 'static>(S);
76-
//~^ ERROR expected at most 2 lifetime parameters, found 3 lifetime parameters
76+
//~^ ERROR wrong number of lifetime arguments: expected 2, found 3
7777
let _: &u8 = S::life_and_type::<'static>(S);
7878
S::life_and_type::<u8>(S);
7979
S::life_and_type::<'static, u8>(S);

src/test/ui/traits/trait-test-2.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ impl bar for i32 { fn dup(&self) -> i32 { *self } fn blah<X>(&self) {} }
1515
impl bar for u32 { fn dup(&self) -> u32 { *self } fn blah<X>(&self) {} }
1616

1717
fn main() {
18-
10.dup::<i32>(); //~ ERROR expected at most 0 type parameters, found 1 type parameter
19-
10.blah::<i32, i32>(); //~ ERROR expected at most 1 type parameter, found 2 type parameters
18+
10.dup::<i32>(); //~ ERROR wrong number of type arguments: expected 0, found 1
19+
10.blah::<i32, i32>(); //~ ERROR wrong number of type arguments: expected 1, found 2
2020
(box 10 as Box<bar>).dup();
2121
//~^ ERROR E0038
2222
//~| ERROR E0038

src/test/ui/ufcs/ufcs-qpath-missing-params.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ impl<'a> IntoCow<'a, str> for String {
2222

2323
fn main() {
2424
<String as IntoCow>::into_cow("foo".to_string());
25-
//~^ ERROR too few type parameters provided: expected 1 type parameter
25+
//~^ ERROR wrong number of type arguments: expected 1, found 0
2626
}

0 commit comments

Comments
 (0)