Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
bd7be36
Allow lifetime elision in `Pin<&(mut) Self>`
taiki-e May 26, 2019
a9a50bc
Remove query for `.pin_type()`
taiki-e May 27, 2019
0bc8878
Make is_self_ty a method on SelfVisitor
taiki-e May 29, 2019
3be8422
Use Set1<Region> instead of Option<Region>
taiki-e May 29, 2019
76794f1
add a bevy of new test cases
nikomatsakis Jun 28, 2019
6018c46
Update src/test/ui/self/elision/README.md
taiki-e Jul 15, 2019
78d2129
Add main functions and check-pass annotations
taiki-e Jul 15, 2019
044d4bb
Minor clean up
taiki-e Jul 15, 2019
d79d13f
Add test for multiple ref-self
taiki-e Jul 15, 2019
44bf6b6
tests: Add minimal reproduction of #61963.
davidtwco Jul 20, 2019
4242206
Re-enable assertions in PPC dist builder
mati865 Jul 19, 2019
c7a599e
bump crossbeam-epoch dependency
RalfJung Jul 25, 2019
eb4fbda
Simplify save-analysis JSON dumper interface
Mark-Simulacrum Jul 25, 2019
68c0ba2
Rename JsonDumper to Dumper
Mark-Simulacrum Jul 25, 2019
7369c17
Add tests for `self: (&)AssocType`
taiki-e Jul 26, 2019
e995523
Break dependencies between `syntax_ext` and some other crates
petrochenkov Jul 17, 2019
a0fb9c9
Move proc macro server into libsyntax
petrochenkov Jul 18, 2019
11137c6
Move test harness generation into libsyntax_ext
petrochenkov Jul 18, 2019
0c0ddcd
Move standard library injection into libsyntax_ext
petrochenkov Jul 18, 2019
0a24e28
syntax_ext: `proc_macro_decls` -> `proc_macro_harness`
petrochenkov Jul 18, 2019
d7b2110
add repr(transparent) to IoSliceMut where missing
nivkner Jul 26, 2019
cae8680
lowering: Omit bare trait lint on macro call sites
davidtwco Jul 26, 2019
7811ae8
Rollup merge of #61207 - taiki-e:arbitrary_self_types-lifetime-elisio…
Centril Jul 26, 2019
01d7e7a
Rollup merge of #62771 - petrochenkov:depext, r=eddyb
Centril Jul 26, 2019
394f049
Rollup merge of #62949 - mati865:patch-1, r=alexcrichton
Centril Jul 26, 2019
75d3a29
Rollup merge of #62974 - RalfJung:crossbeam, r=alexcrichton
Centril Jul 26, 2019
b3e2164
Rollup merge of #62979 - Mark-Simulacrum:json-dumper-pretty, r=Xanewok
Centril Jul 26, 2019
0ae4151
Rollup merge of #63013 - nivkner:ffi-safe-slice, r=sfackler
Centril Jul 26, 2019
f12327b
Rollup merge of #63014 - davidtwco:rustfix-incorrect-dyn-suggestion, …
Centril Jul 26, 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
Prev Previous commit
Next Next commit
Make is_self_ty a method on SelfVisitor
  • Loading branch information
taiki-e committed Jul 15, 2019
commit 0bc887864f0ba762bc5e64b612ea69d1e4cc35a1
67 changes: 35 additions & 32 deletions src/librustc/middle/resolve_lifetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2146,41 +2146,44 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
// First (determined here), if `self` is by-reference, then the
// implied output region is the region of the self parameter.
if has_self {
// Look for `self: &'a Self` - also desugared from `&'a self`,
// and if that matches, use it for elision and return early.
let is_self_ty = |res: Res| {
if let Res::SelfTy(..) = res {
return true;
}

// Can't always rely on literal (or implied) `Self` due
// to the way elision rules were originally specified.
let impl_self = impl_self.map(|ty| &ty.node);
if let Some(&hir::TyKind::Path(hir::QPath::Resolved(None, ref path))) = impl_self {
match path.res {
// Whitelist the types that unambiguously always
// result in the same type constructor being used
// (it can't differ between `Self` and `self`).
Res::Def(DefKind::Struct, _)
| Res::Def(DefKind::Union, _)
| Res::Def(DefKind::Enum, _)
| Res::PrimTy(_) => {
return res == path.res
}
_ => {}
struct SelfVisitor<'a> {
map: &'a NamedRegionMap,
impl_self: Option<&'a hir::TyKind>,
lifetime: Option<Region>,
}

impl SelfVisitor<'_> {
// Look for `self: &'a Self` - also desugared from `&'a self`,
// and if that matches, use it for elision and return early.
fn is_self_ty(&self, res: Res) -> bool {
if let Res::SelfTy(..) = res {
return true;
}
}

false
};
// Can't always rely on literal (or implied) `Self` due
// to the way elision rules were originally specified.
if let Some(&hir::TyKind::Path(hir::QPath::Resolved(None, ref path))) =
self.impl_self
{
match path.res {
// Whitelist the types that unambiguously always
// result in the same type constructor being used
// (it can't differ between `Self` and `self`).
Res::Def(DefKind::Struct, _)
| Res::Def(DefKind::Union, _)
| Res::Def(DefKind::Enum, _)
| Res::PrimTy(_) => {
return res == path.res
}
_ => {}
}
}

struct SelfVisitor<'a, F: FnMut(Res) -> bool> {
is_self_ty: F,
map: &'a NamedRegionMap,
lifetime: Option<Region>,
false
}
}

impl<'a, F: FnMut(Res) -> bool> Visitor<'a> for SelfVisitor<'a, F> {
impl<'a> Visitor<'a> for SelfVisitor<'a> {
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'a> {
NestedVisitorMap::None
}
Expand All @@ -2189,7 +2192,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
if let hir::TyKind::Rptr(lifetime_ref, ref mt) = ty.node {
if let hir::TyKind::Path(hir::QPath::Resolved(None, ref path)) = mt.ty.node
{
if (self.is_self_ty)(path.res) {
if self.is_self_ty(path.res) {
self.lifetime = self.map.defs.get(&lifetime_ref.hir_id).copied();
return;
}
Expand All @@ -2200,8 +2203,8 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
}

let mut visitor = SelfVisitor {
is_self_ty,
map: self.map,
impl_self: impl_self.map(|ty| &ty.node),
lifetime: None,
};
visitor.visit_ty(&inputs[0]);
Expand Down