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

Skip to content
Closed
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
30fc601
Tests for field is never read diagnostic
sunjay Mar 11, 2021
321aace
Added suggestion and note for when a field is never used
sunjay Mar 12, 2021
7faaf39
Updating test stderr files
sunjay Mar 12, 2021
789186d
Trying out a new message that works a little better for values *and* …
sunjay Mar 12, 2021
2acd8eb
New shorter diagnostic note that is different for items versus fields
sunjay Mar 13, 2021
3e34eb8
Putting help message only under the identifier that needs to be prefixed
sunjay Mar 25, 2021
539242a
Add a suggestion when using a type alias instead of trait alias
JohnTitor Mar 31, 2021
eea27b8
Mention trait alias on the E0404 note
JohnTitor Mar 31, 2021
115e216
Rename AssociatedItems to AssocItems
0xPoe Apr 24, 2020
6c3f5b8
resolve conflicts
0xPoe Apr 5, 2021
7efba4f
Implement indexing slices with pairs of ops::Bound<usize>
AnthonyMikh Oct 8, 2020
904ee68
Explicitly implement `!Send` and `!Sync` for `sys::{Args, Env}`
CDirkx Apr 14, 2021
2ecc820
Correct typos
CDirkx Apr 14, 2021
98a11e0
Remove closure_tree
camsteffen Apr 19, 2021
c9c14d0
Small refactor
camsteffen Apr 19, 2021
a10d01b
Uses flex to fix formatting of h1 at any width.
Apr 20, 2021
ba3d22e
Precompute inverse binder depth
jackh726 Apr 12, 2021
32942ab
A non-minimal set of TraitRefBoundarys to work on removing from_poly_…
jackh726 Apr 12, 2021
457c4c1
Add BinderScopeType to replace binder_depth and from_poly_trait_ref
jackh726 Apr 13, 2021
9891582
Remove TraitRefHackInner and use the concatenating functionality inst…
jackh726 Apr 20, 2021
4568e7d
Move nested quantification check to ast_validation
jackh726 Apr 21, 2021
259a368
fix name resolution for param defaults
lcnr Apr 18, 2021
7cb1dcd
loosen ordering restricts for `const_generics_defaults`
lcnr Apr 18, 2021
312b4fd
improve wf check for const param defaults
lcnr Apr 18, 2021
d3e0d2f
supply substs to anon consts in defaults
lcnr Apr 18, 2021
de2a460
rustc: Use LLVM's new saturating float-to-int intrinsics
alexcrichton Apr 19, 2021
e34f7e6
Update LLVM submodule
Amanieu Apr 21, 2021
b78c0d8
Review comments
jackh726 Apr 21, 2021
eb9b0f6
Move `sys_common::rwlock::StaticRWLock` etc. to `sys::unix::rwlock`
CDirkx Apr 21, 2021
c78724f
More review changes
jackh726 Apr 21, 2021
bb91805
Replaced flex gap with margin, for compatibility with older browsers.
Apr 21, 2021
6763a40
Bump slice_index_with_ops_bound_pair to 1.53.0
m-ou-se Apr 21, 2021
134b79c
Rollup merge of #71511 - hi-rustin:rustin-patch-rename-assoc, r=eddyb…
Dylan-DPC Apr 22, 2021
1961911
Rollup merge of #77704 - AnthonyMikh:slice_index_with_ops_bound_pair,…
Dylan-DPC Apr 22, 2021
78cb13a
Rollup merge of #83004 - sunjay:field-never-read-issue-81658, r=pnkfelix
Dylan-DPC Apr 22, 2021
8d1e9f2
Rollup merge of #83729 - JohnTitor:issue-43913, r=estebank
Dylan-DPC Apr 22, 2021
4753698
Rollup merge of #84179 - CDirkx:dont_send_sync, r=m-ou-se
Dylan-DPC Apr 22, 2021
29c2464
Rollup merge of #84299 - lcnr:const-generics-defaults-name-res, r=varkor
Dylan-DPC Apr 22, 2021
f82badd
Rollup merge of #84339 - alexcrichton:llvm-fptoint-sat, r=nagisa
Dylan-DPC Apr 22, 2021
0210f83
Rollup merge of #84343 - camsteffen:closure-tree, r=varkor
Dylan-DPC Apr 22, 2021
3d1b81c
Rollup merge of #84376 - torhovland:issue-84534, r=GuillaumeGomez
Dylan-DPC Apr 22, 2021
c5494aa
Rollup merge of #84377 - jackh726:binder-refactor-fix, r=nikomatsakis
Dylan-DPC Apr 22, 2021
c978584
Rollup merge of #84396 - Amanieu:fix_compiler_builtins_llvm, r=cuviper
Dylan-DPC Apr 22, 2021
1476eb9
Rollup merge of #84402 - CDirkx:rwlock, r=dtolnay
Dylan-DPC Apr 22, 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
Prev Previous commit
Next Next commit
More review changes
  • Loading branch information
jackh726 committed Apr 21, 2021
commit c78724f869add98e0f2af8950f760a37ec35243b
144 changes: 59 additions & 85 deletions compiler/rustc_resolve/src/late/lifetimes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,8 @@ enum Scope<'a> {

#[derive(Copy, Clone, Debug)]
enum BinderScopeType {
/// In a syntactic trait ref, this represents the outermost binder. So, if
/// you had `T: for<'a> Foo<Bar: for<'b> Baz<'a, 'b>>`, then the `for<'a>`
/// scope uses `PolyTraitRef`.
PolyTraitRef,
/// Any non-concatenating binder scopes.
Normal,
/// Within a syntactic trait ref, there may be multiple poly trait refs that
/// are nested (under the `associcated_type_bounds` feature). The binders of
/// the innner poly trait refs are extended from the outer poly trait refs
Expand All @@ -288,10 +286,6 @@ enum BinderScopeType {
/// out any lifetimes because they aren't needed to show the two scopes).
/// The inner `for<>` has a scope of `Concatenating`.
Concatenating,
/// Any other binder scopes. These are "normal" in that they increase the binder
/// depth, are fully syntactic, don't concatenate, and don't have special syntactical
/// considerations.
Other,
}

// A helper struct for debugging scopes without printing parent scopes
Expand Down Expand Up @@ -573,6 +567,43 @@ fn late_region_as_bound_region<'tcx>(tcx: TyCtxt<'tcx>, region: &Region) -> ty::
}
}

impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
/// Returns the binders in scope and the type of `Binder` that should be created for a poly trait ref.
fn poly_trait_ref_binder_info(&mut self) -> (Vec<ty::BoundVariableKind>, BinderScopeType) {
let mut scope = self.scope;
let mut supertrait_lifetimes = vec![];
loop {
match scope {
Scope::Body { .. } | Scope::Root => {
break (vec![], BinderScopeType::Normal);
}

Scope::Elision { s, .. } | Scope::ObjectLifetimeDefault { s, .. } => {
scope = s;
}

Scope::Supertrait { s, lifetimes } => {
supertrait_lifetimes = lifetimes.clone();
scope = s;
}

Scope::TraitRefBoundary { .. } => {
// We should only see super trait lifetimes if there is a `Binder` above
assert!(supertrait_lifetimes.is_empty());
break (vec![], BinderScopeType::Normal);
}

Scope::Binder { hir_id, .. } => {
// Nested poly trait refs have the binders concatenated
let mut full_binders =
self.map.late_bound_vars.entry(*hir_id).or_default().clone();
full_binders.extend(supertrait_lifetimes.into_iter());
break (full_binders, BinderScopeType::Concatenating);
}
}
}
}
}
impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
type Map = Map<'tcx>;

Expand Down Expand Up @@ -630,7 +661,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
s: self.scope,
track_lifetime_uses: true,
opaque_type_parent: false,
scope_type: BinderScopeType::Other,
scope_type: BinderScopeType::Normal,
};
self.with(scope, move |_old_scope, this| {
intravisit::walk_fn(this, fk, fd, b, s, hir_id)
Expand Down Expand Up @@ -755,7 +786,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
next_early_index: index + non_lifetime_count,
opaque_type_parent: true,
track_lifetime_uses,
scope_type: BinderScopeType::Other,
scope_type: BinderScopeType::Normal,
s: ROOT_SCOPE,
};
self.with(scope, |old_scope, this| {
Expand Down Expand Up @@ -827,7 +858,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
next_early_index,
track_lifetime_uses: true,
opaque_type_parent: false,
scope_type: BinderScopeType::Other,
scope_type: BinderScopeType::Normal,
};
self.with(scope, |old_scope, this| {
// a bare fn has no bounds, so everything
Expand Down Expand Up @@ -1023,7 +1054,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
s: this.scope,
track_lifetime_uses: true,
opaque_type_parent: false,
scope_type: BinderScopeType::Other,
scope_type: BinderScopeType::Normal,
};
this.with(scope, |_old_scope, this| {
this.visit_generics(generics);
Expand All @@ -1043,7 +1074,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
s: self.scope,
track_lifetime_uses: true,
opaque_type_parent: false,
scope_type: BinderScopeType::Other,
scope_type: BinderScopeType::Normal,
};
self.with(scope, |_old_scope, this| {
let scope = Scope::TraitRefBoundary { s: this.scope };
Expand Down Expand Up @@ -1102,7 +1133,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
s: self.scope,
track_lifetime_uses: true,
opaque_type_parent: true,
scope_type: BinderScopeType::Other,
scope_type: BinderScopeType::Normal,
};
self.with(scope, |old_scope, this| {
this.check_lifetime_params(old_scope, &generics.params);
Expand Down Expand Up @@ -1171,7 +1202,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
s: self.scope,
track_lifetime_uses: true,
opaque_type_parent: true,
scope_type: BinderScopeType::Other,
scope_type: BinderScopeType::Normal,
};
self.with(scope, |old_scope, this| {
this.check_lifetime_params(old_scope, &generics.params);
Expand Down Expand Up @@ -1287,7 +1318,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
next_early_index,
track_lifetime_uses: true,
opaque_type_parent: false,
scope_type: BinderScopeType::PolyTraitRef,
scope_type: BinderScopeType::Normal,
};
this.with(scope, |old_scope, this| {
this.check_lifetime_params(old_scope, &bound_generic_params);
Expand Down Expand Up @@ -1317,32 +1348,15 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
}

fn visit_param_bound(&mut self, bound: &'tcx hir::GenericBound<'tcx>) {
// FIXME(jackh726): This is pretty weird. `LangItemTrait` doesn't go
// through the regular poly trait ref code, so we don't get another
// chance to introduce a binder. For now, I'm keeping the existing logic
// of "if there isn't a Binder scope above us, add one", but I
// imagine there's a better way to go about this.
let mut scope = self.scope;
let (binders, scope_type) = loop {
match scope {
Scope::TraitRefBoundary { .. } | Scope::Body { .. } | Scope::Root => {
break (vec![], BinderScopeType::PolyTraitRef);
}

Scope::Binder { hir_id, .. } => {
let binders = self.map.late_bound_vars.entry(*hir_id).or_default().clone();
break (binders, BinderScopeType::Concatenating);
}

Scope::Elision { s, .. }
| Scope::ObjectLifetimeDefault { s, .. }
| Scope::Supertrait { s, .. } => {
scope = s;
}
}
};
match bound {
hir::GenericBound::LangItemTrait(_, _, hir_id, _) => {
// FIXME(jackh726): This is pretty weird. `LangItemTrait` doesn't go
// through the regular poly trait ref code, so we don't get another
// chance to introduce a binder. For now, I'm keeping the existing logic
// of "if there isn't a Binder scope above us, add one", but I
// imagine there's a better way to go about this.
let (binders, scope_type) = self.poly_trait_ref_binder_info();

self.map.late_bound_vars.insert(*hir_id, binders);
let scope = Scope::Binder {
hir_id: *hir_id,
Expand Down Expand Up @@ -1371,44 +1385,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
let should_pop_missing_lt = self.is_trait_ref_fn_scope(trait_ref);

let next_early_index = self.next_early_index();
let mut scope = self.scope;
let mut supertrait_lifetimes = vec![];
let (mut binders, scope_type) = loop {
match scope {
Scope::Body { .. } | Scope::Root => {
break (vec![], BinderScopeType::PolyTraitRef);
}

Scope::Elision { s, .. } | Scope::ObjectLifetimeDefault { s, .. } => {
scope = s;
}

Scope::Supertrait { s, lifetimes } => {
supertrait_lifetimes = lifetimes.clone();
scope = s;
}

Scope::TraitRefBoundary { .. } => {
// We should only see super trait lifetimes if there is a `Binder` above
assert!(supertrait_lifetimes.is_empty());
break (vec![], BinderScopeType::PolyTraitRef);
}

Scope::Binder { hir_id, scope_type, .. } => {
if let BinderScopeType::Other = scope_type {
bug!(
"Expected all syntacic poly trait refs to be surrounded by a `TraitRefBoundary`"
)
}

// Nested poly trait refs have the binders concatenated
let mut full_binders =
self.map.late_bound_vars.entry(*hir_id).or_default().clone();
full_binders.extend(supertrait_lifetimes.into_iter());
break (full_binders, BinderScopeType::Concatenating);
}
}
};
let (mut binders, scope_type) = self.poly_trait_ref_binder_info();

let initial_bound_vars = binders.len() as u32;
let mut lifetimes: FxHashMap<hir::ParamName, Region> = FxHashMap::default();
Expand Down Expand Up @@ -2185,7 +2162,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
s: self.scope,
opaque_type_parent: true,
track_lifetime_uses: false,
scope_type: BinderScopeType::Other,
scope_type: BinderScopeType::Normal,
};
self.with(scope, move |old_scope, this| {
this.check_lifetime_params(old_scope, &generics.params);
Expand Down Expand Up @@ -2270,8 +2247,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
_ => bug!("expected LifetimeName::Param"),
}
match scope_type {
BinderScopeType::Other => late_depth += 1,
BinderScopeType::PolyTraitRef => late_depth += 1,
BinderScopeType::Normal => late_depth += 1,
BinderScopeType::Concatenating => {}
}
scope = s;
Expand Down Expand Up @@ -3001,8 +2977,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
}
}
match scope_type {
BinderScopeType::Other => late_depth += 1,
BinderScopeType::PolyTraitRef => late_depth += 1,
BinderScopeType::Normal => late_depth += 1,
BinderScopeType::Concatenating => {}
}
scope = s;
Expand Down Expand Up @@ -3165,8 +3140,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
match *scope {
Scope::Binder { s, scope_type, .. } => {
match scope_type {
BinderScopeType::Other => late_depth += 1,
BinderScopeType::PolyTraitRef => late_depth += 1,
BinderScopeType::Normal => late_depth += 1,
BinderScopeType::Concatenating => {}
}
scope = s;
Expand Down