Skip to content

Commit f111209

Browse files
committed
Auto merge of rust-lang#102644 - matthiaskrgr:rollup-rg0sw41, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#102441 (Suggest unwrap_or_else when a closure is given) - rust-lang#102547 (Migrate CSS theme for search results) - rust-lang#102567 (Delay evaluating lint primary message until after it would be suppressed) - rust-lang#102624 (rustdoc: remove font family CSS on `.rustdoc-toggle summary::before`) - rust-lang#102628 (Change the parameter name of From::from to `value`) - rust-lang#102637 (Ignore fuchsia on two compiler tests) - rust-lang#102639 (Improve spans when splitting multi-char operator tokens for proc macros.) Failed merges: - rust-lang#102496 (Suggest `.into()` when all other coercion suggestions fail) r? `@ghost` `@rustbot` modify labels: rollup
2 parents d9f8b4b + 185ca0f commit f111209

31 files changed

+893
-220
lines changed

compiler/rustc_expand/src/proc_macro_server.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,20 @@ impl FromInternal<(TokenStream, &mut Rustc<'_, '_>)> for Vec<TokenTree<TokenStre
115115
// before that get `joint = true`.
116116
let mut op = |s: &str| {
117117
assert!(s.is_ascii());
118-
trees.extend(s.bytes().enumerate().map(|(idx, ch)| {
119-
let is_final = idx == s.len() - 1;
118+
trees.extend(s.bytes().enumerate().map(|(i, ch)| {
119+
let is_final = i == s.len() - 1;
120+
// Split the token span into single chars. Unless the span
121+
// is an unusual one, e.g. due to proc macro expansion. We
122+
// determine this by assuming any span with a length that
123+
// matches the operator length is a normal one, and any
124+
// span with a different length is an unusual one.
125+
let span = if (span.hi() - span.lo()).to_usize() == s.len() {
126+
let lo = span.lo() + BytePos::from_usize(i);
127+
let hi = lo + BytePos::from_usize(1);
128+
span.with_lo(lo).with_hi(hi)
129+
} else {
130+
span
131+
};
120132
TokenTree::Punct(Punct { ch, joint: if is_final { joint } else { true }, span })
121133
}));
122134
};

compiler/rustc_hir_analysis/src/check/fn_ctxt/suggestions.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
6565
}
6666

6767
/// When encountering an fn-like type, try accessing the output of the type
68-
/// // and suggesting calling it if it satisfies a predicate (i.e. if the
68+
/// and suggesting calling it if it satisfies a predicate (i.e. if the
6969
/// output has a method or a field):
7070
/// ```compile_fail,E0308
7171
/// fn foo(x: usize) -> usize { x }
@@ -139,7 +139,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
139139
sugg,
140140
applicability,
141141
);
142-
143142
return true;
144143
}
145144
false
@@ -338,6 +337,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
338337
} else {
339338
err.span_suggestion(sp, &msg, suggestion, applicability);
340339
}
340+
} else if self.suggest_else_fn_with_closure(err, expr, found, expected)
341+
{
341342
} else if self.suggest_fn_call(err, expr, found, |output| self.can_coerce(output, expected))
342343
&& let ty::FnDef(def_id, ..) = &found.kind()
343344
&& let Some(sp) = self.tcx.hir().span_if_local(*def_id)

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

+54
Original file line numberDiff line numberDiff line change
@@ -2324,6 +2324,60 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
23242324
}
23252325
}
23262326

2327+
/// issue #102320, for `unwrap_or` with closure as argument, suggest `unwrap_or_else`
2328+
/// FIXME: currently not working for suggesting `map_or_else`, see #102408
2329+
pub(crate) fn suggest_else_fn_with_closure(
2330+
&self,
2331+
err: &mut Diagnostic,
2332+
expr: &hir::Expr<'_>,
2333+
found: Ty<'tcx>,
2334+
expected: Ty<'tcx>,
2335+
) -> bool {
2336+
let Some((_def_id_or_name, output, _inputs)) = self.extract_callable_info(expr, found)
2337+
else { return false; };
2338+
2339+
if !self.can_coerce(output, expected) {
2340+
return false;
2341+
}
2342+
2343+
let parent = self.tcx.hir().get_parent_node(expr.hir_id);
2344+
if let Some(Node::Expr(call_expr)) = self.tcx.hir().find(parent) &&
2345+
let hir::ExprKind::MethodCall(
2346+
hir::PathSegment { ident: method_name, .. },
2347+
self_expr,
2348+
args,
2349+
..,
2350+
) = call_expr.kind &&
2351+
let Some(self_ty) = self.typeck_results.borrow().expr_ty_opt(self_expr) {
2352+
let new_name = Ident {
2353+
name: Symbol::intern(&format!("{}_else", method_name.as_str())),
2354+
span: method_name.span,
2355+
};
2356+
let probe = self.lookup_probe(
2357+
expr.span,
2358+
new_name,
2359+
self_ty,
2360+
self_expr,
2361+
ProbeScope::TraitsInScope,
2362+
);
2363+
2364+
// check the method arguments number
2365+
if let Ok(pick) = probe &&
2366+
let fn_sig = self.tcx.fn_sig(pick.item.def_id) &&
2367+
let fn_args = fn_sig.skip_binder().inputs() &&
2368+
fn_args.len() == args.len() + 1 {
2369+
err.span_suggestion_verbose(
2370+
method_name.span.shrink_to_hi(),
2371+
&format!("try calling `{}` instead", new_name.name.as_str()),
2372+
"_else",
2373+
Applicability::MaybeIncorrect,
2374+
);
2375+
return true;
2376+
}
2377+
}
2378+
false
2379+
}
2380+
23272381
/// Checks whether there is a local type somewhere in the chain of
23282382
/// autoderefs of `rcvr_ty`.
23292383
fn type_derefs_to_local(

compiler/rustc_middle/src/lint.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,6 @@ pub fn struct_lint_level(
350350
(Level::Deny | Level::Forbid, None) => sess.diagnostic().struct_err_lint(""),
351351
};
352352

353-
err.set_primary_message(msg);
354353
err.set_is_lint();
355354

356355
// If this code originates in a foreign macro, aka something that this crate
@@ -375,6 +374,10 @@ pub fn struct_lint_level(
375374
}
376375
}
377376

377+
// Delay evaluating and setting the primary message until after we've
378+
// suppressed the lint due to macros.
379+
err.set_primary_message(msg);
380+
378381
// Lint diagnostics that are covered by the expect level will not be emitted outside
379382
// the compiler. It is therefore not necessary to add any information for the user.
380383
// This will therefore directly call the decorate function which will in turn emit

library/core/src/convert/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ pub trait From<T>: Sized {
545545
#[lang = "from"]
546546
#[must_use]
547547
#[stable(feature = "rust1", since = "1.0.0")]
548-
fn from(_: T) -> Self;
548+
fn from(value: T) -> Self;
549549
}
550550

551551
/// An attempted conversion that consumes `self`, which may or may not be

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

+5-4
Original file line numberDiff line numberDiff line change
@@ -194,13 +194,10 @@ h1, h2, h3, h4, h5, h6,
194194
.item-left > a,
195195
.out-of-band,
196196
span.since,
197-
details.rustdoc-toggle > summary::before,
198197
a.srclink,
199198
#help-button > button,
200199
details.rustdoc-toggle.top-doc > summary,
201-
details.rustdoc-toggle.top-doc > summary::before,
202200
details.rustdoc-toggle.non-exhaustive > summary,
203-
details.rustdoc-toggle.non-exhaustive > summary::before,
204201
.scraped-example-title,
205202
.more-examples-toggle summary, .more-examples-toggle .hide-more,
206203
.example-links a,
@@ -970,6 +967,11 @@ so that we can apply CSS-filters to change the arrow color in themes */
970967
padding-right: 1em;
971968
}
972969

970+
.search-results a:hover,
971+
.search-results a:focus {
972+
background-color: var(--search-result-link-focus-background-color);
973+
}
974+
973975
.popover {
974976
font-size: 1rem;
975977
position: absolute;
@@ -1567,7 +1569,6 @@ details.rustdoc-toggle > summary::before {
15671569
}
15681570

15691571
details.rustdoc-toggle > summary.hideme > span,
1570-
details.rustdoc-toggle > summary::before,
15711572
.more-examples-toggle summary, .more-examples-toggle .hide-more {
15721573
color: var(--toggles-color);
15731574
}

src/librustdoc/html/static/css/themes/ayu.css

+1-24
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Original by Dempfi (https://github.com/dempfi/ayu)
3737
--link-color: #39afd7;
3838
--sidebar-link-color: #53b1db;
3939
--sidebar-current-link-background-color: transparent;
40+
--search-result-link-focus-background-color: #3c3c3c;
4041
--stab-background-color: #314559;
4142
--stab-code-color: #e6e1cf;
4243
}
@@ -250,30 +251,6 @@ pre.rust .kw {}
250251
pre.rust .self, pre.rust .bool-val, pre.rust .prelude-val, pre.rust .attribute {}
251252
pre.rust .kw-2, pre.rust .prelude-ty {}
252253

253-
.search-results a:focus span {}
254-
a.result-trait:focus {}
255-
a.result-traitalias:focus {}
256-
a.result-mod:focus,
257-
a.result-externcrate:focus {}
258-
a.result-mod:focus {}
259-
a.result-externcrate:focus {}
260-
a.result-enum:focus {}
261-
a.result-struct:focus {}
262-
a.result-union:focus {}
263-
a.result-fn:focus,
264-
a.result-method:focus,
265-
a.result-tymethod:focus {}
266-
a.result-type:focus {}
267-
a.result-associatedtype:focus {}
268-
a.result-foreigntype:focus {}
269-
a.result-attr:focus,
270-
a.result-derive:focus,
271-
a.result-macro:focus {}
272-
a.result-constant:focus,
273-
a.result-static:focus {}
274-
a.result-primitive:focus {}
275-
a.result-keyword:focus {}
276-
277254
kbd {
278255
color: #c5c5c5;
279256
background-color: #314559;

src/librustdoc/html/static/css/themes/dark.css

+1-30
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
--link-color: #d2991d;
3333
--sidebar-link-color: #fdbf35;
3434
--sidebar-current-link-background-color: #444;
35+
--search-result-link-focus-background-color: #616161;
3536
--stab-background-color: #314559;
3637
--stab-code-color: #e6e1cf;
3738
}
@@ -58,36 +59,6 @@ input:focus + .slider {
5859
background-color: #0a042f !important;
5960
}
6061

61-
.search-results a:hover {
62-
background-color: #777;
63-
}
64-
65-
.search-results a:focus {
66-
color: #eee !important;
67-
background-color: #616161;
68-
}
69-
.search-results a:focus span { color: #eee !important; }
70-
a.result-trait:focus { background-color: #013191; }
71-
a.result-traitalias:focus { background-color: #013191; }
72-
a.result-mod:focus,
73-
a.result-externcrate:focus { background-color: #884719; }
74-
a.result-enum:focus { background-color: #194e9f; }
75-
a.result-struct:focus { background-color: #194e9f; }
76-
a.result-union:focus { background-color: #194e9f; }
77-
a.result-fn:focus,
78-
a.result-method:focus,
79-
a.result-tymethod:focus { background-color: #4950ed; }
80-
a.result-type:focus { background-color: #194e9f; }
81-
a.result-associatedtype:focus { background-color: #884719; }
82-
a.result-foreigntype:focus { background-color: #194e9f; }
83-
a.result-attr:focus,
84-
a.result-derive:focus,
85-
a.result-macro:focus { background-color: #217d1c; }
86-
a.result-constant:focus,
87-
a.result-static:focus { background-color: #884719; }
88-
a.result-primitive:focus { background-color: #194e9f; }
89-
a.result-keyword:focus { background-color: #884719; }
90-
9162
.content .item-info::before { color: #ccc; }
9263

9364
pre.rust .comment { color: #8d8d8b; }

src/librustdoc/html/static/css/themes/light.css

+1-30
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
--link-color: #3873ad;
3333
--sidebar-link-color: #356da4;
3434
--sidebar-current-link-background-color: #fff;
35+
--search-result-link-focus-background-color: #ccc;
3536
--stab-background-color: #fff5d6;
3637
--stab-code-color: #000;
3738
}
@@ -57,36 +58,6 @@ input:focus + .slider {
5758
background-color: #FDFFD3 !important;
5859
}
5960

60-
.search-results a:hover {
61-
background-color: #ddd;
62-
}
63-
64-
.search-results a:focus {
65-
color: #000 !important;
66-
background-color: #ccc;
67-
}
68-
.search-results a:focus span { color: #000 !important; }
69-
a.result-trait:focus { background-color: #c7b6ff; }
70-
a.result-traitalias:focus { background-color: #c7b6ff; }
71-
a.result-mod:focus,
72-
a.result-externcrate:focus { background-color: #afc6e4; }
73-
a.result-enum:focus { background-color: #e7b1a0; }
74-
a.result-struct:focus { background-color: #e7b1a0; }
75-
a.result-union:focus { background-color: #e7b1a0; }
76-
a.result-fn:focus,
77-
a.result-method:focus,
78-
a.result-tymethod:focus { background-color: #c6afb3; }
79-
a.result-type:focus { background-color: #e7b1a0; }
80-
a.result-associatedtype:focus { background-color: #afc6e4; }
81-
a.result-foreigntype:focus { background-color: #e7b1a0; }
82-
a.result-attr:focus,
83-
a.result-derive:focus,
84-
a.result-macro:focus { background-color: #8ce488; }
85-
a.result-constant:focus,
86-
a.result-static:focus { background-color: #afc6e4; }
87-
a.result-primitive:focus { background-color: #e7b1a0; }
88-
a.result-keyword:focus { background-color: #afc6e4; }
89-
9061
.content .item-info::before { color: #ccc; }
9162

9263
body.source .example-wrap pre.rust a {

0 commit comments

Comments
 (0)