Skip to content

Commit 5fecdb7

Browse files
committed
Auto merge of rust-lang#101396 - matthiaskrgr:rollup-9n0257m, r=matthiaskrgr
Rollup of 4 pull requests Successful merges: - rust-lang#100302 (Suggest associated method on deref types when path syntax method fails) - rust-lang#100647 ( Make trait bound not satisfied specify kind) - rust-lang#101349 (rustdoc: remove `.impl-items { flex-basis }` CSS, not in flex container) - rust-lang#101369 (Fix `global_asm` macro pretty printing) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 84f0c3f + a3dda51 commit 5fecdb7

25 files changed

+205
-45
lines changed

compiler/rustc_ast_pretty/src/pprust/state/item.rs

+2
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@ impl<'a> State<'a> {
218218
ast::ItemKind::GlobalAsm(ref asm) => {
219219
self.head(visibility_qualified(&item.vis, "global_asm!"));
220220
self.print_inline_asm(asm);
221+
self.word(";");
222+
self.end();
221223
self.end();
222224
}
223225
ast::ItemKind::TyAlias(box ast::TyAlias {

compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs

+30-7
Original file line numberDiff line numberDiff line change
@@ -450,12 +450,27 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
450450
{
451451
"consider using `()`, or a `Result`".to_owned()
452452
} else {
453-
format!(
454-
"{}the trait `{}` is not implemented for `{}`",
455-
pre_message,
456-
trait_predicate.print_modifiers_and_trait_path(),
457-
trait_ref.skip_binder().self_ty(),
458-
)
453+
let ty_desc = match trait_ref.skip_binder().self_ty().kind() {
454+
ty::FnDef(_, _) => Some("fn item"),
455+
ty::Closure(_, _) => Some("closure"),
456+
_ => None,
457+
};
458+
459+
match ty_desc {
460+
Some(desc) => format!(
461+
"{}the trait `{}` is not implemented for {} `{}`",
462+
pre_message,
463+
trait_predicate.print_modifiers_and_trait_path(),
464+
desc,
465+
trait_ref.skip_binder().self_ty(),
466+
),
467+
None => format!(
468+
"{}the trait `{}` is not implemented for `{}`",
469+
pre_message,
470+
trait_predicate.print_modifiers_and_trait_path(),
471+
trait_ref.skip_binder().self_ty(),
472+
),
473+
}
459474
};
460475

461476
if self.suggest_add_reference_to_arg(
@@ -1805,13 +1820,21 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
18051820
return false;
18061821
}
18071822
if candidates.len() == 1 {
1823+
let ty_desc = match candidates[0].self_ty().kind() {
1824+
ty::FnPtr(_) => Some("fn pointer"),
1825+
_ => None,
1826+
};
1827+
let the_desc = match ty_desc {
1828+
Some(desc) => format!(" implemented for {} `", desc),
1829+
None => " implemented for `".to_string(),
1830+
};
18081831
err.highlighted_help(vec![
18091832
(
18101833
format!("the trait `{}` ", candidates[0].print_only_trait_path()),
18111834
Style::NoStyle,
18121835
),
18131836
("is".to_string(), Style::Highlight),
1814-
(" implemented for `".to_string(), Style::NoStyle),
1837+
(the_desc, Style::NoStyle),
18151838
(candidates[0].self_ty().to_string(), Style::Highlight),
18161839
("`".to_string(), Style::NoStyle),
18171840
]);

compiler/rustc_typeck/src/check/method/suggest.rs

+60-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKi
1616
use rustc_middle::traits::util::supertraits;
1717
use rustc_middle::ty::fast_reject::{simplify_type, TreatParams};
1818
use rustc_middle::ty::print::with_crate_prefix;
19-
use rustc_middle::ty::ToPolyTraitRef;
2019
use rustc_middle::ty::{self, DefIdTree, ToPredicate, Ty, TyCtxt, TypeVisitable};
20+
use rustc_middle::ty::{IsSuggestable, ToPolyTraitRef};
2121
use rustc_span::symbol::{kw, sym, Ident};
2222
use rustc_span::Symbol;
2323
use rustc_span::{lev_distance, source_map, ExpnKind, FileName, MacroKind, Span};
@@ -30,7 +30,7 @@ use rustc_trait_selection::traits::{
3030
use std::cmp::Ordering;
3131
use std::iter;
3232

33-
use super::probe::{Mode, ProbeScope};
33+
use super::probe::{IsSuggestion, Mode, ProbeScope};
3434
use super::{CandidateSource, MethodError, NoMatchData};
3535

3636
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
@@ -1069,6 +1069,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10691069
}
10701070
}
10711071

1072+
self.check_for_deref_method(&mut err, source, rcvr_ty, item_name);
1073+
10721074
return Some(err);
10731075
}
10741076

@@ -1651,6 +1653,62 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
16511653
}
16521654
}
16531655

1656+
fn check_for_deref_method(
1657+
&self,
1658+
err: &mut Diagnostic,
1659+
self_source: SelfSource<'tcx>,
1660+
rcvr_ty: Ty<'tcx>,
1661+
item_name: Ident,
1662+
) {
1663+
let SelfSource::QPath(ty) = self_source else { return; };
1664+
for (deref_ty, _) in self.autoderef(rustc_span::DUMMY_SP, rcvr_ty).skip(1) {
1665+
if let Ok(pick) = self.probe_for_name(
1666+
ty.span,
1667+
Mode::Path,
1668+
item_name,
1669+
IsSuggestion(true),
1670+
deref_ty,
1671+
ty.hir_id,
1672+
ProbeScope::TraitsInScope,
1673+
) {
1674+
if deref_ty.is_suggestable(self.tcx, true)
1675+
// If this method receives `&self`, then the provided
1676+
// argument _should_ coerce, so it's valid to suggest
1677+
// just changing the path.
1678+
&& pick.item.fn_has_self_parameter
1679+
&& let Some(self_ty) =
1680+
self.tcx.fn_sig(pick.item.def_id).inputs().skip_binder().get(0)
1681+
&& self_ty.is_ref()
1682+
{
1683+
let suggested_path = match deref_ty.kind() {
1684+
ty::Bool
1685+
| ty::Char
1686+
| ty::Int(_)
1687+
| ty::Uint(_)
1688+
| ty::Float(_)
1689+
| ty::Adt(_, _)
1690+
| ty::Str
1691+
| ty::Projection(_)
1692+
| ty::Param(_) => format!("{deref_ty}"),
1693+
_ => format!("<{deref_ty}>"),
1694+
};
1695+
err.span_suggestion_verbose(
1696+
ty.span,
1697+
format!("the function `{item_name}` is implemented on `{deref_ty}`"),
1698+
suggested_path,
1699+
Applicability::MaybeIncorrect,
1700+
);
1701+
} else {
1702+
err.span_note(
1703+
ty.span,
1704+
format!("the function `{item_name}` is implemented on `{deref_ty}`"),
1705+
);
1706+
}
1707+
return;
1708+
}
1709+
}
1710+
}
1711+
16541712
/// Print out the type for use in value namespace.
16551713
fn ty_to_value_string(&self, ty: Ty<'tcx>) -> String {
16561714
match ty.kind() {

src/librustdoc/html/static/css/rustdoc.css

-4
Original file line numberDiff line numberDiff line change
@@ -778,10 +778,6 @@ pre, .rustdoc.source .example-wrap {
778778
margin-bottom: .6em;
779779
}
780780

781-
.impl-items {
782-
flex-basis: 100%;
783-
}
784-
785781
#main-content > .item-info {
786782
margin-top: 0;
787783
margin-left: 0;

src/test/ui/asm/unpretty-expanded.rs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// check-pass
2+
// compile-flags: -Zunpretty=expanded
3+
core::arch::global_asm!("x: .byte 42");
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#![feature(prelude_import)]
2+
#![no_std]
3+
#[prelude_import]
4+
use ::std::prelude::rust_2015::*;
5+
#[macro_use]
6+
extern crate std;
7+
// check-pass
8+
// compile-flags: -Zunpretty=expanded
9+
global_asm! ("x: .byte 42");

src/test/ui/async-await/issues/issue-62009-1.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ error[E0277]: `[closure@$DIR/issue-62009-1.rs:12:6: 12:9]` is not a future
3030
LL | (|_| 2333).await;
3131
| ^^^^^^ `[closure@$DIR/issue-62009-1.rs:12:6: 12:9]` is not a future
3232
|
33-
= help: the trait `Future` is not implemented for `[closure@$DIR/issue-62009-1.rs:12:6: 12:9]`
33+
= help: the trait `Future` is not implemented for closure `[closure@$DIR/issue-62009-1.rs:12:6: 12:9]`
3434
= note: [closure@$DIR/issue-62009-1.rs:12:6: 12:9] must be a future or must implement `IntoFuture` to be awaited
3535
= note: required for `[closure@$DIR/issue-62009-1.rs:12:6: 12:9]` to implement `IntoFuture`
3636
help: remove the `.await`

src/test/ui/binop/issue-77910-1.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ LL | fn foo(s: &i32) -> &i32 {
1818
LL | assert_eq!(foo, y);
1919
| ^^^^^^^^^^^^^^^^^^ `for<'r> fn(&'r i32) -> &'r i32 {foo}` cannot be formatted using `{:?}` because it doesn't implement `Debug`
2020
|
21-
= help: the trait `Debug` is not implemented for `for<'r> fn(&'r i32) -> &'r i32 {foo}`
21+
= help: the trait `Debug` is not implemented for fn item `for<'r> fn(&'r i32) -> &'r i32 {foo}`
2222
= help: use parentheses to call the function: `foo(s)`
2323
= note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
2424

src/test/ui/closures/coerce-unsafe-to-closure.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ LL | let x: Option<&[u8]> = Some("foo").map(std::mem::transmute);
66
| |
77
| required by a bound introduced by this call
88
|
9-
= help: the trait `FnOnce<(&str,)>` is not implemented for `unsafe extern "rust-intrinsic" fn(_) -> _ {transmute::<_, _>}`
9+
= help: the trait `FnOnce<(&str,)>` is not implemented for fn item `unsafe extern "rust-intrinsic" fn(_) -> _ {transmute::<_, _>}`
1010
= note: unsafe function cannot be called generically without an unsafe block
1111
note: required by a bound in `Option::<T>::map`
1212
--> $SRC_DIR/core/src/option.rs:LL:COL

src/test/ui/extern/extern-wrong-value-type.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ LL | is_fn(f);
66
| |
77
| required by a bound introduced by this call
88
|
9-
= help: the trait `Fn<()>` is not implemented for `extern "C" fn() {f}`
9+
= help: the trait `Fn<()>` is not implemented for fn item `extern "C" fn() {f}`
1010
= note: wrap the `extern "C" fn() {f}` in a closure with no arguments: `|| { /* code */ }`
1111
note: required by a bound in `is_fn`
1212
--> $DIR/extern-wrong-value-type.rs:4:28

src/test/ui/intrinsics/const-eval-select-bad.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ LL | const_eval_select((), || {}, || {});
66
| |
77
| required by a bound introduced by this call
88
|
9-
= help: the trait `~const FnOnce<()>` is not implemented for `[closure@$DIR/const-eval-select-bad.rs:7:27: 7:29]`
9+
= help: the trait `~const FnOnce<()>` is not implemented for closure `[closure@$DIR/const-eval-select-bad.rs:7:27: 7:29]`
1010
note: the trait `FnOnce<()>` is implemented for `[closure@$DIR/const-eval-select-bad.rs:7:27: 7:29]`, but that implementation is not `const`
1111
--> $DIR/const-eval-select-bad.rs:7:27
1212
|

src/test/ui/issues/issue-59488.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ error[E0277]: `fn(usize) -> Foo {Foo::Bar}` doesn't implement `Debug`
8989
LL | assert_eq!(Foo::Bar, i);
9090
| ^^^^^^^^^^^^^^^^^^^^^^^ `fn(usize) -> Foo {Foo::Bar}` cannot be formatted using `{:?}` because it doesn't implement `Debug`
9191
|
92-
= help: the trait `Debug` is not implemented for `fn(usize) -> Foo {Foo::Bar}`
92+
= help: the trait `Debug` is not implemented for fn item `fn(usize) -> Foo {Foo::Bar}`
9393
= help: the following other types implement trait `Debug`:
9494
extern "C" fn() -> Ret
9595
extern "C" fn(A, B) -> Ret
@@ -108,7 +108,7 @@ error[E0277]: `fn(usize) -> Foo {Foo::Bar}` doesn't implement `Debug`
108108
LL | assert_eq!(Foo::Bar, i);
109109
| ^^^^^^^^^^^^^^^^^^^^^^^ `fn(usize) -> Foo {Foo::Bar}` cannot be formatted using `{:?}` because it doesn't implement `Debug`
110110
|
111-
= help: the trait `Debug` is not implemented for `fn(usize) -> Foo {Foo::Bar}`
111+
= help: the trait `Debug` is not implemented for fn item `fn(usize) -> Foo {Foo::Bar}`
112112
= help: the following other types implement trait `Debug`:
113113
extern "C" fn() -> Ret
114114
extern "C" fn(A, B) -> Ret

src/test/ui/issues/issue-70724-add_type_neq_err_label-unwrap.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ LL | fn a() -> i32 {
2828
LL | assert_eq!(a, 0);
2929
| ^^^^^^^^^^^^^^^^ `fn() -> i32 {a}` cannot be formatted using `{:?}` because it doesn't implement `Debug`
3030
|
31-
= help: the trait `Debug` is not implemented for `fn() -> i32 {a}`
31+
= help: the trait `Debug` is not implemented for fn item `fn() -> i32 {a}`
3232
= help: use parentheses to call the function: `a()`
3333
= note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
3434

src/test/ui/issues/issue-99875.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
struct Argument;
2+
struct Return;
3+
4+
fn function(_: Argument) -> Return { todo!() }
5+
6+
trait Trait {}
7+
impl Trait for fn(Argument) -> Return {}
8+
9+
fn takes(_: impl Trait) {}
10+
11+
fn main() {
12+
takes(function);
13+
//~^ ERROR the trait bound
14+
takes(|_: Argument| -> Return { todo!() });
15+
//~^ ERROR the trait bound
16+
}

src/test/ui/issues/issue-99875.stderr

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
error[E0277]: the trait bound `fn(Argument) -> Return {function}: Trait` is not satisfied
2+
--> $DIR/issue-99875.rs:12:11
3+
|
4+
LL | takes(function);
5+
| ----- ^^^^^^^^ the trait `Trait` is not implemented for fn item `fn(Argument) -> Return {function}`
6+
| |
7+
| required by a bound introduced by this call
8+
|
9+
= help: the trait `Trait` is implemented for fn pointer `fn(Argument) -> Return`
10+
note: required by a bound in `takes`
11+
--> $DIR/issue-99875.rs:9:18
12+
|
13+
LL | fn takes(_: impl Trait) {}
14+
| ^^^^^ required by this bound in `takes`
15+
16+
error[E0277]: the trait bound `[closure@$DIR/issue-99875.rs:14:11: 14:34]: Trait` is not satisfied
17+
--> $DIR/issue-99875.rs:14:11
18+
|
19+
LL | takes(|_: Argument| -> Return { todo!() });
20+
| ----- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Trait` is not implemented for closure `[closure@$DIR/issue-99875.rs:14:11: 14:34]`
21+
| |
22+
| required by a bound introduced by this call
23+
|
24+
= help: the trait `Trait` is implemented for fn pointer `fn(Argument) -> Return`
25+
note: required by a bound in `takes`
26+
--> $DIR/issue-99875.rs:9:18
27+
|
28+
LL | fn takes(_: impl Trait) {}
29+
| ^^^^^ required by this bound in `takes`
30+
31+
error: aborting due to 2 previous errors
32+
33+
For more information about this error, try `rustc --explain E0277`.

src/test/ui/namespace/namespace-mix.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ error[E0277]: the trait bound `fn() -> c::TS {c::TS}: Impossible` is not satisfi
218218
--> $DIR/namespace-mix.rs:56:11
219219
|
220220
LL | check(m3::TS);
221-
| ----- ^^^^^^ the trait `Impossible` is not implemented for `fn() -> c::TS {c::TS}`
221+
| ----- ^^^^^^ the trait `Impossible` is not implemented for fn item `fn() -> c::TS {c::TS}`
222222
| |
223223
| required by a bound introduced by this call
224224
|
@@ -274,7 +274,7 @@ error[E0277]: the trait bound `fn() -> namespace_mix::c::TS {namespace_mix::c::T
274274
--> $DIR/namespace-mix.rs:62:11
275275
|
276276
LL | check(xm3::TS);
277-
| ----- ^^^^^^^ the trait `Impossible` is not implemented for `fn() -> namespace_mix::c::TS {namespace_mix::c::TS}`
277+
| ----- ^^^^^^^ the trait `Impossible` is not implemented for fn item `fn() -> namespace_mix::c::TS {namespace_mix::c::TS}`
278278
| |
279279
| required by a bound introduced by this call
280280
|
@@ -526,7 +526,7 @@ error[E0277]: the trait bound `fn() -> c::E {c::E::TV}: Impossible` is not satis
526526
--> $DIR/namespace-mix.rs:122:11
527527
|
528528
LL | check(m9::TV);
529-
| ----- ^^^^^^ the trait `Impossible` is not implemented for `fn() -> c::E {c::E::TV}`
529+
| ----- ^^^^^^ the trait `Impossible` is not implemented for fn item `fn() -> c::E {c::E::TV}`
530530
| |
531531
| required by a bound introduced by this call
532532
|
@@ -582,7 +582,7 @@ error[E0277]: the trait bound `fn() -> namespace_mix::c::E {namespace_mix::xm7::
582582
--> $DIR/namespace-mix.rs:128:11
583583
|
584584
LL | check(xm9::TV);
585-
| ----- ^^^^^^^ the trait `Impossible` is not implemented for `fn() -> namespace_mix::c::E {namespace_mix::xm7::TV}`
585+
| ----- ^^^^^^^ the trait `Impossible` is not implemented for fn item `fn() -> namespace_mix::c::E {namespace_mix::xm7::TV}`
586586
| |
587587
| required by a bound introduced by this call
588588
|

src/test/ui/proc-macro/signature.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ LL | | }
1010
| |_call the function in a closure: `|| unsafe { /* code */ }`
1111
| required by a bound introduced by this call
1212
|
13-
= help: the trait `Fn<(proc_macro::TokenStream,)>` is not implemented for `unsafe extern "C" fn(i32, u32) -> u32 {foo}`
13+
= help: the trait `Fn<(proc_macro::TokenStream,)>` is not implemented for fn item `unsafe extern "C" fn(i32, u32) -> u32 {foo}`
1414
= note: unsafe function cannot be called generically without an unsafe block
1515
note: required by a bound in `ProcMacro::custom_derive`
1616
--> $SRC_DIR/proc_macro/src/bridge/client.rs:LL:COL

0 commit comments

Comments
 (0)