Skip to content

Commit 721af40

Browse files
authored
Rollup merge of #100155 - compiler-errors:issue-100154, r=jackh726
Use `node_type_opt` to skip over generics that were not expected Fixes #100154
2 parents 9e4feff + 5bb50dd commit 721af40

File tree

4 files changed

+51
-9
lines changed

4 files changed

+51
-9
lines changed

compiler/rustc_typeck/src/check/fn_ctxt/checks.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1761,13 +1761,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
17611761
.filter_map(|seg| seg.args.as_ref())
17621762
.flat_map(|a| a.args.iter())
17631763
{
1764-
if let hir::GenericArg::Type(hir_ty) = &arg {
1765-
let ty = self.resolve_vars_if_possible(
1766-
self.typeck_results.borrow().node_type(hir_ty.hir_id),
1767-
);
1768-
if ty == predicate.self_ty() {
1769-
error.obligation.cause.span = hir_ty.span;
1770-
}
1764+
if let hir::GenericArg::Type(hir_ty) = &arg
1765+
&& let Some(ty) =
1766+
self.typeck_results.borrow().node_type_opt(hir_ty.hir_id)
1767+
&& self.resolve_vars_if_possible(ty) == predicate.self_ty()
1768+
{
1769+
error.obligation.cause.span = hir_ty.span;
1770+
break;
17711771
}
17721772
}
17731773
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
fn foo(i: impl std::fmt::Display) {}
2+
3+
fn main() {
4+
foo::<()>(());
5+
//~^ ERROR this function takes 0 generic arguments but 1 generic argument was supplied
6+
//~| ERROR `()` doesn't implement `std::fmt::Display`
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
error[E0107]: this function takes 0 generic arguments but 1 generic argument was supplied
2+
--> $DIR/issue-100154.rs:4:5
3+
|
4+
LL | foo::<()>(());
5+
| ^^^------ help: remove these generics
6+
| |
7+
| expected 0 generic arguments
8+
|
9+
note: function defined here, with 0 generic parameters
10+
--> $DIR/issue-100154.rs:1:4
11+
|
12+
LL | fn foo(i: impl std::fmt::Display) {}
13+
| ^^^
14+
= note: `impl Trait` cannot be explicitly specified as a generic argument
15+
16+
error[E0277]: `()` doesn't implement `std::fmt::Display`
17+
--> $DIR/issue-100154.rs:4:15
18+
|
19+
LL | foo::<()>(());
20+
| --------- ^^ `()` cannot be formatted with the default formatter
21+
| |
22+
| required by a bound introduced by this call
23+
|
24+
= help: the trait `std::fmt::Display` is not implemented for `()`
25+
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
26+
note: required by a bound in `foo`
27+
--> $DIR/issue-100154.rs:1:16
28+
|
29+
LL | fn foo(i: impl std::fmt::Display) {}
30+
| ^^^^^^^^^^^^^^^^^ required by this bound in `foo`
31+
32+
error: aborting due to 2 previous errors
33+
34+
Some errors have detailed explanations: E0107, E0277.
35+
For more information about an error, try `rustc --explain E0107`.

src/test/ui/transmutability/references.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0277]: `&'static Unit` cannot be safely transmuted into `&'static Unit` in the defining scope of `assert::Context`.
2-
--> $DIR/references.rs:19:52
2+
--> $DIR/references.rs:19:37
33
|
44
LL | assert::is_maybe_transmutable::<&'static Unit, &'static Unit>();
5-
| ^^^^^^^^^^^^^ `&'static Unit` cannot be safely transmuted into `&'static Unit` in the defining scope of `assert::Context`.
5+
| ^^^^^^^^^^^^^ `&'static Unit` cannot be safely transmuted into `&'static Unit` in the defining scope of `assert::Context`.
66
|
77
= help: the trait `BikeshedIntrinsicFrom<&'static Unit, assert::Context, true, true, true, true>` is not implemented for `&'static Unit`
88
note: required by a bound in `is_maybe_transmutable`

0 commit comments

Comments
 (0)