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 14 pull requests #88527

Merged
merged 38 commits into from
Aug 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
50da1eb
Document `std::env::current_exe` rename behaviour
ChrisDenton Aug 27, 2021
5c7400c
Add nested TAIT inference test
spastorino Aug 27, 2021
d7a777f
Add nested TAIT inference test that fails
spastorino Aug 27, 2021
1ba86f2
Add inference cycle TAIT test
spastorino Aug 27, 2021
5ac46d7
Add auto trait leakage TAIT test
spastorino Aug 27, 2021
d0e08df
Add auto trait that shouldn't leak TAIT test
spastorino Aug 28, 2021
c85529e
Add auto trait leakage TAIT test that should work but currently doesn't
spastorino Aug 28, 2021
6ac2235
Add weird return types TAIT test
spastorino Aug 28, 2021
d562848
fix(rustc_parse): incorrect span information for macro block expr
notriddle Aug 29, 2021
f7c0566
fix(rustc_parse): incorrect span information for macro path expr
notriddle Aug 29, 2021
b8728e7
rustdoc: Stop using resolver for macro loading
petrochenkov Aug 29, 2021
faf5985
Adding examples to docs of std::time module
marcospb19 Aug 29, 2021
1a2fe87
Remove unused arena macro args
bjorn3 Aug 30, 2021
403b80d
Use MaybeUninit::write in functor.rs
est31 Aug 30, 2021
a4f6d3e
Fix lifetime generics in <T as Trait<..>>::try_from suggestion.
m-ou-se Aug 30, 2021
e2abf06
Fix lifetime generics in <T<..> as Trait>::try_from suggestion.
m-ou-se Aug 30, 2021
78a7d1c
Add and update tests.
m-ou-se Aug 30, 2021
51e4fba
Fix prelude collision suggestions for glob imported traits.
m-ou-se Aug 30, 2021
89a9867
Add test for glob imported prelude collision trait.
m-ou-se Aug 30, 2021
336f314
Warn when [T; N].into_iter() is ambiguous in the new edition.
m-ou-se Aug 30, 2021
756ef3b
Add test for 2021 ambiguous [T; N].into_iter().
m-ou-se Aug 30, 2021
23d2cb8
Don't suggest extra <> in dyn suggestion.
m-ou-se Aug 30, 2021
f8beb8f
Add test for extra <> in dyn suggestion.
m-ou-se Aug 30, 2021
ac93ca3
Turn to ifs into a match.
m-ou-se Aug 30, 2021
cd20fbd
Rollup merge of #88394 - ChrisDenton:patch-1, r=joshtriplett
m-ou-se Aug 31, 2021
5eeeb0b
Rollup merge of #88406 - spastorino:tait-nest-infer-test, r=oli-obk
m-ou-se Aug 31, 2021
b490f35
Rollup merge of #88408 - spastorino:inference-cycle-tait-test, r=oli-obk
m-ou-se Aug 31, 2021
0e49feb
Rollup merge of #88409 - spastorino:autoleakage-tait-test, r=oli-obk
m-ou-se Aug 31, 2021
2013792
Rollup merge of #88413 - spastorino:weird-return-types-tait-test, r=o…
m-ou-se Aug 31, 2021
7696aca
Rollup merge of #88450 - notriddle:notriddle/maybe_whole_expr, r=cjgi…
m-ou-se Aug 31, 2021
d47b7d7
Rollup merge of #88462 - petrochenkov:macstore, r=jyn514
m-ou-se Aug 31, 2021
497267a
Rollup merge of #88465 - marcospb19:master, r=joshtriplett
m-ou-se Aug 31, 2021
e094380
Rollup merge of #88486 - bjorn3:better_arena_macro, r=jackh726
m-ou-se Aug 31, 2021
4adacfd
Rollup merge of #88492 - est31:maybe_uninit_write, r=wesleywiser
m-ou-se Aug 31, 2021
fdf9c09
Rollup merge of #88496 - m-ou-se:prelude-collision-lifetime-generics,…
m-ou-se Aug 31, 2021
db44069
Rollup merge of #88497 - m-ou-se:prelude-collision-glob, r=nikomatsakis
m-ou-se Aug 31, 2021
caca256
Rollup merge of #88503 - m-ou-se:array-into-inter-ambiguous, r=cjgillot
m-ou-se Aug 31, 2021
feafda8
Rollup merge of #88509 - m-ou-se:dyn-no-left-shift-right-shift-just-s…
m-ou-se Aug 31, 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 Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4405,6 +4405,7 @@ dependencies = [
"rustc_hir_pretty",
"rustc_index",
"rustc_infer",
"rustc_lint",
"rustc_macros",
"rustc_middle",
"rustc_session",
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_arena/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ pub macro which_arena_for_type {
}

#[rustc_macro_transparency = "semitransparent"]
pub macro declare_arena([], [$($a:tt $name:ident: $ty:ty,)*], $tcx:lifetime) {
pub macro declare_arena([$($a:tt $name:ident: $ty:ty,)*], $tcx:lifetime) {
#[derive(Default)]
pub struct Arena<$tcx> {
pub dropless: $crate::DroplessArena,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ mod path;

const HIR_ID_COUNTER_LOCKED: u32 = 0xFFFFFFFF;

rustc_hir::arena_types!(rustc_arena::declare_arena, [], 'tcx);
rustc_hir::arena_types!(rustc_arena::declare_arena, 'tcx);

struct LoweringContext<'a, 'hir: 'a> {
/// Used to assign IDs to HIR nodes that do not directly correspond to AST nodes.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_data_structures/src/functor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl<T> IdFunctor for Box<T> {
// inverse of `Box::assume_init()` and should be safe.
let mut raw: Box<mem::MaybeUninit<T>> = Box::from_raw(raw.cast());
// SAFETY: Write the mapped value back into the `Box`.
ptr::write(raw.as_mut_ptr(), f(value));
raw.write(f(value));
// SAFETY: We just initialized `raw`.
raw.assume_init()
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir/src/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
/// where `T` is the type listed. These impls will appear in the implement_ty_decoder! macro.
#[macro_export]
macro_rules! arena_types {
($macro:path, $args:tt, $tcx:lifetime) => (
$macro!($args, [
($macro:path, $tcx:lifetime) => (
$macro!([
// HIR types
[few] hir_krate: rustc_hir::Crate<$tcx>,
[] arm: rustc_hir::Arm<$tcx>,
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_lint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ mod traits;
mod types;
mod unused;

pub use array_into_iter::ARRAY_INTO_ITER;

use rustc_ast as ast;
use rustc_hir as hir;
use rustc_hir::def_id::LocalDefId;
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_middle/src/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
/// listed. These impls will appear in the implement_ty_decoder! macro.
#[macro_export]
macro_rules! arena_types {
($macro:path, $args:tt, $tcx:lifetime) => (
$macro!($args, [
($macro:path, $tcx:lifetime) => (
$macro!([
[] layouts: rustc_target::abi::Layout,
// AdtDef are interned and compared by address
[] adt_def: rustc_middle::ty::AdtDef,
Expand Down Expand Up @@ -109,4 +109,4 @@ macro_rules! arena_types {
)
}

arena_types!(rustc_arena::declare_arena, [], 'tcx);
arena_types!(rustc_arena::declare_arena, 'tcx);
6 changes: 3 additions & 3 deletions compiler/rustc_middle/src/ty/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,15 +437,15 @@ macro_rules! impl_arena_allocatable_decoder {
}

macro_rules! impl_arena_allocatable_decoders {
([], [$($a:tt $name:ident: $ty:ty,)*], $tcx:lifetime) => {
([$($a:tt $name:ident: $ty:ty,)*], $tcx:lifetime) => {
$(
impl_arena_allocatable_decoder!($a [[$name: $ty], $tcx]);
)*
}
}

rustc_hir::arena_types!(impl_arena_allocatable_decoders, [], 'tcx);
arena_types!(impl_arena_allocatable_decoders, [], 'tcx);
rustc_hir::arena_types!(impl_arena_allocatable_decoders, 'tcx);
arena_types!(impl_arena_allocatable_decoders, 'tcx);

#[macro_export]
macro_rules! implement_ty_decoder {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_parse/src/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ macro_rules! maybe_whole_expr {
let path = path.clone();
$p.bump();
return Ok($p.mk_expr(
$p.token.span,
$p.prev_token.span,
ExprKind::Path(None, path),
AttrVec::new(),
));
Expand All @@ -50,7 +50,7 @@ macro_rules! maybe_whole_expr {
let block = block.clone();
$p.bump();
return Ok($p.mk_expr(
$p.token.span,
$p.prev_token.span,
ExprKind::Block(block, None),
AttrVec::new(),
));
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_typeck/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ rustc_index = { path = "../rustc_index" }
rustc_infer = { path = "../rustc_infer" }
rustc_trait_selection = { path = "../rustc_trait_selection" }
rustc_ty_utils = { path = "../rustc_ty_utils" }
rustc_lint = { path = "../rustc_lint" }
15 changes: 10 additions & 5 deletions compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
});

if result.is_ok() {
self.maybe_lint_bare_trait(qpath, hir_id);
self.maybe_lint_bare_trait(qpath, hir_id, span);
self.register_wf_obligation(ty.into(), qself.span, traits::WellFormed(None));
}

Expand All @@ -927,18 +927,23 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
)
}

fn maybe_lint_bare_trait(&self, qpath: &QPath<'_>, hir_id: hir::HirId) {
fn maybe_lint_bare_trait(&self, qpath: &QPath<'_>, hir_id: hir::HirId, span: Span) {
if let QPath::TypeRelative(self_ty, _) = qpath {
if let TyKind::TraitObject([poly_trait_ref, ..], _, TraitObjectSyntax::None) =
self_ty.kind
{
let msg = "trait objects without an explicit `dyn` are deprecated";
let (sugg, app) = match self.tcx.sess.source_map().span_to_snippet(self_ty.span) {
Ok(s) if poly_trait_ref.trait_ref.path.is_global() => {
(format!("<dyn ({})>", s), Applicability::MachineApplicable)
(format!("dyn ({})", s), Applicability::MachineApplicable)
}
Ok(s) => (format!("<dyn {}>", s), Applicability::MachineApplicable),
Err(_) => ("<dyn <type>>".to_string(), Applicability::HasPlaceholders),
Ok(s) => (format!("dyn {}", s), Applicability::MachineApplicable),
Err(_) => ("dyn <type>".to_string(), Applicability::HasPlaceholders),
};
// Wrap in `<..>` if it isn't already.
let sugg = match self.tcx.sess.source_map().span_to_snippet(span) {
Ok(s) if s.starts_with('<') => sugg,
_ => format!("<{}>", sugg),
};
let replace = String::from("use `dyn`");
if self.sess().edition() >= Edition::Edition2021 {
Expand Down
98 changes: 62 additions & 36 deletions compiler/rustc_typeck/src/check/method/prelude2021.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use rustc_ast::Mutability;
use rustc_errors::Applicability;
use rustc_hir as hir;
use rustc_middle::ty::subst::InternalSubsts;
use rustc_middle::ty::{Adt, Ref, Ty};
use rustc_middle::ty::{Adt, Array, Ref, Ty};
use rustc_session::lint::builtin::RUST_2021_PRELUDE_COLLISIONS;
use rustc_span::symbol::kw::Underscore;
use rustc_span::symbol::kw::{Empty, Underscore};
use rustc_span::symbol::{sym, Ident};
use rustc_span::Span;
use rustc_trait_selection::infer::InferCtxtExt;
Expand Down Expand Up @@ -38,10 +38,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
return;
}

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

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

let parameter_count = trait_generics.count() - (trait_generics.has_self as usize);
let trait_name = if parameter_count == 0 {
trait_path
} else {
format!(
"{}<{}>",
trait_path,
std::iter::repeat("_").take(parameter_count).collect::<Vec<_>>().join(", ")
)
};
let trait_name =
if trait_generics.params.len() <= trait_generics.has_self as usize {
trait_path
} else {
let counts = trait_generics.own_counts();
format!(
"{}<{}>",
trait_path,
std::iter::repeat("'_")
.take(counts.lifetimes)
.chain(std::iter::repeat("_").take(
counts.types + counts.consts - trait_generics.has_self as usize
))
.collect::<Vec<_>>()
.join(", ")
)
};

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

let self_ty_name = self
let mut self_ty_name = self
.sess()
.source_map()
.span_to_snippet(self_ty_span)
.unwrap_or_else(|_| self_ty.to_string());

let self_ty_generics_count = match self_ty.kind() {
// Get the number of generics the self type has (if an Adt) unless we can determine that
// the user has written the self type with generics already which we (naively) do by looking
// for a "<" in `self_ty_name`.
Adt(def, _) if !self_ty_name.contains('<') => self.tcx.generics_of(def.did).count(),
_ => 0,
};
let self_ty_generics = if self_ty_generics_count > 0 {
format!("<{}>", vec!["_"; self_ty_generics_count].join(", "))
} else {
String::new()
};
// Get the number of generics the self type has (if an Adt) unless we can determine that
// the user has written the self type with generics already which we (naively) do by looking
// for a "<" in `self_ty_name`.
if !self_ty_name.contains('<') {
if let Adt(def, _) = self_ty.kind() {
let generics = self.tcx.generics_of(def.did);
if !generics.params.is_empty() {
let counts = generics.own_counts();
self_ty_name += &format!(
"<{}>",
std::iter::repeat("'_")
.take(counts.lifetimes)
.chain(std::iter::repeat("_").take(counts.types + counts.consts))
.collect::<Vec<_>>()
.join(", ")
);
}
}
}
lint.span_suggestion(
span,
"disambiguate the associated function",
format!(
"<{}{} as {}>::{}",
self_ty_name, self_ty_generics, trait_name, method_name.name,
),
format!("<{} as {}>::{}", self_ty_name, trait_name, method_name.name,),
Applicability::MachineApplicable,
);

Expand Down Expand Up @@ -322,7 +343,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.filter_map(|item| if item.ident.name != Underscore { Some(item.ident) } else { None })
.next();
if let Some(any_id) = any_id {
return Some(format!("{}", any_id));
if any_id.name == Empty {
// Glob import, so just use its name.
return None;
} else {
return Some(format!("{}", any_id));
}
}

// All that is left is `_`! We need to use the full path. It doesn't matter which one we pick,
Expand Down
17 changes: 12 additions & 5 deletions library/core/src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@

//! Temporal quantification.
//!
//! Example:
//! # Examples:
//!
//! There are multiple ways to create a new [`Duration`]:
//!
//! ```
//! use std::time::Duration;
//! # use std::time::Duration;
//! let five_seconds = Duration::from_secs(5);
//! assert_eq!(five_seconds, Duration::from_millis(5_000));
//! assert_eq!(five_seconds, Duration::from_micros(5_000_000));
//! assert_eq!(five_seconds, Duration::from_nanos(5_000_000_000));
//!
//! let five_seconds = Duration::new(5, 0);
//! // both declarations are equivalent
//! assert_eq!(Duration::new(5, 0), Duration::from_secs(5));
//! let ten_seconds = Duration::from_secs(10);
//! let seven_nanos = Duration::from_nanos(7);
//! let total = ten_seconds + seven_nanos;
//! assert_eq!(total, Duration::new(10, 7));
//! ```

use crate::fmt;
Expand Down
3 changes: 3 additions & 0 deletions library/std/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,9 @@ pub fn temp_dir() -> PathBuf {
/// return the path of the symbolic link and other platforms will return the
/// path of the symbolic link’s target.
///
/// If the executable is renamed while it is running, platforms may return the
/// path at the time it was loaded instead of the new path.
///
/// # Errors
///
/// Acquiring the path of the current executable is a platform-specific operation
Expand Down
31 changes: 25 additions & 6 deletions library/std/src/time.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
//! Temporal quantification.
//!
//! Example:
//! # Examples:
//!
//! There are multiple ways to create a new [`Duration`]:
//!
//! ```
//! # use std::time::Duration;
//! let five_seconds = Duration::from_secs(5);
//! assert_eq!(five_seconds, Duration::from_millis(5_000));
//! assert_eq!(five_seconds, Duration::from_micros(5_000_000));
//! assert_eq!(five_seconds, Duration::from_nanos(5_000_000_000));
//!
//! let ten_seconds = Duration::from_secs(10);
//! let seven_nanos = Duration::from_nanos(7);
//! let total = ten_seconds + seven_nanos;
//! assert_eq!(total, Duration::new(10, 7));
//! ```
//! use std::time::Duration;
//!
//! let five_seconds = Duration::new(5, 0);
//! // both declarations are equivalent
//! assert_eq!(Duration::new(5, 0), Duration::from_secs(5));
//! Using [`Instant`] to calculate how long a function took to run:
//!
//! ```ignore (incomplete)
//! let now = Instant::now();
//!
//! // Calling a slow function, it may take a while
//! slow_function();
//!
//! let elapsed_time = now.elapsed();
//! println!("Running slow_function() took {} seconds.", elapsed_time.as_secs());
//! ```

#![stable(feature = "time", since = "1.3.0")]
Expand All @@ -26,7 +45,7 @@ use crate::sys_common::FromInner;
pub use core::time::Duration;

/// A measurement of a monotonically nondecreasing clock.
/// Opaque and useful only with `Duration`.
/// Opaque and useful only with [`Duration`].
///
/// Instants are always guaranteed to be no less than any previously measured
/// instant when created, and are often useful for tasks such as measuring
Expand Down
Loading