Skip to content

Rollup of 7 pull requests #102644

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

Merged
merged 16 commits into from
Oct 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
f088e54
Delay evaluating lint primary message until after it would be suppressed
compiler-errors Oct 2, 2022
0188273
fix #102320, suggest unwrap_or_else when a closure is passed to unwra…
chenyukang Sep 28, 2022
177b3d2
Add some more operator cases to `dump-debug-span-debug.rs`.
nnethercote Oct 3, 2022
d33e113
rustdoc: remove font family CSS on `.rustdoc-toggle summary::before`
notriddle Oct 3, 2022
8dcecdb
Change the parameter name of From::from to `value`
Oct 3, 2022
8a103f5
Ignore fuchsia on two compiler tests
andrewpollack Oct 3, 2022
4ae58d6
Migrate search results theme style to CSS variables
GuillaumeGomez Oct 1, 2022
b8a63a6
Extend GUI test to check hover and focus on search results
GuillaumeGomez Oct 1, 2022
88dab8d
Improve spans when splitting multi-char operator tokens for proc macros.
nnethercote Oct 3, 2022
a2126e7
Rollup merge of #102441 - chenyukang:fix-102320-unwrap_or_else, r=com…
matthiaskrgr Oct 4, 2022
f333436
Rollup merge of #102547 - GuillaumeGomez:migrate-css-theme-search-res…
matthiaskrgr Oct 4, 2022
8a0fda2
Rollup merge of #102567 - compiler-errors:issue-102561, r=davidtwco
matthiaskrgr Oct 4, 2022
cdb114e
Rollup merge of #102624 - notriddle:notriddle/summary-before, r=Guill…
matthiaskrgr Oct 4, 2022
17c6582
Rollup merge of #102628 - H4x5:master, r=scottmcm
matthiaskrgr Oct 4, 2022
f86ee78
Rollup merge of #102637 - andrewpollack:ignore-fuchsia-two-tests, r=t…
matthiaskrgr Oct 4, 2022
185ca0f
Rollup merge of #102639 - nnethercote:improve-spans-splitting, r=Aaro…
matthiaskrgr Oct 4, 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
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