Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 8 pull requests #100516

Merged
merged 22 commits into from
Aug 14, 2022
Merged
Changes from 5 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
86bdb3e
Rustdoc-Json: Add `Path` type for traits.
aDotInTheVoid Aug 9, 2022
0fb4ef6
Suggest path separator when a dot is used on a trait
fmease Aug 10, 2022
48c0341
suggest removing a semicolon after impl/trait items
TaKO8Ki Aug 12, 2022
b821ce6
enum variant ctor inherits stability of variant
compiler-errors Aug 11, 2022
6925f41
Check ctor for missing stability
compiler-errors Aug 11, 2022
20121fa
Point out a single arg if we have a single arg incompatibility
compiler-errors Jul 23, 2022
262644d
And for closures
compiler-errors Jul 23, 2022
237cbe9
Adjust span of closure param
compiler-errors Jul 23, 2022
c608918
Address nit
compiler-errors Aug 12, 2022
de8dedb
Use an extensionless `x` script for non-Windows
cuviper Aug 12, 2022
d47df26
use `span_suggestion` instead of `span_suggestion_verbose`
TaKO8Ki Aug 13, 2022
b0cd1e1
Label argument coercion errors
compiler-errors Aug 13, 2022
aa1a07f
Do not inline non-simple argument type errors into labels
compiler-errors Aug 13, 2022
752b0e0
make clean::Item::span return option instead of dummy span
compiler-errors Aug 9, 2022
2af3445
Rollup merge of #99646 - compiler-errors:arg-mismatch-single-arg-labe…
compiler-errors Aug 14, 2022
d496c4e
Rollup merge of #100299 - compiler-errors:issue-100283, r=notriddle
compiler-errors Aug 14, 2022
4989f6a
Rollup merge of #100335 - aDotInTheVoid:rdj-resolved-path, r=Guillaum…
compiler-errors Aug 14, 2022
e248c7f
Rollup merge of #100367 - fmease:fix-100365, r=compiler-errors
compiler-errors Aug 14, 2022
d46451c
Rollup merge of #100431 - compiler-errors:enum-ctor-variant-stab, r=e…
compiler-errors Aug 14, 2022
86e1d1e
Rollup merge of #100446 - TaKO8Ki:suggest-removing-semicolon-after-im…
compiler-errors Aug 14, 2022
809fc86
Rollup merge of #100468 - cuviper:lazy-x, r=jyn514
compiler-errors Aug 14, 2022
b3e76aa
Rollup merge of #100479 - compiler-errors:argument-type-error-improve…
compiler-errors Aug 14, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_parse/src/parser/expr.rs
Original file line number Diff line number Diff line change
@@ -2268,7 +2268,7 @@ impl<'a> Parser<'a> {
attrs: attrs.into(),
ty,
pat,
span: lo.to(this.token.span),
span: lo.to(this.prev_token.span),
id: DUMMY_NODE_ID,
is_placeholder: false,
},
58 changes: 40 additions & 18 deletions compiler/rustc_typeck/src/check/fn_ctxt/checks.rs
Original file line number Diff line number Diff line change
@@ -440,30 +440,29 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
call_expr: &hir::Expr<'tcx>,
) {
// Next, let's construct the error
let (error_span, full_call_span, ctor_of) = match &call_expr.kind {
let (error_span, full_call_span, ctor_of, is_method) = match &call_expr.kind {
hir::ExprKind::Call(
hir::Expr { hir_id, span, kind: hir::ExprKind::Path(qpath), .. },
_,
) => {
if let Res::Def(DefKind::Ctor(of, _), _) =
self.typeck_results.borrow().qpath_res(qpath, *hir_id)
{
(call_span, *span, Some(of))
(call_span, *span, Some(of), false)
} else {
(call_span, *span, None)
(call_span, *span, None, false)
}
}
hir::ExprKind::Call(hir::Expr { span, .. }, _) => (call_span, *span, None),
hir::ExprKind::Call(hir::Expr { span, .. }, _) => (call_span, *span, None, false),
hir::ExprKind::MethodCall(path_segment, _, span) => {
let ident_span = path_segment.ident.span;
let ident_span = if let Some(args) = path_segment.args {
ident_span.with_hi(args.span_ext.hi())
} else {
ident_span
};
(
*span, ident_span, None, // methods are never ctors
)
// methods are never ctors
(*span, ident_span, None, true)
}
k => span_bug!(call_span, "checking argument types on a non-call: `{:?}`", k),
};
@@ -659,7 +658,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
Applicability::MachineApplicable,
);
};
self.label_fn_like(&mut err, fn_def_id, callee_ty);
self.label_fn_like(&mut err, fn_def_id, callee_ty, Some(mismatch_idx), is_method);
err.emit();
return;
}
@@ -701,16 +700,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}

errors.drain_filter(|error| {
let Error::Invalid(provided_idx, expected_idx, Compatibility::Incompatible(error)) = error else { return false };
let Error::Invalid(provided_idx, expected_idx, Compatibility::Incompatible(Some(e))) = error else { return false };
let (provided_ty, provided_span) = provided_arg_tys[*provided_idx];
let (expected_ty, _) = formal_and_expected_inputs[*expected_idx];
let cause = &self.misc(provided_span);
let trace = TypeTrace::types(cause, true, expected_ty, provided_ty);
if let Some(e) = error {
if !matches!(trace.cause.as_failure_code(e), FailureCode::Error0308(_)) {
self.report_and_explain_type_error(trace, e).emit();
return true;
}
if !matches!(trace.cause.as_failure_code(e), FailureCode::Error0308(_)) {
self.report_and_explain_type_error(trace, e).emit();
return true;
}
false
});
@@ -749,7 +746,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
format!("arguments to this {} are incorrect", call_name),
);
// Call out where the function is defined
self.label_fn_like(&mut err, fn_def_id, callee_ty);
self.label_fn_like(
&mut err,
fn_def_id,
callee_ty,
Some(expected_idx.as_usize()),
is_method,
);
err.emit();
return;
}
@@ -1031,7 +1034,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}

// Call out where the function is defined
self.label_fn_like(&mut err, fn_def_id, callee_ty);
self.label_fn_like(&mut err, fn_def_id, callee_ty, None, is_method);

// And add a suggestion block for all of the parameters
let suggestion_text = match suggestion_text {
@@ -1781,6 +1784,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
err: &mut Diagnostic,
callable_def_id: Option<DefId>,
callee_ty: Option<Ty<'tcx>>,
// A specific argument should be labeled, instead of all of them
expected_idx: Option<usize>,
is_method: bool,
) {
let Some(mut def_id) = callable_def_id else {
return;
@@ -1881,14 +1887,30 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.get_if_local(def_id)
.and_then(|node| node.body_id())
.into_iter()
.flat_map(|id| self.tcx.hir().body(id).params);
.flat_map(|id| self.tcx.hir().body(id).params)
.skip(if is_method { 1 } else { 0 });

for param in params {
for (_, param) in params
.into_iter()
.enumerate()
.filter(|(idx, _)| expected_idx.map_or(true, |expected_idx| expected_idx == *idx))
{
spans.push_span_label(param.span, "");
}

let def_kind = self.tcx.def_kind(def_id);
err.span_note(spans, &format!("{} defined here", def_kind.descr(def_id)));
} else if let Some(hir::Node::Expr(e)) = self.tcx.hir().get_if_local(def_id)
&& let hir::ExprKind::Closure(hir::Closure { body, .. }) = &e.kind
{
let param = expected_idx
.and_then(|expected_idx| self.tcx.hir().body(*body).params.get(expected_idx));
let (kind, span) = if let Some(param) = param {
("closure parameter", param.span)
} else {
("closure", self.tcx.def_span(def_id))
};
err.span_note(span, &format!("{} defined here", kind));
} else {
let def_kind = self.tcx.def_kind(def_id);
err.span_note(
20 changes: 10 additions & 10 deletions src/test/ui/argument-suggestions/invalid_arguments.stderr
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ note: function defined here
--> $DIR/invalid_arguments.rs:6:4
|
LL | fn two_arg_same(_a: i32, _b: i32) {}
| ^^^^^^^^^^^^ ------- -------
| ^^^^^^^^^^^^ -------

error[E0308]: mismatched types
--> $DIR/invalid_arguments.rs:17:16
@@ -38,7 +38,7 @@ note: function defined here
--> $DIR/invalid_arguments.rs:6:4
|
LL | fn two_arg_same(_a: i32, _b: i32) {}
| ^^^^^^^^^^^^ ------- -------
| ^^^^^^^^^^^^ -------

error[E0308]: arguments to this function are incorrect
--> $DIR/invalid_arguments.rs:18:3
@@ -66,7 +66,7 @@ note: function defined here
--> $DIR/invalid_arguments.rs:7:4
|
LL | fn two_arg_diff(_a: i32, _b: f32) {}
| ^^^^^^^^^^^^ ------- -------
| ^^^^^^^^^^^^ -------

error[E0308]: mismatched types
--> $DIR/invalid_arguments.rs:20:16
@@ -80,7 +80,7 @@ note: function defined here
--> $DIR/invalid_arguments.rs:7:4
|
LL | fn two_arg_diff(_a: i32, _b: f32) {}
| ^^^^^^^^^^^^ ------- -------
| ^^^^^^^^^^^^ -------

error[E0308]: arguments to this function are incorrect
--> $DIR/invalid_arguments.rs:21:3
@@ -108,7 +108,7 @@ note: function defined here
--> $DIR/invalid_arguments.rs:8:4
|
LL | fn three_arg_diff(_a: i32, _b: f32, _c: &str) {}
| ^^^^^^^^^^^^^^ ------- ------- --------
| ^^^^^^^^^^^^^^ -------

error[E0308]: mismatched types
--> $DIR/invalid_arguments.rs:25:21
@@ -122,7 +122,7 @@ note: function defined here
--> $DIR/invalid_arguments.rs:8:4
|
LL | fn three_arg_diff(_a: i32, _b: f32, _c: &str) {}
| ^^^^^^^^^^^^^^ ------- ------- --------
| ^^^^^^^^^^^^^^ -------

error[E0308]: mismatched types
--> $DIR/invalid_arguments.rs:26:26
@@ -136,7 +136,7 @@ note: function defined here
--> $DIR/invalid_arguments.rs:8:4
|
LL | fn three_arg_diff(_a: i32, _b: f32, _c: &str) {}
| ^^^^^^^^^^^^^^ ------- ------- --------
| ^^^^^^^^^^^^^^ --------

error[E0308]: arguments to this function are incorrect
--> $DIR/invalid_arguments.rs:28:3
@@ -207,7 +207,7 @@ note: function defined here
--> $DIR/invalid_arguments.rs:9:4
|
LL | fn three_arg_repeat(_a: i32, _b: i32, _c: &str) {}
| ^^^^^^^^^^^^^^^^ ------- ------- --------
| ^^^^^^^^^^^^^^^^ -------

error[E0308]: mismatched types
--> $DIR/invalid_arguments.rs:35:23
@@ -221,7 +221,7 @@ note: function defined here
--> $DIR/invalid_arguments.rs:9:4
|
LL | fn three_arg_repeat(_a: i32, _b: i32, _c: &str) {}
| ^^^^^^^^^^^^^^^^ ------- ------- --------
| ^^^^^^^^^^^^^^^^ -------

error[E0308]: mismatched types
--> $DIR/invalid_arguments.rs:36:26
@@ -235,7 +235,7 @@ note: function defined here
--> $DIR/invalid_arguments.rs:9:4
|
LL | fn three_arg_repeat(_a: i32, _b: i32, _c: &str) {}
| ^^^^^^^^^^^^^^^^ ------- ------- --------
| ^^^^^^^^^^^^^^^^ --------

error[E0308]: arguments to this function are incorrect
--> $DIR/invalid_arguments.rs:38:3
41 changes: 41 additions & 0 deletions src/test/ui/argument-suggestions/too-long.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
struct Qux;

impl Qux {
fn foo(
&self,
a: i32,
b: i32,
c: i32,
d: i32,
e: i32,
f: i32,
g: i32,
h: i32,
i: i32,
j: i32,
k: i32,
l: i32,
) {
}
}

fn what(
qux: &Qux,
a: i32,
b: i32,
c: i32,
d: i32,
e: i32,
f: &i32,
g: i32,
h: i32,
i: i32,
j: i32,
k: i32,
l: i32,
) {
qux.foo(a, b, c, d, e, f, g, h, i, j, k, l);
//~^ ERROR mismatched types
}

fn main() {}
24 changes: 24 additions & 0 deletions src/test/ui/argument-suggestions/too-long.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
error[E0308]: mismatched types
--> $DIR/too-long.rs:37:28
|
LL | qux.foo(a, b, c, d, e, f, g, h, i, j, k, l);
| --- ^ expected `i32`, found `&i32`
| |
| arguments to this function are incorrect
|
note: associated function defined here
--> $DIR/too-long.rs:4:8
|
LL | fn foo(
| ^^^
...
LL | f: i32,
| ------
help: consider dereferencing the borrow
|
LL | qux.foo(a, b, c, d, e, *f, g, h, i, j, k, l);
| +

error: aborting due to previous error

For more information about this error, try `rustc --explain E0308`.
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ note: function defined here
--> $DIR/associated-type-projection-from-supertrait.rs:25:4
|
LL | fn dent<C:Car>(c: C, color: C::Color) { c.chip_paint(color) }
| ^^^^ ---- ---------------
| ^^^^ ---------------

error[E0308]: mismatched types
--> $DIR/associated-type-projection-from-supertrait.rs:28:23
@@ -24,7 +24,7 @@ note: function defined here
--> $DIR/associated-type-projection-from-supertrait.rs:25:4
|
LL | fn dent<C:Car>(c: C, color: C::Color) { c.chip_paint(color) }
| ^^^^ ---- ---------------
| ^^^^ ---------------

error[E0308]: mismatched types
--> $DIR/associated-type-projection-from-supertrait.rs:32:28
@@ -38,7 +38,7 @@ note: associated function defined here
--> $DIR/associated-type-projection-from-supertrait.rs:12:8
|
LL | fn chip_paint(&self, c: Self::Color) { }
| ^^^^^^^^^^ ----- --------------
| ^^^^^^^^^^ --------------

error[E0308]: mismatched types
--> $DIR/associated-type-projection-from-supertrait.rs:33:28
@@ -52,7 +52,7 @@ note: associated function defined here
--> $DIR/associated-type-projection-from-supertrait.rs:12:8
|
LL | fn chip_paint(&self, c: Self::Color) { }
| ^^^^^^^^^^ ----- --------------
| ^^^^^^^^^^ --------------

error: aborting due to 4 previous errors

Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ note: function defined here
--> $DIR/associated-types-path-2.rs:13:8
|
LL | pub fn f1<T: Foo>(a: T, x: T::A) {}
| ^^ ---- -------
| ^^ -------
help: change the type of the numeric literal from `i32` to `u32`
|
LL | f1(2i32, 4u32);
4 changes: 2 additions & 2 deletions src/test/ui/async-await/generator-desc.stderr
Original file line number Diff line number Diff line change
@@ -42,7 +42,7 @@ note: function defined here
--> $DIR/generator-desc.rs:8:4
|
LL | fn fun<F: Future<Output = ()>>(f1: F, f2: F) {}
| ^^^ ----- -----
| ^^^ -----

error[E0308]: mismatched types
--> $DIR/generator-desc.rs:14:26
@@ -67,7 +67,7 @@ note: function defined here
--> $DIR/generator-desc.rs:8:4
|
LL | fn fun<F: Future<Output = ()>>(f1: F, f2: F) {}
| ^^^ ----- -----
| ^^^ -----

error: aborting due to 3 previous errors

2 changes: 1 addition & 1 deletion src/test/ui/coercion/coerce-reborrow-multi-arg-fail.stderr
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ note: function defined here
--> $DIR/coerce-reborrow-multi-arg-fail.rs:1:4
|
LL | fn test<T>(_a: T, _b: T) {}
| ^^^^ ----- -----
| ^^^^ -----

error: aborting due to previous error

Loading