Skip to content

Rollup of 7 pull requests #85981

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

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
c5233b7
Fix typo in internal documentation for `TrustedRandomAccess`
steffahn Jun 1, 2021
c63cb01
updated shlex for jsondocck
klensy Jun 1, 2021
5afc594
replace lazy_static with once_cell, drop direct dependency on serde
klensy Jun 1, 2021
80828f2
Improve check_ref suggestions in macros.
m-ou-se Jun 2, 2021
e735f60
Add test for ref suggestions in macros.
m-ou-se Jun 2, 2021
d4ea9fa
Restore the num_def_ids_untracked public function giving the total nu…
denismerigoux Jun 1, 2021
32ee368
Show `::{{constructor}}` in std::any::type_name().
m-ou-se Jun 3, 2021
e3b19e5
Add test for issue 84666.
m-ou-se Jun 3, 2021
7f1f90a
Add debug info tests for range, fix-sized array, and cell types
nanguye Mar 30, 2021
98c9052
Fix linkcheck script from getting out of sync.
ehuss Jun 3, 2021
095f09a
Build linkcheck script as release to run faster.
ehuss Jun 3, 2021
6f4405f
Rollup merge of #85448 - nanguye2496:nanguye2496/debuginfo_tests, r=M…
JohnTitor Jun 3, 2021
1d77ec5
Rollup merge of #85888 - steffahn:fix_internal_trustedrandomaccess_do…
JohnTitor Jun 3, 2021
5a4484c
Rollup merge of #85889 - denismerigoux:master, r=petrochenkov
JohnTitor Jun 3, 2021
b8cc847
Rollup merge of #85899 - klensy:jsondocck-f, r=Mark-Simulacrum
JohnTitor Jun 3, 2021
2bd3237
Rollup merge of #85937 - m-ou-se:macro-ref-suggestions, r=estebank
JohnTitor Jun 3, 2021
26cf10e
Rollup merge of #85963 - m-ou-se:constructor-type-name, r=yaahc
JohnTitor Jun 3, 2021
6678349
Rollup merge of #85977 - ehuss:linkcheck-nightly, r=Mark-Simulacrum
JohnTitor Jun 3, 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
13 changes: 3 additions & 10 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1753,11 +1753,10 @@ dependencies = [
"fs-err",
"getopts",
"jsonpath_lib",
"lazy_static",
"once_cell",
"regex",
"serde",
"serde_json",
"shlex 0.1.1",
"shlex",
]

[[package]]
Expand Down Expand Up @@ -2138,7 +2137,7 @@ dependencies = [
"serde",
"serde_derive",
"serde_json",
"shlex 1.0.0",
"shlex",
"tempfile",
"toml",
]
Expand Down Expand Up @@ -4813,12 +4812,6 @@ version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "45bb67a18fa91266cc7807181f62f9178a6873bfad7dc788c42e6430db40184f"

[[package]]
name = "shlex"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fdf1b9db47230893d76faad238fd6097fd6d6a9245cd7a4d90dbd639536bbd2"

[[package]]
name = "shlex"
version = "1.0.0"
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_metadata/src/rmeta/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1931,6 +1931,10 @@ impl CrateMetadata {
self.root.hash
}

fn num_def_ids(&self) -> usize {
self.root.tables.def_keys.size()
}

fn local_def_id(&self, index: DefIndex) -> DefId {
DefId { krate: self.cnum, index }
}
Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,13 @@ impl CStore {
self.get_crate_data(def_id.krate).module_expansion(def_id.index, sess)
}

/// Only public-facing way to traverse all the definitions in a non-local crate.
/// Critically useful for this third-party project: <https://github.com/hacspec/hacspec>.
/// See <https://github.com/rust-lang/rust/pull/85889> for context.
pub fn num_def_ids_untracked(&self, cnum: CrateNum) -> usize {
self.get_crate_data(cnum).num_def_ids()
}

pub fn item_attrs(&self, def_id: DefId, sess: &Session) -> Vec<ast::Attribute> {
self.get_crate_data(def_id.krate).get_item_attrs(def_id.index, sess).collect()
}
Expand Down
7 changes: 1 addition & 6 deletions compiler/rustc_mir/src/interpret/intrinsics/type_name.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use rustc_hir::def_id::CrateNum;
use rustc_hir::definitions::{DefPathData, DisambiguatedDefPathData};
use rustc_hir::definitions::DisambiguatedDefPathData;
use rustc_middle::mir::interpret::Allocation;
use rustc_middle::ty::{
self,
Expand Down Expand Up @@ -127,11 +127,6 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> {
) -> Result<Self::Path, Self::Error> {
self = print_prefix(self)?;

// Skip `::{{constructor}}` on tuple/unit structs.
if disambiguated_data.data == DefPathData::Ctor {
return Ok(self);
}

write!(self.path, "::{}", disambiguated_data.data).unwrap();

Ok(self)
Expand Down
38 changes: 18 additions & 20 deletions compiler/rustc_typeck/src/check/demand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use rustc_errors::{Applicability, DiagnosticBuilder};
use rustc_hir as hir;
use rustc_hir::lang_items::LangItem;
use rustc_hir::{is_range_literal, Node};
use rustc_middle::lint::in_external_macro;
use rustc_middle::ty::adjustment::AllowTwoPhase;
use rustc_middle::ty::{self, AssocItem, Ty, TypeAndMut};
use rustc_span::symbol::sym;
Expand Down Expand Up @@ -412,25 +413,23 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
checked_ty: Ty<'tcx>,
expected: Ty<'tcx>,
) -> Option<(Span, &'static str, String, Applicability)> {
let sm = self.sess().source_map();
let sess = self.sess();
let sp = expr.span;
if sm.is_imported(sp) {
// Ignore if span is from within a macro #41858, #58298. We previously used the macro
// call span, but that breaks down when the type error comes from multiple calls down.

// If the span is from an external macro, there's no suggestion we can make.
if in_external_macro(sess, sp) {
return None;
}

let sm = sess.source_map();

let replace_prefix = |s: &str, old: &str, new: &str| {
s.strip_prefix(old).map(|stripped| new.to_string() + stripped)
};

let is_struct_pat_shorthand_field =
self.is_hir_id_from_struct_pattern_shorthand_field(expr.hir_id, sp);

// If the span is from a macro, then it's hard to extract the text
// and make a good suggestion, so don't bother.
let is_macro = sp.from_expansion() && sp.desugaring_kind().is_none();

// `ExprKind::DropTemps` is semantically irrelevant for these suggestions.
let expr = expr.peel_drop_temps();

Expand Down Expand Up @@ -570,10 +569,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
hir::ExprKind::AddrOf(hir::BorrowKind::Ref, _, ref expr),
_,
&ty::Ref(_, checked, _),
) if {
self.infcx.can_sub(self.param_env, checked, &expected).is_ok() && !is_macro
} =>
{
) if self.infcx.can_sub(self.param_env, checked, &expected).is_ok() => {
// We have `&T`, check if what was expected was `T`. If so,
// we may want to suggest removing a `&`.
if sm.is_imported(expr.span) {
Expand All @@ -589,13 +585,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
return None;
}
if let Ok(code) = sm.span_to_snippet(expr.span) {
return Some((
sp,
"consider removing the borrow",
code,
Applicability::MachineApplicable,
));
if sp.contains(expr.span) {
if let Ok(code) = sm.span_to_snippet(expr.span) {
return Some((
sp,
"consider removing the borrow",
code,
Applicability::MachineApplicable,
));
}
}
}
(
Expand Down Expand Up @@ -643,7 +641,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
}
}
_ if sp == expr.span && !is_macro => {
_ if sp == expr.span => {
if let Some(steps) = self.deref_steps(checked_ty, expected) {
let expr = expr.peel_blocks();

Expand Down
2 changes: 1 addition & 1 deletion library/core/src/iter/adapters/zip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ impl<A: Debug + TrustedRandomAccess, B: Debug + TrustedRandomAccess> ZipFmt<A, B
/// called on `self`:
/// * `std::clone::Clone::clone()`
/// * `std::iter::Iterator::size_hint()`
/// * `std::iter::Iterator::next_back()`
/// * `std::iter::DoubleEndedIterator::next_back()`
/// * `std::iter::Iterator::__iterator_get_unchecked()`
/// * `std::iter::TrustedRandomAccess::size()`
///
Expand Down
13 changes: 13 additions & 0 deletions library/core/tests/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,16 @@ fn any_unsized() {
fn is_any<T: Any + ?Sized>() {}
is_any::<[i32]>();
}

#[test]
fn distinct_type_names() {
// https://github.com/rust-lang/rust/issues/84666

struct Velocity(f32, f32);

fn type_name_of_val<T>(_: T) -> &'static str {
type_name::<T>()
}

assert_ne!(type_name_of_val(Velocity), type_name_of_val(Velocity(0.0, -9.8)),);
}
39 changes: 39 additions & 0 deletions src/test/debuginfo/fixed-sized-array.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Testing the display of fixed sized arrays in cdb.

// cdb-only
// min-cdb-version: 10.0.18317.1001
// compile-flags:-g

// === CDB TESTS ==================================================================================

// cdb-command: g

// cdb-command: dx xs,d
// cdb-check:xs,d [Type: int [5]]
// cdb-check: [0] : 1 [Type: int]
// cdb-check: [1] : 2 [Type: int]
// cdb-check: [2] : 3 [Type: int]
// cdb-check: [3] : 4 [Type: int]
// cdb-check: [4] : 5 [Type: int]

// cdb-command: dx ys,d
// cdb-check:ys,d [Type: int [3]]
// cdb-check: [0] : 0 [Type: int]
// cdb-check: [1] : 0 [Type: int]
// cdb-check: [2] : 0 [Type: int]

fn main() {
// Fixed-size array (type signature is superfluous)
let xs: [i32; 5] = [1, 2, 3, 4, 5];

// All elements can be initialized to the same value
let ys: [i32; 3] = [0; 3];

// Indexing starts at 0
println!("first element of the array: {}", xs[0]);
println!("second element of the array: {}", xs[1]);

zzz(); // #break
}

fn zzz() { () }
51 changes: 51 additions & 0 deletions src/test/debuginfo/mutable-locs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Testing the display of Cell, RefCell, and RefMut in cdb.

// cdb-only
// min-cdb-version: 10.0.18317.1001
// compile-flags:-g

// === CDB TESTS ==================================================================================

// cdb-command: g

// cdb-command:dx static_c,d
// cdb-check:static_c,d [Type: core::cell::Cell<i32>]
// cdb-check: [+0x000] value [Type: core::cell::UnsafeCell<i32>]

// cdb-command: dx static_c.value,d
// cdb-check:static_c.value,d [Type: core::cell::UnsafeCell<i32>]
// cdb-check: [+0x000] value : 10 [Type: int]

// cdb-command: dx dynamic_c,d
// cdb-check:dynamic_c,d [Type: core::cell::RefCell<i32>]
// cdb-check: [+0x000] borrow [Type: core::cell::Cell<isize>]
// cdb-check: [...] value [Type: core::cell::UnsafeCell<i32>]

// cdb-command: dx dynamic_c.value,d
// cdb-check:dynamic_c.value,d [Type: core::cell::UnsafeCell<i32>]
// cdb-check: [+0x000] value : 15 [Type: int]

// cdb-command: dx b,d
// cdb-check:b,d [Type: core::cell::RefMut<i32>]
// cdb-check: [+0x000] value : [...] : 42 [Type: int *]
// cdb-check: [...] borrow [Type: core::cell::BorrowRefMut]

#![allow(unused_variables)]

use std::cell::{Cell, RefCell};

fn main() {
let static_c = Cell::new(5);
static_c.set(10);

let dynamic_c = RefCell::new(5);
dynamic_c.replace(15);

let dynamic_c_0 = RefCell::new(15);
let mut b = dynamic_c_0.borrow_mut();
*b = 42;

zzz(); // #break
}

fn zzz() {()}
38 changes: 38 additions & 0 deletions src/test/debuginfo/mutex.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Testing the display of Mutex and MutexGuard in cdb.

// cdb-only
// min-cdb-version: 10.0.21287.1005
// compile-flags:-g
// ignore-tidy-linelength

// === CDB TESTS ==================================================================================
//
// cdb-command:g
//
// cdb-command:dx m,d
// cdb-check:m,d [Type: std::sync::mutex::Mutex<i32>]
// cdb-check: [+0x000] inner [Type: std::sys_common::mutex::MovableMutex]
// cdb-check: [+0x008] poison [Type: std::sync::poison::Flag]
// cdb-check: [+0x00c] data [Type: core::cell::UnsafeCell<i32>]

//
// cdb-command:dx m.data,d
// cdb-check:m.data,d [Type: core::cell::UnsafeCell<i32>]
// cdb-check: [+0x000] value : 0 [Type: int]

//
// cdb-command:dx lock,d
// cdb-check:lock,d : Ok({...}) [Type: core::result::Result<std::sync::mutex::MutexGuard<i32>, std::sync::poison::TryLockError<std::sync::mutex::MutexGuard<i32>>>]
// cdb-check: [value] [Type: std::sync::mutex::MutexGuard<i32>]

use std::sync::Mutex;

#[allow(unused_variables)]
fn main()
{
let m = Mutex::new(0);
let lock = m.try_lock();
zzz(); // #break
}

fn zzz() {}
12 changes: 8 additions & 4 deletions src/test/debuginfo/pretty-std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// compile-flags:-g
// min-gdb-version: 7.7
// min-lldb-version: 310
// min-cdb-version: 10.0.18317.1001

// === GDB TESTS ===================================================================================

Expand Down Expand Up @@ -71,8 +72,12 @@
// cdb-command: g

// cdb-command: dx slice,d
// cdb-check:slice,d [...]
// NOTE: While slices have a .natvis entry that works in VS & VS Code, it fails in CDB 10.0.18362.1
// cdb-check:slice,d : { len=4 } [Type: slice<i32>]
// cdb-check: [len] : 4 [Type: unsigned __int64]
// cdb-check: [0] : 0 [Type: int]
// cdb-check: [1] : 1 [Type: int]
// cdb-check: [2] : 2 [Type: int]
// cdb-check: [3] : 3 [Type: int]

// cdb-command: dx vec,d
// cdb-check:vec,d [...] : { len=4 } [Type: [...]::Vec<u64, alloc::alloc::Global>]
Expand All @@ -84,8 +89,7 @@
// cdb-check: [3] : 7 [Type: unsigned __int64]

// cdb-command: dx str_slice
// cdb-check:str_slice [...]
// NOTE: While string slices have a .natvis entry that works in VS & VS Code, it fails in CDB
// cdb-check:str_slice : "IAMA string slice!" [Type: str]

// cdb-command: dx string
// cdb-check:string : "IAMA string!" [Type: [...]::String]
Expand Down
Loading