Skip to content

Rollup of 7 pull requests #89984

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 15 commits into from
Oct 17, 2021
Merged
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions compiler/rustc_ast/src/util/parser.rs
Original file line number Diff line number Diff line change
@@ -357,13 +357,13 @@ impl ExprPrecedence {
}
}

/// In `let p = e`, operators with precedence `<=` this one requires parenthesis in `e`.
/// In `let p = e`, operators with precedence `<=` this one requires parentheses in `e`.
pub fn prec_let_scrutinee_needs_par() -> usize {
AssocOp::LAnd.precedence()
}

/// Suppose we have `let _ = e` and the `order` of `e`.
/// Is the `order` such that `e` in `let _ = e` needs parenthesis when it is on the RHS?
/// Is the `order` such that `e` in `let _ = e` needs parentheses when it is on the RHS?
///
/// Conversely, suppose that we have `(let _ = a) OP b` and `order` is that of `OP`.
/// Can we print this as `let _ = a OP b`?
2 changes: 1 addition & 1 deletion compiler/rustc_ast_passes/src/ast_validation.rs
Original file line number Diff line number Diff line change
@@ -113,7 +113,7 @@ impl<'a> AstValidator<'a> {
if sess.opts.unstable_features.is_nightly_build() {
sess.struct_span_err(expr.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("as well as when nested within `&&` and parentheses in those conditions")
.emit();
} else {
sess.struct_span_err(expr.span, "expected expression, found statement (`let`)")
2 changes: 1 addition & 1 deletion compiler/rustc_ast_pretty/src/pprust/state.rs
Original file line number Diff line number Diff line change
@@ -1675,7 +1675,7 @@ impl<'a> State<'a> {
self.print_expr_cond_paren(expr, Self::cond_needs_par(expr))
}

// Does `expr` need parenthesis when printed in a condition position?
// Does `expr` need parentheses when printed in a condition position?
//
// These cases need parens due to the parse error observed in #26461: `if return {}`
// parses as the erroneous construct `if (return {})`, not `if (return) {}`.
2 changes: 1 addition & 1 deletion compiler/rustc_hir_pretty/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1168,7 +1168,7 @@ impl<'a> State<'a> {
self.print_expr_cond_paren(expr, Self::cond_needs_par(expr) || npals())
}

// Does `expr` need parenthesis when printed in a condition position?
// Does `expr` need parentheses when printed in a condition position?
//
// These cases need parens due to the parse error observed in #26461: `if return {}`
// parses as the erroneous construct `if (return {})`, not `if (return) {}`.
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/unused.rs
Original file line number Diff line number Diff line change
@@ -670,7 +670,7 @@ declare_lint! {
///
/// ### Explanation
///
/// The parenthesis are not needed, and should be removed. This is the
/// The parentheses are not needed, and should be removed. This is the
/// preferred style for writing these expressions.
pub(super) UNUSED_PARENS,
Warn,
15 changes: 10 additions & 5 deletions compiler/rustc_middle/src/ty/error.rs
Original file line number Diff line number Diff line change
@@ -769,11 +769,16 @@ fn foo(&self) -> Self::T { String::new() }
) -> bool {
let assoc = self.associated_item(proj_ty.item_def_id);
if let ty::Opaque(def_id, _) = *proj_ty.self_ty().kind() {
let opaque_local_def_id = def_id.expect_local();
let opaque_hir_id = self.hir().local_def_id_to_hir_id(opaque_local_def_id);
let opaque_hir_ty = match &self.hir().expect_item(opaque_hir_id).kind {
hir::ItemKind::OpaqueTy(opaque_hir_ty) => opaque_hir_ty,
_ => bug!("The HirId comes from a `ty::Opaque`"),
let opaque_local_def_id = def_id.as_local();
let opaque_hir_ty = if let Some(opaque_local_def_id) = opaque_local_def_id {
let hir = self.hir();
let opaque_hir_id = hir.local_def_id_to_hir_id(opaque_local_def_id);
match &hir.expect_item(opaque_hir_id).kind {
hir::ItemKind::OpaqueTy(opaque_hir_ty) => opaque_hir_ty,
_ => bug!("The HirId comes from a `ty::Opaque`"),
}
} else {
return false;
};

let (trait_ref, assoc_substs) = proj_ty.trait_ref_and_own_substs(self);
28 changes: 18 additions & 10 deletions compiler/rustc_middle/src/ty/print/pretty.rs
Original file line number Diff line number Diff line change
@@ -350,18 +350,26 @@ pub trait PrettyPrinter<'tcx>:
match self.tcx().extern_crate(def_id) {
Some(&ExternCrate { src, dependency_of, span, .. }) => match (src, dependency_of) {
(ExternCrateSource::Extern(def_id), LOCAL_CRATE) => {
debug!("try_print_visible_def_path: def_id={:?}", def_id);
return Ok((
if !span.is_dummy() {
self.print_def_path(def_id, &[])?
} else {
self.path_crate(cnum)?
},
true,
));
// NOTE(eddyb) the only reason `span` might be dummy,
// that we're aware of, is that it's the `std`/`core`
// `extern crate` injected by default.
// FIXME(eddyb) find something better to key this on,
// or avoid ending up with `ExternCrateSource::Extern`,
// for the injected `std`/`core`.
if span.is_dummy() {
return Ok((self.path_crate(cnum)?, true));
}

// Disable `try_print_trimmed_def_path` behavior within
// the `print_def_path` call, to avoid infinite recursion
// in cases where the `extern crate foo` has non-trivial
// parents, e.g. it's nested in `impl foo::Trait for Bar`
// (see also issues #55779 and #87932).
self = with_no_visible_paths(|| self.print_def_path(def_id, &[]))?;

return Ok((self, true));
}
(ExternCrateSource::Path, LOCAL_CRATE) => {
debug!("try_print_visible_def_path: def_id={:?}", def_id);
return Ok((self.path_crate(cnum)?, true));
}
_ => {}
4 changes: 2 additions & 2 deletions compiler/rustc_parse/src/parser/diagnostics.rs
Original file line number Diff line number Diff line change
@@ -1342,10 +1342,10 @@ impl<'a> Parser<'a> {

self.struct_span_err(
MultiSpan::from_spans(vec![begin_par_sp, self.prev_token.span]),
"unexpected parenthesis surrounding `for` loop head",
"unexpected parentheses surrounding `for` loop head",
)
.multipart_suggestion(
"remove parenthesis in `for` loop",
"remove parentheses in `for` loop",
vec![(begin_par_sp, String::new()), (self.prev_token.span, String::new())],
// With e.g. `for (x) in y)` this would replace `(x) in y)`
// with `x) in y)` which is syntactically invalid.
2 changes: 1 addition & 1 deletion compiler/rustc_parse/src/parser/mod.rs
Original file line number Diff line number Diff line change
@@ -1258,7 +1258,7 @@ impl<'a> Parser<'a> {
/// Parses `pub`, `pub(crate)` and `pub(in path)` plus shortcuts `crate` for `pub(crate)`,
/// `pub(self)` for `pub(in self)` and `pub(super)` for `pub(in super)`.
/// If the following element can't be a tuple (i.e., it's a function definition), then
/// it's not a tuple struct field), and the contents within the parentheses isn't valid,
/// it's not a tuple struct field), and the contents within the parentheses aren't valid,
/// so emit a proper diagnostic.
// Public for rustfmt usage.
pub fn parse_visibility(&mut self, fbt: FollowedByType) -> PResult<'a, Visibility> {
4 changes: 2 additions & 2 deletions compiler/rustc_parse/src/parser/stmt.rs
Original file line number Diff line number Diff line change
@@ -328,7 +328,7 @@ impl<'a> Parser<'a> {
),
)
.multipart_suggestion(
"wrap the expression in parenthesis",
"wrap the expression in parentheses",
suggs,
Applicability::MachineApplicable,
)
@@ -349,7 +349,7 @@ impl<'a> Parser<'a> {
"right curly brace `}` before `else` in a `let...else` statement not allowed",
)
.multipart_suggestion(
"try wrapping the expression in parenthesis",
"try wrapping the expression in parentheses",
suggs,
Applicability::MachineApplicable,
)
2 changes: 1 addition & 1 deletion compiler/rustc_parse/src/parser/ty.rs
Original file line number Diff line number Diff line change
@@ -430,7 +430,7 @@ impl<'a> Parser<'a> {
}

// Parses the `typeof(EXPR)`.
// To avoid ambiguity, the type is surrounded by parenthesis.
// To avoid ambiguity, the type is surrounded by parentheses.
fn parse_typeof_ty(&mut self) -> PResult<'a, TyKind> {
self.expect(&token::OpenDelim(token::Paren))?;
let expr = self.parse_anon_const_expr()?;
2 changes: 1 addition & 1 deletion compiler/rustc_resolve/src/late/diagnostics.rs
Original file line number Diff line number Diff line change
@@ -1552,7 +1552,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
matches!(source, PathSource::TupleStruct(..)) || source.is_call();
if suggest_only_tuple_variants {
// Suggest only tuple variants regardless of whether they have fields and do not
// suggest path with added parenthesis.
// suggest path with added parentheses.
let mut suggestable_variants = variants
.iter()
.filter(|(.., kind)| *kind == CtorKind::Fn)
4 changes: 2 additions & 2 deletions compiler/rustc_typeck/src/check/callee.rs
Original file line number Diff line number Diff line change
@@ -300,7 +300,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let end = callee_span.shrink_to_hi();
err.multipart_suggestion(
"if you meant to create this closure and immediately call it, surround the \
closure with parenthesis",
closure with parentheses",
vec![(start, "(".to_string()), (end, ")".to_string())],
Applicability::MaybeIncorrect,
);
@@ -383,7 +383,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
call_expr.span,
&format!(
"`{}` is a unit variant, you need to write it \
without the parenthesis",
without the parentheses",
path
),
path.to_string(),
2 changes: 1 addition & 1 deletion compiler/rustc_typeck/src/check/op.rs
Original file line number Diff line number Diff line change
@@ -492,7 +492,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
other_ty: Ty<'tcx>,
op: hir::BinOp,
is_assign: IsAssign,
) -> bool /* did we suggest to call a function because of missing parenthesis? */ {
) -> bool /* did we suggest to call a function because of missing parentheses? */ {
err.span_label(span, ty.to_string());
if let FnDef(def_id, _) = *ty.kind() {
let source_map = self.tcx.sess.source_map();
3 changes: 2 additions & 1 deletion library/core/src/result.rs
Original file line number Diff line number Diff line change
@@ -729,7 +729,8 @@ impl<T, E> Result<T, E> {
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn as_mut(&mut self) -> Result<&mut T, &mut E> {
#[rustc_const_unstable(feature = "const_result", issue = "82814")]
pub const fn as_mut(&mut self) -> Result<&mut T, &mut E> {
match *self {
Ok(ref mut x) => Ok(x),
Err(ref mut x) => Err(x),
3 changes: 0 additions & 3 deletions library/core/src/slice/mod.rs
Original file line number Diff line number Diff line change
@@ -2953,9 +2953,6 @@ impl<T> [T] {
///
/// The length of `src` must be the same as `self`.
///
/// If `T` implements `Copy`, it can be more performant to use
/// [`copy_from_slice`].
///
/// # Panics
///
/// This function will panic if the two slices have different lengths.
1 change: 1 addition & 0 deletions library/core/tests/lib.rs
Original file line number Diff line number Diff line change
@@ -65,6 +65,7 @@
#![feature(once_cell)]
#![feature(unsized_tuple_coercion)]
#![feature(const_option)]
#![feature(const_result)]
#![feature(integer_atomics)]
#![feature(int_roundings)]
#![feature(slice_group_by)]
23 changes: 23 additions & 0 deletions library/core/tests/result.rs
Original file line number Diff line number Diff line change
@@ -352,6 +352,29 @@ fn result_const() {
assert!(!IS_ERR)
}

#[test]
const fn result_const_mut() {
let mut result: Result<usize, bool> = Ok(32);

{
let as_mut = result.as_mut();
match as_mut {
Ok(v) => *v = 42,
Err(_) => unreachable!(),
}
}

let mut result_err: Result<usize, bool> = Err(false);

{
let as_mut = result_err.as_mut();
match as_mut {
Ok(_) => unreachable!(),
Err(v) => *v = true,
}
}
}

#[test]
fn result_opt_conversions() {
#[derive(Copy, Clone, Debug, PartialEq)]
25 changes: 23 additions & 2 deletions src/bootstrap/bootstrap.py
Original file line number Diff line number Diff line change
@@ -492,10 +492,11 @@ def download_toolchain(self, stage0=True, rustc_channel=None):

def downloading_llvm(self):
opt = self.get_toml('download-ci-llvm', 'llvm')
# This is currently all tier 1 targets (since others may not have CI
# artifacts)
# This is currently all tier 1 targets and tier 2 targets with host tools
# (since others may not have CI artifacts)
# https://doc.rust-lang.org/rustc/platform-support.html#tier-1
supported_platforms = [
# tier 1
"aarch64-unknown-linux-gnu",
"i686-pc-windows-gnu",
"i686-pc-windows-msvc",
@@ -504,6 +505,26 @@ def downloading_llvm(self):
"x86_64-apple-darwin",
"x86_64-pc-windows-gnu",
"x86_64-pc-windows-msvc",
# tier 2 with host tools
"aarch64-apple-darwin",
"aarch64-pc-windows-msvc",
"aarch64-unknown-linux-musl",
"arm-unknown-linux-gnueabi",
"arm-unknown-linux-gnueabihf",
"armv7-unknown-linux-gnueabihf",
"mips-unknown-linux-gnu",
"mips64-unknown-linux-gnuabi64",
"mips64el-unknown-linux-gnuabi64",
"mipsel-unknown-linux-gnu",
"powerpc-unknown-linux-gnu",
"powerpc64-unknown-linux-gnu",
"powerpc64le-unknown-linux-gnu",
"riscv64gc-unknown-linux-gnu",
"s390x-unknown-linux-gnu",
"x86_64-unknown-freebsd",
"x86_64-unknown-illumos",
"x86_64-unknown-linux-musl",
"x86_64-unknown-netbsd",
]
return opt == "true" \
or (opt == "if-available" and self.build in supported_platforms)
24 changes: 23 additions & 1 deletion src/bootstrap/config.rs
Original file line number Diff line number Diff line change
@@ -765,10 +765,12 @@ impl Config {
config.llvm_from_ci = match llvm.download_ci_llvm {
Some(StringOrBool::String(s)) => {
assert!(s == "if-available", "unknown option `{}` for download-ci-llvm", s);
// This is currently all tier 1 targets (since others may not have CI artifacts)
// This is currently all tier 1 targets and tier 2 targets with host tools
// (since others may not have CI artifacts)
// https://doc.rust-lang.org/rustc/platform-support.html#tier-1
// FIXME: this is duplicated in bootstrap.py
let supported_platforms = [
// tier 1
"aarch64-unknown-linux-gnu",
"i686-pc-windows-gnu",
"i686-pc-windows-msvc",
@@ -777,6 +779,26 @@ impl Config {
"x86_64-apple-darwin",
"x86_64-pc-windows-gnu",
"x86_64-pc-windows-msvc",
// tier 2 with host tools
"aarch64-apple-darwin",
"aarch64-pc-windows-msvc",
"aarch64-unknown-linux-musl",
"arm-unknown-linux-gnueabi",
"arm-unknown-linux-gnueabihf",
"armv7-unknown-linux-gnueabihf",
"mips-unknown-linux-gnu",
"mips64-unknown-linux-gnuabi64",
"mips64el-unknown-linux-gnuabi64",
"mipsel-unknown-linux-gnu",
"powerpc-unknown-linux-gnu",
"powerpc64-unknown-linux-gnu",
"powerpc64le-unknown-linux-gnu",
"riscv64gc-unknown-linux-gnu",
"s390x-unknown-linux-gnu",
"x86_64-unknown-freebsd",
"x86_64-unknown-illumos",
"x86_64-unknown-linux-musl",
"x86_64-unknown-netbsd",
];
supported_platforms.contains(&&*config.build.triple)
}
2 changes: 1 addition & 1 deletion src/librustdoc/clean/auto_trait.rs
Original file line number Diff line number Diff line change
@@ -576,7 +576,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
rhs,
});
continue; // If something other than a Fn ends up
// with parenthesis, leave it alone
// with parentheses, leave it alone
}
}

4 changes: 2 additions & 2 deletions src/test/ui/empty/empty-struct-unit-expr.stderr
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ LL | let e4 = E::Empty4();
| |
| call expression requires function
|
help: `E::Empty4` is a unit variant, you need to write it without the parenthesis
help: `E::Empty4` is a unit variant, you need to write it without the parentheses
|
LL | let e4 = E::Empty4;
| ~~~~~~~~~
@@ -41,7 +41,7 @@ LL | let xe4 = XE::XEmpty4();
| |
| call expression requires function
|
help: `XE::XEmpty4` is a unit variant, you need to write it without the parenthesis
help: `XE::XEmpty4` is a unit variant, you need to write it without the parentheses
|
LL | let xe4 = XE::XEmpty4;
| ~~~~~~~~~~~
2 changes: 1 addition & 1 deletion src/test/ui/error-codes/E0618.stderr
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ LL | X::Entry();
| |
| call expression requires function
|
help: `X::Entry` is a unit variant, you need to write it without the parenthesis
help: `X::Entry` is a unit variant, you need to write it without the parentheses
|
LL | X::Entry;
| ~~~~~~~~
19 changes: 19 additions & 0 deletions src/test/ui/generic-associated-types/issue-85921.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// check-pass

#![feature(generic_associated_types)]

trait Trait {
type Assoc<'a>;

fn with_assoc(f: impl FnOnce(Self::Assoc<'_>));
}

impl Trait for () {
type Assoc<'a> = i32;

fn with_assoc(f: impl FnOnce(Self::Assoc<'_>)) {
f(5i32)
}
}

fn main() {}
Loading