Skip to content

Commit

Permalink
Auto merge of rust-lang#102644 - matthiaskrgr:rollup-rg0sw41, r=matth…
Browse files Browse the repository at this point in the history
…iaskrgr

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
  • Loading branch information
bors committed Oct 4, 2022
2 parents d9f8b4b + 185ca0f commit f111209
Show file tree
Hide file tree
Showing 31 changed files with 893 additions and 220 deletions.
16 changes: 14 additions & 2 deletions compiler/rustc_expand/src/proc_macro_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,20 @@ impl FromInternal<(TokenStream, &mut Rustc<'_, '_>)> for Vec<TokenTree<TokenStre
// before that get `joint = true`.
let mut op = |s: &str| {
assert!(s.is_ascii());
trees.extend(s.bytes().enumerate().map(|(idx, ch)| {
let is_final = idx == s.len() - 1;
trees.extend(s.bytes().enumerate().map(|(i, ch)| {
let is_final = i == s.len() - 1;
// Split the token span into single chars. Unless the span
// is an unusual one, e.g. due to proc macro expansion. We
// determine this by assuming any span with a length that
// matches the operator length is a normal one, and any
// span with a different length is an unusual one.
let span = if (span.hi() - span.lo()).to_usize() == s.len() {
let lo = span.lo() + BytePos::from_usize(i);
let hi = lo + BytePos::from_usize(1);
span.with_lo(lo).with_hi(hi)
} else {
span
};
TokenTree::Punct(Punct { ch, joint: if is_final { joint } else { true }, span })
}));
};
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_hir_analysis/src/check/fn_ctxt/suggestions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}

/// When encountering an fn-like type, try accessing the output of the type
/// // and suggesting calling it if it satisfies a predicate (i.e. if the
/// and suggesting calling it if it satisfies a predicate (i.e. if the
/// output has a method or a field):
/// ```compile_fail,E0308
/// fn foo(x: usize) -> usize { x }
Expand Down Expand Up @@ -139,7 +139,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
sugg,
applicability,
);

return true;
}
false
Expand Down Expand Up @@ -338,6 +337,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} else {
err.span_suggestion(sp, &msg, suggestion, applicability);
}
} else if self.suggest_else_fn_with_closure(err, expr, found, expected)
{
} else if self.suggest_fn_call(err, expr, found, |output| self.can_coerce(output, expected))
&& let ty::FnDef(def_id, ..) = &found.kind()
&& let Some(sp) = self.tcx.hir().span_if_local(*def_id)
Expand Down
54 changes: 54 additions & 0 deletions compiler/rustc_hir_analysis/src/check/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2324,6 +2324,60 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
}

/// issue #102320, for `unwrap_or` with closure as argument, suggest `unwrap_or_else`
/// FIXME: currently not working for suggesting `map_or_else`, see #102408
pub(crate) fn suggest_else_fn_with_closure(
&self,
err: &mut Diagnostic,
expr: &hir::Expr<'_>,
found: Ty<'tcx>,
expected: Ty<'tcx>,
) -> bool {
let Some((_def_id_or_name, output, _inputs)) = self.extract_callable_info(expr, found)
else { return false; };

if !self.can_coerce(output, expected) {
return false;
}

let parent = self.tcx.hir().get_parent_node(expr.hir_id);
if let Some(Node::Expr(call_expr)) = self.tcx.hir().find(parent) &&
let hir::ExprKind::MethodCall(
hir::PathSegment { ident: method_name, .. },
self_expr,
args,
..,
) = call_expr.kind &&
let Some(self_ty) = self.typeck_results.borrow().expr_ty_opt(self_expr) {
let new_name = Ident {
name: Symbol::intern(&format!("{}_else", method_name.as_str())),
span: method_name.span,
};
let probe = self.lookup_probe(
expr.span,
new_name,
self_ty,
self_expr,
ProbeScope::TraitsInScope,
);

// check the method arguments number
if let Ok(pick) = probe &&
let fn_sig = self.tcx.fn_sig(pick.item.def_id) &&
let fn_args = fn_sig.skip_binder().inputs() &&
fn_args.len() == args.len() + 1 {
err.span_suggestion_verbose(
method_name.span.shrink_to_hi(),
&format!("try calling `{}` instead", new_name.name.as_str()),
"_else",
Applicability::MaybeIncorrect,
);
return true;
}
}
false
}

/// Checks whether there is a local type somewhere in the chain of
/// autoderefs of `rcvr_ty`.
fn type_derefs_to_local(
Expand Down
5 changes: 4 additions & 1 deletion compiler/rustc_middle/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,6 @@ pub fn struct_lint_level(
(Level::Deny | Level::Forbid, None) => sess.diagnostic().struct_err_lint(""),
};

err.set_primary_message(msg);
err.set_is_lint();

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

// Delay evaluating and setting the primary message until after we've
// suppressed the lint due to macros.
err.set_primary_message(msg);

// Lint diagnostics that are covered by the expect level will not be emitted outside
// the compiler. It is therefore not necessary to add any information for the user.
// This will therefore directly call the decorate function which will in turn emit
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/convert/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ pub trait From<T>: Sized {
#[lang = "from"]
#[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
fn from(_: T) -> Self;
fn from(value: T) -> Self;
}

/// An attempted conversion that consumes `self`, which may or may not be
Expand Down
9 changes: 5 additions & 4 deletions src/librustdoc/html/static/css/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,10 @@ h1, h2, h3, h4, h5, h6,
.item-left > a,
.out-of-band,
span.since,
details.rustdoc-toggle > summary::before,
a.srclink,
#help-button > button,
details.rustdoc-toggle.top-doc > summary,
details.rustdoc-toggle.top-doc > summary::before,
details.rustdoc-toggle.non-exhaustive > summary,
details.rustdoc-toggle.non-exhaustive > summary::before,
.scraped-example-title,
.more-examples-toggle summary, .more-examples-toggle .hide-more,
.example-links a,
Expand Down Expand Up @@ -970,6 +967,11 @@ so that we can apply CSS-filters to change the arrow color in themes */
padding-right: 1em;
}

.search-results a:hover,
.search-results a:focus {
background-color: var(--search-result-link-focus-background-color);
}

.popover {
font-size: 1rem;
position: absolute;
Expand Down Expand Up @@ -1567,7 +1569,6 @@ details.rustdoc-toggle > summary::before {
}

details.rustdoc-toggle > summary.hideme > span,
details.rustdoc-toggle > summary::before,
.more-examples-toggle summary, .more-examples-toggle .hide-more {
color: var(--toggles-color);
}
Expand Down
25 changes: 1 addition & 24 deletions src/librustdoc/html/static/css/themes/ayu.css
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Original by Dempfi (https://github.com/dempfi/ayu)
--link-color: #39afd7;
--sidebar-link-color: #53b1db;
--sidebar-current-link-background-color: transparent;
--search-result-link-focus-background-color: #3c3c3c;
--stab-background-color: #314559;
--stab-code-color: #e6e1cf;
}
Expand Down Expand Up @@ -250,30 +251,6 @@ pre.rust .kw {}
pre.rust .self, pre.rust .bool-val, pre.rust .prelude-val, pre.rust .attribute {}
pre.rust .kw-2, pre.rust .prelude-ty {}

.search-results a:focus span {}
a.result-trait:focus {}
a.result-traitalias:focus {}
a.result-mod:focus,
a.result-externcrate:focus {}
a.result-mod:focus {}
a.result-externcrate:focus {}
a.result-enum:focus {}
a.result-struct:focus {}
a.result-union:focus {}
a.result-fn:focus,
a.result-method:focus,
a.result-tymethod:focus {}
a.result-type:focus {}
a.result-associatedtype:focus {}
a.result-foreigntype:focus {}
a.result-attr:focus,
a.result-derive:focus,
a.result-macro:focus {}
a.result-constant:focus,
a.result-static:focus {}
a.result-primitive:focus {}
a.result-keyword:focus {}

kbd {
color: #c5c5c5;
background-color: #314559;
Expand Down
31 changes: 1 addition & 30 deletions src/librustdoc/html/static/css/themes/dark.css
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
--link-color: #d2991d;
--sidebar-link-color: #fdbf35;
--sidebar-current-link-background-color: #444;
--search-result-link-focus-background-color: #616161;
--stab-background-color: #314559;
--stab-code-color: #e6e1cf;
}
Expand All @@ -58,36 +59,6 @@ input:focus + .slider {
background-color: #0a042f !important;
}

.search-results a:hover {
background-color: #777;
}

.search-results a:focus {
color: #eee !important;
background-color: #616161;
}
.search-results a:focus span { color: #eee !important; }
a.result-trait:focus { background-color: #013191; }
a.result-traitalias:focus { background-color: #013191; }
a.result-mod:focus,
a.result-externcrate:focus { background-color: #884719; }
a.result-enum:focus { background-color: #194e9f; }
a.result-struct:focus { background-color: #194e9f; }
a.result-union:focus { background-color: #194e9f; }
a.result-fn:focus,
a.result-method:focus,
a.result-tymethod:focus { background-color: #4950ed; }
a.result-type:focus { background-color: #194e9f; }
a.result-associatedtype:focus { background-color: #884719; }
a.result-foreigntype:focus { background-color: #194e9f; }
a.result-attr:focus,
a.result-derive:focus,
a.result-macro:focus { background-color: #217d1c; }
a.result-constant:focus,
a.result-static:focus { background-color: #884719; }
a.result-primitive:focus { background-color: #194e9f; }
a.result-keyword:focus { background-color: #884719; }

.content .item-info::before { color: #ccc; }

pre.rust .comment { color: #8d8d8b; }
Expand Down
31 changes: 1 addition & 30 deletions src/librustdoc/html/static/css/themes/light.css
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
--link-color: #3873ad;
--sidebar-link-color: #356da4;
--sidebar-current-link-background-color: #fff;
--search-result-link-focus-background-color: #ccc;
--stab-background-color: #fff5d6;
--stab-code-color: #000;
}
Expand All @@ -57,36 +58,6 @@ input:focus + .slider {
background-color: #FDFFD3 !important;
}

.search-results a:hover {
background-color: #ddd;
}

.search-results a:focus {
color: #000 !important;
background-color: #ccc;
}
.search-results a:focus span { color: #000 !important; }
a.result-trait:focus { background-color: #c7b6ff; }
a.result-traitalias:focus { background-color: #c7b6ff; }
a.result-mod:focus,
a.result-externcrate:focus { background-color: #afc6e4; }
a.result-enum:focus { background-color: #e7b1a0; }
a.result-struct:focus { background-color: #e7b1a0; }
a.result-union:focus { background-color: #e7b1a0; }
a.result-fn:focus,
a.result-method:focus,
a.result-tymethod:focus { background-color: #c6afb3; }
a.result-type:focus { background-color: #e7b1a0; }
a.result-associatedtype:focus { background-color: #afc6e4; }
a.result-foreigntype:focus { background-color: #e7b1a0; }
a.result-attr:focus,
a.result-derive:focus,
a.result-macro:focus { background-color: #8ce488; }
a.result-constant:focus,
a.result-static:focus { background-color: #afc6e4; }
a.result-primitive:focus { background-color: #e7b1a0; }
a.result-keyword:focus { background-color: #afc6e4; }

.content .item-info::before { color: #ccc; }

body.source .example-wrap pre.rust a {
Expand Down
Loading

0 comments on commit f111209

Please sign in to comment.