Skip to content

Commit 1f12ac8

Browse files
committed
Auto merge of #89984 - matthiaskrgr:rollup-ikmyhmx, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - #89738 (ty::pretty: prevent infinite recursion for `extern crate` paths.) - #89888 (Make `llvm.download-ci-llvm="if-available"` work for tier 2 targets with host tools) - #89945 (Remove a mention to `copy_from_slice` from `clone_from_slice` doc) - #89946 (Fix an ICE with TAITs and Future) - #89963 (Some "parenthesis" and "parentheses" fixes) - #89975 (Add a regression test for #85921) - #89977 (Make Result::as_mut const) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 8db8f48 + f044a84 commit 1f12ac8

File tree

46 files changed

+343
-122
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+343
-122
lines changed

compiler/rustc_ast/src/util/parser.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,13 +357,13 @@ impl ExprPrecedence {
357357
}
358358
}
359359

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

365365
/// Suppose we have `let _ = e` and the `order` of `e`.
366-
/// Is the `order` such that `e` in `let _ = e` needs parenthesis when it is on the RHS?
366+
/// Is the `order` such that `e` in `let _ = e` needs parentheses when it is on the RHS?
367367
///
368368
/// Conversely, suppose that we have `(let _ = a) OP b` and `order` is that of `OP`.
369369
/// Can we print this as `let _ = a OP b`?

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ impl<'a> AstValidator<'a> {
113113
if sess.opts.unstable_features.is_nightly_build() {
114114
sess.struct_span_err(expr.span, "`let` expressions are not supported here")
115115
.note("only supported directly in conditions of `if`- and `while`-expressions")
116-
.note("as well as when nested within `&&` and parenthesis in those conditions")
116+
.note("as well as when nested within `&&` and parentheses in those conditions")
117117
.emit();
118118
} else {
119119
sess.struct_span_err(expr.span, "expected expression, found statement (`let`)")

compiler/rustc_ast_pretty/src/pprust/state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1675,7 +1675,7 @@ impl<'a> State<'a> {
16751675
self.print_expr_cond_paren(expr, Self::cond_needs_par(expr))
16761676
}
16771677

1678-
// Does `expr` need parenthesis when printed in a condition position?
1678+
// Does `expr` need parentheses when printed in a condition position?
16791679
//
16801680
// These cases need parens due to the parse error observed in #26461: `if return {}`
16811681
// parses as the erroneous construct `if (return {})`, not `if (return) {}`.

compiler/rustc_hir_pretty/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1168,7 +1168,7 @@ impl<'a> State<'a> {
11681168
self.print_expr_cond_paren(expr, Self::cond_needs_par(expr) || npals())
11691169
}
11701170

1171-
// Does `expr` need parenthesis when printed in a condition position?
1171+
// Does `expr` need parentheses when printed in a condition position?
11721172
//
11731173
// These cases need parens due to the parse error observed in #26461: `if return {}`
11741174
// parses as the erroneous construct `if (return {})`, not `if (return) {}`.

compiler/rustc_lint/src/unused.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ declare_lint! {
670670
///
671671
/// ### Explanation
672672
///
673-
/// The parenthesis are not needed, and should be removed. This is the
673+
/// The parentheses are not needed, and should be removed. This is the
674674
/// preferred style for writing these expressions.
675675
pub(super) UNUSED_PARENS,
676676
Warn,

compiler/rustc_middle/src/ty/error.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -769,11 +769,16 @@ fn foo(&self) -> Self::T { String::new() }
769769
) -> bool {
770770
let assoc = self.associated_item(proj_ty.item_def_id);
771771
if let ty::Opaque(def_id, _) = *proj_ty.self_ty().kind() {
772-
let opaque_local_def_id = def_id.expect_local();
773-
let opaque_hir_id = self.hir().local_def_id_to_hir_id(opaque_local_def_id);
774-
let opaque_hir_ty = match &self.hir().expect_item(opaque_hir_id).kind {
775-
hir::ItemKind::OpaqueTy(opaque_hir_ty) => opaque_hir_ty,
776-
_ => bug!("The HirId comes from a `ty::Opaque`"),
772+
let opaque_local_def_id = def_id.as_local();
773+
let opaque_hir_ty = if let Some(opaque_local_def_id) = opaque_local_def_id {
774+
let hir = self.hir();
775+
let opaque_hir_id = hir.local_def_id_to_hir_id(opaque_local_def_id);
776+
match &hir.expect_item(opaque_hir_id).kind {
777+
hir::ItemKind::OpaqueTy(opaque_hir_ty) => opaque_hir_ty,
778+
_ => bug!("The HirId comes from a `ty::Opaque`"),
779+
}
780+
} else {
781+
return false;
777782
};
778783

779784
let (trait_ref, assoc_substs) = proj_ty.trait_ref_and_own_substs(self);

compiler/rustc_middle/src/ty/print/pretty.rs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -350,18 +350,26 @@ pub trait PrettyPrinter<'tcx>:
350350
match self.tcx().extern_crate(def_id) {
351351
Some(&ExternCrate { src, dependency_of, span, .. }) => match (src, dependency_of) {
352352
(ExternCrateSource::Extern(def_id), LOCAL_CRATE) => {
353-
debug!("try_print_visible_def_path: def_id={:?}", def_id);
354-
return Ok((
355-
if !span.is_dummy() {
356-
self.print_def_path(def_id, &[])?
357-
} else {
358-
self.path_crate(cnum)?
359-
},
360-
true,
361-
));
353+
// NOTE(eddyb) the only reason `span` might be dummy,
354+
// that we're aware of, is that it's the `std`/`core`
355+
// `extern crate` injected by default.
356+
// FIXME(eddyb) find something better to key this on,
357+
// or avoid ending up with `ExternCrateSource::Extern`,
358+
// for the injected `std`/`core`.
359+
if span.is_dummy() {
360+
return Ok((self.path_crate(cnum)?, true));
361+
}
362+
363+
// Disable `try_print_trimmed_def_path` behavior within
364+
// the `print_def_path` call, to avoid infinite recursion
365+
// in cases where the `extern crate foo` has non-trivial
366+
// parents, e.g. it's nested in `impl foo::Trait for Bar`
367+
// (see also issues #55779 and #87932).
368+
self = with_no_visible_paths(|| self.print_def_path(def_id, &[]))?;
369+
370+
return Ok((self, true));
362371
}
363372
(ExternCrateSource::Path, LOCAL_CRATE) => {
364-
debug!("try_print_visible_def_path: def_id={:?}", def_id);
365373
return Ok((self.path_crate(cnum)?, true));
366374
}
367375
_ => {}

compiler/rustc_parse/src/parser/diagnostics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,10 +1342,10 @@ impl<'a> Parser<'a> {
13421342

13431343
self.struct_span_err(
13441344
MultiSpan::from_spans(vec![begin_par_sp, self.prev_token.span]),
1345-
"unexpected parenthesis surrounding `for` loop head",
1345+
"unexpected parentheses surrounding `for` loop head",
13461346
)
13471347
.multipart_suggestion(
1348-
"remove parenthesis in `for` loop",
1348+
"remove parentheses in `for` loop",
13491349
vec![(begin_par_sp, String::new()), (self.prev_token.span, String::new())],
13501350
// With e.g. `for (x) in y)` this would replace `(x) in y)`
13511351
// with `x) in y)` which is syntactically invalid.

compiler/rustc_parse/src/parser/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1258,7 +1258,7 @@ impl<'a> Parser<'a> {
12581258
/// Parses `pub`, `pub(crate)` and `pub(in path)` plus shortcuts `crate` for `pub(crate)`,
12591259
/// `pub(self)` for `pub(in self)` and `pub(super)` for `pub(in super)`.
12601260
/// If the following element can't be a tuple (i.e., it's a function definition), then
1261-
/// it's not a tuple struct field), and the contents within the parentheses isn't valid,
1261+
/// it's not a tuple struct field), and the contents within the parentheses aren't valid,
12621262
/// so emit a proper diagnostic.
12631263
// Public for rustfmt usage.
12641264
pub fn parse_visibility(&mut self, fbt: FollowedByType) -> PResult<'a, Visibility> {

compiler/rustc_parse/src/parser/stmt.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ impl<'a> Parser<'a> {
328328
),
329329
)
330330
.multipart_suggestion(
331-
"wrap the expression in parenthesis",
331+
"wrap the expression in parentheses",
332332
suggs,
333333
Applicability::MachineApplicable,
334334
)
@@ -349,7 +349,7 @@ impl<'a> Parser<'a> {
349349
"right curly brace `}` before `else` in a `let...else` statement not allowed",
350350
)
351351
.multipart_suggestion(
352-
"try wrapping the expression in parenthesis",
352+
"try wrapping the expression in parentheses",
353353
suggs,
354354
Applicability::MachineApplicable,
355355
)

0 commit comments

Comments
 (0)