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 7 pull requests #65896

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
893ab67
Custom lifetime error for `impl` item doesn't conform to `trait`
estebank Oct 3, 2019
3e2bc19
review comments
estebank Oct 4, 2019
1e95b5c
Point at the trait item and tweak wording
estebank Oct 15, 2019
e383b7c
Make error apply only to impl/trait mismatch
estebank Oct 15, 2019
3aba2d0
Fix NLL test
estebank Oct 15, 2019
76b8fd8
Add long error explanation for E0587
GuillaumeGomez Oct 18, 2019
42a805e
Update ui tests
GuillaumeGomez Oct 18, 2019
6661db0
Correct handling of type flags with `ConstValue::Placeholder`
varkor Oct 20, 2019
2af50a9
Improve the "try using a variant of the expected type" hint.
Patryk27 Oct 18, 2019
97b10b7
Fix a previously forgotten pretty-printing test after a change to the…
Patryk27 Oct 26, 2019
1c5d0be
Improve pretty-printing for compound qualified paths.
Patryk27 Oct 27, 2019
e2c450b
doc: mention `get(_mut)` in Vec
tesuji Oct 28, 2019
cc575a6
rustc: use IndexVec<DefIndex, T> instead of Vec<T>.
eddyb Oct 25, 2019
46a39a2
self-profiling: Record something more useful for crate metadata gener…
michaelwoerister Oct 28, 2019
05ff8db
Rollup merge of #65068 - estebank:trait-impl-lt-mismatch, r=nikomatsakis
JohnTitor Oct 28, 2019
7ba2aa8
Rollup merge of #65562 - Patryk27:master, r=estebank
JohnTitor Oct 28, 2019
84cb9af
Rollup merge of #65563 - GuillaumeGomez:long-err-explanation-E0587, r…
JohnTitor Oct 28, 2019
4867ce4
Rollup merge of #65643 - varkor:remove-free-regions-from-const-placeh…
JohnTitor Oct 28, 2019
e1c36fd
Rollup merge of #65825 - eddyb:def-index-vec, r=varkor
JohnTitor Oct 28, 2019
ea3548b
Rollup merge of #65887 - lzutao:doc-vec-get, r=rkruppe
JohnTitor Oct 28, 2019
6d092ac
Rollup merge of #65891 - michaelwoerister:sp-crate-metadata, r=wesley…
JohnTitor Oct 28, 2019
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
6 changes: 4 additions & 2 deletions src/liballoc/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ use crate::raw_vec::RawVec;
/// println!("{}", v[6]); // it will panic!
/// ```
///
/// In conclusion: always check if the index you want to get really exists
/// before doing it.
/// Use [`get`] and [`get_mut`] if you want to check whether the index is in
/// the `Vec`.
///
/// # Slicing
///
Expand Down Expand Up @@ -277,6 +277,8 @@ use crate::raw_vec::RawVec;
/// The order has changed in the past and may change again.
///
/// [`vec!`]: ../../std/macro.vec.html
/// [`get`]: ../../std/vec/struct.Vec.html#method.get
/// [`get_mut`]: ../../std/vec/struct.Vec.html#method.get_mut
/// [`Index`]: ../../std/ops/trait.Index.html
/// [`String`]: ../../std/string/struct.String.html
/// [`&str`]: ../../std/primitive.str.html
Expand Down
8 changes: 2 additions & 6 deletions src/librustc/hir/map/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
let mut collector = NodeCollector {
krate,
source_map: sess.source_map(),
map: vec![None; definitions.def_index_count()],
map: IndexVec::from_elem_n(IndexVec::new(), definitions.def_index_count()),
parent_node: hir::CRATE_HIR_ID,
current_signature_dep_index: root_mod_sig_dep_index,
current_full_dep_index: root_mod_full_dep_index,
Expand Down Expand Up @@ -227,12 +227,8 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {

fn insert_entry(&mut self, id: HirId, entry: Entry<'hir>) {
debug!("hir_map: {:?} => {:?}", id, entry);
let local_map = &mut self.map[id.owner.index()];
let local_map = &mut self.map[id.owner];
let i = id.local_id.as_u32() as usize;
if local_map.is_none() {
*local_map = Some(IndexVec::with_capacity(i + 1));
}
let local_map = local_map.as_mut().unwrap();
let len = local_map.len();
if i >= len {
local_map.extend(repeat(None).take(i - len + 1));
Expand Down
18 changes: 9 additions & 9 deletions src/librustc/hir/map/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ use syntax_pos::{Span, DUMMY_SP};
/// There is one `DefPathTable` for each crate.
#[derive(Clone, Default, RustcDecodable, RustcEncodable)]
pub struct DefPathTable {
index_to_key: Vec<DefKey>,
def_path_hashes: Vec<DefPathHash>,
index_to_key: IndexVec<DefIndex, DefKey>,
def_path_hashes: IndexVec<DefIndex, DefPathHash>,
}

impl DefPathTable {
Expand All @@ -53,14 +53,14 @@ impl DefPathTable {

#[inline(always)]
pub fn def_key(&self, index: DefIndex) -> DefKey {
self.index_to_key[index.index()]
self.index_to_key[index]
}

#[inline(always)]
pub fn def_path_hash(&self, index: DefIndex) -> DefPathHash {
let ret = self.def_path_hashes[index.index()];
debug!("def_path_hash({:?}) = {:?}", index, ret);
return ret
let hash = self.def_path_hashes[index];
debug!("def_path_hash({:?}) = {:?}", index, hash);
hash
}

pub fn add_def_path_hashes_to(&self,
Expand Down Expand Up @@ -92,7 +92,7 @@ impl DefPathTable {
pub struct Definitions {
table: DefPathTable,
node_to_def_index: NodeMap<DefIndex>,
def_index_to_node: Vec<ast::NodeId>,
def_index_to_node: IndexVec<DefIndex, ast::NodeId>,
pub(super) node_to_hir_id: IndexVec<ast::NodeId, hir::HirId>,
/// If `ExpnId` is an ID of some macro expansion,
/// then `DefId` is the normal module (`mod`) in which the expanded macro was defined.
Expand Down Expand Up @@ -375,7 +375,7 @@ impl Definitions {
#[inline]
pub fn as_local_node_id(&self, def_id: DefId) -> Option<ast::NodeId> {
if def_id.krate == LOCAL_CRATE {
let node_id = self.def_index_to_node[def_id.index.index()];
let node_id = self.def_index_to_node[def_id.index];
if node_id != ast::DUMMY_NODE_ID {
return Some(node_id);
}
Expand Down Expand Up @@ -404,7 +404,7 @@ impl Definitions {

#[inline]
pub fn def_index_to_hir_id(&self, def_index: DefIndex) -> hir::HirId {
let node_id = self.def_index_to_node[def_index.index()];
let node_id = self.def_index_to_node[def_index];
self.node_to_hir_id[node_id]
}

Expand Down
14 changes: 6 additions & 8 deletions src/librustc/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ impl Forest {

/// This type is effectively a `HashMap<HirId, Entry<'hir>>`,
/// but it is implemented as 2 layers of arrays.
/// - first we have `A = Vec<Option<B>>` mapping a `DefIndex`'s index to an inner value
/// - first we have `A = IndexVec<DefIndex, B>` mapping `DefIndex`s to an inner value
/// - which is `B = IndexVec<ItemLocalId, Option<Entry<'hir>>` which gives you the `Entry`.
pub(super) type HirEntryMap<'hir> = Vec<Option<IndexVec<ItemLocalId, Option<Entry<'hir>>>>>;
pub(super) type HirEntryMap<'hir> = IndexVec<DefIndex, IndexVec<ItemLocalId, Option<Entry<'hir>>>>;

/// Represents a mapping from `NodeId`s to AST elements and their parent `NodeId`s.
#[derive(Clone)]
Expand Down Expand Up @@ -222,8 +222,8 @@ impl<'map> Iterator for ParentHirIterator<'map> {
impl<'hir> Map<'hir> {
#[inline]
fn lookup(&self, id: HirId) -> Option<&Entry<'hir>> {
let local_map = self.map.get(id.owner.index())?;
local_map.as_ref()?.get(id.local_id)?.as_ref()
let local_map = self.map.get(id.owner)?;
local_map.get(id.local_id)?.as_ref()
}

/// Registers a read in the dependency graph of the AST node with
Expand Down Expand Up @@ -1031,14 +1031,12 @@ impl<'hir> Map<'hir> {
// see the comment on `HirEntryMap`.
// Iterate over all the indices and return a reference to
// local maps and their index given that they exist.
self.map.iter().enumerate().filter_map(|(i, local_map)| {
local_map.as_ref().map(|m| (i, m))
}).flat_map(move |(array_index, local_map)| {
self.map.iter_enumerated().flat_map(move |(owner, local_map)| {
// Iterate over each valid entry in the local map.
local_map.iter_enumerated().filter_map(move |(i, entry)| entry.map(move |_| {
// Reconstruct the `HirId` based on the 3 indices we used to find it.
HirId {
owner: DefIndex::from(array_index),
owner,
local_id: i,
}
}))
Expand Down
14 changes: 11 additions & 3 deletions src/librustc/hir/print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1523,9 +1523,17 @@ impl<'a> State<'a> {
colons_before_params)
}
hir::QPath::TypeRelative(ref qself, ref item_segment) => {
self.s.word("<");
self.print_type(qself);
self.s.word(">");
// If we've got a compound-qualified-path, let's push an additional pair of angle
// brackets, so that we pretty-print `<<A::B>::C>` as `<A::B>::C`, instead of just
// `A::B::C` (since the latter could be ambiguous to the user)
if let hir::TyKind::Path(hir::QPath::Resolved(None, _)) = &qself.kind {
self.print_type(qself);
} else {
self.s.word("<");
self.print_type(qself);
self.s.word(">");
}

self.s.word("::");
self.print_ident(item_segment.ident);
self.print_generic_args(item_segment.generic_args(),
Expand Down
2 changes: 2 additions & 0 deletions src/librustc/infer/error_reporting/nice_region_error/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ mod named_anon_conflict;
mod placeholder_error;
mod outlives_closure;
mod static_impl_trait;
mod trait_impl_difference;
mod util;

impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
Expand Down Expand Up @@ -73,6 +74,7 @@ impl<'cx, 'tcx> NiceRegionError<'cx, 'tcx> {
.or_else(|| self.try_report_anon_anon_conflict())
.or_else(|| self.try_report_outlives_closure())
.or_else(|| self.try_report_static_impl_trait())
.or_else(|| self.try_report_impl_not_conforming_to_trait())
}

pub fn get_regions(&self) -> (Span, ty::Region<'tcx>, ty::Region<'tcx>) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//! Error Reporting for `impl` items that do not match the obligations from their `trait`.

use syntax_pos::Span;
use crate::ty::Ty;
use crate::infer::{ValuePairs, Subtype};
use crate::infer::error_reporting::nice_region_error::NiceRegionError;
use crate::infer::lexical_region_resolve::RegionResolutionError;
use crate::util::common::ErrorReported;
use crate::traits::ObligationCauseCode::CompareImplMethodObligation;

impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
/// Print the error message for lifetime errors when the `impl` doesn't conform to the `trait`.
pub(super) fn try_report_impl_not_conforming_to_trait(&self) -> Option<ErrorReported> {
if let Some(ref error) = self.error {
debug!("try_report_impl_not_conforming_to_trait {:?}", error);
if let RegionResolutionError::SubSupConflict(
_,
var_origin,
sub_origin,
_sub,
sup_origin,
_sup,
) = error.clone() {
match (&sup_origin, &sub_origin) {
(&Subtype(ref sup_trace), &Subtype(ref sub_trace)) => {
if let (
ValuePairs::Types(sub_expected_found),
ValuePairs::Types(sup_expected_found),
CompareImplMethodObligation { trait_item_def_id, .. },
) = (&sub_trace.values, &sup_trace.values, &sub_trace.cause.code) {
if sup_expected_found == sub_expected_found {
self.emit_err(
var_origin.span(),
sub_expected_found.expected,
sub_expected_found.found,
self.tcx().def_span(*trait_item_def_id),
);
return Some(ErrorReported);
}
}
}
_ => {}
}
}
}
None
}

fn emit_err(&self, sp: Span, expected: Ty<'tcx>, found: Ty<'tcx>, impl_sp: Span) {
let mut err = self.tcx().sess.struct_span_err(
sp,
"`impl` item signature doesn't match `trait` item signature",
);
err.note(&format!("expected `{:?}`\n found `{:?}`", expected, found));
err.span_label(sp, &format!("found {:?}", found));
err.span_label(impl_sp, &format!("expected {:?}", expected));
err.emit();
}
}
1 change: 1 addition & 0 deletions src/librustc/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1408,6 +1408,7 @@ impl<'tcx> TyCtxt<'tcx> {
}

pub fn encode_metadata(self)-> EncodedMetadata {
let _prof_timer = self.prof.generic_activity("generate_crate_metadata");
self.cstore.encode_metadata(self)
}

Expand Down
16 changes: 9 additions & 7 deletions src/librustc/ty/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ impl FlagComputation {
}

&ty::Placeholder(..) => {
self.add_flags(TypeFlags::HAS_FREE_LOCAL_NAMES);
self.add_flags(TypeFlags::HAS_TY_PLACEHOLDER);
}

Expand All @@ -123,8 +124,7 @@ impl FlagComputation {
match infer {
ty::FreshTy(_) |
ty::FreshIntTy(_) |
ty::FreshFloatTy(_) => {
}
ty::FreshFloatTy(_) => {}

ty::TyVar(_) |
ty::IntVar(_) |
Expand Down Expand Up @@ -245,14 +245,16 @@ impl FlagComputation {
}
ConstValue::Bound(debruijn, _) => self.add_binder(debruijn),
ConstValue::Param(_) => {
self.add_flags(TypeFlags::HAS_FREE_LOCAL_NAMES | TypeFlags::HAS_PARAMS);
self.add_flags(TypeFlags::HAS_FREE_LOCAL_NAMES);
self.add_flags(TypeFlags::HAS_PARAMS);
}
ConstValue::Placeholder(_) => {
self.add_flags(TypeFlags::HAS_FREE_REGIONS | TypeFlags::HAS_CT_PLACEHOLDER);
self.add_flags(TypeFlags::HAS_FREE_LOCAL_NAMES);
self.add_flags(TypeFlags::HAS_CT_PLACEHOLDER);
}
ConstValue::Scalar(_) => { }
ConstValue::Slice { data: _, start: _, end: _ } => { }
ConstValue::ByRef { alloc: _, offset: _ } => { }
ConstValue::Scalar(_) => {}
ConstValue::Slice { .. } => {}
ConstValue::ByRef { .. } => {}
}
}

Expand Down
2 changes: 0 additions & 2 deletions src/librustc_codegen_ssa/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -574,8 +574,6 @@ pub fn codegen_crate<B: ExtraBackendMethods>(

if need_metadata_module {
// Codegen the encoded metadata.
let _prof_timer = tcx.prof.generic_activity("codegen_crate_metadata");

let metadata_cgu_name = cgu_name_builder.build_cgu_name(LOCAL_CRATE,
&["crate"],
Some("metadata")).as_str()
Expand Down
9 changes: 7 additions & 2 deletions src/librustc_typeck/check/demand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}).peekable();

if compatible_variants.peek().is_some() {
let expr_text = print::to_string(print::NO_ANN, |s| s.print_expr(expr));
let expr_text = self.tcx.sess
.source_map()
.span_to_snippet(expr.span)
.unwrap_or_else(|_| {
print::to_string(print::NO_ANN, |s| s.print_expr(expr))
});
let suggestions = compatible_variants
.map(|v| format!("{}({})", v, expr_text));
let msg = "try using a variant of the expected type";
let msg = "try using a variant of the expected enum";
err.span_suggestions(expr.span, msg, suggestions, Applicability::MaybeIncorrect);
}
}
Expand Down
20 changes: 19 additions & 1 deletion src/librustc_typeck/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3891,6 +3891,25 @@ details.
[issue #33685]: https://github.com/rust-lang/rust/issues/33685
"##,

E0587: r##"
A type has both `packed` and `align` representation hints.

Erroneous code example:

```compile_fail,E0587
#[repr(packed, align(8))] // error!
struct Umbrella(i32);
```

You cannot use `packed` and `align` hints on a same type. If you want to pack a
type to a given size, you should provide a size to packed:

```
#[repr(packed)] // ok!
struct Umbrella(i32);
```
"##,

E0588: r##"
A type with `packed` representation hint has a field with `align`
representation hint.
Expand Down Expand Up @@ -5097,7 +5116,6 @@ struct B<const X: A>; // ok!
// E0563, // cannot determine a type for this `impl Trait` removed in 6383de15
// E0564, // only named lifetimes are allowed in `impl Trait`,
// but `{}` was found in the type `{}`
E0587, // type has conflicting packed and align representation hints
// E0611, // merged into E0616
// E0612, // merged into E0609
// E0613, // Removed (merged with E0609)
Expand Down
2 changes: 1 addition & 1 deletion src/test/pretty/issue-4264.pp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@


((::alloc::fmt::format as
for<'r> fn(std::fmt::Arguments<'r>) -> std::string::String {std::fmt::format})(((<::core::fmt::Arguments>::new_v1
for<'r> fn(std::fmt::Arguments<'r>) -> std::string::String {std::fmt::format})(((::core::fmt::Arguments::new_v1
as
fn(&[&str], &[std::fmt::ArgumentV1<'_>]) -> std::fmt::Arguments<'_> {std::fmt::Arguments::<'_>::new_v1})((&([("test"
as
Expand Down
3 changes: 2 additions & 1 deletion src/test/ui/conflicting-repr-hints.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,5 @@ LL | | }

error: aborting due to 8 previous errors

For more information about this error, try `rustc --explain E0566`.
Some errors have detailed explanations: E0566, E0587.
For more information about an error, try `rustc --explain E0566`.
2 changes: 1 addition & 1 deletion src/test/ui/did_you_mean/issue-42764.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn main() {
let n: usize = 42;
this_function_expects_a_double_option(n);
//~^ ERROR mismatched types
//~| HELP try using a variant of the expected type
//~| HELP try using a variant of the expected enum
}


Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/did_you_mean/issue-42764.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ LL | this_function_expects_a_double_option(n);
|
= note: expected type `DoubleOption<_>`
found type `usize`
help: try using a variant of the expected type
help: try using a variant of the expected enum
|
LL | this_function_expects_a_double_option(DoubleOption::FirstSome(n));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/error-codes/E0164.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0164]: expected tuple struct/variant, found associated constant `<Foo>::B`
error[E0164]: expected tuple struct/variant, found associated constant `Foo::B`
--> $DIR/E0164.rs:9:9
|
LL | Foo::B(i) => i,
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/fn-in-pat.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0164]: expected tuple struct/variant, found method `<A>::new`
error[E0164]: expected tuple struct/variant, found method `A::new`
--> $DIR/fn-in-pat.rs:11:9
|
LL | A::new() => (),
Expand Down
Loading