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 #88881

Merged
merged 39 commits into from
Sep 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
76e09eb
Do not unshallow -- already done by other code
Mark-Simulacrum Sep 6, 2021
af9de99
Detect stricter constraints on gats where clauses in impls vs trait
jackh726 Aug 25, 2021
890de33
Fix duplicate error
jackh726 Sep 7, 2021
c9d46eb
Rework DepthFirstSearch API
nikomatsakis Nov 23, 2020
2987f4b
WIP state
BoxyUwU Sep 6, 2021
9b29138
as casts and block exprs
BoxyUwU Sep 6, 2021
4483c2b
dont support blocks
BoxyUwU Sep 6, 2021
47b16f4
bless stderr
BoxyUwU Sep 6, 2021
c170dcf
tidy
BoxyUwU Sep 6, 2021
08e8644
move thir visitor to rustc_middle
BoxyUwU Sep 6, 2021
fc63e9a
dont build abstract const for monomorphic consts
BoxyUwU Sep 6, 2021
4cbcb09
handle `ExprKind::NeverToAny`
BoxyUwU Sep 6, 2021
1f57f8b
remove `WorkNode`
BoxyUwU Sep 6, 2021
15101c8
remove debug stmts
BoxyUwU Sep 7, 2021
406d2ab
rename mir -> thir around abstract consts
BoxyUwU Sep 7, 2021
79be080
remove comment
BoxyUwU Sep 7, 2021
955e2b2
nits
BoxyUwU Sep 7, 2021
8c7954d
add a `CastKind` to `Node::Cast`
BoxyUwU Sep 7, 2021
3212734
resolve `from_hir_call` FIXME
BoxyUwU Sep 7, 2021
cd2915e
fmt
BoxyUwU Sep 7, 2021
fd9bb30
CI please
BoxyUwU Sep 7, 2021
8295e4a
add test for builtin types N + N unifying with fn call
BoxyUwU Sep 9, 2021
44e6f2e
Remove unnecessary `Cache.*_did` fields
camelid Aug 22, 2021
294510e
rustc: Remove local variable IDs from `Export`s
petrochenkov Sep 5, 2021
03f9fe2
explicitly link to external `ena` docs
lcnr Sep 11, 2021
df281ee
Only take `tcx` when it's all that's needed
camelid Aug 27, 2021
0bb1c28
rustdoc: Get symbol for `TyParam` directly
camelid Aug 23, 2021
6a84d34
Create a valid `Res` in `external_path()`
camelid Aug 24, 2021
c2207f5
Remove unused `hir_id` parameter from `resolve_type`
camelid Aug 27, 2021
5321b35
Fix redundant arguments in `external_path()`
camelid Sep 11, 2021
913764d
Remove unnecessary `is_trait` argument
camelid Sep 11, 2021
280fc2d
rustdoc: Cleanup a pattern match in `external_generic_args()`
camelid Sep 11, 2021
6d4f27e
Rollup merge of #88336 - jackh726:gats-where-constraints, r=estebank
Manishearth Sep 12, 2021
bb5ca58
Rollup merge of #88677 - petrochenkov:exportid, r=davidtwco
Manishearth Sep 12, 2021
a8e3afe
Rollup merge of #88699 - Mark-Simulacrum:fixes-cherry-picker, r=pietr…
Manishearth Sep 12, 2021
f5ac5ca
Rollup merge of #88709 - BoxyUwU:thir-abstract-const, r=lcnr
Manishearth Sep 12, 2021
b87d0d0
Rollup merge of #88711 - Mark-Simulacrum:fix-dfs-bug, r=jackh726
Manishearth Sep 12, 2021
b3af37a
Rollup merge of #88810 - camelid:cleanup-pt1, r=jyn514
Manishearth Sep 12, 2021
146aee6
Rollup merge of #88813 - lcnr:ena-docs, r=jyn514
Manishearth Sep 12, 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
54 changes: 52 additions & 2 deletions compiler/rustc_data_structures/src/graph/iterate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,58 @@ impl<G> DepthFirstSearch<'graph, G>
where
G: ?Sized + DirectedGraph + WithNumNodes + WithSuccessors,
{
pub fn new(graph: &'graph G, start_node: G::Node) -> Self {
Self { graph, stack: vec![start_node], visited: BitSet::new_empty(graph.num_nodes()) }
pub fn new(graph: &'graph G) -> Self {
Self { graph, stack: vec![], visited: BitSet::new_empty(graph.num_nodes()) }
}

/// Version of `push_start_node` that is convenient for chained
/// use.
pub fn with_start_node(mut self, start_node: G::Node) -> Self {
self.push_start_node(start_node);
self
}

/// Pushes another start node onto the stack. If the node
/// has not already been visited, then you will be able to
/// walk its successors (and so forth) after the current
/// contents of the stack are drained. If multiple start nodes
/// are added into the walk, then their mutual successors
/// will all be walked. You can use this method once the
/// iterator has been completely drained to add additional
/// start nodes.
pub fn push_start_node(&mut self, start_node: G::Node) {
if self.visited.insert(start_node) {
self.stack.push(start_node);
}
}

/// Searches all nodes reachable from the current start nodes.
/// This is equivalent to just invoke `next` repeatedly until
/// you get a `None` result.
pub fn complete_search(&mut self) {
while let Some(_) = self.next() {}
}

/// Returns true if node has been visited thus far.
/// A node is considered "visited" once it is pushed
/// onto the internal stack; it may not yet have been yielded
/// from the iterator. This method is best used after
/// the iterator is completely drained.
pub fn visited(&self, node: G::Node) -> bool {
self.visited.contains(node)
}
}

impl<G> std::fmt::Debug for DepthFirstSearch<'_, G>
where
G: ?Sized + DirectedGraph + WithNumNodes + WithSuccessors,
{
fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let mut f = fmt.debug_set();
for n in self.visited.iter() {
f.entry(&n);
}
f.finish()
}
}

Expand Down
16 changes: 16 additions & 0 deletions compiler/rustc_data_structures/src/graph/iterate/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,19 @@ fn is_cyclic() {
assert!(!is_cyclic(&diamond_acyclic));
assert!(is_cyclic(&diamond_cyclic));
}

#[test]
fn dfs() {
let graph = TestGraph::new(0, &[(0, 1), (0, 2), (1, 3), (2, 3), (3, 0)]);

let result: Vec<usize> = DepthFirstSearch::new(&graph).with_start_node(0).collect();
assert_eq!(result, vec![0, 2, 3, 1]);
}

#[test]
fn dfs_debug() {
let graph = TestGraph::new(0, &[(0, 1), (0, 2), (1, 3), (2, 3), (3, 0)]);
let mut dfs = DepthFirstSearch::new(&graph).with_start_node(0);
dfs.complete_search();
assert_eq!(format!("{{0, 1, 2, 3}}"), format!("{:?}", dfs));
}
2 changes: 1 addition & 1 deletion compiler/rustc_data_structures/src/graph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ where
where
Self: WithNumNodes,
{
iterate::DepthFirstSearch::new(self, from)
iterate::DepthFirstSearch::new(self).with_start_node(from)
}
}

Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_data_structures/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#![feature(iter_map_while)]
#![feature(maybe_uninit_uninit_array)]
#![feature(min_specialization)]
#![feature(never_type)]
#![feature(type_alias_impl_trait)]
#![feature(new_uninit)]
#![feature(nll)]
Expand Down
6 changes: 6 additions & 0 deletions compiler/rustc_data_structures/src/stable_hasher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,12 @@ impl_stable_hash_via_hash!(i128);
impl_stable_hash_via_hash!(char);
impl_stable_hash_via_hash!(());

impl<CTX> HashStable<CTX> for ! {
fn hash_stable(&self, _ctx: &mut CTX, _hasher: &mut StableHasher) {
unreachable!()
}
}

impl<CTX> HashStable<CTX> for ::std::num::NonZeroU32 {
fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) {
self.get().hash_stable(ctx, hasher)
Expand Down
5 changes: 5 additions & 0 deletions compiler/rustc_hir/src/def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,11 @@ impl<Id> Res<Id> {
}
}

#[track_caller]
pub fn expect_non_local<OtherId>(self) -> Res<OtherId> {
self.map_id(|_| panic!("unexpected `Res::Local`"))
}

pub fn macro_kind(self) -> Option<MacroKind> {
match self {
Res::Def(DefKind::Macro(kind), _) => Some(kind),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use crate::infer::error_reporting::nice_region_error::NiceRegionError;
use crate::infer::lexical_region_resolve::RegionResolutionError;
use crate::infer::{Subtype, ValuePairs};
use crate::infer::{SubregionOrigin, Subtype, ValuePairs};
use crate::traits::ObligationCauseCode::CompareImplMethodObligation;
use rustc_errors::ErrorReported;
use rustc_hir as hir;
Expand All @@ -11,44 +11,53 @@ use rustc_hir::def_id::DefId;
use rustc_hir::intravisit::Visitor;
use rustc_middle::ty::error::ExpectedFound;
use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_span::{MultiSpan, Span};
use rustc_span::{MultiSpan, Span, Symbol};

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()
{
if let (&Subtype(ref sup_trace), &Subtype(ref sub_trace)) =
(&sup_origin, &sub_origin)
let error = self.error.as_ref()?;
debug!("try_report_impl_not_conforming_to_trait {:?}", error);
if let RegionResolutionError::SubSupConflict(
_,
var_origin,
sub_origin,
_sub,
sup_origin,
_sup,
) = error.clone()
{
if let (&Subtype(ref sup_trace), &Subtype(ref sub_trace)) = (&sup_origin, &sub_origin) {
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 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,
*trait_item_def_id,
);
return Some(ErrorReported);
}
if sup_expected_found == sub_expected_found {
self.emit_err(
var_origin.span(),
sub_expected_found.expected,
sub_expected_found.found,
*trait_item_def_id,
);
return Some(ErrorReported);
}
}
}
}
if let RegionResolutionError::ConcreteFailure(origin, _, _) = error.clone() {
if let SubregionOrigin::CompareImplTypeObligation {
span,
item_name,
impl_item_def_id,
trait_item_def_id,
} = origin
{
self.emit_associated_type_err(span, item_name, impl_item_def_id, trait_item_def_id);
return Some(ErrorReported);
}
}
None
}

Expand Down Expand Up @@ -107,6 +116,25 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
}
err.emit();
}

fn emit_associated_type_err(
&self,
span: Span,
item_name: Symbol,
impl_item_def_id: DefId,
trait_item_def_id: DefId,
) {
let impl_sp = self.tcx().def_span(impl_item_def_id);
let trait_sp = self.tcx().def_span(trait_item_def_id);
let mut err = self
.tcx()
.sess
.struct_span_err(span, &format!("`impl` associated type signature for `{}` doesn't match `trait` associated type signature", item_name));
err.span_label(impl_sp, &format!("found"));
err.span_label(trait_sp, &format!("expected"));

err.emit();
}
}

struct TypeParamSpanVisitor<'tcx> {
Expand Down
18 changes: 18 additions & 0 deletions compiler/rustc_infer/src/infer/error_reporting/note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
"...so that the definition in impl matches the definition from the trait",
);
}
infer::CompareImplTypeObligation { span, .. } => {
label_or_note(
span,
"...so that the definition in impl matches the definition from the trait",
);
}
}
}

Expand Down Expand Up @@ -356,6 +362,18 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
trait_item_def_id,
&format!("`{}: {}`", sup, sub),
),
infer::CompareImplTypeObligation {
span,
item_name,
impl_item_def_id,
trait_item_def_id,
} => self.report_extra_impl_obligation(
span,
item_name,
impl_item_def_id,
trait_item_def_id,
&format!("`{}: {}`", sup, sub),
),
}
}

Expand Down
21 changes: 21 additions & 0 deletions compiler/rustc_infer/src/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,15 @@ pub enum SubregionOrigin<'tcx> {
impl_item_def_id: DefId,
trait_item_def_id: DefId,
},

/// Comparing the signature and requirements of an impl associated type
/// against the containing trait
CompareImplTypeObligation {
span: Span,
item_name: Symbol,
impl_item_def_id: DefId,
trait_item_def_id: DefId,
},
}

// `SubregionOrigin` is used a lot. Make sure it doesn't unintentionally get bigger.
Expand Down Expand Up @@ -1810,6 +1819,7 @@ impl<'tcx> SubregionOrigin<'tcx> {
ReferenceOutlivesReferent(_, a) => a,
CallReturn(a) => a,
CompareImplMethodObligation { span, .. } => span,
CompareImplTypeObligation { span, .. } => span,
}
}

Expand All @@ -1833,6 +1843,17 @@ impl<'tcx> SubregionOrigin<'tcx> {
trait_item_def_id,
},

traits::ObligationCauseCode::CompareImplTypeObligation {
item_name,
impl_item_def_id,
trait_item_def_id,
} => SubregionOrigin::CompareImplTypeObligation {
span: cause.span,
item_name,
impl_item_def_id,
trait_item_def_id,
},

_ => default(),
}
}
Expand Down
14 changes: 6 additions & 8 deletions compiler/rustc_metadata/src/rmeta/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use rustc_middle::middle::cstore::{ForeignModule, LinkagePreference, NativeLib};
use rustc_middle::middle::exported_symbols::{ExportedSymbol, SymbolExportLevel};
use rustc_middle::mir::interpret::{AllocDecodingSession, AllocDecodingState};
use rustc_middle::mir::{self, Body, Promoted};
use rustc_middle::thir;
use rustc_middle::ty::codec::TyDecoder;
use rustc_middle::ty::{self, Ty, TyCtxt, Visibility};
use rustc_serialize::{opaque, Decodable, Decoder};
Expand Down Expand Up @@ -541,7 +542,7 @@ impl<'a, 'tcx> Decodable<DecodeContext<'a, 'tcx>> for Span {
}
}

impl<'a, 'tcx> Decodable<DecodeContext<'a, 'tcx>> for &'tcx [mir::abstract_const::Node<'tcx>] {
impl<'a, 'tcx> Decodable<DecodeContext<'a, 'tcx>> for &'tcx [thir::abstract_const::Node<'tcx>] {
fn decode(d: &mut DecodeContext<'a, 'tcx>) -> Result<Self, String> {
ty::codec::RefDecodable::decode(d)
}
Expand Down Expand Up @@ -1020,10 +1021,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
}

/// Iterates over each child of the given item.
fn each_child_of_item<F>(&self, id: DefIndex, mut callback: F, sess: &Session)
where
F: FnMut(Export<hir::HirId>),
{
fn each_child_of_item(&self, id: DefIndex, mut callback: impl FnMut(Export), sess: &Session) {
if let Some(data) = &self.root.proc_macro_data {
/* If we are loading as a proc macro, we want to return the view of this crate
* as a proc macro crate.
Expand Down Expand Up @@ -1199,14 +1197,14 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
.decode((self, tcx))
}

fn get_mir_abstract_const(
fn get_thir_abstract_const(
&self,
tcx: TyCtxt<'tcx>,
id: DefIndex,
) -> Result<Option<&'tcx [mir::abstract_const::Node<'tcx>]>, ErrorReported> {
) -> Result<Option<&'tcx [thir::abstract_const::Node<'tcx>]>, ErrorReported> {
self.root
.tables
.mir_abstract_consts
.thir_abstract_consts
.get(self, id)
.map_or(Ok(None), |v| Ok(Some(v.decode((self, tcx)))))
}
Expand Down
Loading