Skip to content
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

Rollup of 11 pull requests #82911

Merged
merged 28 commits into from
Mar 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
2a57a5d
Typo fix: cargo cov -> cargo profdata
amaurremi Mar 5, 2021
6052211
Update minifier dependency version
GuillaumeGomez Mar 4, 2021
6e4dcea
Handle negative literals in cast overflow warning
JohnTitor Mar 6, 2021
c40ef91
Add note about the `#[doc(no-inline)]` usage
jfrimmel Mar 7, 2021
e62a543
Account for `if (let pat = expr) {}`
estebank Mar 7, 2021
23bcea4
Add help suggesting `matches` to `let_chains` lint
estebank Mar 7, 2021
ac7f9cc
diagnostics: Differentiate between edition meanings of ::foo in resol…
Manishearth Mar 7, 2021
9d5d669
diagnostics: Differentiate between edition meanings of ::foo in resol…
Manishearth Mar 7, 2021
63fb294
Add help for `matches` for `if let` in arm guard
estebank Mar 7, 2021
9386370
add codegen tests for some issues closed by LLVM 12
erikdesjardins Mar 7, 2021
aa7ac6e
Remove notes, increase S/N ratio
estebank Mar 7, 2021
0eeae1a
diagnostics: Don't mention external crates when hitting import errors…
Manishearth Mar 7, 2021
69a37a6
Add documentation for string->Cow conversions
notriddle Mar 2, 2021
2aa28ad
Grammar Fixes
daggy1234 Mar 8, 2021
84bfa38
[.mailmap] Add entry for Ramkumar Ramachandra
artagnon Mar 8, 2021
bc1fbf5
Move rustdoc UI tests into a subdirectory
jyn514 Mar 5, 2021
655155c
Update library/core/src/array/mod.rs
daggy1234 Mar 8, 2021
3114e2b
Rollup merge of #82711 - notriddle:string-cow-docs, r=Mark-Simulacrum
m-ou-se Mar 8, 2021
6e9a94a
Rollup merge of #82767 - GuillaumeGomez:update-minifier-crate-version…
m-ou-se Mar 8, 2021
5ff52cb
Rollup merge of #82800 - jyn514:group-rustdoc-tests, r=Mark-Simulacrum
m-ou-se Mar 8, 2021
09b17a1
Rollup merge of #82810 - amaurremi:source-based-coverage-typo, r=ehuss
m-ou-se Mar 8, 2021
0ee2f4c
Rollup merge of #82829 - JohnTitor:handle-neg-val, r=estebank
m-ou-se Mar 8, 2021
6a55aa1
Rollup merge of #82854 - estebank:issue-82827, r=oli-obk
m-ou-se Mar 8, 2021
a55b192
Rollup merge of #82870 - jfrimmel:improve-docs, r=jyn514
m-ou-se Mar 8, 2021
a5035c9
Rollup merge of #82874 - erikdesjardins:cgtests, r=nagisa
m-ou-se Mar 8, 2021
3908eec
Rollup merge of #82881 - Manishearth:crate-root, r=estebank
m-ou-se Mar 8, 2021
2d3ba78
Rollup merge of #82888 - Daggy1234:patch-1, r=joshtriplett
m-ou-se Mar 8, 2021
54add8d
Rollup merge of #82897 - artagnon:patch-2, r=joshtriplett
m-ou-se Mar 8, 2021
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
1 change: 1 addition & 0 deletions .mailmap
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ Philipp Matthias Schäfer <philipp.matthias.schaefer@posteo.de>
Przemysław Wesołek <jest@go.art.pl> Przemek Wesołek <jest@go.art.pl>
Rafael Ávila de Espíndola <respindola@mozilla.com> Rafael Avila de Espindola <espindola@dream.(none)>
Ralph Giles <giles@thaumas.net> Ralph Giles <giles@mozilla.com>
Ramkumar Ramachandra <r@artagnon.com> <artagnon@gmail.com>
Renato Riccieri Santos Zannon <renato@rrsz.com.br>
Richard Diamond <wichard@vitalitystudios.com> <wichard@hahbee.co>
Rob Arnold <robarnold@cs.cmu.edu>
Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2214,9 +2214,9 @@ dependencies = [

[[package]]
name = "minifier"
version = "0.0.33"
version = "0.0.39"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "70bf0db2475f5e627787da77ca52fe33c294063f49f4134b8bc662eedb5e7332"
checksum = "6cdf618de5c9c98d4a7b2e0d1f1e44f82a19196cfd94040bb203621c25d28d98"
dependencies = [
"macro-utils",
]
Expand Down
8 changes: 8 additions & 0 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1129,6 +1129,14 @@ impl Expr {
}
}

pub fn peel_parens(&self) -> &Expr {
let mut expr = self;
while let ExprKind::Paren(inner) = &expr.kind {
expr = &inner;
}
expr
}

/// Attempts to reparse as `Ty` (for diagnostic purposes).
pub fn to_ty(&self) -> Option<P<Ty>> {
let kind = match &self.kind {
Expand Down
42 changes: 40 additions & 2 deletions compiler/rustc_ast_lowering/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,23 @@ impl<'hir> LoweringContext<'_, 'hir> {
ExprKind::Let(ref pat, ref scrutinee) => {
self.lower_expr_if_let(e.span, pat, scrutinee, then, else_opt.as_deref())
}
ExprKind::Paren(ref paren) => match paren.peel_parens().kind {
ExprKind::Let(ref pat, ref scrutinee) => {
// A user has written `if (let Some(x) = foo) {`, we want to avoid
// confusing them with mentions of nightly features.
// If this logic is changed, you will also likely need to touch
// `unused::UnusedParens::check_expr`.
self.if_let_expr_with_parens(cond, &paren.peel_parens());
self.lower_expr_if_let(
e.span,
pat,
scrutinee,
then,
else_opt.as_deref(),
)
}
_ => self.lower_expr_if(cond, then, else_opt.as_deref()),
},
_ => self.lower_expr_if(cond, then, else_opt.as_deref()),
},
ExprKind::While(ref cond, ref body, opt_label) => self
Expand Down Expand Up @@ -346,6 +363,25 @@ impl<'hir> LoweringContext<'_, 'hir> {
hir::ExprKind::Call(f, self.lower_exprs(&real_args))
}

fn if_let_expr_with_parens(&mut self, cond: &Expr, paren: &Expr) {
let start = cond.span.until(paren.span);
let end = paren.span.shrink_to_hi().until(cond.span.shrink_to_hi());
self.sess
.struct_span_err(
vec![start, end],
"invalid parentheses around `let` expression in `if let`",
)
.multipart_suggestion(
"`if let` needs to be written without parentheses",
vec![(start, String::new()), (end, String::new())],
rustc_errors::Applicability::MachineApplicable,
)
.emit();
// Ideally, we'd remove the feature gating of a `let` expression since we are already
// complaining about it here, but `feature_gate::check_crate` has already run by now:
// self.sess.parse_sess.gated_spans.ungate_last(sym::let_chains, paren.span);
}

/// Emit an error and lower `ast::ExprKind::Let(pat, scrutinee)` into:
/// ```rust
/// match scrutinee { pats => true, _ => false }
Expand All @@ -356,8 +392,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
if self.sess.opts.unstable_features.is_nightly_build() {
self.sess
.struct_span_err(span, "`let` expressions are not supported here")
.note("only supported directly in conditions of `if`- and `while`-expressions")
.note("as well as when nested within `&&` and parenthesis in those conditions")
.note(
"only supported directly without parentheses in conditions of `if`- and \
`while`-expressions, as well as in `let` chains within parentheses",
)
.emit();
} else {
self.sess
Expand Down
12 changes: 10 additions & 2 deletions compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -638,8 +638,16 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session) {
}
};
}
gate_all!(if_let_guard, "`if let` guards are experimental");
gate_all!(let_chains, "`let` expressions in this position are experimental");
gate_all!(
if_let_guard,
"`if let` guards are experimental",
"you can write `if matches!(<expr>, <pattern>)` instead of `if let <pattern> = <expr>`"
);
gate_all!(
let_chains,
"`let` expressions in this position are experimental",
"you can write `matches!(<expr>, <pattern>)` instead of `let <pattern> = <expr>`"
);
gate_all!(
async_closure,
"async closures are unstable",
Expand Down
27 changes: 21 additions & 6 deletions compiler/rustc_lint/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,11 @@ fn report_bin_hex_error(
cx.struct_span_lint(OVERFLOWING_LITERALS, expr.span, |lint| {
let (t, actually) = match ty {
attr::IntType::SignedInt(t) => {
let actually = size.sign_extend(val) as i128;
let actually = if negative {
-(size.sign_extend(val) as i128)
} else {
size.sign_extend(val) as i128
};
(t.name_str(), actually.to_string())
}
attr::IntType::UnsignedInt(t) => {
Expand All @@ -226,11 +230,22 @@ fn report_bin_hex_error(
}
};
let mut err = lint.build(&format!("literal out of range for `{}`", t));
err.note(&format!(
"the literal `{}` (decimal `{}`) does not fit into \
the type `{}` and will become `{}{}`",
repr_str, val, t, actually, t
));
if negative {
// If the value is negative,
// emits a note about the value itself, apart from the literal.
err.note(&format!(
"the literal `{}` (decimal `{}`) does not fit into \
the type `{}`",
repr_str, val, t
));
err.note(&format!("and the value `-{}` will become `{}{}`", repr_str, actually, t));
} else {
err.note(&format!(
"the literal `{}` (decimal `{}`) does not fit into \
the type `{}` and will become `{}{}`",
repr_str, val, t, actually, t
));
}
if let Some(sugg_ty) =
get_type_suggestion(&cx.typeck_results().node_type(expr.hir_id), val, negative)
{
Expand Down
31 changes: 28 additions & 3 deletions compiler/rustc_lint/src/unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ trait UnusedDelimLint {
use rustc_ast::ExprKind::*;
let (value, ctx, followed_by_block, left_pos, right_pos) = match e.kind {
// Do not lint `unused_braces` in `if let` expressions.
If(ref cond, ref block, ..)
If(ref cond, ref block, _)
if !matches!(cond.kind, Let(_, _)) || Self::LINT_EXPR_IN_PATTERN_MATCHING_CTX =>
{
let left = e.span.lo() + rustc_span::BytePos(2);
Expand Down Expand Up @@ -816,8 +816,33 @@ impl UnusedParens {

impl EarlyLintPass for UnusedParens {
fn check_expr(&mut self, cx: &EarlyContext<'_>, e: &ast::Expr) {
if let ExprKind::Let(ref pat, ..) | ExprKind::ForLoop(ref pat, ..) = e.kind {
self.check_unused_parens_pat(cx, pat, false, false);
match e.kind {
ExprKind::Let(ref pat, _) | ExprKind::ForLoop(ref pat, ..) => {
self.check_unused_parens_pat(cx, pat, false, false);
}
// We ignore parens in cases like `if (((let Some(0) = Some(1))))` because we already
// handle a hard error for them during AST lowering in `lower_expr_mut`, but we still
// want to complain about things like `if let 42 = (42)`.
ExprKind::If(ref cond, ref block, ref else_)
if matches!(cond.peel_parens().kind, ExprKind::Let(..)) =>
{
self.check_unused_delims_expr(
cx,
cond.peel_parens(),
UnusedDelimsCtx::LetScrutineeExpr,
true,
None,
None,
);
for stmt in &block.stmts {
<Self as UnusedDelimLint>::check_stmt(self, cx, stmt);
}
if let Some(e) = else_ {
<Self as UnusedDelimLint>::check_expr(self, cx, e);
}
return;
}
_ => {}
}

<Self as UnusedDelimLint>::check_expr(self, cx, e)
Expand Down
12 changes: 11 additions & 1 deletion compiler/rustc_resolve/src/late/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use rustc_hir::def::{self, CtorKind, CtorOf, DefKind};
use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE};
use rustc_hir::PrimTy;
use rustc_session::parse::feature_err;
use rustc_span::edition::Edition;
use rustc_span::hygiene::MacroKind;
use rustc_span::lev_distance::find_best_match_for_name;
use rustc_span::symbol::{kw, sym, Ident, Symbol};
Expand Down Expand Up @@ -133,7 +134,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
let is_enum_variant = &|res| matches!(res, Res::Def(DefKind::Variant, _));

// Make the base error.
let expected = source.descr_expected();
let mut expected = source.descr_expected();
let path_str = Segment::names_to_string(path);
let item_str = path.last().unwrap().ident;
let (base_msg, fallback_label, base_span, could_be_expr) = if let Some(res) = res {
Expand Down Expand Up @@ -166,6 +167,15 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
let (mod_prefix, mod_str) = if path.len() == 1 {
(String::new(), "this scope".to_string())
} else if path.len() == 2 && path[0].ident.name == kw::PathRoot {
if self.r.session.edition() > Edition::Edition2015 {
// In edition 2018 onwards, the `::foo` syntax may only pull from the extern prelude
// which overrides all other expectations of item type
expected = "crate";
(String::new(), "the list of imported crates".to_string())
} else {
(String::new(), "the crate root".to_string())
}
} else if path.len() == 2 && path[0].ident.name == kw::Crate {
(String::new(), "the crate root".to_string())
} else {
let mod_path = &path[..path.len() - 1];
Expand Down
18 changes: 13 additions & 5 deletions compiler/rustc_resolve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2433,8 +2433,10 @@ impl<'a> Resolver<'a> {
Applicability::MaybeIncorrect,
)),
)
} else {
} else if self.session.edition() == Edition::Edition2015 {
(format!("maybe a missing crate `{}`?", ident), None)
} else {
(format!("could not find `{}` in the crate root", ident), None)
}
} else if i == 0 {
if ident
Expand All @@ -2450,10 +2452,16 @@ impl<'a> Resolver<'a> {
}
} else {
let parent = path[i - 1].ident.name;
let parent = if parent == kw::PathRoot {
"crate root".to_owned()
} else {
format!("`{}`", parent)
let parent = match parent {
// ::foo is mounted at the crate root for 2015, and is the extern
// prelude for 2018+
kw::PathRoot if self.session.edition() > Edition::Edition2015 => {
"the list of imported crates".to_owned()
}
kw::PathRoot | kw::Crate => "the crate root".to_owned(),
_ => {
format!("`{}`", parent)
}
};

let mut msg = format!("could not find `{}` in {}", ident, parent);
Expand Down
33 changes: 33 additions & 0 deletions library/alloc/src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2352,6 +2352,16 @@ impl<'a> From<Cow<'a, str>> for String {

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> From<&'a str> for Cow<'a, str> {
/// Converts a string slice into a Borrowed variant.
/// No heap allocation is performed, and the string
/// is not copied.
///
/// # Example
///
/// ```
/// # use std::borrow::Cow;
/// assert_eq!(Cow::from("eggplant"), Cow::Borrowed("eggplant"));
/// ```
#[inline]
fn from(s: &'a str) -> Cow<'a, str> {
Cow::Borrowed(s)
Expand All @@ -2360,6 +2370,18 @@ impl<'a> From<&'a str> for Cow<'a, str> {

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> From<String> for Cow<'a, str> {
/// Converts a String into an Owned variant.
/// No heap allocation is performed, and the string
/// is not copied.
///
/// # Example
///
/// ```
/// # use std::borrow::Cow;
/// let s = "eggplant".to_string();
/// let s2 = "eggplant".to_string();
/// assert_eq!(Cow::from(s), Cow::<'static, str>::Owned(s2));
/// ```
#[inline]
fn from(s: String) -> Cow<'a, str> {
Cow::Owned(s)
Expand All @@ -2368,6 +2390,17 @@ impl<'a> From<String> for Cow<'a, str> {

#[stable(feature = "cow_from_string_ref", since = "1.28.0")]
impl<'a> From<&'a String> for Cow<'a, str> {
/// Converts a String reference into a Borrowed variant.
/// No heap allocation is performed, and the string
/// is not copied.
///
/// # Example
///
/// ```
/// # use std::borrow::Cow;
/// let s = "eggplant".to_string();
/// assert_eq!(Cow::from(&s), Cow::Borrowed("eggplant"));
/// ```
#[inline]
fn from(s: &'a String) -> Cow<'a, str> {
Cow::Borrowed(s.as_str())
Expand Down
6 changes: 3 additions & 3 deletions library/core/src/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub fn from_mut<T>(s: &mut T) -> &mut [T; 1] {
/// without causing much metadata bloat.
///
/// The trait is marked unsafe in order to restrict implementors to fixed-size
/// arrays. User of this trait can assume that implementors have the exact
/// arrays. A user of this trait can assume that implementors have the exact
/// layout in memory of a fixed size array (for example, for unsafe
/// initialization).
///
Expand Down Expand Up @@ -489,7 +489,7 @@ impl<T, const N: usize> [T; N] {
/// ```
///
/// This method is particularly useful if combined with other methods, like
/// [`map`](#method.map). This way, you can can avoid moving the original
/// [`map`](#method.map). This way, you can avoid moving the original
/// array if its elements are not `Copy`.
///
/// ```
Expand Down Expand Up @@ -564,7 +564,7 @@ where
/// yields fewer than `N` items, `None` is returned and all already yielded
/// items are dropped.
///
/// Since the iterator is passed as mutable reference and this function calls
/// Since the iterator is passed as a mutable reference and this function calls
/// `next` at most `N` times, the iterator can still be used afterwards to
/// retrieve the remaining items.
///
Expand Down
6 changes: 5 additions & 1 deletion library/std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,11 @@ pub use alloc_crate::vec;
#[stable(feature = "rust1", since = "1.0.0")]
pub use core::any;
#[stable(feature = "simd_arch", since = "1.27.0")]
#[doc(no_inline)]
// The `no_inline`-attribute is required to make the documentation of all
// targets available.
// See https://github.com/rust-lang/rust/pull/57808#issuecomment-457390549 for
// more information.
#[doc(no_inline)] // Note (#82861): required for correct documentation
pub use core::arch;
#[stable(feature = "core_array", since = "1.36.0")]
pub use core::array;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ $ cargo profdata -- --help # note the additional "--" preceding the tool-specif

## Creating coverage reports

Raw profiles have to be indexed before they can be used to generate coverage reports. This is done using [`llvm-profdata merge`] (or `cargo cov -- merge`), which can combine multiple raw profiles and index them at the same time:
Raw profiles have to be indexed before they can be used to generate coverage reports. This is done using [`llvm-profdata merge`] (or `cargo profdata -- merge`), which can combine multiple raw profiles and index them at the same time:

```shell
$ llvm-profdata merge -sparse formatjson5.profraw -o formatjson5.profdata
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ path = "lib.rs"
[dependencies]
arrayvec = { version = "0.5.1", default-features = false }
pulldown-cmark = { version = "0.8", default-features = false }
minifier = "0.0.33"
minifier = "0.0.39"
rayon = { version = "0.3.0", package = "rustc-rayon" }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
Expand Down
Loading