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

[beta] resolve: Implement uniform paths 2.0 #55884

Merged
merged 18 commits into from
Nov 18, 2018
Merged
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
3724f16
resolve: Prohibit relative paths in visibilities on 2018 edition
petrochenkov Oct 30, 2018
c8aacf2
resolve: Stop generating uniform path canaries
petrochenkov Nov 3, 2018
8e8e33b
resolve: Resolve multi-segment imports using in-scope resolution on 2…
petrochenkov Nov 3, 2018
3ba2761
resolve: Simplify ambiguity checking for built-in attributes
petrochenkov Nov 4, 2018
dcaeced
resolve: Improve diagnostics for resolution ambiguities
petrochenkov Nov 4, 2018
35b778f
resolve: More precise determinacy tracking during import/macro resolu…
petrochenkov Nov 7, 2018
82ee839
resolve: Resolve single-segment imports using in-scope resolution on …
petrochenkov Nov 8, 2018
e8bc1d1
resolve: Check resolution consistency for import paths and multi-segm…
petrochenkov Nov 10, 2018
f62f8a5
resolve: Recover "did you mean" suggestions in imports
petrochenkov Nov 11, 2018
9355653
resolve: Tweak some articles in ambiguity diagnostics
petrochenkov Nov 11, 2018
e4a8bb7
Fix ICEs from imports of items not defined in modules
petrochenkov Nov 11, 2018
a0929dc
resolve: Reintroduce feature gate for uniform paths in imports
petrochenkov Nov 12, 2018
3421387
resolve: Avoid marking `extern crate` items as used in certain cases
petrochenkov Nov 13, 2018
738d27f
resolve: Support resolving macros without leaving traces
petrochenkov Nov 13, 2018
696fbc0
resolve: Avoid sentence breaks in diagnostics
petrochenkov Nov 13, 2018
22a13ef
resolve: Future-proof against imports referring to local variables an…
petrochenkov Nov 17, 2018
10ac957
resolve: Refactor away `DeterminacyExt`
petrochenkov Nov 17, 2018
b366415
Add a couple more tests + address review comments
petrochenkov Nov 17, 2018
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ introducing `extern crate` items, using keyword `extern`.

For example, `extern::my_crat::a::b` will resolve to path `a::b` in crate `my_crate`.

`feature(extern_absolute_paths)` mode provides the same effect by resolving absolute paths like
`::my_crate::a::b` to paths from extern crates by default.
Absolute paths on 2018 edition (e.g. `::my_crate::a::b`) provide the same effect
and resolve to extern crates (built-in or passed with `--extern`).

```rust,ignore
#![feature(extern_in_paths)]
Expand Down
31 changes: 19 additions & 12 deletions src/librustc/hir/def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,6 @@ impl PathResolution {
pub fn unresolved_segments(&self) -> usize {
self.unresolved_segments
}

pub fn kind_name(&self) -> &'static str {
if self.unresolved_segments != 0 {
"associated item"
} else {
self.base_def.kind_name()
}
}
}

/// Different kinds of symbols don't influence each other.
Expand Down Expand Up @@ -269,27 +261,33 @@ impl NonMacroAttrKind {

impl Def {
pub fn def_id(&self) -> DefId {
self.opt_def_id().unwrap_or_else(|| {
bug!("attempted .def_id() on invalid def: {:?}", self)
})
}

pub fn opt_def_id(&self) -> Option<DefId> {
match *self {
Def::Fn(id) | Def::Mod(id) | Def::Static(id, _) |
Def::Variant(id) | Def::VariantCtor(id, ..) | Def::Enum(id) |
Def::TyAlias(id) | Def::TraitAlias(id) |
Def::AssociatedTy(id) | Def::TyParam(id) | Def::Struct(id) | Def::StructCtor(id, ..) |
Def::Union(id) | Def::Trait(id) | Def::Method(id) | Def::Const(id) |
Def::AssociatedConst(id) | Def::Macro(id, ..) |
Def::Existential(id) | Def::AssociatedExistential(id) | Def::ForeignTy(id) |
Def::SelfCtor(id) => {
id
Def::Existential(id) | Def::AssociatedExistential(id) | Def::ForeignTy(id) => {
Some(id)
}

Def::Local(..) |
Def::Upvar(..) |
Def::Label(..) |
Def::PrimTy(..) |
Def::SelfTy(..) |
Def::SelfCtor(..) |
Def::ToolMod |
Def::NonMacroAttr(..) |
Def::Err => {
bug!("attempted .def_id() on invalid def: {:?}", self)
None
}
}
}
Expand Down Expand Up @@ -333,4 +331,13 @@ impl Def {
Def::Err => "unresolved item",
}
}

pub fn article(&self) -> &'static str {
match *self {
Def::AssociatedTy(..) | Def::AssociatedConst(..) | Def::AssociatedExistential(..) |
Def::Enum(..) | Def::Existential(..) | Def::Err => "an",
Def::Macro(.., macro_kind) => macro_kind.article(),
_ => "a",
}
}
}
4 changes: 2 additions & 2 deletions src/librustc/hir/def_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ pub struct DefId {

impl fmt::Debug for DefId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "DefId({:?}/{}:{}",
self.krate.index(),
write!(f, "DefId({}/{}:{}",
self.krate,
self.index.address_space().index(),
self.index.as_array_index())?;

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/dead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
self.check_def_id(def.def_id());
}
_ if self.in_pat => (),
Def::PrimTy(..) | Def::SelfTy(..) |
Def::PrimTy(..) | Def::SelfTy(..) | Def::SelfCtor(..) |
Def::Local(..) | Def::Upvar(..) => {}
Def::Variant(variant_id) | Def::VariantCtor(variant_id, ..) => {
if let Some(enum_id) = self.tcx.parent_def_id(variant_id) {
Expand Down
6 changes: 2 additions & 4 deletions src/librustc/middle/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -781,10 +781,8 @@ impl<'a, 'tcx> Visitor<'tcx> for Checker<'a, 'tcx> {

fn visit_path(&mut self, path: &'tcx hir::Path, id: hir::HirId) {
let id = self.tcx.hir.hir_to_node_id(id);
match path.def {
Def::Local(..) | Def::Upvar(..) | Def::SelfCtor(..) |
Def::PrimTy(..) | Def::SelfTy(..) | Def::Err => {}
_ => self.tcx.check_stability(path.def.def_id(), Some(id), path.span)
if let Some(def_id) = path.def.opt_def_id() {
self.tcx.check_stability(def_id, Some(id), path.span)
}
intravisit::walk_path(self, path)
}
Expand Down
3 changes: 2 additions & 1 deletion src/librustc_mir/hair/pattern/check_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,8 @@ impl<'a, 'tcx> MatchVisitor<'a, 'tcx> {
let label_msg = match pat.node {
PatKind::Path(hir::QPath::Resolved(None, ref path))
if path.segments.len() == 1 && path.segments[0].args.is_none() => {
format!("interpreted as a {} pattern, not new variable", path.def.kind_name())
format!("interpreted as {} {} pattern, not new variable",
path.def.article(), path.def.kind_name())
}
_ => format!("pattern `{}` not covered", pattern_string),
};
Expand Down
8 changes: 5 additions & 3 deletions src/librustc_privacy/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,9 +361,11 @@ impl<'a, 'tcx> Visitor<'tcx> for EmbargoVisitor<'a, 'tcx> {
let def_id = self.tcx.hir.local_def_id(id);
if let Some(exports) = self.tcx.module_exports(def_id) {
for export in exports.iter() {
if let Some(node_id) = self.tcx.hir.as_local_node_id(export.def.def_id()) {
if export.vis == ty::Visibility::Public {
self.update(node_id, Some(AccessLevel::Exported));
if export.vis == ty::Visibility::Public {
if let Some(def_id) = export.def.opt_def_id() {
if let Some(node_id) = self.tcx.hir.as_local_node_id(def_id) {
self.update(node_id, Some(AccessLevel::Exported));
}
}
}
}
Expand Down
Loading