Skip to content

Commit 76d18cf

Browse files
committed
Auto merge of rust-lang#88527 - m-ou-se:rollup-az6xtc5, r=m-ou-se
Rollup of 14 pull requests Successful merges: - rust-lang#88394 (Document `std::env::current_exe` possible rename behaviour) - rust-lang#88406 (Tait nest infer test) - rust-lang#88408 (Add inference cycle TAIT test) - rust-lang#88409 (Add auto trait leakage TAIT test) - rust-lang#88413 (Add weird return types TAIT test) - rust-lang#88450 (fix(rustc_parse): correct span in `maybe_whole_expr!`) - rust-lang#88462 (rustdoc: Stop using resolver for macro loading) - rust-lang#88465 (Adding examples to docs of `std::time` module) - rust-lang#88486 (Remove unused arena macro args) - rust-lang#88492 (Use MaybeUninit::write in functor.rs) - rust-lang#88496 (Fix prelude collision lint suggestion for generics with lifetimes) - rust-lang#88497 (Fix prelude collision suggestions for glob imported traits. ) - rust-lang#88503 (Warn when [T; N].into_iter() is ambiguous in the new edition. ) - rust-lang#88509 (Don't suggest extra <> in dyn suggestion.) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents fe37929 + feafda8 commit 76d18cf

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

+698
-89
lines changed

Diff for: Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -4405,6 +4405,7 @@ dependencies = [
44054405
"rustc_hir_pretty",
44064406
"rustc_index",
44074407
"rustc_infer",
4408+
"rustc_lint",
44084409
"rustc_macros",
44094410
"rustc_middle",
44104411
"rustc_session",

Diff for: compiler/rustc_arena/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ pub macro which_arena_for_type {
635635
}
636636

637637
#[rustc_macro_transparency = "semitransparent"]
638-
pub macro declare_arena([], [$($a:tt $name:ident: $ty:ty,)*], $tcx:lifetime) {
638+
pub macro declare_arena([$($a:tt $name:ident: $ty:ty,)*], $tcx:lifetime) {
639639
#[derive(Default)]
640640
pub struct Arena<$tcx> {
641641
pub dropless: $crate::DroplessArena,

Diff for: compiler/rustc_ast_lowering/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ mod path;
8484

8585
const HIR_ID_COUNTER_LOCKED: u32 = 0xFFFFFFFF;
8686

87-
rustc_hir::arena_types!(rustc_arena::declare_arena, [], 'tcx);
87+
rustc_hir::arena_types!(rustc_arena::declare_arena, 'tcx);
8888

8989
struct LoweringContext<'a, 'hir: 'a> {
9090
/// Used to assign IDs to HIR nodes that do not directly correspond to AST nodes.

Diff for: compiler/rustc_data_structures/src/functor.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ impl<T> IdFunctor for Box<T> {
2626
// inverse of `Box::assume_init()` and should be safe.
2727
let mut raw: Box<mem::MaybeUninit<T>> = Box::from_raw(raw.cast());
2828
// SAFETY: Write the mapped value back into the `Box`.
29-
ptr::write(raw.as_mut_ptr(), f(value));
29+
raw.write(f(value));
3030
// SAFETY: We just initialized `raw`.
3131
raw.assume_init()
3232
}

Diff for: compiler/rustc_hir/src/arena.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
/// where `T` is the type listed. These impls will appear in the implement_ty_decoder! macro.
1010
#[macro_export]
1111
macro_rules! arena_types {
12-
($macro:path, $args:tt, $tcx:lifetime) => (
13-
$macro!($args, [
12+
($macro:path, $tcx:lifetime) => (
13+
$macro!([
1414
// HIR types
1515
[few] hir_krate: rustc_hir::Crate<$tcx>,
1616
[] arm: rustc_hir::Arm<$tcx>,

Diff for: compiler/rustc_lint/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ mod traits;
6262
mod types;
6363
mod unused;
6464

65+
pub use array_into_iter::ARRAY_INTO_ITER;
66+
6567
use rustc_ast as ast;
6668
use rustc_hir as hir;
6769
use rustc_hir::def_id::LocalDefId;

Diff for: compiler/rustc_middle/src/arena.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
/// listed. These impls will appear in the implement_ty_decoder! macro.
1010
#[macro_export]
1111
macro_rules! arena_types {
12-
($macro:path, $args:tt, $tcx:lifetime) => (
13-
$macro!($args, [
12+
($macro:path, $tcx:lifetime) => (
13+
$macro!([
1414
[] layouts: rustc_target::abi::Layout,
1515
// AdtDef are interned and compared by address
1616
[] adt_def: rustc_middle::ty::AdtDef,
@@ -109,4 +109,4 @@ macro_rules! arena_types {
109109
)
110110
}
111111

112-
arena_types!(rustc_arena::declare_arena, [], 'tcx);
112+
arena_types!(rustc_arena::declare_arena, 'tcx);

Diff for: compiler/rustc_middle/src/ty/codec.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -437,15 +437,15 @@ macro_rules! impl_arena_allocatable_decoder {
437437
}
438438

439439
macro_rules! impl_arena_allocatable_decoders {
440-
([], [$($a:tt $name:ident: $ty:ty,)*], $tcx:lifetime) => {
440+
([$($a:tt $name:ident: $ty:ty,)*], $tcx:lifetime) => {
441441
$(
442442
impl_arena_allocatable_decoder!($a [[$name: $ty], $tcx]);
443443
)*
444444
}
445445
}
446446

447-
rustc_hir::arena_types!(impl_arena_allocatable_decoders, [], 'tcx);
448-
arena_types!(impl_arena_allocatable_decoders, [], 'tcx);
447+
rustc_hir::arena_types!(impl_arena_allocatable_decoders, 'tcx);
448+
arena_types!(impl_arena_allocatable_decoders, 'tcx);
449449

450450
#[macro_export]
451451
macro_rules! implement_ty_decoder {

Diff for: compiler/rustc_parse/src/parser/expr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ macro_rules! maybe_whole_expr {
4141
let path = path.clone();
4242
$p.bump();
4343
return Ok($p.mk_expr(
44-
$p.token.span,
44+
$p.prev_token.span,
4545
ExprKind::Path(None, path),
4646
AttrVec::new(),
4747
));
@@ -50,7 +50,7 @@ macro_rules! maybe_whole_expr {
5050
let block = block.clone();
5151
$p.bump();
5252
return Ok($p.mk_expr(
53-
$p.token.span,
53+
$p.prev_token.span,
5454
ExprKind::Block(block, None),
5555
AttrVec::new(),
5656
));

Diff for: compiler/rustc_typeck/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ rustc_index = { path = "../rustc_index" }
2626
rustc_infer = { path = "../rustc_infer" }
2727
rustc_trait_selection = { path = "../rustc_trait_selection" }
2828
rustc_ty_utils = { path = "../rustc_ty_utils" }
29+
rustc_lint = { path = "../rustc_lint" }

Diff for: compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -914,7 +914,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
914914
});
915915

916916
if result.is_ok() {
917-
self.maybe_lint_bare_trait(qpath, hir_id);
917+
self.maybe_lint_bare_trait(qpath, hir_id, span);
918918
self.register_wf_obligation(ty.into(), qself.span, traits::WellFormed(None));
919919
}
920920

@@ -927,18 +927,23 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
927927
)
928928
}
929929

930-
fn maybe_lint_bare_trait(&self, qpath: &QPath<'_>, hir_id: hir::HirId) {
930+
fn maybe_lint_bare_trait(&self, qpath: &QPath<'_>, hir_id: hir::HirId, span: Span) {
931931
if let QPath::TypeRelative(self_ty, _) = qpath {
932932
if let TyKind::TraitObject([poly_trait_ref, ..], _, TraitObjectSyntax::None) =
933933
self_ty.kind
934934
{
935935
let msg = "trait objects without an explicit `dyn` are deprecated";
936936
let (sugg, app) = match self.tcx.sess.source_map().span_to_snippet(self_ty.span) {
937937
Ok(s) if poly_trait_ref.trait_ref.path.is_global() => {
938-
(format!("<dyn ({})>", s), Applicability::MachineApplicable)
938+
(format!("dyn ({})", s), Applicability::MachineApplicable)
939939
}
940-
Ok(s) => (format!("<dyn {}>", s), Applicability::MachineApplicable),
941-
Err(_) => ("<dyn <type>>".to_string(), Applicability::HasPlaceholders),
940+
Ok(s) => (format!("dyn {}", s), Applicability::MachineApplicable),
941+
Err(_) => ("dyn <type>".to_string(), Applicability::HasPlaceholders),
942+
};
943+
// Wrap in `<..>` if it isn't already.
944+
let sugg = match self.tcx.sess.source_map().span_to_snippet(span) {
945+
Ok(s) if s.starts_with('<') => sugg,
946+
_ => format!("<{}>", sugg),
942947
};
943948
let replace = String::from("use `dyn`");
944949
if self.sess().edition() >= Edition::Edition2021 {

Diff for: compiler/rustc_typeck/src/check/method/prelude2021.rs

+62-36
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ use rustc_ast::Mutability;
55
use rustc_errors::Applicability;
66
use rustc_hir as hir;
77
use rustc_middle::ty::subst::InternalSubsts;
8-
use rustc_middle::ty::{Adt, Ref, Ty};
8+
use rustc_middle::ty::{Adt, Array, Ref, Ty};
99
use rustc_session::lint::builtin::RUST_2021_PRELUDE_COLLISIONS;
10-
use rustc_span::symbol::kw::Underscore;
10+
use rustc_span::symbol::kw::{Empty, Underscore};
1111
use rustc_span::symbol::{sym, Ident};
1212
use rustc_span::Span;
1313
use rustc_trait_selection::infer::InferCtxtExt;
@@ -38,10 +38,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
3838
return;
3939
}
4040

41-
// These are the method names that were added to prelude in Rust 2021
42-
if !matches!(segment.ident.name, sym::try_into) {
43-
return;
44-
}
41+
let prelude_or_array_lint = match segment.ident.name {
42+
// `try_into` was added to the prelude in Rust 2021.
43+
sym::try_into => RUST_2021_PRELUDE_COLLISIONS,
44+
// `into_iter` wasn't added to the prelude,
45+
// but `[T; N].into_iter()` doesn't resolve to IntoIterator::into_iter
46+
// before Rust 2021, which results in the same problem.
47+
// It is only a problem for arrays.
48+
sym::into_iter if let Array(..) = self_ty.kind() => {
49+
// In this case, it wasn't really a prelude addition that was the problem.
50+
// Instead, the problem is that the array-into_iter hack will no longer apply in Rust 2021.
51+
rustc_lint::ARRAY_INTO_ITER
52+
}
53+
_ => return,
54+
};
4555

4656
// No need to lint if method came from std/core, as that will now be in the prelude
4757
if matches!(self.tcx.crate_name(pick.item.def_id.krate), sym::std | sym::core) {
@@ -69,7 +79,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
6979
// Inherent impls only require not relying on autoref and autoderef in order to
7080
// ensure that the trait implementation won't be used
7181
self.tcx.struct_span_lint_hir(
72-
RUST_2021_PRELUDE_COLLISIONS,
82+
prelude_or_array_lint,
7383
self_expr.hir_id,
7484
self_expr.span,
7585
|lint| {
@@ -130,7 +140,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
130140
// trait implementations require full disambiguation to not clash with the new prelude
131141
// additions (i.e. convert from dot-call to fully-qualified call)
132142
self.tcx.struct_span_lint_hir(
133-
RUST_2021_PRELUDE_COLLISIONS,
143+
prelude_or_array_lint,
134144
call_expr.hir_id,
135145
call_expr.span,
136146
|lint| {
@@ -239,47 +249,58 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
239249
let trait_path = self.trait_path_or_bare_name(span, expr_id, pick.item.container.id());
240250
let trait_generics = self.tcx.generics_of(pick.item.container.id());
241251

242-
let parameter_count = trait_generics.count() - (trait_generics.has_self as usize);
243-
let trait_name = if parameter_count == 0 {
244-
trait_path
245-
} else {
246-
format!(
247-
"{}<{}>",
248-
trait_path,
249-
std::iter::repeat("_").take(parameter_count).collect::<Vec<_>>().join(", ")
250-
)
251-
};
252+
let trait_name =
253+
if trait_generics.params.len() <= trait_generics.has_self as usize {
254+
trait_path
255+
} else {
256+
let counts = trait_generics.own_counts();
257+
format!(
258+
"{}<{}>",
259+
trait_path,
260+
std::iter::repeat("'_")
261+
.take(counts.lifetimes)
262+
.chain(std::iter::repeat("_").take(
263+
counts.types + counts.consts - trait_generics.has_self as usize
264+
))
265+
.collect::<Vec<_>>()
266+
.join(", ")
267+
)
268+
};
252269

253270
let mut lint = lint.build(&format!(
254271
"trait-associated function `{}` will become ambiguous in Rust 2021",
255272
method_name.name
256273
));
257274

258-
let self_ty_name = self
275+
let mut self_ty_name = self
259276
.sess()
260277
.source_map()
261278
.span_to_snippet(self_ty_span)
262279
.unwrap_or_else(|_| self_ty.to_string());
263280

264-
let self_ty_generics_count = match self_ty.kind() {
265-
// Get the number of generics the self type has (if an Adt) unless we can determine that
266-
// the user has written the self type with generics already which we (naively) do by looking
267-
// for a "<" in `self_ty_name`.
268-
Adt(def, _) if !self_ty_name.contains('<') => self.tcx.generics_of(def.did).count(),
269-
_ => 0,
270-
};
271-
let self_ty_generics = if self_ty_generics_count > 0 {
272-
format!("<{}>", vec!["_"; self_ty_generics_count].join(", "))
273-
} else {
274-
String::new()
275-
};
281+
// Get the number of generics the self type has (if an Adt) unless we can determine that
282+
// the user has written the self type with generics already which we (naively) do by looking
283+
// for a "<" in `self_ty_name`.
284+
if !self_ty_name.contains('<') {
285+
if let Adt(def, _) = self_ty.kind() {
286+
let generics = self.tcx.generics_of(def.did);
287+
if !generics.params.is_empty() {
288+
let counts = generics.own_counts();
289+
self_ty_name += &format!(
290+
"<{}>",
291+
std::iter::repeat("'_")
292+
.take(counts.lifetimes)
293+
.chain(std::iter::repeat("_").take(counts.types + counts.consts))
294+
.collect::<Vec<_>>()
295+
.join(", ")
296+
);
297+
}
298+
}
299+
}
276300
lint.span_suggestion(
277301
span,
278302
"disambiguate the associated function",
279-
format!(
280-
"<{}{} as {}>::{}",
281-
self_ty_name, self_ty_generics, trait_name, method_name.name,
282-
),
303+
format!("<{} as {}>::{}", self_ty_name, trait_name, method_name.name,),
283304
Applicability::MachineApplicable,
284305
);
285306

@@ -322,7 +343,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
322343
.filter_map(|item| if item.ident.name != Underscore { Some(item.ident) } else { None })
323344
.next();
324345
if let Some(any_id) = any_id {
325-
return Some(format!("{}", any_id));
346+
if any_id.name == Empty {
347+
// Glob import, so just use its name.
348+
return None;
349+
} else {
350+
return Some(format!("{}", any_id));
351+
}
326352
}
327353

328354
// All that is left is `_`! We need to use the full path. It doesn't matter which one we pick,

Diff for: library/core/src/time.rs

+12-5
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,21 @@
22

33
//! Temporal quantification.
44
//!
5-
//! Example:
5+
//! # Examples:
6+
//!
7+
//! There are multiple ways to create a new [`Duration`]:
68
//!
79
//! ```
8-
//! use std::time::Duration;
10+
//! # use std::time::Duration;
11+
//! let five_seconds = Duration::from_secs(5);
12+
//! assert_eq!(five_seconds, Duration::from_millis(5_000));
13+
//! assert_eq!(five_seconds, Duration::from_micros(5_000_000));
14+
//! assert_eq!(five_seconds, Duration::from_nanos(5_000_000_000));
915
//!
10-
//! let five_seconds = Duration::new(5, 0);
11-
//! // both declarations are equivalent
12-
//! assert_eq!(Duration::new(5, 0), Duration::from_secs(5));
16+
//! let ten_seconds = Duration::from_secs(10);
17+
//! let seven_nanos = Duration::from_nanos(7);
18+
//! let total = ten_seconds + seven_nanos;
19+
//! assert_eq!(total, Duration::new(10, 7));
1320
//! ```
1421
1522
use crate::fmt;

Diff for: library/std/src/env.rs

+3
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,9 @@ pub fn temp_dir() -> PathBuf {
616616
/// return the path of the symbolic link and other platforms will return the
617617
/// path of the symbolic link’s target.
618618
///
619+
/// If the executable is renamed while it is running, platforms may return the
620+
/// path at the time it was loaded instead of the new path.
621+
///
619622
/// # Errors
620623
///
621624
/// Acquiring the path of the current executable is a platform-specific operation

Diff for: library/std/src/time.rs

+25-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,32 @@
11
//! Temporal quantification.
22
//!
3-
//! Example:
3+
//! # Examples:
44
//!
5+
//! There are multiple ways to create a new [`Duration`]:
6+
//!
7+
//! ```
8+
//! # use std::time::Duration;
9+
//! let five_seconds = Duration::from_secs(5);
10+
//! assert_eq!(five_seconds, Duration::from_millis(5_000));
11+
//! assert_eq!(five_seconds, Duration::from_micros(5_000_000));
12+
//! assert_eq!(five_seconds, Duration::from_nanos(5_000_000_000));
13+
//!
14+
//! let ten_seconds = Duration::from_secs(10);
15+
//! let seven_nanos = Duration::from_nanos(7);
16+
//! let total = ten_seconds + seven_nanos;
17+
//! assert_eq!(total, Duration::new(10, 7));
518
//! ```
6-
//! use std::time::Duration;
719
//!
8-
//! let five_seconds = Duration::new(5, 0);
9-
//! // both declarations are equivalent
10-
//! assert_eq!(Duration::new(5, 0), Duration::from_secs(5));
20+
//! Using [`Instant`] to calculate how long a function took to run:
21+
//!
22+
//! ```ignore (incomplete)
23+
//! let now = Instant::now();
24+
//!
25+
//! // Calling a slow function, it may take a while
26+
//! slow_function();
27+
//!
28+
//! let elapsed_time = now.elapsed();
29+
//! println!("Running slow_function() took {} seconds.", elapsed_time.as_secs());
1130
//! ```
1231
1332
#![stable(feature = "time", since = "1.3.0")]
@@ -26,7 +45,7 @@ use crate::sys_common::FromInner;
2645
pub use core::time::Duration;
2746

2847
/// A measurement of a monotonically nondecreasing clock.
29-
/// Opaque and useful only with `Duration`.
48+
/// Opaque and useful only with [`Duration`].
3049
///
3150
/// Instants are always guaranteed to be no less than any previously measured
3251
/// instant when created, and are often useful for tasks such as measuring

0 commit comments

Comments
 (0)