Skip to content

Commit fe9babb

Browse files
authored
Rollup merge of rust-lang#73783 - estebank:impl-dyn-trait-static-lifetime, r=nikomatsakis
Detect when `'static` obligation might come from an `impl` Partly address rust-lang#71341.
2 parents bbebe73 + 889a4d9 commit fe9babb

File tree

60 files changed

+1301
-439
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1301
-439
lines changed

src/librustc_error_codes/error_codes.rs

+1
Original file line numberDiff line numberDiff line change
@@ -633,4 +633,5 @@ E0771: include_str!("./error_codes/E0771.md"),
633633
E0755, // `#[ffi_pure]` is only allowed on foreign functions
634634
E0756, // `#[ffi_const]` is only allowed on foreign functions
635635
E0757, // `#[ffi_const]` functions cannot be `#[ffi_pure]`
636+
E0772, // `'static' obligation coming from `impl dyn Trait {}` or `impl Foo for dyn Bar {}`.
636637
}

src/librustc_hir/hir.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -2198,7 +2198,17 @@ pub enum IsAsync {
21982198
NotAsync,
21992199
}
22002200

2201-
#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)]
2201+
#[derive(
2202+
Copy,
2203+
Clone,
2204+
PartialEq,
2205+
RustcEncodable,
2206+
RustcDecodable,
2207+
Debug,
2208+
HashStable_Generic,
2209+
Eq,
2210+
Hash
2211+
)]
22022212
pub enum Defaultness {
22032213
Default { has_value: bool },
22042214
Final,

src/librustc_infer/infer/combine.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,13 @@ use crate::traits::{Obligation, PredicateObligations};
3636

3737
use rustc_ast::ast;
3838
use rustc_hir::def_id::DefId;
39+
use rustc_middle::traits::ObligationCause;
3940
use rustc_middle::ty::error::TypeError;
4041
use rustc_middle::ty::relate::{self, Relate, RelateResult, TypeRelation};
4142
use rustc_middle::ty::subst::SubstsRef;
4243
use rustc_middle::ty::{self, InferConst, ToPredicate, Ty, TyCtxt, TypeFoldable};
4344
use rustc_middle::ty::{IntType, UintType};
44-
use rustc_span::{Span, DUMMY_SP};
45+
use rustc_span::DUMMY_SP;
4546

4647
#[derive(Clone)]
4748
pub struct CombineFields<'infcx, 'tcx> {
@@ -367,10 +368,11 @@ impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> {
367368
};
368369

369370
debug!("generalize: for_universe = {:?}", for_universe);
371+
debug!("generalize: trace = {:?}", self.trace);
370372

371373
let mut generalize = Generalizer {
372374
infcx: self.infcx,
373-
span: self.trace.cause.span,
375+
cause: &self.trace.cause,
374376
for_vid_sub_root: self.infcx.inner.borrow_mut().type_variables().sub_root_var(for_vid),
375377
for_universe,
376378
ambient_variance,
@@ -414,7 +416,7 @@ struct Generalizer<'cx, 'tcx> {
414416
infcx: &'cx InferCtxt<'cx, 'tcx>,
415417

416418
/// The span, used when creating new type variables and things.
417-
span: Span,
419+
cause: &'cx ObligationCause<'tcx>,
418420

419421
/// The vid of the type variable that is in the process of being
420422
/// instantiated; if we find this within the type we are folding,
@@ -639,7 +641,7 @@ impl TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
639641

640642
// FIXME: This is non-ideal because we don't give a
641643
// very descriptive origin for this region variable.
642-
Ok(self.infcx.next_region_var_in_universe(MiscVariable(self.span), self.for_universe))
644+
Ok(self.infcx.next_region_var_in_universe(MiscVariable(self.cause.span), self.for_universe))
643645
}
644646

645647
fn consts(

src/librustc_infer/infer/error_reporting/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2010,7 +2010,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
20102010
infer::MiscVariable(_) => String::new(),
20112011
infer::PatternRegion(_) => " for pattern".to_string(),
20122012
infer::AddrOfRegion(_) => " for borrow expression".to_string(),
2013-
infer::Autoref(_) => " for autoref".to_string(),
2013+
infer::Autoref(_, _) => " for autoref".to_string(),
20142014
infer::Coercion(_) => " for automatic coercion".to_string(),
20152015
infer::LateBoundRegion(_, br, infer::FnCall) => {
20162016
format!(" for lifetime parameter {}in function call", br_string(br))

0 commit comments

Comments
 (0)