-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Remove redundant flags from lower_ty_common
that can be inferred from the HIR
#129519
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { | |
hir_id: hir::HirId, | ||
hir_trait_bounds: &[(hir::PolyTraitRef<'tcx>, hir::TraitBoundModifier)], | ||
lifetime: &hir::Lifetime, | ||
borrowed: bool, | ||
representation: DynKind, | ||
) -> Ty<'tcx> { | ||
let tcx = self.tcx(); | ||
|
@@ -325,22 +324,32 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { | |
v.dedup(); | ||
let existential_predicates = tcx.mk_poly_existential_predicates(&v); | ||
|
||
// Use explicitly-specified region bound. | ||
// Use explicitly-specified region bound, unless the bound is missing. | ||
let region_bound = if !lifetime.is_elided() { | ||
self.lower_lifetime(lifetime, RegionInferReason::ObjectLifetimeDefault) | ||
self.lower_lifetime(lifetime, RegionInferReason::ExplicitObjectLifetime) | ||
} else { | ||
self.compute_object_lifetime_bound(span, existential_predicates).unwrap_or_else(|| { | ||
// Curiously, we prefer object lifetime default for `+ '_`... | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Curious indeed. I'm gonna investigate this at some point) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think ironically that it's beneficial -- I tried preferring the explicit elided lifetime and it causes some outlives bounds to fail. |
||
if tcx.named_bound_var(lifetime.hir_id).is_some() { | ||
self.lower_lifetime(lifetime, RegionInferReason::ObjectLifetimeDefault) | ||
self.lower_lifetime(lifetime, RegionInferReason::ExplicitObjectLifetime) | ||
} else { | ||
self.re_infer( | ||
span, | ||
if borrowed { | ||
compiler-errors marked this conversation as resolved.
Show resolved
Hide resolved
|
||
RegionInferReason::ObjectLifetimeDefault | ||
let reason = | ||
if let hir::LifetimeName::ImplicitObjectLifetimeDefault = lifetime.res { | ||
if let hir::Node::Ty(hir::Ty { | ||
kind: hir::TyKind::Ref(parent_lifetime, _), | ||
.. | ||
}) = tcx.parent_hir_node(hir_id) | ||
&& tcx.named_bound_var(parent_lifetime.hir_id).is_none() | ||
{ | ||
// Parent lifetime must have failed to resolve. Don't emit a redundant error. | ||
RegionInferReason::ExplicitObjectLifetime | ||
} else { | ||
RegionInferReason::ObjectLifetimeDefault | ||
} | ||
} else { | ||
RegionInferReason::BorrowedObjectLifetimeDefault | ||
}, | ||
) | ||
RegionInferReason::ExplicitObjectLifetime | ||
}; | ||
self.re_infer(span, reason) | ||
} | ||
}) | ||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
//@ edition: 2021 | ||
|
||
trait Trait {} | ||
|
||
impl dyn Trait { | ||
const CONST: () = (); | ||
} | ||
|
||
fn main() { | ||
match () { | ||
Trait::CONST => {} | ||
//~^ ERROR trait objects must include the `dyn` keyword | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
error[E0782]: trait objects must include the `dyn` keyword | ||
--> $DIR/suggest-dyn-on-bare-trait-in-pat.rs:11:9 | ||
| | ||
LL | Trait::CONST => {} | ||
| ^^^^^ | ||
| | ||
help: add `dyn` keyword before this trait | ||
| | ||
LL | <dyn Trait>::CONST => {} | ||
| ++++ + | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0782`. |
Uh oh!
There was an error while loading. Please reload this page.