Skip to content

Commit

Permalink
Auto merge of rust-lang#81784 - m-ou-se:rollup-s23fow7, r=m-ou-se
Browse files Browse the repository at this point in the history
Rollup of 15 pull requests

Successful merges:

 - rust-lang#79554 (Generic associated types in trait paths)
 - rust-lang#80726 (relax adt unsizing requirements)
 - rust-lang#81307 (Handle `Span`s for byte and raw strings and add more detail )
 - rust-lang#81318 (rustdoc-json: Fix has_body)
 - rust-lang#81456 (Make remote-test-server easier to use with new targets)
 - rust-lang#81497 (rustdoc: Move `display_fn` struct inside `display_fn`)
 - rust-lang#81500 (Remove struct_type from union output)
 - rust-lang#81542 (Expose correct symlink API on WASI)
 - rust-lang#81676 (Add more information to the error code for 'crate not found')
 - rust-lang#81682 (Add additional bitset benchmarks)
 - rust-lang#81730 (Make `Allocator` object-safe)
 - rust-lang#81763 (Cleanup rustdoc pass descriptions a bit)
 - rust-lang#81767 (Update LayoutError/LayoutErr stability attributes)
 - rust-lang#81771 (Indicate change in RSS from start to end of pass in time-passes output)
 - rust-lang#81781 (Fix `install-awscli.sh` error in CI)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Feb 5, 2021
2 parents 730d6df + 2383cd4 commit f9435f4
Show file tree
Hide file tree
Showing 106 changed files with 1,599 additions and 385 deletions.
39 changes: 32 additions & 7 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1076,16 +1076,40 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
fn lower_assoc_ty_constraint(
&mut self,
constraint: &AssocTyConstraint,
itctx: ImplTraitContext<'_, 'hir>,
mut itctx: ImplTraitContext<'_, 'hir>,
) -> hir::TypeBinding<'hir> {
debug!("lower_assoc_ty_constraint(constraint={:?}, itctx={:?})", constraint, itctx);

if let Some(ref gen_args) = constraint.gen_args {
self.sess.span_fatal(
gen_args.span(),
"generic associated types in trait paths are currently not implemented",
);
}
// lower generic arguments of identifier in constraint
let gen_args = if let Some(ref gen_args) = constraint.gen_args {
let gen_args_ctor = match gen_args {
GenericArgs::AngleBracketed(ref data) => {
self.lower_angle_bracketed_parameter_data(
data,
ParamMode::Explicit,
itctx.reborrow(),
)
.0
}
GenericArgs::Parenthesized(ref data) => {
let mut err = self.sess.struct_span_err(
gen_args.span(),
"parenthesized generic arguments cannot be used in associated type constraints"
);
// FIXME: try to write a suggestion here
err.emit();
self.lower_angle_bracketed_parameter_data(
&data.as_angle_bracketed_args(),
ParamMode::Explicit,
itctx.reborrow(),
)
.0
}
};
self.arena.alloc(gen_args_ctor.into_generic_args(&self.arena))
} else {
self.arena.alloc(hir::GenericArgs::none())
};

let kind = match constraint.kind {
AssocTyConstraintKind::Equality { ref ty } => {
Expand Down Expand Up @@ -1182,6 +1206,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
hir::TypeBinding {
hir_id: self.lower_node_id(constraint.id),
ident: constraint.ident,
gen_args,
kind,
span: constraint.span,
}
Expand Down
7 changes: 5 additions & 2 deletions compiler/rustc_ast_lowering/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
}
}

fn lower_angle_bracketed_parameter_data(
pub(crate) fn lower_angle_bracketed_parameter_data(
&mut self,
data: &AngleBracketedArgs,
param_mode: ParamMode,
Expand Down Expand Up @@ -426,6 +426,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
) -> hir::TypeBinding<'hir> {
let ident = Ident::with_dummy_span(hir::FN_OUTPUT_NAME);
let kind = hir::TypeBindingKind::Equality { ty };
hir::TypeBinding { hir_id: self.next_id(), span, ident, kind }
let args = arena_vec![self;];
let bindings = arena_vec![self;];
let gen_args = self.arena.alloc(hir::GenericArgs { args, bindings, parenthesized: false });
hir::TypeBinding { hir_id: self.next_id(), gen_args, span, ident, kind }
}
}
25 changes: 11 additions & 14 deletions compiler/rustc_data_structures/src/profiling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -590,24 +590,21 @@ pub fn print_time_passes_entry(
end_rss: Option<usize>,
) {
let rss_to_mb = |rss| (rss as f64 / 1_000_000.0).round() as usize;
let rss_change_to_mb = |rss| (rss as f64 / 1_000_000.0).round() as i128;

let mem_string = match (start_rss, end_rss) {
(Some(start_rss), Some(end_rss)) => {
// It's tempting to add the change in RSS from start to end, but its somewhat confusing
// and misleading when looking at time-passes output. Consider two adjacent entries:
//
// time: 10.000; rss start: 1000MB, end: 1000MB, change: 0MB pass1
// time: 5.000; rss start: 2000MB, end: 2000MB, change: 0MB pass2
//
// If you're looking for jumps in RSS based on the change column, you miss the fact
// that a 1GB jump happened between pass1 and pass2 (supposing pass1 and pass2 actually
// occur sequentially and pass1 isn't just nested within pass2). It's easy to imagine
// someone missing this or being confused by the fact that the change is zero.

format!("; rss: {:>5}MB -> {:>5}MB", rss_to_mb(start_rss), rss_to_mb(end_rss))
let change_rss = end_rss as i128 - start_rss as i128;

format!(
"; rss: {:>4}MB -> {:>4}MB ({:>+5}MB)",
rss_to_mb(start_rss),
rss_to_mb(end_rss),
rss_change_to_mb(change_rss),
)
}
(Some(start_rss), None) => format!("; rss start: {:>5}MB", rss_to_mb(start_rss)),
(None, Some(end_rss)) => format!("; rss end: {:5>}MB", rss_to_mb(end_rss)),
(Some(start_rss), None) => format!("; rss start: {:>4}MB", rss_to_mb(start_rss)),
(None, Some(end_rss)) => format!("; rss end: {:>4}MB", rss_to_mb(end_rss)),
(None, None) => String::new(),
};

Expand Down
21 changes: 21 additions & 0 deletions compiler/rustc_error_codes/src/error_codes/E0463.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,24 @@ extern crate cake_is_a_lie; // error: can't find crate for `cake_is_a_lie`
You need to link your code to the relevant crate in order to be able to use it
(through Cargo or the `-L` option of rustc example). Plugins are crates as
well, and you link to them the same way.

## Common causes

- The crate is not present at all. If using Cargo, add it to `[dependencies]`
in Cargo.toml.
- The crate is present, but under a different name. If using Cargo, look for
`package = ` under `[dependencies]` in Cargo.toml.

## Common causes for missing `std` or `core`

- You are cross-compiling for a target which doesn't have `std` prepackaged.
Consider one of the following:
+ Adding a pre-compiled version of std with `rustup target add`
+ Building std from source with `cargo build -Z build-std`
+ Using `#![no_std]` at the crate root, so you won't need `std` in the first
place.
- You are developing the compiler itself and haven't built libstd from source.
You can usually build it with `x.py build library/std`. More information
about x.py is available in the [rustc-dev-guide].

[rustc-dev-guide]: https://rustc-dev-guide.rust-lang.org/building/how-to-build-and-run.html#building-the-compiler
3 changes: 3 additions & 0 deletions compiler/rustc_feature/src/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,9 @@ declare_features! (

/// Allows `extern "C-cmse-nonsecure-call" fn()`.
(active, abi_c_cmse_nonsecure_call, "1.51.0", Some(81391), None),

/// Lessens the requirements for structs to implement `Unsize`.
(active, relaxed_struct_unsize, "1.51.0", Some(1), None),
// -------------------------------------------------------------------------
// feature-group-end: actual feature gates
// -------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2015,6 +2015,7 @@ pub struct TypeBinding<'hir> {
pub hir_id: HirId,
#[stable_hasher(project(name))]
pub ident: Ident,
pub gen_args: &'hir GenericArgs<'hir>,
pub kind: TypeBindingKind<'hir>,
pub span: Span,
}
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_hir/src/intravisit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,7 @@ pub fn walk_assoc_type_binding<'v, V: Visitor<'v>>(
) {
visitor.visit_id(type_binding.hir_id);
visitor.visit_ident(type_binding.ident);
visitor.visit_generic_args(type_binding.span, type_binding.gen_args);
match type_binding.kind {
TypeBindingKind::Equality { ref ty } => {
visitor.visit_ty(ty);
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_hir_pretty/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1840,6 +1840,7 @@ impl<'a> State<'a> {
for binding in generic_args.bindings.iter() {
start_or_comma(self);
self.print_ident(binding.ident);
self.print_generic_args(binding.gen_args, false, false);
self.s.space();
match generic_args.bindings[0].kind {
hir::TypeBindingKind::Equality { ref ty } => {
Expand Down
12 changes: 12 additions & 0 deletions compiler/rustc_index/src/bit_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,18 @@ impl<T: Idx> GrowableBitSet<T> {
self.bit_set.insert(elem)
}

/// Returns `true` if the set has changed.
#[inline]
pub fn remove(&mut self, elem: T) -> bool {
self.ensure(elem.index() + 1);
self.bit_set.remove(elem)
}

#[inline]
pub fn is_empty(&self) -> bool {
self.bit_set.is_empty()
}

#[inline]
pub fn contains(&self, elem: T) -> bool {
let (word_index, mask) = word_index_and_mask(elem);
Expand Down
34 changes: 34 additions & 0 deletions compiler/rustc_index/src/bit_set/tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::*;

extern crate test;
use std::hint::black_box;
use test::Bencher;

#[test]
Expand Down Expand Up @@ -364,3 +365,36 @@ fn union_hybrid_sparse_full_small_domain(b: &mut Bencher) {
sparse.union(&dense);
})
}

#[bench]
fn bench_insert(b: &mut Bencher) {
let mut bs = BitSet::new_filled(99999usize);
b.iter(|| {
black_box(bs.insert(black_box(100u32)));
});
}

#[bench]
fn bench_remove(b: &mut Bencher) {
let mut bs = BitSet::new_filled(99999usize);
b.iter(|| {
black_box(bs.remove(black_box(100u32)));
});
}

#[bench]
fn bench_iter(b: &mut Bencher) {
let bs = BitSet::new_filled(99999usize);
b.iter(|| {
bs.iter().map(|b: usize| black_box(b)).for_each(drop);
});
}

#[bench]
fn bench_intersect(b: &mut Bencher) {
let mut ba: BitSet<u32> = BitSet::new_filled(99999usize);
let bb = BitSet::new_filled(99999usize);
b.iter(|| {
ba.intersect(black_box(&bb));
});
}
10 changes: 9 additions & 1 deletion compiler/rustc_middle/src/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1132,8 +1132,16 @@ impl<'tcx> ProjectionTy<'tcx> {
/// For example, if this is a projection of `<T as Iterator>::Item`,
/// then this function would return a `T: Iterator` trait reference.
pub fn trait_ref(&self, tcx: TyCtxt<'tcx>) -> ty::TraitRef<'tcx> {
// FIXME: This method probably shouldn't exist at all, since it's not
// clear what this method really intends to do. Be careful when
// using this method since the resulting TraitRef additionally
// contains the substs for the assoc_item, which strictly speaking
// is not correct
let def_id = tcx.associated_item(self.item_def_id).container.id();
ty::TraitRef { def_id, substs: self.substs.truncate_to(tcx, tcx.generics_of(def_id)) }
// Include substitutions for generic arguments of associated types
let assoc_item = tcx.associated_item(self.item_def_id);
let substs_assoc_item = self.substs.truncate_to(tcx, tcx.generics_of(assoc_item.def_id));
ty::TraitRef { def_id, substs: substs_assoc_item }
}

pub fn self_ty(&self) -> Ty<'tcx> {
Expand Down
30 changes: 20 additions & 10 deletions compiler/rustc_parse/src/lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ mod tokentrees;
mod unescape_error_reporting;
mod unicode_chars;

use unescape_error_reporting::{emit_unescape_error, push_escaped_char};
use unescape_error_reporting::{emit_unescape_error, escaped_char};

#[derive(Clone, Debug)]
pub struct UnmatchedBrace {
Expand Down Expand Up @@ -122,11 +122,9 @@ impl<'a> StringReader<'a> {
m: &str,
c: char,
) -> DiagnosticBuilder<'a> {
let mut m = m.to_string();
m.push_str(": ");
push_escaped_char(&mut m, c);

self.sess.span_diagnostic.struct_span_fatal(self.mk_sp(from_pos, to_pos), &m[..])
self.sess
.span_diagnostic
.struct_span_fatal(self.mk_sp(from_pos, to_pos), &format!("{}: {}", m, escaped_char(c)))
}

/// Turns simple `rustc_lexer::TokenKind` enum into a rich
Expand Down Expand Up @@ -421,7 +419,7 @@ impl<'a> StringReader<'a> {
let content_start = start + BytePos(prefix_len);
let content_end = suffix_start - BytePos(postfix_len);
let id = self.symbol_from_to(content_start, content_end);
self.validate_literal_escape(mode, content_start, content_end);
self.validate_literal_escape(mode, content_start, content_end, prefix_len, postfix_len);
(lit_kind, id)
}

Expand Down Expand Up @@ -525,17 +523,29 @@ impl<'a> StringReader<'a> {
.raise();
}

fn validate_literal_escape(&self, mode: Mode, content_start: BytePos, content_end: BytePos) {
fn validate_literal_escape(
&self,
mode: Mode,
content_start: BytePos,
content_end: BytePos,
prefix_len: u32,
postfix_len: u32,
) {
let lit_content = self.str_from_to(content_start, content_end);
unescape::unescape_literal(lit_content, mode, &mut |range, result| {
// Here we only check for errors. The actual unescaping is done later.
if let Err(err) = result {
let span_with_quotes =
self.mk_sp(content_start - BytePos(1), content_end + BytePos(1));
let span_with_quotes = self
.mk_sp(content_start - BytePos(prefix_len), content_end + BytePos(postfix_len));
let (start, end) = (range.start as u32, range.end as u32);
let lo = content_start + BytePos(start);
let hi = lo + BytePos(end - start);
let span = self.mk_sp(lo, hi);
emit_unescape_error(
&self.sess.span_diagnostic,
lit_content,
span_with_quotes,
span,
mode,
range,
err,
Expand Down
Loading

0 comments on commit f9435f4

Please sign in to comment.