branches:
- auto
- try
+ - try-perf
- master
pull_request:
branches:
CACHES_AWS_ACCESS_KEY_ID: AKIA46X5W6CZI5DHEBFL
ARTIFACTS_AWS_ACCESS_KEY_ID: AKIA46X5W6CZN24CBO55
CACHE_DOMAIN: ci-caches.rust-lang.org
- if: "github.event_name == 'push' && github.ref == 'refs/heads/try' && github.repository == 'rust-lang-ci/rust'"
+ if: "github.event_name == 'push' && (github.ref == 'refs/heads/try' || github.ref == 'refs/heads/try-perf') && github.repository == 'rust-lang-ci/rust'"
strategy:
matrix:
include:
try-success:
needs:
- try
- if: "success() && github.event_name == 'push' && github.ref == 'refs/heads/try' && github.repository == 'rust-lang-ci/rust'"
+ if: "success() && github.event_name == 'push' && (github.ref == 'refs/heads/try' || github.ref == 'refs/heads/try-perf') && github.repository == 'rust-lang-ci/rust'"
steps:
- name: mark the job as a success
run: exit 0
try-failure:
needs:
- try
- if: "!success() && github.event_name == 'push' && github.ref == 'refs/heads/try' && github.repository == 'rust-lang-ci/rust'"
+ if: "!success() && github.event_name == 'push' && (github.ref == 'refs/heads/try' || github.ref == 'refs/heads/try-perf') && github.repository == 'rust-lang-ci/rust'"
steps:
- name: mark the job as a failure
run: exit 1
[[package]]
name = "cc"
-version = "1.0.57"
+version = "1.0.58"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0fde55d2a2bfaa4c9668bbc63f531fbdeee3ffe188f4662511ce2c22b3eedebe"
+checksum = "f9a06fb2e53271d7c279ec1efea6ab691c35a2ae67ec0d91d7acec0caf13b518"
dependencies = [
"jobserver",
]
[[package]]
name = "libc"
-version = "0.2.71"
+version = "0.2.73"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9457b06509d27052635f90d6466700c65095fdf75409b3fbdd903e988b886f49"
+checksum = "bd7d4bd64732af4bf3a67f367c27df8520ad7e230c5817b8ff485864d80242b9"
dependencies = [
"rustc-std-workspace-core",
]
+use std::ffi::{OsStr, OsString};
+use std::fmt::Display;
use std::path::{Path, PathBuf};
use std::process::{Command, Stdio};
use std::time::{SystemTime, UNIX_EPOCH};
};
}
+/// Reads an environment variable and adds it to dependencies.
+/// Supposed to be used for all variables except those set for build scripts by cargo
+/// https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-build-scripts
+pub fn tracked_env_var_os<K: AsRef<OsStr> + Display>(key: K) -> Option<OsString> {
+ println!("cargo:rerun-if-env-changed={}", key);
+ env::var_os(key)
+}
+
// Because Cargo adds the compiler's dylib path to our library search path, llvm-config may
// break: the dylib path for the compiler, as of this writing, contains a copy of the LLVM
// shared library, which means that when our freshly built llvm-config goes to load it's
// perfect -- we might actually want to see something from Cargo's added library paths -- but
// for now it works.
pub fn restore_library_path() {
- println!("cargo:rerun-if-env-changed=REAL_LIBRARY_PATH_VAR");
- println!("cargo:rerun-if-env-changed=REAL_LIBRARY_PATH");
- let key = env::var_os("REAL_LIBRARY_PATH_VAR").expect("REAL_LIBRARY_PATH_VAR");
- if let Some(env) = env::var_os("REAL_LIBRARY_PATH") {
+ let key = tracked_env_var_os("REAL_LIBRARY_PATH_VAR").expect("REAL_LIBRARY_PATH_VAR");
+ if let Some(env) = tracked_env_var_os("REAL_LIBRARY_PATH") {
env::set_var(&key, &env);
} else {
env::remove_var(&key);
branches:
- auto
- try
+ - try-perf
- master
pull_request:
branches:
name: try
env:
<<: [*shared-ci-variables, *prod-variables]
- if: github.event_name == 'push' && github.ref == 'refs/heads/try' && github.repository == 'rust-lang-ci/rust'
+ if: github.event_name == 'push' && (github.ref == 'refs/heads/try' || github.ref == 'refs/heads/try-perf') && github.repository == 'rust-lang-ci/rust'
strategy:
matrix:
include:
# successful listening to webhooks only.
try-success:
needs: [try]
- if: "success() && github.event_name == 'push' && github.ref == 'refs/heads/try' && github.repository == 'rust-lang-ci/rust'"
+ if: "success() && github.event_name == 'push' && (github.ref == 'refs/heads/try' || github.ref == 'refs/heads/try-perf') && github.repository == 'rust-lang-ci/rust'"
<<: *base-success-job
try-failure:
needs: [try]
- if: "!success() && github.event_name == 'push' && github.ref == 'refs/heads/try' && github.repository == 'rust-lang-ci/rust'"
+ if: "!success() && github.event_name == 'push' && (github.ref == 'refs/heads/try' || github.ref == 'refs/heads/try-perf') && github.repository == 'rust-lang-ci/rust'"
<<: *base-failure-job
auto-success:
needs: [auto]
[package]
authors = ["The Rust Project Developers"]
-build = "build.rs"
name = "profiler_builtins"
version = "0.0.0"
edition = "2018"
let target = env::var("TARGET").expect("TARGET was not set");
let cfg = &mut cc::Build::new();
+ // FIXME: `rerun-if-changed` directives are not currently emitted and the build script
+ // will not rerun on changes in these source files or headers included into them.
let mut profile_sources = vec![
"GCDAProfiling.c",
"InstrProfiling.c",
+++ /dev/null
-fn main() {
- println!("cargo:rerun-if-changed=build.rs");
- println!("cargo:rerun-if-env-changed=CFG_RELEASE_CHANNEL");
- println!("cargo:rerun-if-env-changed=CFG_DISABLE_UNSTABLE_FEATURES");
-}
name = "rustc_attr"
version = "0.0.0"
edition = "2018"
-build = "build.rs"
[lib]
name = "rustc_attr"
+++ /dev/null
-fn main() {
- println!("cargo:rerun-if-changed=build.rs");
- println!("cargo:rerun-if-env-changed=CFG_RELEASE");
- println!("cargo:rerun-if-env-changed=CFG_RELEASE_CHANNEL");
-}
+++ /dev/null
-fn main() {
- println!("cargo:rerun-if-changed=build.rs");
- println!("cargo:rerun-if-env-changed=CFG_VERSION");
- println!("cargo:rerun-if-env-changed=CFG_PREFIX");
- println!("cargo:rerun-if-env-changed=CFG_LLVM_ROOT");
-}
}
// NO-OPT-OUT, OBJECT-FILES-NO, AUDIT-ORDER
- cmd.add_eh_frame_header();
+ if sess.target.target.options.eh_frame_header {
+ cmd.add_eh_frame_header();
+ }
// NO-OPT-OUT, OBJECT-FILES-NO
if crt_objects_fallback {
// Some versions of `gcc` add it implicitly, some (e.g. `musl-gcc`) don't,
// so we just always add it.
fn add_eh_frame_header(&mut self) {
- if !self.sess.target.target.options.is_like_osx
- && !self.sess.target.target.options.is_like_windows
- && !self.sess.target.target.options.is_like_solaris
- && self.sess.target.target.target_os != "uefi"
- {
- self.linker_arg("--eh-frame-hdr");
- }
+ self.linker_arg("--eh-frame-hdr");
}
}
+++ /dev/null
-fn main() {
- println!("cargo:rerun-if-changed=build.rs");
- println!("cargo:rerun-if-env-changed=CFG_RELEASE_CHANNEL");
-}
+++ /dev/null
-fn main() {
- println!("cargo:rerun-if-changed=build.rs");
- println!("cargo:rerun-if-env-changed=CFG_RELEASE");
- println!("cargo:rerun-if-env-changed=CFG_VERSION");
- println!("cargo:rerun-if-env-changed=CFG_VER_DATE");
- println!("cargo:rerun-if-env-changed=CFG_VER_HASH");
-}
E0755, // `#[ffi_pure]` is only allowed on foreign functions
E0756, // `#[ffi_const]` is only allowed on foreign functions
E0757, // `#[ffi_const]` functions cannot be `#[ffi_pure]`
+ E0772, // `'static' obligation coming from `impl dyn Trait {}` or `impl Foo for dyn Bar {}`.
}
/// Allows using subslice patterns, `[a, .., b]` and `[a, xs @ .., b]`.
(accepted, slice_patterns, "1.42.0", Some(62254), None),
/// Allows the use of `if` and `match` in constants.
- (accepted, const_if_match, "1.45.0", Some(49146), None),
+ (accepted, const_if_match, "1.46.0", Some(49146), None),
/// Allows the use of `loop` and `while` in constants.
- (accepted, const_loop, "1.45.0", Some(52000), None),
+ (accepted, const_loop, "1.46.0", Some(52000), None),
/// Allows `#[track_caller]` to be used which provides
/// accurate caller location reporting during panic (RFC 2091).
(accepted, track_caller, "1.46.0", Some(47809), None),
NotAsync,
}
-#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)]
+#[derive(
+ Copy,
+ Clone,
+ PartialEq,
+ RustcEncodable,
+ RustcDecodable,
+ Debug,
+ HashStable_Generic,
+ Eq,
+ Hash
+)]
pub enum Defaultness {
Default { has_value: bool },
Final,
+++ /dev/null
-fn main() {
- println!("cargo:rerun-if-changed=build.rs");
- println!("cargo:rerun-if-env-changed=CFG_VERSION");
-}
use rustc_ast::ast;
use rustc_hir::def_id::DefId;
+use rustc_middle::traits::ObligationCause;
use rustc_middle::ty::error::TypeError;
use rustc_middle::ty::relate::{self, Relate, RelateResult, TypeRelation};
use rustc_middle::ty::subst::SubstsRef;
use rustc_middle::ty::{self, InferConst, ToPredicate, Ty, TyCtxt, TypeFoldable};
use rustc_middle::ty::{IntType, UintType};
-use rustc_span::{Span, DUMMY_SP};
+use rustc_span::DUMMY_SP;
#[derive(Clone)]
pub struct CombineFields<'infcx, 'tcx> {
};
debug!("generalize: for_universe = {:?}", for_universe);
+ debug!("generalize: trace = {:?}", self.trace);
let mut generalize = Generalizer {
infcx: self.infcx,
- span: self.trace.cause.span,
+ cause: &self.trace.cause,
for_vid_sub_root: self.infcx.inner.borrow_mut().type_variables().sub_root_var(for_vid),
for_universe,
ambient_variance,
infcx: &'cx InferCtxt<'cx, 'tcx>,
/// The span, used when creating new type variables and things.
- span: Span,
+ cause: &'cx ObligationCause<'tcx>,
/// The vid of the type variable that is in the process of being
/// instantiated; if we find this within the type we are folding,
// FIXME: This is non-ideal because we don't give a
// very descriptive origin for this region variable.
- Ok(self.infcx.next_region_var_in_universe(MiscVariable(self.span), self.for_universe))
+ Ok(self.infcx.next_region_var_in_universe(MiscVariable(self.cause.span), self.for_universe))
}
fn consts(
infer::MiscVariable(_) => String::new(),
infer::PatternRegion(_) => " for pattern".to_string(),
infer::AddrOfRegion(_) => " for borrow expression".to_string(),
- infer::Autoref(_) => " for autoref".to_string(),
+ infer::Autoref(_, _) => " for autoref".to_string(),
infer::Coercion(_) => " for automatic coercion".to_string(),
infer::LateBoundRegion(_, br, infer::FnCall) => {
format!(" for lifetime parameter {}in function call", br_string(br))
use crate::infer::error_reporting::nice_region_error::NiceRegionError;
use crate::infer::lexical_region_resolve::RegionResolutionError;
-use rustc_errors::{struct_span_err, Applicability, ErrorReported};
-use rustc_hir::{GenericBound, ItemKind, Lifetime, LifetimeName, TyKind};
-use rustc_middle::ty::RegionKind;
+use crate::infer::{SubregionOrigin, TypeTrace};
+use crate::traits::{ObligationCauseCode, UnifyReceiverContext};
+use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder, ErrorReported};
+use rustc_hir::def_id::DefId;
+use rustc_hir::intravisit::{walk_ty, ErasedMap, NestedVisitorMap, Visitor};
+use rustc_hir::{
+ self as hir, GenericBound, ImplItem, Item, ItemKind, Lifetime, LifetimeName, Node, TraitItem,
+ TyKind,
+};
+use rustc_middle::ty::{self, AssocItemContainer, RegionKind, Ty, TypeFoldable, TypeVisitor};
+use rustc_span::symbol::Ident;
+use rustc_span::{MultiSpan, Span};
impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
- /// Print the error message for lifetime errors when the return type is a static impl Trait.
+ /// Print the error message for lifetime errors when the return type is a static `impl Trait`,
+ /// `dyn Trait` or if a method call on a trait object introduces a static requirement.
pub(super) fn try_report_static_impl_trait(&self) -> Option<ErrorReported> {
debug!("try_report_static_impl_trait(error={:?})", self.error);
- if let Some(RegionResolutionError::SubSupConflict(
- _,
- var_origin,
- ref sub_origin,
- sub_r,
- ref sup_origin,
- sup_r,
- )) = self.error
- {
- debug!(
- "try_report_static_impl_trait(var={:?}, sub={:?} {:?} sup={:?} {:?})",
- var_origin, sub_origin, sub_r, sup_origin, sup_r
- );
- let anon_reg_sup = self.tcx().is_suitable_region(sup_r)?;
- debug!("try_report_static_impl_trait: anon_reg_sup={:?}", anon_reg_sup);
- let fn_returns = self.tcx().return_type_impl_or_dyn_traits(anon_reg_sup.def_id);
- if fn_returns.is_empty() {
+ let tcx = self.tcx();
+ let (var_origin, sub_origin, sub_r, sup_origin, sup_r) = match self.error.as_ref()? {
+ RegionResolutionError::SubSupConflict(
+ _,
+ var_origin,
+ sub_origin,
+ sub_r,
+ sup_origin,
+ sup_r,
+ ) if **sub_r == RegionKind::ReStatic => {
+ (var_origin, sub_origin, sub_r, sup_origin, sup_r)
+ }
+ RegionResolutionError::ConcreteFailure(
+ SubregionOrigin::Subtype(box TypeTrace { cause, .. }),
+ sub_r,
+ sup_r,
+ ) if **sub_r == RegionKind::ReStatic => {
+ // This is for an implicit `'static` requirement coming from `impl dyn Trait {}`.
+ if let ObligationCauseCode::UnifyReceiver(ctxt) = &cause.code {
+ let param = self.find_param_with_region(sup_r, sub_r)?;
+ let lifetime = if sup_r.has_name() {
+ format!("lifetime `{}`", sup_r)
+ } else {
+ "an anonymous lifetime `'_`".to_string()
+ };
+ let mut err = struct_span_err!(
+ tcx.sess,
+ cause.span,
+ E0772,
+ "{} has {} but calling `{}` introduces an implicit `'static` lifetime \
+ requirement",
+ param
+ .param
+ .pat
+ .simple_ident()
+ .map(|s| format!("`{}`", s))
+ .unwrap_or_else(|| "`fn` parameter".to_string()),
+ lifetime,
+ ctxt.assoc_item.ident,
+ );
+ err.span_label(param.param_ty_span, &format!("this data with {}...", lifetime));
+ err.span_label(
+ cause.span,
+ &format!(
+ "...is captured and required to live as long as `'static` here \
+ because of an implicit lifetime bound on the {}",
+ match ctxt.assoc_item.container {
+ AssocItemContainer::TraitContainer(id) =>
+ format!("`impl` of `{}`", tcx.def_path_str(id)),
+ AssocItemContainer::ImplContainer(_) =>
+ "inherent `impl`".to_string(),
+ },
+ ),
+ );
+ if self.find_impl_on_dyn_trait(&mut err, param.param_ty, &ctxt) {
+ err.emit();
+ return Some(ErrorReported);
+ } else {
+ err.cancel();
+ }
+ }
return None;
}
- debug!("try_report_static_impl_trait: fn_return={:?}", fn_returns);
- if *sub_r == RegionKind::ReStatic {
- let sp = var_origin.span();
- let return_sp = sub_origin.span();
- let param_info = self.find_param_with_region(sup_r, sub_r)?;
- let (lifetime_name, lifetime) = if sup_r.has_name() {
- (sup_r.to_string(), format!("lifetime `{}`", sup_r))
- } else {
- ("'_".to_owned(), "an anonymous lifetime `'_`".to_string())
- };
- let mut err = struct_span_err!(
- self.tcx().sess,
- sp,
- E0759,
- "cannot infer an appropriate lifetime"
- );
+ _ => return None,
+ };
+ debug!(
+ "try_report_static_impl_trait(var={:?}, sub={:?} {:?} sup={:?} {:?})",
+ var_origin, sub_origin, sub_r, sup_origin, sup_r
+ );
+ let anon_reg_sup = tcx.is_suitable_region(sup_r)?;
+ debug!("try_report_static_impl_trait: anon_reg_sup={:?}", anon_reg_sup);
+ let sp = var_origin.span();
+ let return_sp = sub_origin.span();
+ let param = self.find_param_with_region(sup_r, sub_r)?;
+ let (lifetime_name, lifetime) = if sup_r.has_name() {
+ (sup_r.to_string(), format!("lifetime `{}`", sup_r))
+ } else {
+ ("'_".to_owned(), "an anonymous lifetime `'_`".to_string())
+ };
+ let param_name = param
+ .param
+ .pat
+ .simple_ident()
+ .map(|s| format!("`{}`", s))
+ .unwrap_or_else(|| "`fn` parameter".to_string());
+ let mut err = struct_span_err!(
+ tcx.sess,
+ sp,
+ E0759,
+ "{} has {} but it needs to satisfy a `'static` lifetime requirement",
+ param_name,
+ lifetime,
+ );
+ err.span_label(param.param_ty_span, &format!("this data with {}...", lifetime));
+ debug!("try_report_static_impl_trait: param_info={:?}", param);
+
+ // We try to make the output have fewer overlapping spans if possible.
+ if (sp == sup_origin.span() || !return_sp.overlaps(sup_origin.span()))
+ && sup_origin.span() != return_sp
+ {
+ // FIXME: account for `async fn` like in `async-await/issues/issue-62097.rs`
+
+ // Customize the spans and labels depending on their relative order so
+ // that split sentences flow correctly.
+ if sup_origin.span().overlaps(return_sp) && sp == sup_origin.span() {
+ // Avoid the following:
+ //
+ // error: cannot infer an appropriate lifetime
+ // --> $DIR/must_outlive_least_region_or_bound.rs:18:50
+ // |
+ // LL | fn foo(x: &i32) -> Box<dyn Debug> { Box::new(x) }
+ // | ---- ---------^-
+ //
+ // and instead show:
+ //
+ // error: cannot infer an appropriate lifetime
+ // --> $DIR/must_outlive_least_region_or_bound.rs:18:50
+ // |
+ // LL | fn foo(x: &i32) -> Box<dyn Debug> { Box::new(x) }
+ // | ---- ^
err.span_label(
- param_info.param_ty_span,
- &format!("this data with {}...", lifetime),
+ sup_origin.span(),
+ "...is captured here, requiring it to live as long as `'static`",
);
- debug!("try_report_static_impl_trait: param_info={:?}", param_info);
+ } else {
+ err.span_label(sup_origin.span(), "...is captured here...");
+ if return_sp < sup_origin.span() {
+ err.span_note(
+ return_sp,
+ "...and is required to live as long as `'static` here",
+ );
+ } else {
+ err.span_label(
+ return_sp,
+ "...and is required to live as long as `'static` here",
+ );
+ }
+ }
+ } else {
+ err.span_label(
+ return_sp,
+ "...is captured and required to live as long as `'static` here",
+ );
+ }
+
+ let fn_returns = tcx.return_type_impl_or_dyn_traits(anon_reg_sup.def_id);
- // We try to make the output have fewer overlapping spans if possible.
- if (sp == sup_origin.span() || !return_sp.overlaps(sup_origin.span()))
- && sup_origin.span() != return_sp
+ let mut override_error_code = None;
+ if let SubregionOrigin::Subtype(box TypeTrace { cause, .. }) = &sup_origin {
+ if let ObligationCauseCode::UnifyReceiver(ctxt) = &cause.code {
+ // Handle case of `impl Foo for dyn Bar { fn qux(&self) {} }` introducing a
+ // `'static` lifetime when called as a method on a binding: `bar.qux()`.
+ if self.find_impl_on_dyn_trait(&mut err, param.param_ty, &ctxt) {
+ override_error_code = Some(ctxt.assoc_item.ident);
+ }
+ }
+ }
+ if let SubregionOrigin::Subtype(box TypeTrace { cause, .. }) = &sub_origin {
+ if let ObligationCauseCode::ItemObligation(item_def_id) = cause.code {
+ // Same case of `impl Foo for dyn Bar { fn qux(&self) {} }` introducing a `'static`
+ // lifetime as above, but called using a fully-qualified path to the method:
+ // `Foo::qux(bar)`.
+ let mut v = TraitObjectVisitor(vec![]);
+ v.visit_ty(param.param_ty);
+ if let Some((ident, self_ty)) =
+ self.get_impl_ident_and_self_ty_from_trait(item_def_id, &v.0[..])
{
- // FIXME: account for `async fn` like in `async-await/issues/issue-62097.rs`
-
- // Customize the spans and labels depending on their relative order so
- // that split sentences flow correctly.
- if sup_origin.span().overlaps(return_sp) && sp == sup_origin.span() {
- // Avoid the following:
- //
- // error: cannot infer an appropriate lifetime
- // --> $DIR/must_outlive_least_region_or_bound.rs:18:50
- // |
- // LL | fn foo(x: &i32) -> Box<dyn Debug> { Box::new(x) }
- // | ---- ---------^-
- //
- // and instead show:
- //
- // error: cannot infer an appropriate lifetime
- // --> $DIR/must_outlive_least_region_or_bound.rs:18:50
- // |
- // LL | fn foo(x: &i32) -> Box<dyn Debug> { Box::new(x) }
- // | ---- ^
- err.span_label(
- sup_origin.span(),
- "...is captured here, requiring it to live as long as `'static`",
+ if self.suggest_constrain_dyn_trait_in_impl(&mut err, &v.0[..], ident, self_ty)
+ {
+ override_error_code = Some(ident);
+ }
+ }
+ }
+ }
+ if let (Some(ident), true) = (override_error_code, fn_returns.is_empty()) {
+ // Provide a more targetted error code and description.
+ err.code(rustc_errors::error_code!(E0772));
+ err.set_primary_message(&format!(
+ "{} has {} but calling `{}` introduces an implicit `'static` lifetime \
+ requirement",
+ param_name, lifetime, ident,
+ ));
+ }
+
+ debug!("try_report_static_impl_trait: fn_return={:?}", fn_returns);
+ // FIXME: account for the need of parens in `&(dyn Trait + '_)`
+ let consider = "consider changing the";
+ let declare = "to declare that the";
+ let arg = match param.param.pat.simple_ident() {
+ Some(simple_ident) => format!("argument `{}`", simple_ident),
+ None => "the argument".to_string(),
+ };
+ let explicit = format!("you can add an explicit `{}` lifetime bound", lifetime_name);
+ let explicit_static = format!("explicit `'static` bound to the lifetime of {}", arg);
+ let captures = format!("captures data from {}", arg);
+ let add_static_bound = "alternatively, add an explicit `'static` bound to this reference";
+ let plus_lt = format!(" + {}", lifetime_name);
+ for fn_return in fn_returns {
+ if fn_return.span.desugaring_kind().is_some() {
+ // Skip `async` desugaring `impl Future`.
+ continue;
+ }
+ match fn_return.kind {
+ TyKind::OpaqueDef(item_id, _) => {
+ let item = tcx.hir().item(item_id.id);
+ let opaque = if let ItemKind::OpaqueTy(opaque) = &item.kind {
+ opaque
+ } else {
+ err.emit();
+ return Some(ErrorReported);
+ };
+
+ if let Some(span) = opaque
+ .bounds
+ .iter()
+ .filter_map(|arg| match arg {
+ GenericBound::Outlives(Lifetime {
+ name: LifetimeName::Static,
+ span,
+ ..
+ }) => Some(*span),
+ _ => None,
+ })
+ .next()
+ {
+ err.span_suggestion_verbose(
+ span,
+ &format!("{} `impl Trait`'s {}", consider, explicit_static),
+ lifetime_name.clone(),
+ Applicability::MaybeIncorrect,
+ );
+ err.span_suggestion_verbose(
+ param.param_ty_span,
+ add_static_bound,
+ param.param_ty.to_string(),
+ Applicability::MaybeIncorrect,
);
+ } else if let Some(_) = opaque
+ .bounds
+ .iter()
+ .filter_map(|arg| match arg {
+ GenericBound::Outlives(Lifetime { name, span, .. })
+ if name.ident().to_string() == lifetime_name =>
+ {
+ Some(*span)
+ }
+ _ => None,
+ })
+ .next()
+ {
} else {
- err.span_label(sup_origin.span(), "...is captured here...");
- if return_sp < sup_origin.span() {
- err.span_note(
- return_sp,
- "...and is required to live as long as `'static` here",
- );
- } else {
- err.span_label(
- return_sp,
- "...and is required to live as long as `'static` here",
- );
- }
+ err.span_suggestion_verbose(
+ fn_return.span.shrink_to_hi(),
+ &format!(
+ "{declare} `impl Trait` {captures}, {explicit}",
+ declare = declare,
+ captures = captures,
+ explicit = explicit,
+ ),
+ plus_lt.clone(),
+ Applicability::MaybeIncorrect,
+ );
}
- } else {
- err.span_label(
- return_sp,
- "...is captured and required to live as long as `'static` here",
- );
}
+ TyKind::TraitObject(_, lt) => match lt.name {
+ LifetimeName::ImplicitObjectLifetimeDefault => {
+ err.span_suggestion_verbose(
+ fn_return.span.shrink_to_hi(),
+ &format!(
+ "{declare} trait object {captures}, {explicit}",
+ declare = declare,
+ captures = captures,
+ explicit = explicit,
+ ),
+ plus_lt.clone(),
+ Applicability::MaybeIncorrect,
+ );
+ }
+ name if name.ident().to_string() != lifetime_name => {
+ // With this check we avoid suggesting redundant bounds. This
+ // would happen if there are nested impl/dyn traits and only
+ // one of them has the bound we'd suggest already there, like
+ // in `impl Foo<X = dyn Bar> + '_`.
+ err.span_suggestion_verbose(
+ lt.span,
+ &format!("{} trait object's {}", consider, explicit_static),
+ lifetime_name.clone(),
+ Applicability::MaybeIncorrect,
+ );
+ err.span_suggestion_verbose(
+ param.param_ty_span,
+ add_static_bound,
+ param.param_ty.to_string(),
+ Applicability::MaybeIncorrect,
+ );
+ }
+ _ => {}
+ },
+ _ => {}
+ }
+ }
+ err.emit();
+ Some(ErrorReported)
+ }
- // FIXME: account for the need of parens in `&(dyn Trait + '_)`
- let consider = "consider changing the";
- let declare = "to declare that the";
- let arg = match param_info.param.pat.simple_ident() {
- Some(simple_ident) => format!("argument `{}`", simple_ident),
- None => "the argument".to_string(),
- };
- let explicit =
- format!("you can add an explicit `{}` lifetime bound", lifetime_name);
- let explicit_static =
- format!("explicit `'static` bound to the lifetime of {}", arg);
- let captures = format!("captures data from {}", arg);
- let add_static_bound =
- "alternatively, add an explicit `'static` bound to this reference";
- let plus_lt = format!(" + {}", lifetime_name);
- for fn_return in fn_returns {
- if fn_return.span.desugaring_kind().is_some() {
- // Skip `async` desugaring `impl Future`.
- continue;
+ fn get_impl_ident_and_self_ty_from_trait(
+ &self,
+ def_id: DefId,
+ trait_objects: &[DefId],
+ ) -> Option<(Ident, &'tcx hir::Ty<'tcx>)> {
+ let tcx = self.tcx();
+ match tcx.hir().get_if_local(def_id) {
+ Some(Node::ImplItem(ImplItem { ident, hir_id, .. })) => {
+ match tcx.hir().find(tcx.hir().get_parent_item(*hir_id)) {
+ Some(Node::Item(Item { kind: ItemKind::Impl { self_ty, .. }, .. })) => {
+ Some((*ident, self_ty))
}
- match fn_return.kind {
- TyKind::OpaqueDef(item_id, _) => {
- let item = self.tcx().hir().item(item_id.id);
- let opaque = if let ItemKind::OpaqueTy(opaque) = &item.kind {
- opaque
- } else {
- err.emit();
- return Some(ErrorReported);
- };
-
- if let Some(span) = opaque
- .bounds
- .iter()
- .filter_map(|arg| match arg {
- GenericBound::Outlives(Lifetime {
- name: LifetimeName::Static,
- span,
+ _ => None,
+ }
+ }
+ Some(Node::TraitItem(TraitItem { ident, hir_id, .. })) => {
+ let parent_id = tcx.hir().get_parent_item(*hir_id);
+ match tcx.hir().find(parent_id) {
+ Some(Node::Item(Item { kind: ItemKind::Trait(..), .. })) => {
+ // The method being called is defined in the `trait`, but the `'static`
+ // obligation comes from the `impl`. Find that `impl` so that we can point
+ // at it in the suggestion.
+ let trait_did = tcx.hir().local_def_id(parent_id).to_def_id();
+ match tcx
+ .hir()
+ .trait_impls(trait_did)
+ .iter()
+ .filter_map(|impl_node| {
+ let impl_did = tcx.hir().local_def_id(*impl_node);
+ match tcx.hir().get_if_local(impl_did.to_def_id()) {
+ Some(Node::Item(Item {
+ kind: ItemKind::Impl { self_ty, .. },
..
- }) => Some(*span),
- _ => None,
- })
- .next()
- {
- err.span_suggestion_verbose(
- span,
- &format!("{} `impl Trait`'s {}", consider, explicit_static),
- lifetime_name.clone(),
- Applicability::MaybeIncorrect,
- );
- err.span_suggestion_verbose(
- param_info.param_ty_span,
- add_static_bound,
- param_info.param_ty.to_string(),
- Applicability::MaybeIncorrect,
- );
- } else if let Some(_) = opaque
- .bounds
- .iter()
- .filter_map(|arg| match arg {
- GenericBound::Outlives(Lifetime { name, span, .. })
- if name.ident().to_string() == lifetime_name =>
+ })) if trait_objects.iter().all(|did| {
+ // FIXME: we should check `self_ty` against the receiver
+ // type in the `UnifyReceiver` context, but for now, use
+ // this imperfect proxy. This will fail if there are
+ // multiple `impl`s for the same trait like
+ // `impl Foo for Box<dyn Bar>` and `impl Foo for dyn Bar`.
+ // In that case, only the first one will get suggestions.
+ let mut hir_v = HirTraitObjectVisitor(vec![], *did);
+ hir_v.visit_ty(self_ty);
+ !hir_v.0.is_empty()
+ }) =>
{
- Some(*span)
+ Some(self_ty)
}
_ => None,
- })
- .next()
- {
- } else {
- err.span_suggestion_verbose(
- fn_return.span.shrink_to_hi(),
- &format!(
- "{declare} `impl Trait` {captures}, {explicit}",
- declare = declare,
- captures = captures,
- explicit = explicit,
- ),
- plus_lt.clone(),
- Applicability::MaybeIncorrect,
- );
- }
+ }
+ })
+ .next()
+ {
+ Some(self_ty) => Some((*ident, self_ty)),
+ _ => None,
}
- TyKind::TraitObject(_, lt) => match lt.name {
- LifetimeName::ImplicitObjectLifetimeDefault => {
- err.span_suggestion_verbose(
- fn_return.span.shrink_to_hi(),
- &format!(
- "{declare} trait object {captures}, {explicit}",
- declare = declare,
- captures = captures,
- explicit = explicit,
- ),
- plus_lt.clone(),
- Applicability::MaybeIncorrect,
- );
- }
- name if name.ident().to_string() != lifetime_name => {
- // With this check we avoid suggesting redundant bounds. This
- // would happen if there are nested impl/dyn traits and only
- // one of them has the bound we'd suggest already there, like
- // in `impl Foo<X = dyn Bar> + '_`.
- err.span_suggestion_verbose(
- lt.span,
- &format!("{} trait object's {}", consider, explicit_static),
- lifetime_name.clone(),
- Applicability::MaybeIncorrect,
- );
- err.span_suggestion_verbose(
- param_info.param_ty_span,
- add_static_bound,
- param_info.param_ty.to_string(),
- Applicability::MaybeIncorrect,
- );
- }
- _ => {}
- },
- _ => {}
+ }
+ _ => None,
+ }
+ }
+ _ => None,
+ }
+ }
+
+ /// When we call a method coming from an `impl Foo for dyn Bar`, `dyn Bar` introduces a default
+ /// `'static` obligation. Suggest relaxing that implicit bound.
+ fn find_impl_on_dyn_trait(
+ &self,
+ err: &mut DiagnosticBuilder<'_>,
+ ty: Ty<'_>,
+ ctxt: &UnifyReceiverContext<'tcx>,
+ ) -> bool {
+ let tcx = self.tcx();
+
+ // Find the method being called.
+ let instance = match ty::Instance::resolve(
+ tcx,
+ ctxt.param_env,
+ ctxt.assoc_item.def_id,
+ self.infcx.resolve_vars_if_possible(&ctxt.substs),
+ ) {
+ Ok(Some(instance)) => instance,
+ _ => return false,
+ };
+
+ let mut v = TraitObjectVisitor(vec![]);
+ v.visit_ty(ty);
+
+ // Get the `Ident` of the method being called and the corresponding `impl` (to point at
+ // `Bar` in `impl Foo for dyn Bar {}` and the definition of the method being called).
+ let (ident, self_ty) =
+ match self.get_impl_ident_and_self_ty_from_trait(instance.def_id(), &v.0[..]) {
+ Some((ident, self_ty)) => (ident, self_ty),
+ None => return false,
+ };
+
+ // Find the trait object types in the argument, so we point at *only* the trait object.
+ self.suggest_constrain_dyn_trait_in_impl(err, &v.0[..], ident, self_ty)
+ }
+
+ fn suggest_constrain_dyn_trait_in_impl(
+ &self,
+ err: &mut DiagnosticBuilder<'_>,
+ found_dids: &[DefId],
+ ident: Ident,
+ self_ty: &hir::Ty<'_>,
+ ) -> bool {
+ let mut suggested = false;
+ for found_did in found_dids {
+ let mut hir_v = HirTraitObjectVisitor(vec![], *found_did);
+ hir_v.visit_ty(&self_ty);
+ for span in &hir_v.0 {
+ let mut multi_span: MultiSpan = vec![*span].into();
+ multi_span.push_span_label(
+ *span,
+ "this has an implicit `'static` lifetime requirement".to_string(),
+ );
+ multi_span.push_span_label(
+ ident.span,
+ "calling this method introduces the `impl`'s 'static` requirement".to_string(),
+ );
+ err.span_note(multi_span, "the used `impl` has a `'static` requirement");
+ err.span_suggestion_verbose(
+ span.shrink_to_hi(),
+ "consider relaxing the implicit `'static` requirement",
+ " + '_".to_string(),
+ Applicability::MaybeIncorrect,
+ );
+ suggested = true;
+ }
+ }
+ suggested
+ }
+}
+
+/// Collect all the trait objects in a type that could have received an implicit `'static` lifetime.
+struct TraitObjectVisitor(Vec<DefId>);
+
+impl TypeVisitor<'_> for TraitObjectVisitor {
+ fn visit_ty(&mut self, t: Ty<'_>) -> bool {
+ match t.kind {
+ ty::Dynamic(preds, RegionKind::ReStatic) => {
+ if let Some(def_id) = preds.principal_def_id() {
+ self.0.push(def_id);
+ }
+ false
+ }
+ _ => t.super_visit_with(self),
+ }
+ }
+}
+
+/// Collect all `hir::Ty<'_>` `Span`s for trait objects with an implicit lifetime.
+struct HirTraitObjectVisitor(Vec<Span>, DefId);
+
+impl<'tcx> Visitor<'tcx> for HirTraitObjectVisitor {
+ type Map = ErasedMap<'tcx>;
+
+ fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map> {
+ NestedVisitorMap::None
+ }
+
+ fn visit_ty(&mut self, t: &'tcx hir::Ty<'tcx>) {
+ match t.kind {
+ TyKind::TraitObject(
+ poly_trait_refs,
+ Lifetime { name: LifetimeName::ImplicitObjectLifetimeDefault, .. },
+ ) => {
+ for ptr in poly_trait_refs {
+ if Some(self.1) == ptr.trait_ref.trait_def_id() {
+ self.0.push(ptr.span);
}
}
- err.emit();
- return Some(ErrorReported);
}
+ _ => {}
}
- None
+ walk_ty(self, t);
}
}
use rustc_middle::ty::{self, DefIdTree, Region, Ty};
use rustc_span::Span;
-// The struct contains the information about the anonymous region
-// we are searching for.
+/// Information about the anonymous region we are searching for.
#[derive(Debug)]
pub(super) struct AnonymousParamInfo<'tcx> {
- // the parameter corresponding to the anonymous region
+ /// The parameter corresponding to the anonymous region.
pub param: &'tcx hir::Param<'tcx>,
- // the type corresponding to the anonymopus region parameter
+ /// The type corresponding to the anonymous region parameter.
pub param_ty: Ty<'tcx>,
- // the ty::BoundRegion corresponding to the anonymous region
+ /// The ty::BoundRegion corresponding to the anonymous region.
pub bound_region: ty::BoundRegion,
- // param_ty_span contains span of parameter type
+ /// The `Span` of the parameter type.
pub param_ty_span: Span,
- // corresponds to id the argument is the first parameter
- // in the declaration
+ /// Signals that the argument is the first parameter in the declaration.
pub is_first: bool,
}
AddrOfRegion(Span),
/// Regions created as part of an autoref of a method receiver
- Autoref(Span),
+ Autoref(Span, ty::AssocItem),
/// Regions created as part of an automatic coercion
Coercion(Span),
impl RegionVariableOrigin {
pub fn span(&self) -> Span {
match *self {
- MiscVariable(a) => a,
- PatternRegion(a) => a,
- AddrOfRegion(a) => a,
- Autoref(a) => a,
- Coercion(a) => a,
- EarlyBoundRegion(a, ..) => a,
- LateBoundRegion(a, ..) => a,
+ MiscVariable(a)
+ | PatternRegion(a)
+ | AddrOfRegion(a)
+ | Autoref(a, _)
+ | Coercion(a)
+ | EarlyBoundRegion(a, ..)
+ | LateBoundRegion(a, ..)
+ | UpvarRegion(_, a) => a,
BoundRegionInCoherence(_) => rustc_span::DUMMY_SP,
- UpvarRegion(_, a) => a,
NLL(..) => bug!("NLL variable used with `span`"),
}
}
//! This API is completely unstable and subject to change.
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/")]
+#![feature(bindings_after_at)]
#![feature(bool_to_option)]
#![feature(box_patterns)]
#![feature(box_syntax)]
+++ /dev/null
-fn main() {
- println!("cargo:rerun-if-changed=build.rs");
- println!("cargo:rerun-if-env-changed=RUSTC_INSTALL_BINDIR");
-}
authors = ["The Rust Project Developers"]
name = "rustc_llvm"
version = "0.0.0"
-build = "build.rs"
edition = "2018"
[lib]
emscripten = []
[dependencies]
-libc = "0.2"
+libc = "0.2.73"
[build-dependencies]
build_helper = { path = "../build_helper" }
-cc = "1.0.1"
+cc = "1.0.58"
use std::path::{Path, PathBuf};
use std::process::Command;
-use build_helper::output;
+use build_helper::{output, tracked_env_var_os};
fn detect_llvm_link() -> (&'static str, &'static str) {
// Force the link mode we want, preferring static by default, but
// possibly overridden by `configure --enable-llvm-link-shared`.
- if env::var_os("LLVM_LINK_SHARED").is_some() {
+ if tracked_env_var_os("LLVM_LINK_SHARED").is_some() {
("dylib", "--link-shared")
} else {
("static", "--link-static")
}
fn main() {
- println!("cargo:rerun-if-env-changed=RUST_CHECK");
- if env::var_os("RUST_CHECK").is_some() {
+ if tracked_env_var_os("RUST_CHECK").is_some() {
// If we're just running `check`, there's no need for LLVM to be built.
return;
}
let target = env::var("TARGET").expect("TARGET was not set");
let llvm_config =
- env::var_os("LLVM_CONFIG").map(|x| Some(PathBuf::from(x))).unwrap_or_else(|| {
- if let Some(dir) = env::var_os("CARGO_TARGET_DIR").map(PathBuf::from) {
+ tracked_env_var_os("LLVM_CONFIG").map(|x| Some(PathBuf::from(x))).unwrap_or_else(|| {
+ if let Some(dir) = tracked_env_var_os("CARGO_TARGET_DIR").map(PathBuf::from) {
let to_test = dir
.parent()
.unwrap()
}
let llvm_config = llvm_config.unwrap_or_else(|| PathBuf::from("llvm-config"));
- println!("cargo:rerun-if-env-changed=LLVM_CONFIG");
-
// Test whether we're cross-compiling LLVM. This is a pretty rare case
// currently where we're producing an LLVM for a different platform than
// what this build script is currently running on.
cfg.define(&flag, None);
}
- println!("cargo:rerun-if-changed-env=LLVM_RUSTLLVM");
- if env::var_os("LLVM_RUSTLLVM").is_some() {
+ if tracked_env_var_os("LLVM_RUSTLLVM").is_some() {
cfg.define("LLVM_RUSTLLVM", None);
}
- if env::var_os("LLVM_NDEBUG").is_some() {
+ if tracked_env_var_os("LLVM_NDEBUG").is_some() {
cfg.define("NDEBUG", None);
cfg.debug(false);
}
// librustc_llvm, for example when using static libc++, we may need to
// manually specify the library search path and -ldl -lpthread as link
// dependencies.
- let llvm_linker_flags = env::var_os("LLVM_LINKER_FLAGS");
+ let llvm_linker_flags = tracked_env_var_os("LLVM_LINKER_FLAGS");
if let Some(s) = llvm_linker_flags {
for lib in s.into_string().unwrap().split_whitespace() {
if lib.starts_with("-l") {
}
}
- let llvm_static_stdcpp = env::var_os("LLVM_STATIC_STDCPP");
- let llvm_use_libcxx = env::var_os("LLVM_USE_LIBCXX");
+ let llvm_static_stdcpp = tracked_env_var_os("LLVM_STATIC_STDCPP");
+ let llvm_use_libcxx = tracked_env_var_os("LLVM_USE_LIBCXX");
let stdcppname = if target.contains("openbsd") {
if target.contains("sparc64") { "estdc++" } else { "c++" }
+++ /dev/null
-fn main() {
- println!("cargo:rerun-if-changed=build.rs");
- println!("cargo:rerun-if-env-changed=CFG_VERSION");
- println!("cargo:rerun-if-env-changed=CFG_VIRTUAL_RUST_SOURCE_BASE_DIR");
-}
+++ /dev/null
-use std::env;
-
-fn main() {
- println!("cargo:rerun-if-changed=build.rs");
- println!("cargo:rerun-if-env-changed=CFG_LIBDIR_RELATIVE");
- println!("cargo:rerun-if-env-changed=CFG_COMPILER_HOST_TRIPLE");
- println!("cargo:rerun-if-env-changed=RUSTC_VERIFY_LLVM_IR");
-
- if env::var_os("RUSTC_VERIFY_LLVM_IR").is_some() {
- println!("cargo:rustc-cfg=always_verify_llvm_ir");
- }
-}
}
}
+#[derive(Clone, Debug, PartialEq, Eq, Hash)]
+pub struct UnifyReceiverContext<'tcx> {
+ pub assoc_item: ty::AssocItem,
+ pub param_env: ty::ParamEnv<'tcx>,
+ pub substs: SubstsRef<'tcx>,
+}
+
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub enum ObligationCauseCode<'tcx> {
/// Not well classified or should be obvious from the span.
/// Method receiver
MethodReceiver,
+ UnifyReceiver(Box<UnifyReceiverContext<'tcx>>),
+
/// `return` with no expression
ReturnNoExpression,
super::StartFunctionType => Some(super::StartFunctionType),
super::IntrinsicType => Some(super::IntrinsicType),
super::MethodReceiver => Some(super::MethodReceiver),
+ super::UnifyReceiver(ref ctxt) => tcx.lift(ctxt).map(|ctxt| super::UnifyReceiver(ctxt)),
super::BlockTailExpression(id) => Some(super::BlockTailExpression(id)),
super::TrivialBound => Some(super::TrivialBound),
}
}
}
+impl<'a, 'tcx> Lift<'tcx> for traits::UnifyReceiverContext<'a> {
+ type Lifted = traits::UnifyReceiverContext<'tcx>;
+ fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
+ tcx.lift(&self.param_env).and_then(|param_env| {
+ tcx.lift(&self.substs).map(|substs| traits::UnifyReceiverContext {
+ assoc_item: self.assoc_item,
+ param_env,
+ substs,
+ })
+ })
+ }
+}
+
impl<'a, 'tcx> Lift<'tcx> for traits::DerivedObligationCause<'a> {
type Lifted = traits::DerivedObligationCause<'tcx>;
fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
pub extern_prelude: FxHashMap<Symbol, bool>,
}
-#[derive(Clone, Copy, PartialEq, Eq, Debug, HashStable)]
+#[derive(Clone, Copy, PartialEq, Eq, Debug, HashStable, Hash)]
pub enum AssocItemContainer {
TraitContainer(DefId),
ImplContainer(DefId),
Reservation,
}
-#[derive(Copy, Clone, Debug, PartialEq, HashStable)]
+#[derive(Copy, Clone, Debug, PartialEq, HashStable, Eq, Hash)]
pub struct AssocItem {
pub def_id: DefId,
#[stable_hasher(project(name))]
pub fn_has_self_parameter: bool,
}
-#[derive(Copy, Clone, PartialEq, Debug, HashStable)]
+#[derive(Copy, Clone, PartialEq, Debug, HashStable, Eq, Hash)]
pub enum AssocKind {
Const,
Fn,
}
}
-#[derive(Clone, Debug, PartialEq, Eq, Copy, RustcEncodable, RustcDecodable, HashStable)]
+#[derive(Clone, Debug, PartialEq, Eq, Copy, RustcEncodable, RustcDecodable, HashStable, Hash)]
pub enum Visibility {
/// Visible everywhere (including in other crates).
Public,
};
use rustc_middle::ty;
use rustc_middle::ty::subst::SubstsRef;
-use rustc_middle::ty::{Ty, TyCtxt};
+use rustc_middle::ty::{Ty, TyCtxt, TypeFoldable};
use rustc_span::symbol::{sym, Symbol};
use rustc_target::abi::{Abi, LayoutOf as _, Primitive, Size};
let name = tcx.item_name(def_id);
Ok(match name {
sym::type_name => {
+ if tp_ty.needs_subst() {
+ throw_inval!(TooGeneric);
+ }
let alloc = type_name::alloc_type_name(tcx, tp_ty);
ConstValue::Slice { data: alloc, start: 0, end: alloc.len() }
}
};
ConstValue::from_machine_usize(n, &tcx)
}
- sym::type_id => ConstValue::from_u64(tcx.type_id_hash(tp_ty)),
+ sym::type_id => {
+ if tp_ty.needs_subst() {
+ throw_inval!(TooGeneric);
+ }
+ ConstValue::from_u64(tcx.type_id_hash(tp_ty))
+ }
sym::variant_count => {
if let ty::Adt(ref adt, _) = tp_ty.kind {
ConstValue::from_machine_usize(adt.variants.len() as u64, &tcx)
self.opts.debugging_opts.asm_comments
}
pub fn verify_llvm_ir(&self) -> bool {
- self.opts.debugging_opts.verify_llvm_ir || cfg!(always_verify_llvm_ir)
+ self.opts.debugging_opts.verify_llvm_ir || option_env!("RUSTC_VERIFY_LLVM_IR").is_some()
}
pub fn borrowck_stats(&self) -> bool {
self.opts.debugging_opts.borrowck_stats
+++ /dev/null
-fn main() {
- println!("cargo:rerun-if-changed=build.rs");
- println!("cargo:rerun-if-env-changed=CFG_DEFAULT_LINKER");
-}
--- /dev/null
+use crate::spec::{LinkerFlavor, Target, TargetOptions, TargetResult};
+
+pub fn target() -> TargetResult {
+ let mut base = super::apple_base::opts();
+ base.cpu = "apple-a12".to_string();
+ base.max_atomic_width = Some(128);
+ base.pre_link_args.insert(LinkerFlavor::Gcc, vec!["-arch".to_string(), "arm64".to_string()]);
+
+ base.link_env_remove.extend(super::apple_base::macos_link_env_remove());
+
+ // Clang automatically chooses a more specific target based on
+ // MACOSX_DEPLOYMENT_TARGET. To enable cross-language LTO to work
+ // correctly, we do too.
+ let arch = "aarch64";
+ let llvm_target = super::apple_base::macos_llvm_target(&arch);
+
+ Ok(Target {
+ llvm_target,
+ target_endian: "little".to_string(),
+ target_pointer_width: "64".to_string(),
+ target_c_int_width: "32".to_string(),
+ data_layout: "e-m:o-i64:64-i128:128-n32:64-S128".to_string(),
+ arch: arch.to_string(),
+ target_os: "macos".to_string(),
+ target_env: String::new(),
+ target_vendor: "apple".to_string(),
+ linker_flavor: LinkerFlavor::Gcc,
+ options: TargetOptions { target_mcount: "\u{1}mcount".to_string(), ..base },
+ })
+}
has_elf_tls: version >= (10, 7),
abi_return_struct_as_int: true,
emit_debug_gdb_scripts: false,
+ eh_frame_header: false,
// This environment variable is pretty magical but is intended for
// producing deterministic builds. This was first discovered to be used
has_rpath: false,
pre_link_args: args,
position_independent_executables: false,
+ eh_frame_header: false,
..Default::default()
}
}
is_like_solaris: true,
limit_rdylib_exports: false, // Linker doesn't support this
eliminate_frame_pointer: false,
+ eh_frame_header: false,
late_link_args,
// While we support ELF TLS, rust requires a way to register
("i686-unknown-haiku", i686_unknown_haiku),
("x86_64-unknown-haiku", x86_64_unknown_haiku),
+ ("aarch64-apple-darwin", aarch64_apple_darwin),
("x86_64-apple-darwin", x86_64_apple_darwin),
("i686-apple-darwin", i686_apple_darwin),
/// Whether to use legacy .ctors initialization hooks rather than .init_array. Defaults
/// to false (uses .init_array).
pub use_ctors_section: bool,
+
+ /// Whether the linker is instructed to add a `GNU_EH_FRAME` ELF header
+ /// used to locate unwinding information is passed
+ /// (only has effect if the linker is `ld`-like).
+ pub eh_frame_header: bool,
}
impl Default for TargetOptions {
relax_elf_relocations: false,
llvm_args: vec![],
use_ctors_section: false,
+ eh_frame_header: true,
}
}
}
key!(relax_elf_relocations, bool);
key!(llvm_args, list);
key!(use_ctors_section, bool);
+ key!(eh_frame_header, bool);
// NB: The old name is deprecated, but support for it is retained for
// compatibility.
target_option_val!(relax_elf_relocations);
target_option_val!(llvm_args);
target_option_val!(use_ctors_section);
+ target_option_val!(eh_frame_header);
if default.unsupported_abis != self.options.unsupported_abis {
d.insert(
// See the thumb_base.rs file for an explanation of this value
emit_debug_gdb_scripts: false,
+ eh_frame_header: false,
+
..Default::default()
},
})
relocation_model: RelocModel::Static,
emit_debug_gdb_scripts: false,
unsupported_abis: super::riscv_base::unsupported_abis(),
+ eh_frame_header: false,
..Default::default()
},
})
relocation_model: RelocModel::Static,
emit_debug_gdb_scripts: false,
unsupported_abis: super::riscv_base::unsupported_abis(),
+ eh_frame_header: false,
..Default::default()
},
})
relocation_model: RelocModel::Static,
emit_debug_gdb_scripts: false,
unsupported_abis: super::riscv_base::unsupported_abis(),
+ eh_frame_header: false,
..Default::default()
},
})
code_model: Some(CodeModel::Medium),
emit_debug_gdb_scripts: false,
unsupported_abis: super::riscv_base::unsupported_abis(),
+ eh_frame_header: false,
..Default::default()
},
})
code_model: Some(CodeModel::Medium),
emit_debug_gdb_scripts: false,
unsupported_abis: super::riscv_base::unsupported_abis(),
+ eh_frame_header: false,
..Default::default()
},
})
target_family: Some("unix".to_string()),
is_like_solaris: true,
limit_rdylib_exports: false, // Linker doesn't support this
+ eh_frame_header: false,
..Default::default()
}
abi_return_struct_as_int: true,
emit_debug_gdb_scripts: false,
requires_uwtable: true,
+ eh_frame_header: false,
..Default::default()
}
base.cpu = "core2".to_string();
base.max_atomic_width = Some(128); // core2 support cmpxchg16b
base.eliminate_frame_pointer = false;
- base.pre_link_args.insert(LinkerFlavor::Gcc, vec!["-m64".to_string()]);
+ base.pre_link_args.insert(
+ LinkerFlavor::Gcc,
+ vec!["-m64".to_string(), "-arch".to_string(), "x86_64".to_string()],
+ );
base.link_env_remove.extend(super::apple_base::macos_link_env_remove());
base.stack_probes = true;
use crate::infer::{InferCtxt, TyCtxtInferExt};
use crate::traits::{
FulfillmentContext, ImplSource, Obligation, ObligationCause, SelectionContext, TraitEngine,
+ Unimplemented,
};
use rustc_errors::ErrorReported;
use rustc_middle::ty::fold::TypeFoldable;
);
return Err(ErrorReported);
}
+ Err(Unimplemented) => {
+ // This can trigger when we probe for the source of a `'static` lifetime requirement
+ // on a trait object: `impl Foo for dyn Trait {}` has an implicit `'static` bound.
+ infcx.tcx.sess.delay_span_bug(
+ rustc_span::DUMMY_SP,
+ &format!(
+ "Encountered error `Unimplemented` selecting `{:?}` during codegen",
+ trait_ref
+ ),
+ );
+ return Err(ErrorReported);
+ }
Err(e) => {
bug!("Encountered error `{:?}` selecting `{:?}` during codegen", e, trait_ref)
}
| ObligationCauseCode::IntrinsicType
| ObligationCauseCode::MethodReceiver
| ObligationCauseCode::ReturnNoExpression
+ | ObligationCauseCode::UnifyReceiver(..)
| ObligationCauseCode::MiscObligation => {}
ObligationCauseCode::SliceOrArrayElem => {
err.note("slice and array elements must have `Sized` type");
use crate::hir::GenericArg;
use rustc_hir as hir;
use rustc_infer::infer::{self, InferOk};
+use rustc_middle::traits::{ObligationCauseCode, UnifyReceiverContext};
use rustc_middle::ty::adjustment::{Adjust, Adjustment, PointerCast};
use rustc_middle::ty::adjustment::{AllowTwoPhase, AutoBorrow, AutoBorrowMutability};
use rustc_middle::ty::fold::TypeFoldable;
// signature (which is also done during probing).
let method_sig_rcvr =
self.normalize_associated_types_in(self.span, &method_sig.inputs()[0]);
- self.unify_receivers(self_ty, method_sig_rcvr);
+ debug!(
+ "confirm: self_ty={:?} method_sig_rcvr={:?} method_sig={:?} method_predicates={:?}",
+ self_ty, method_sig_rcvr, method_sig, method_predicates
+ );
+ self.unify_receivers(self_ty, method_sig_rcvr, &pick, all_substs);
let (method_sig, method_predicates) =
self.normalize_associated_types_in(self.span, &(method_sig, method_predicates));
self.structurally_resolved_type(autoderef.span(), autoderef.final_ty(false));
if let Some(mutbl) = pick.autoref {
- let region = self.next_region_var(infer::Autoref(self.span));
+ let region = self.next_region_var(infer::Autoref(self.span, pick.item));
target = self.tcx.mk_ref(region, ty::TypeAndMut { mutbl, ty: target });
let mutbl = match mutbl {
hir::Mutability::Not => AutoBorrowMutability::Not,
)
}
- fn unify_receivers(&mut self, self_ty: Ty<'tcx>, method_self_ty: Ty<'tcx>) {
- match self.at(&self.misc(self.span), self.param_env).sup(method_self_ty, self_ty) {
+ fn unify_receivers(
+ &mut self,
+ self_ty: Ty<'tcx>,
+ method_self_ty: Ty<'tcx>,
+ pick: &probe::Pick<'tcx>,
+ substs: SubstsRef<'tcx>,
+ ) {
+ debug!(
+ "unify_receivers: self_ty={:?} method_self_ty={:?} span={:?} pick={:?}",
+ self_ty, method_self_ty, self.span, pick
+ );
+ let cause = self.cause(
+ self.span,
+ ObligationCauseCode::UnifyReceiver(Box::new(UnifyReceiverContext {
+ assoc_item: pick.item,
+ param_env: self.param_env,
+ substs,
+ })),
+ );
+ match self.at(&cause, self.param_env).sup(method_self_ty, self_ty) {
Ok(InferOk { obligations, value: () }) => {
self.register_predicates(obligations);
}
placeholder_type_error(tcx, None, &[], visitor.0, false);
}
- hir::TraitItemKind::Type(_, None) => {}
+ hir::TraitItemKind::Type(_, None) => {
+ // #74612: Visit and try to find bad placeholders
+ // even if there is no concrete type.
+ let mut visitor = PlaceholderHirTyCollector::default();
+ visitor.visit_trait_item(trait_item);
+ placeholder_type_error(tcx, None, &[], visitor.0, false);
+ }
};
tcx.ensure().predicates_of(def_id);
item.attrs.links.push((ori_link, None, fragment));
} else {
debug!("intra-doc link to {} resolved to {:?}", path_str, res);
- if let Some(local) = res.opt_def_id().and_then(|def_id| def_id.as_local()) {
+
+ // item can be non-local e.g. when using #[doc(primitive = "pointer")]
+ if let Some((src_id, dst_id)) = res
+ .opt_def_id()
+ .and_then(|def_id| def_id.as_local())
+ .and_then(|dst_id| item.def_id.as_local().map(|src_id| (src_id, dst_id)))
+ {
use rustc_hir::def_id::LOCAL_CRATE;
- let hir_id = self.cx.tcx.hir().as_local_hir_id(local);
- if !self.cx.tcx.privacy_access_levels(LOCAL_CRATE).is_exported(hir_id)
- && (item.visibility == Visibility::Public)
- && !self.cx.render_options.document_private
+ let hir_src = self.cx.tcx.hir().as_local_hir_id(src_id);
+ let hir_dst = self.cx.tcx.hir().as_local_hir_id(dst_id);
+
+ if self.cx.tcx.privacy_access_levels(LOCAL_CRATE).is_exported(hir_src)
+ && !self.cx.tcx.privacy_access_levels(LOCAL_CRATE).is_exported(hir_dst)
{
privacy_error(cx, &item, &path_str, &dox, link_range);
continue;
if let Some(sp) = sp {
diag.span_label(sp, "this item is private");
}
+
+ let note_msg = if cx.render_options.document_private {
+ "this link resolves only because you passed `--document-private-items`, but will break without"
+ } else {
+ "this link will resolve properly if you pass `--document-private-items`"
+ };
+ diag.note(note_msg);
});
}
authors = ["The Rust Project Developers"]
name = "std"
version = "0.0.0"
-build = "build.rs"
license = "MIT OR Apache-2.0"
repository = "https://github.com/rust-lang/rust.git"
description = "The Rust Standard Library"
use std::env;
fn main() {
+ println!("cargo:rerun-if-changed=build.rs");
let target = env::var("TARGET").expect("TARGET was not set");
if target.contains("linux") {
if target.contains("android") {
authors = ["The Rust Project Developers"]
name = "unwind"
version = "0.0.0"
-build = "build.rs"
edition = "2018"
include = [
'/libunwind/*',
--- /dev/null
+warning: public documentation for `DocMe` links to private item `DontDocMe`
+ --> $DIR/intra-links-private.rs:5:11
+ |
+LL | /// docs [DontDocMe]
+ | ^^^^^^^^^ this item is private
+ |
+ = note: `#[warn(intra_doc_link_resolution_failure)]` on by default
+ = note: this link resolves only because you passed `--document-private-items`, but will break without
+
+warning: 1 warning emitted
+
warning: public documentation for `DocMe` links to private item `DontDocMe`
- --> $DIR/intra-links-private.rs:6:11
+ --> $DIR/intra-links-private.rs:5:11
|
LL | /// docs [DontDocMe]
| ^^^^^^^^^ this item is private
|
= note: `#[warn(intra_doc_link_resolution_failure)]` on by default
+ = note: this link will resolve properly if you pass `--document-private-items`
warning: 1 warning emitted
// check-pass
// revisions: public private
// [private]compile-flags: --document-private-items
-#![cfg_attr(private, deny(intra_doc_link_resolution_failure))]
/// docs [DontDocMe]
-//[public]~^ WARNING public documentation for `DocMe` links to private item `DontDocMe`
+//~^ WARNING public documentation for `DocMe` links to private item `DontDocMe`
// FIXME: for [private] we should also make sure the link was actually generated
pub struct DocMe;
struct DontDocMe;
--- /dev/null
+warning: public documentation for `public_item` links to private item `PrivateType`
+ --> $DIR/issue-74134.rs:19:10
+ |
+LL | /// [`PrivateType`]
+ | ^^^^^^^^^^^^^ this item is private
+ |
+ = note: `#[warn(intra_doc_link_resolution_failure)]` on by default
+ = note: this link resolves only because you passed `--document-private-items`, but will break without
+
+warning: 1 warning emitted
+
| ^^^^^^^^^^^^^ this item is private
|
= note: `#[warn(intra_doc_link_resolution_failure)]` on by default
+ = note: this link will resolve properly if you pass `--document-private-items`
warning: 1 warning emitted
// There are 4 cases here:
// 1. public item -> public type: no warning
-// 2. public item -> private type: warning, if --document-private-items is not passed
+// 2. public item -> private type: warning
// 3. private item -> public type: no warning
// 4. private item -> private type: no warning
// All 4 cases are tested with and without --document-private-items.
pub struct Public {
/// [`PublicType`]
/// [`PrivateType`]
- //[public]~^ WARNING public documentation for `public_item` links to private item `PrivateType`
+ //~^ WARNING public documentation for `public_item` links to private item `PrivateType`
pub public_item: u32,
/// [`PublicType`]
#[cfg(transmute)] // one instantiations: BAD
fn baz<'a,'b>(x: &'a u32) -> &'static u32 {
- bar(foo, x) //[transmute]~ ERROR E0495
+ bar(foo, x) //[transmute]~ ERROR E0759
}
#[cfg(krisskross)] // two instantiations, mixing and matching: BAD
-error[E0495]: cannot infer an appropriate lifetime due to conflicting requirements
+error[E0759]: `x` has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement
--> $DIR/project-fn-ret-contravariant.rs:38:8
|
-LL | bar(foo, x)
- | ^^^
- |
-note: first, the lifetime cannot outlive the lifetime `'a` as defined on the function body at 37:8...
- --> $DIR/project-fn-ret-contravariant.rs:37:8
- |
LL | fn baz<'a,'b>(x: &'a u32) -> &'static u32 {
- | ^^
-note: ...so that reference does not outlive borrowed content
- --> $DIR/project-fn-ret-contravariant.rs:38:13
- |
-LL | bar(foo, x)
- | ^
- = note: but, the lifetime must be valid for the static lifetime...
-note: ...so that reference does not outlive borrowed content
- --> $DIR/project-fn-ret-contravariant.rs:38:4
- |
+ | ------- this data with lifetime `'a`...
LL | bar(foo, x)
- | ^^^^^^^^^^^
+ | ----^^^---- ...is captured and required to live as long as `'static` here
error: aborting due to previous error
-For more information about this error, try `rustc --explain E0495`.
+For more information about this error, try `rustc --explain E0759`.
// Cannot instantiate `foo` with any lifetime other than `'a`,
// since it is provided as input.
- bar(foo, x) //[transmute]~ ERROR E0495
+ bar(foo, x) //[transmute]~ ERROR E0759
}
#[cfg(krisskross)] // two instantiations, mixing and matching: BAD
-error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'a` due to conflicting requirements
+error[E0759]: `x` has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement
--> $DIR/project-fn-ret-invariant.rs:49:9
|
-LL | bar(foo, x)
- | ^^^
- |
-note: first, the lifetime cannot outlive the lifetime `'a` as defined on the function body at 45:8...
- --> $DIR/project-fn-ret-invariant.rs:45:8
- |
LL | fn baz<'a, 'b>(x: Type<'a>) -> Type<'static> {
- | ^^
-note: ...so that the expression is assignable
- --> $DIR/project-fn-ret-invariant.rs:49:14
- |
-LL | bar(foo, x)
- | ^
- = note: expected `Type<'_>`
- found `Type<'a>`
- = note: but, the lifetime must be valid for the static lifetime...
-note: ...so that the expression is assignable
- --> $DIR/project-fn-ret-invariant.rs:49:5
- |
+ | -------- this data with lifetime `'a`...
+...
LL | bar(foo, x)
- | ^^^^^^^^^^^
- = note: expected `Type<'static>`
- found `Type<'_>`
+ | ----^^^---- ...is captured and required to live as long as `'static` here
error: aborting due to previous error
-For more information about this error, try `rustc --explain E0495`.
+For more information about this error, try `rustc --explain E0759`.
struct Struct;
impl Struct {
- pub async fn run_dummy_fn(&self) { //~ ERROR cannot infer
+ pub async fn run_dummy_fn(&self) { //~ ERROR E0759
foo(|| self.bar()).await;
}
-error[E0759]: cannot infer an appropriate lifetime
+error[E0759]: `self` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement
--> $DIR/issue-62097.rs:12:31
|
LL | pub async fn run_dummy_fn(&self) {
--- /dev/null
+// check-pass
+//
+// This test is complement to the test in issue-73976-polymorphic.rs.
+// In that test we ensure that polymorphic use of type_id and type_name in patterns
+// will be properly rejected. This test will ensure that monomorphic use of these
+// would not be wrongly rejected in patterns.
+
+#![feature(const_type_id)]
+#![feature(const_type_name)]
+
+use std::any::{self, TypeId};
+
+pub struct GetTypeId<T>(T);
+
+impl<T: 'static> GetTypeId<T> {
+ pub const VALUE: TypeId = TypeId::of::<T>();
+}
+
+const fn check_type_id<T: 'static>() -> bool {
+ matches!(GetTypeId::<T>::VALUE, GetTypeId::<usize>::VALUE)
+}
+
+pub struct GetTypeNameLen<T>(T);
+
+impl<T: 'static> GetTypeNameLen<T> {
+ pub const VALUE: usize = any::type_name::<T>().len();
+}
+
+const fn check_type_name_len<T: 'static>() -> bool {
+ matches!(GetTypeNameLen::<T>::VALUE, GetTypeNameLen::<usize>::VALUE)
+}
+
+fn main() {
+ assert!(check_type_id::<usize>());
+ assert!(check_type_name_len::<usize>());
+}
--- /dev/null
+// This test is from #73976. We previously did not check if a type is monomorphized
+// before calculating its type id, which leads to the bizzare behaviour below that
+// TypeId of a generic type does not match itself.
+//
+// This test case should either run-pass or be rejected at compile time.
+// Currently we just disallow this usage and require pattern is monomorphic.
+
+#![feature(const_type_id)]
+#![feature(const_type_name)]
+
+use std::any::{self, TypeId};
+
+pub struct GetTypeId<T>(T);
+
+impl<T: 'static> GetTypeId<T> {
+ pub const VALUE: TypeId = TypeId::of::<T>();
+}
+
+const fn check_type_id<T: 'static>() -> bool {
+ matches!(GetTypeId::<T>::VALUE, GetTypeId::<T>::VALUE)
+ //~^ ERROR could not evaluate constant pattern
+ //~| ERROR could not evaluate constant pattern
+}
+
+pub struct GetTypeNameLen<T>(T);
+
+impl<T: 'static> GetTypeNameLen<T> {
+ pub const VALUE: usize = any::type_name::<T>().len();
+}
+
+const fn check_type_name_len<T: 'static>() -> bool {
+ matches!(GetTypeNameLen::<T>::VALUE, GetTypeNameLen::<T>::VALUE)
+ //~^ ERROR could not evaluate constant pattern
+ //~| ERROR could not evaluate constant pattern
+}
+
+fn main() {
+ assert!(check_type_id::<usize>());
+ assert!(check_type_name_len::<usize>());
+}
--- /dev/null
+error: could not evaluate constant pattern
+ --> $DIR/issue-73976-polymorphic.rs:20:37
+ |
+LL | matches!(GetTypeId::<T>::VALUE, GetTypeId::<T>::VALUE)
+ | ^^^^^^^^^^^^^^^^^^^^^
+
+error: could not evaluate constant pattern
+ --> $DIR/issue-73976-polymorphic.rs:32:42
+ |
+LL | matches!(GetTypeNameLen::<T>::VALUE, GetTypeNameLen::<T>::VALUE)
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: could not evaluate constant pattern
+ --> $DIR/issue-73976-polymorphic.rs:20:37
+ |
+LL | matches!(GetTypeId::<T>::VALUE, GetTypeId::<T>::VALUE)
+ | ^^^^^^^^^^^^^^^^^^^^^
+
+error: could not evaluate constant pattern
+ --> $DIR/issue-73976-polymorphic.rs:32:42
+ |
+LL | matches!(GetTypeNameLen::<T>::VALUE, GetTypeNameLen::<T>::VALUE)
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 4 previous errors
+
}
fn with_dyn_debug_static<'a>(x: Box<dyn Debug + 'a>) {
- static_val(x); //~ ERROR cannot infer
+ static_val(x); //~ ERROR E0759
}
fn not_static_val<T: NotStaticTrait>(_: T) {
-error[E0495]: cannot infer an appropriate lifetime due to conflicting requirements
+error[E0759]: `x` has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement
--> $DIR/dyn-trait.rs:20:16
|
-LL | static_val(x);
- | ^
- |
-note: first, the lifetime cannot outlive the lifetime `'a` as defined on the function body at 19:26...
- --> $DIR/dyn-trait.rs:19:26
- |
LL | fn with_dyn_debug_static<'a>(x: Box<dyn Debug + 'a>) {
- | ^^
-note: ...so that the expression is assignable
- --> $DIR/dyn-trait.rs:20:16
- |
+ | ------------------- this data with lifetime `'a`...
LL | static_val(x);
- | ^
- = note: expected `std::boxed::Box<dyn std::fmt::Debug>`
- found `std::boxed::Box<(dyn std::fmt::Debug + 'a)>`
- = note: but, the lifetime must be valid for the static lifetime...
-note: ...so that the types are compatible
+ | ^ ...is captured here...
+ |
+note: ...and is required to live as long as `'static` here
--> $DIR/dyn-trait.rs:20:5
|
LL | static_val(x);
| ^^^^^^^^^^
- = note: expected `StaticTrait`
- found `StaticTrait`
error: aborting due to previous error
-For more information about this error, try `rustc --explain E0495`.
+For more information about this error, try `rustc --explain E0759`.
| ^^^^^^^^^^^^^^
error: lifetime may not live long enough
- --> $DIR/must_outlive_least_region_or_bound.rs:6:32
+ --> $DIR/must_outlive_least_region_or_bound.rs:5:32
|
LL | fn explicit<'a>(x: &'a i32) -> impl Copy { x }
| -- ^^^^^^^^^ opaque type requires that `'a` must outlive `'static`
| ^^^^^^^^^^^^^^
error: lifetime may not live long enough
- --> $DIR/must_outlive_least_region_or_bound.rs:9:46
+ --> $DIR/must_outlive_least_region_or_bound.rs:7:46
|
LL | fn elided2(x: &i32) -> impl Copy + 'static { x }
| - ^ returning this value requires that `'1` must outlive `'static`
= help: consider replacing `'1` with `'static`
error: lifetime may not live long enough
- --> $DIR/must_outlive_least_region_or_bound.rs:12:55
+ --> $DIR/must_outlive_least_region_or_bound.rs:9:55
|
LL | fn explicit2<'a>(x: &'a i32) -> impl Copy + 'static { x }
| -- lifetime `'a` defined here ^ returning this value requires that `'a` must outlive `'static`
= help: consider replacing `'a` with `'static`
error[E0621]: explicit lifetime required in the type of `x`
- --> $DIR/must_outlive_least_region_or_bound.rs:15:41
+ --> $DIR/must_outlive_least_region_or_bound.rs:11:41
|
LL | fn foo<'a>(x: &i32) -> impl Copy + 'a { x }
| ---- ^ lifetime `'a` required
| help: add explicit lifetime `'a` to the type of `x`: `&'a i32`
error: lifetime may not live long enough
- --> $DIR/must_outlive_least_region_or_bound.rs:30:24
+ --> $DIR/must_outlive_least_region_or_bound.rs:22:24
|
LL | fn elided5(x: &i32) -> (Box<dyn Debug>, impl Debug) { (Box::new(x), x) }
| - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ opaque type requires that `'1` must outlive `'static`
| let's call the lifetime of this reference `'1`
error: lifetime may not live long enough
- --> $DIR/must_outlive_least_region_or_bound.rs:37:69
+ --> $DIR/must_outlive_least_region_or_bound.rs:28:69
|
LL | fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'static { x }
| -- lifetime `'a` defined here ^ returning this value requires that `'a` must outlive `'static`
= help: consider replacing `'a` with `'static`
error: lifetime may not live long enough
- --> $DIR/must_outlive_least_region_or_bound.rs:42:61
+ --> $DIR/must_outlive_least_region_or_bound.rs:32:61
|
LL | fn move_lifetime_into_fn<'a, 'b>(x: &'a u32, y: &'b u32) -> impl Fn(&'a u32) {
| -- -- lifetime `'b` defined here ^^^^^^^^^^^^^^^^ opaque type requires that `'b` must outlive `'a`
= help: consider adding the following bound: `'b: 'a`
error[E0310]: the parameter type `T` may not live long enough
- --> $DIR/must_outlive_least_region_or_bound.rs:47:51
+ --> $DIR/must_outlive_least_region_or_bound.rs:37:51
|
LL | fn ty_param_wont_outlive_static<T:Debug>(x: T) -> impl Debug + 'static {
| ^^^^^^^^^^^^^^^^^^^^
use std::fmt::Debug;
-fn elided(x: &i32) -> impl Copy { x }
-//~^ ERROR cannot infer an appropriate lifetime
+fn elided(x: &i32) -> impl Copy { x } //~ ERROR E0759
-fn explicit<'a>(x: &'a i32) -> impl Copy { x }
-//~^ ERROR cannot infer an appropriate lifetime
+fn explicit<'a>(x: &'a i32) -> impl Copy { x } //~ ERROR E0759
-fn elided2(x: &i32) -> impl Copy + 'static { x }
-//~^ ERROR cannot infer an appropriate lifetime
+fn elided2(x: &i32) -> impl Copy + 'static { x } //~ ERROR E0759
-fn explicit2<'a>(x: &'a i32) -> impl Copy + 'static { x }
-//~^ ERROR cannot infer an appropriate lifetime
+fn explicit2<'a>(x: &'a i32) -> impl Copy + 'static { x } //~ ERROR E0759
fn foo<'a>(x: &i32) -> impl Copy + 'a { x }
//~^ ERROR explicit lifetime required in the type of `x`
-fn elided3(x: &i32) -> Box<dyn Debug> { Box::new(x) }
-//~^ ERROR cannot infer an appropriate lifetime
+fn elided3(x: &i32) -> Box<dyn Debug> { Box::new(x) } //~ ERROR E0759
-fn explicit3<'a>(x: &'a i32) -> Box<dyn Debug> { Box::new(x) }
-//~^ ERROR cannot infer an appropriate lifetime
+fn explicit3<'a>(x: &'a i32) -> Box<dyn Debug> { Box::new(x) } //~ ERROR E0759
-fn elided4(x: &i32) -> Box<dyn Debug + 'static> { Box::new(x) }
-//~^ ERROR cannot infer an appropriate lifetime
+fn elided4(x: &i32) -> Box<dyn Debug + 'static> { Box::new(x) } //~ ERROR E0759
-fn explicit4<'a>(x: &'a i32) -> Box<dyn Debug + 'static> { Box::new(x) }
-//~^ ERROR cannot infer an appropriate lifetime
+fn explicit4<'a>(x: &'a i32) -> Box<dyn Debug + 'static> { Box::new(x) } //~ ERROR E0759
-fn elided5(x: &i32) -> (Box<dyn Debug>, impl Debug) { (Box::new(x), x) }
-//~^ ERROR cannot infer an appropriate lifetime
-//~| ERROR cannot infer an appropriate lifetime
+fn elided5(x: &i32) -> (Box<dyn Debug>, impl Debug) { (Box::new(x), x) } //~ ERROR E0759
+//~^ ERROR E0759
trait LifetimeTrait<'a> {}
impl<'a> LifetimeTrait<'a> for &'a i32 {}
-fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'static { x }
-//~^ ERROR cannot infer an appropriate lifetime
+fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'static { x } //~ ERROR E0759
// Tests that a closure type containing 'b cannot be returned from a type where
// only 'a was expected.
-error[E0759]: cannot infer an appropriate lifetime
+error[E0759]: `x` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement
--> $DIR/must_outlive_least_region_or_bound.rs:3:35
|
LL | fn elided(x: &i32) -> impl Copy { x }
LL | fn elided(x: &i32) -> impl Copy + '_ { x }
| ^^^^
-error[E0759]: cannot infer an appropriate lifetime
- --> $DIR/must_outlive_least_region_or_bound.rs:6:44
+error[E0759]: `x` has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement
+ --> $DIR/must_outlive_least_region_or_bound.rs:5:44
|
LL | fn explicit<'a>(x: &'a i32) -> impl Copy { x }
| ------- ^ ...is captured here...
| this data with lifetime `'a`...
|
note: ...and is required to live as long as `'static` here
- --> $DIR/must_outlive_least_region_or_bound.rs:6:32
+ --> $DIR/must_outlive_least_region_or_bound.rs:5:32
|
LL | fn explicit<'a>(x: &'a i32) -> impl Copy { x }
| ^^^^^^^^^
LL | fn explicit<'a>(x: &'a i32) -> impl Copy + 'a { x }
| ^^^^
-error[E0759]: cannot infer an appropriate lifetime
- --> $DIR/must_outlive_least_region_or_bound.rs:9:46
+error[E0759]: `x` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement
+ --> $DIR/must_outlive_least_region_or_bound.rs:7:46
|
LL | fn elided2(x: &i32) -> impl Copy + 'static { x }
| ---- ^ ...is captured here...
| this data with an anonymous lifetime `'_`...
|
note: ...and is required to live as long as `'static` here
- --> $DIR/must_outlive_least_region_or_bound.rs:9:24
+ --> $DIR/must_outlive_least_region_or_bound.rs:7:24
|
LL | fn elided2(x: &i32) -> impl Copy + 'static { x }
| ^^^^^^^^^^^^^^^^^^^
LL | fn elided2(x: &'static i32) -> impl Copy + 'static { x }
| ^^^^^^^^^^^^
-error[E0759]: cannot infer an appropriate lifetime
- --> $DIR/must_outlive_least_region_or_bound.rs:12:55
+error[E0759]: `x` has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement
+ --> $DIR/must_outlive_least_region_or_bound.rs:9:55
|
LL | fn explicit2<'a>(x: &'a i32) -> impl Copy + 'static { x }
| ------- ^ ...is captured here...
| this data with lifetime `'a`...
|
note: ...and is required to live as long as `'static` here
- --> $DIR/must_outlive_least_region_or_bound.rs:12:33
+ --> $DIR/must_outlive_least_region_or_bound.rs:9:33
|
LL | fn explicit2<'a>(x: &'a i32) -> impl Copy + 'static { x }
| ^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^
error[E0621]: explicit lifetime required in the type of `x`
- --> $DIR/must_outlive_least_region_or_bound.rs:15:24
+ --> $DIR/must_outlive_least_region_or_bound.rs:11:24
|
LL | fn foo<'a>(x: &i32) -> impl Copy + 'a { x }
| ---- ^^^^^^^^^^^^^^ lifetime `'a` required
| |
| help: add explicit lifetime `'a` to the type of `x`: `&'a i32`
-error[E0759]: cannot infer an appropriate lifetime
- --> $DIR/must_outlive_least_region_or_bound.rs:30:65
+error[E0759]: `x` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement
+ --> $DIR/must_outlive_least_region_or_bound.rs:22:65
|
LL | fn elided5(x: &i32) -> (Box<dyn Debug>, impl Debug) { (Box::new(x), x) }
| ---- this data with an anonymous lifetime `'_`... ^ ...is captured here, requiring it to live as long as `'static`
LL | fn elided5(x: &i32) -> (Box<dyn Debug>, impl Debug + '_) { (Box::new(x), x) }
| ^^^^
-error[E0759]: cannot infer an appropriate lifetime
- --> $DIR/must_outlive_least_region_or_bound.rs:30:69
+error[E0759]: `x` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement
+ --> $DIR/must_outlive_least_region_or_bound.rs:22:69
|
LL | fn elided5(x: &i32) -> (Box<dyn Debug>, impl Debug) { (Box::new(x), x) }
| ---- this data with an anonymous lifetime `'_`... ^ ...is captured here...
|
note: ...and is required to live as long as `'static` here
- --> $DIR/must_outlive_least_region_or_bound.rs:30:41
+ --> $DIR/must_outlive_least_region_or_bound.rs:22:41
|
LL | fn elided5(x: &i32) -> (Box<dyn Debug>, impl Debug) { (Box::new(x), x) }
| ^^^^^^^^^^
LL | fn elided5(x: &i32) -> (Box<dyn Debug>, impl Debug + '_) { (Box::new(x), x) }
| ^^^^
-error[E0759]: cannot infer an appropriate lifetime
- --> $DIR/must_outlive_least_region_or_bound.rs:37:69
+error[E0759]: `x` has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement
+ --> $DIR/must_outlive_least_region_or_bound.rs:28:69
|
LL | fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'static { x }
| ------- this data with lifetime `'a`... ^ ...is captured here...
|
note: ...and is required to live as long as `'static` here
- --> $DIR/must_outlive_least_region_or_bound.rs:37:34
+ --> $DIR/must_outlive_least_region_or_bound.rs:28:34
|
LL | fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'static { x }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^
error[E0623]: lifetime mismatch
- --> $DIR/must_outlive_least_region_or_bound.rs:42:61
+ --> $DIR/must_outlive_least_region_or_bound.rs:32:61
|
LL | fn move_lifetime_into_fn<'a, 'b>(x: &'a u32, y: &'b u32) -> impl Fn(&'a u32) {
| ------- ^^^^^^^^^^^^^^^^
| this parameter and the return type are declared with different lifetimes...
error[E0310]: the parameter type `T` may not live long enough
- --> $DIR/must_outlive_least_region_or_bound.rs:47:51
+ --> $DIR/must_outlive_least_region_or_bound.rs:37:51
|
LL | fn ty_param_wont_outlive_static<T:Debug>(x: T) -> impl Debug + 'static {
| -- ^^^^^^^^^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds
| |
| help: consider adding an explicit lifetime bound...: `T: 'static +`
-error[E0759]: cannot infer an appropriate lifetime
- --> $DIR/must_outlive_least_region_or_bound.rs:18:50
+error[E0759]: `x` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement
+ --> $DIR/must_outlive_least_region_or_bound.rs:14:50
|
LL | fn elided3(x: &i32) -> Box<dyn Debug> { Box::new(x) }
| ---- ^ ...is captured here, requiring it to live as long as `'static`
LL | fn elided3(x: &i32) -> Box<dyn Debug + '_> { Box::new(x) }
| ^^^^
-error[E0759]: cannot infer an appropriate lifetime
- --> $DIR/must_outlive_least_region_or_bound.rs:21:59
+error[E0759]: `x` has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement
+ --> $DIR/must_outlive_least_region_or_bound.rs:16:59
|
LL | fn explicit3<'a>(x: &'a i32) -> Box<dyn Debug> { Box::new(x) }
| ------- ^ ...is captured here, requiring it to live as long as `'static`
LL | fn explicit3<'a>(x: &'a i32) -> Box<dyn Debug + 'a> { Box::new(x) }
| ^^^^
-error[E0759]: cannot infer an appropriate lifetime
- --> $DIR/must_outlive_least_region_or_bound.rs:24:60
+error[E0759]: `x` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement
+ --> $DIR/must_outlive_least_region_or_bound.rs:18:60
|
LL | fn elided4(x: &i32) -> Box<dyn Debug + 'static> { Box::new(x) }
| ---- ^ ...is captured here, requiring it to live as long as `'static`
LL | fn elided4(x: &'static i32) -> Box<dyn Debug + 'static> { Box::new(x) }
| ^^^^^^^^^^^^
-error[E0759]: cannot infer an appropriate lifetime
- --> $DIR/must_outlive_least_region_or_bound.rs:27:69
+error[E0759]: `x` has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement
+ --> $DIR/must_outlive_least_region_or_bound.rs:20:69
|
LL | fn explicit4<'a>(x: &'a i32) -> Box<dyn Debug + 'static> { Box::new(x) }
| ------- this data with lifetime `'a`... ^ ...is captured here, requiring it to live as long as `'static`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: lifetime may not live long enough
- --> $DIR/static-return-lifetime-infered.rs:10:37
+ --> $DIR/static-return-lifetime-infered.rs:9:37
|
LL | fn iter_values<'a>(&'a self) -> impl Iterator<Item=u32> {
| -- ^^^^^^^^^^^^^^^^^^^^^^^ opaque type requires that `'a` must outlive `'static`
impl A {
fn iter_values_anon(&self) -> impl Iterator<Item=u32> {
- self.x.iter().map(|a| a.0)
+ self.x.iter().map(|a| a.0) //~ ERROR E0759
}
- //~^^ ERROR cannot infer an appropriate lifetime
fn iter_values<'a>(&'a self) -> impl Iterator<Item=u32> {
- self.x.iter().map(|a| a.0)
+ self.x.iter().map(|a| a.0) //~ ERROR E0759
}
- //~^^ ERROR cannot infer an appropriate lifetime
}
fn main() {}
-error[E0759]: cannot infer an appropriate lifetime
+error[E0759]: `self` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement
--> $DIR/static-return-lifetime-infered.rs:7:16
|
LL | fn iter_values_anon(&self) -> impl Iterator<Item=u32> {
LL | fn iter_values_anon(&self) -> impl Iterator<Item=u32> + '_ {
| ^^^^
-error[E0759]: cannot infer an appropriate lifetime
- --> $DIR/static-return-lifetime-infered.rs:11:16
+error[E0759]: `self` has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement
+ --> $DIR/static-return-lifetime-infered.rs:10:16
|
LL | fn iter_values<'a>(&'a self) -> impl Iterator<Item=u32> {
| -------- this data with lifetime `'a`...
| ...is captured here...
|
note: ...and is required to live as long as `'static` here
- --> $DIR/static-return-lifetime-infered.rs:10:37
+ --> $DIR/static-return-lifetime-infered.rs:9:37
|
LL | fn iter_values<'a>(&'a self) -> impl Iterator<Item=u32> {
| ^^^^^^^^^^^^^^^^^^^^^^^
use std::any::Any;
fn foo<T: Any>(value: &T) -> Box<dyn Any> {
- Box::new(value) as Box<dyn Any>
- //~^ ERROR cannot infer an appropriate lifetime
+ Box::new(value) as Box<dyn Any> //~ ERROR E0759
}
fn main() {
-error[E0759]: cannot infer an appropriate lifetime
+error[E0759]: `value` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement
--> $DIR/issue-16922.rs:4:14
|
LL | fn foo<T: Any>(value: &T) -> Box<dyn Any> {
-error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'a` due to conflicting requirements
+error[E0759]: `fn` parameter has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement
--> $DIR/constant-in-expr-inherent-1.rs:8:5
|
-LL | <Foo<'a>>::C
- | ^^^^^^^^^^^^
- |
-note: first, the lifetime cannot outlive the lifetime `'a` as defined on the function body at 7:8...
- --> $DIR/constant-in-expr-inherent-1.rs:7:8
- |
LL | fn foo<'a>(_: &'a u32) -> &'static u32 {
- | ^^
-note: ...so that the types are compatible
- --> $DIR/constant-in-expr-inherent-1.rs:8:5
- |
-LL | <Foo<'a>>::C
- | ^^^^^^^^^^^^
- = note: expected `Foo<'_>`
- found `Foo<'a>`
- = note: but, the lifetime must be valid for the static lifetime...
-note: ...so that reference does not outlive borrowed content
- --> $DIR/constant-in-expr-inherent-1.rs:8:5
- |
+ | ------- this data with lifetime `'a`...
LL | <Foo<'a>>::C
- | ^^^^^^^^^^^^
+ | ^^^^^^^^^^^^ ...is captured and required to live as long as `'static` here
error: aborting due to previous error
-For more information about this error, try `rustc --explain E0495`.
+For more information about this error, try `rustc --explain E0759`.
// `Box<SomeTrait>` defaults to a `'static` bound, so this return
// is illegal.
- ss.r //~ ERROR cannot infer an appropriate lifetime
+ ss.r //~ ERROR E0759
}
fn store(ss: &mut SomeStruct, b: Box<dyn SomeTrait>) {
-error[E0759]: cannot infer an appropriate lifetime
+error[E0759]: `ss` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement
--> $DIR/object-lifetime-default-from-box-error.rs:18:5
|
LL | fn load(ss: &mut SomeStruct) -> Box<dyn SomeTrait> {
impl<'a> Foo for &'a [u8] {}
fn a(v: &[u8]) -> Box<dyn Foo + 'static> {
- let x: Box<dyn Foo + 'static> = Box::new(v); //~ ERROR cannot infer an appropriate lifetime
+ let x: Box<dyn Foo + 'static> = Box::new(v); //~ ERROR E0759
x
}
fn b(v: &[u8]) -> Box<dyn Foo + 'static> {
- Box::new(v) //~ ERROR cannot infer an appropriate lifetime
+ Box::new(v) //~ ERROR E0759
}
fn c(v: &[u8]) -> Box<dyn Foo> {
// same as previous case due to RFC 599
- Box::new(v) //~ ERROR cannot infer an appropriate lifetime
+ Box::new(v) //~ ERROR E0759
}
fn d<'a,'b>(v: &'a [u8]) -> Box<dyn Foo+'b> {
-error[E0759]: cannot infer an appropriate lifetime
+error[E0759]: `v` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement
--> $DIR/region-object-lifetime-in-coercion.rs:8:46
|
LL | fn a(v: &[u8]) -> Box<dyn Foo + 'static> {
LL | fn a(v: &'static [u8]) -> Box<dyn Foo + 'static> {
| ^^^^^^^^^^^^^
-error[E0759]: cannot infer an appropriate lifetime
+error[E0759]: `v` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement
--> $DIR/region-object-lifetime-in-coercion.rs:13:14
|
LL | fn b(v: &[u8]) -> Box<dyn Foo + 'static> {
LL | fn b(v: &'static [u8]) -> Box<dyn Foo + 'static> {
| ^^^^^^^^^^^^^
-error[E0759]: cannot infer an appropriate lifetime
+error[E0759]: `v` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement
--> $DIR/region-object-lifetime-in-coercion.rs:19:14
|
LL | fn c(v: &[u8]) -> Box<dyn Foo> {
impl Dog {
pub fn chase_cat(&mut self) {
- let p: &'static mut usize = &mut self.cats_chased; //~ ERROR cannot infer
+ let p: &'static mut usize = &mut self.cats_chased; //~ ERROR E0759
*p += 1;
}
-error[E0495]: cannot infer an appropriate lifetime for borrow expression due to conflicting requirements
+error[E0759]: `self` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement
--> $DIR/regions-addr-of-self.rs:7:37
|
+LL | pub fn chase_cat(&mut self) {
+ | --------- this data with an anonymous lifetime `'_`...
LL | let p: &'static mut usize = &mut self.cats_chased;
- | ^^^^^^^^^^^^^^^^^^^^^
- |
-note: first, the lifetime cannot outlive the anonymous lifetime #1 defined on the method body at 6:5...
- --> $DIR/regions-addr-of-self.rs:6:5
- |
-LL | / pub fn chase_cat(&mut self) {
-LL | | let p: &'static mut usize = &mut self.cats_chased;
-LL | | *p += 1;
-LL | | }
- | |_____^
-note: ...so that reference does not outlive borrowed content
- --> $DIR/regions-addr-of-self.rs:7:37
- |
-LL | let p: &'static mut usize = &mut self.cats_chased;
- | ^^^^^^^^^^^^^^^^^^^^^
- = note: but, the lifetime must be valid for the static lifetime...
-note: ...so that reference does not outlive borrowed content
- --> $DIR/regions-addr-of-self.rs:7:37
- |
-LL | let p: &'static mut usize = &mut self.cats_chased;
- | ^^^^^^^^^^^^^^^^^^^^^
+ | ^^^^^^^^^^^^^^^^^^^^^ ...is captured and required to live as long as `'static` here
error: aborting due to previous error
-For more information about this error, try `rustc --explain E0495`.
+For more information about this error, try `rustc --explain E0759`.
impl<'a, T> X for B<'a, T> {}
fn g<'a, T: 'static>(v: Box<dyn A<T> + 'a>) -> Box<dyn X + 'static> {
- box B(&*v) as Box<dyn X> //~ ERROR cannot infer
+ box B(&*v) as Box<dyn X> //~ ERROR E0759
}
fn main() { }
-error[E0759]: cannot infer an appropriate lifetime
+error[E0759]: `v` has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement
--> $DIR/regions-close-object-into-object-2.rs:10:11
|
LL | fn g<'a, T: 'static>(v: Box<dyn A<T> + 'a>) -> Box<dyn X + 'static> {
impl<'a, T> X for B<'a, T> {}
fn i<'a, T, U>(v: Box<dyn A<U>+'a>) -> Box<dyn X + 'static> {
- box B(&*v) as Box<dyn X> //~ ERROR cannot infer
+ box B(&*v) as Box<dyn X> //~ ERROR E0759
}
fn main() {}
-error[E0759]: cannot infer an appropriate lifetime
+error[E0759]: `v` has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement
--> $DIR/regions-close-object-into-object-4.rs:10:11
|
LL | fn i<'a, T, U>(v: Box<dyn A<U>+'a>) -> Box<dyn X + 'static> {
fn static_proc(x: &isize) -> Box<dyn FnMut() -> (isize) + 'static> {
// This is illegal, because the region bound on `proc` is 'static.
- Box::new(move || { *x }) //~ ERROR cannot infer an appropriate lifetime
+ Box::new(move || { *x }) //~ ERROR E0759
}
fn main() { }
-error[E0759]: cannot infer an appropriate lifetime
+error[E0759]: `x` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement
--> $DIR/regions-proc-bound-capture.rs:9:14
|
LL | fn static_proc(x: &isize) -> Box<dyn FnMut() -> (isize) + 'static> {
impl Foo {
async fn f(self: Pin<&Self>) -> impl Clone { self }
- //~^ ERROR cannot infer an appropriate lifetime
+ //~^ ERROR E0759
}
fn main() {
-error[E0759]: cannot infer an appropriate lifetime
+error[E0759]: `self` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement
--> $DIR/arbitrary_self_types_pin_lifetime_impl_trait-async.rs:8:16
|
LL | async fn f(self: Pin<&Self>) -> impl Clone { self }
struct Foo;
impl Foo {
- fn f(self: Pin<&Self>) -> impl Clone { self } //~ ERROR cannot infer an appropriate lifetime
+ fn f(self: Pin<&Self>) -> impl Clone { self } //~ ERROR E0759
}
fn main() {
-error[E0759]: cannot infer an appropriate lifetime
+error[E0759]: `self` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement
--> $DIR/arbitrary_self_types_pin_lifetime_impl_trait.rs:6:44
|
LL | fn f(self: Pin<&Self>) -> impl Clone { self }
--- /dev/null
+error[E0597]: `val` does not live long enough
+ --> $DIR/impl-on-dyn-trait-with-implicit-static-bound-needing-more-suggestions.rs:21:9
+ |
+LL | fn use_it<'a>(val: Box<dyn ObjectTrait<Assoc = i32>>) -> impl OtherTrait<'a> {
+ | -- lifetime `'a` defined here ------------------- opaque type requires that `val` is borrowed for `'a`
+LL | val.use_self()
+ | ^^^ borrowed value does not live long enough
+LL | }
+ | - `val` dropped here while still borrowed
+ |
+help: you can add a bound to the opaque type to make it last less than `'static` and match `'a`
+ |
+LL | fn use_it<'a>(val: Box<dyn ObjectTrait<Assoc = i32>>) -> impl OtherTrait<'a> + 'a {
+ | ^^^^
+
+error[E0515]: cannot return value referencing function parameter `val`
+ --> $DIR/impl-on-dyn-trait-with-implicit-static-bound-needing-more-suggestions.rs:43:9
+ |
+LL | val.use_self()
+ | ---^^^^^^^^^^^
+ | |
+ | returns a value referencing data owned by the current function
+ | `val` is borrowed here
+
+error[E0515]: cannot return value referencing function parameter `val`
+ --> $DIR/impl-on-dyn-trait-with-implicit-static-bound-needing-more-suggestions.rs:109:9
+ |
+LL | val.use_self()
+ | ---^^^^^^^^^^^
+ | |
+ | returns a value referencing data owned by the current function
+ | `val` is borrowed here
+
+error: aborting due to 3 previous errors
+
+Some errors have detailed explanations: E0515, E0597.
+For more information about an error, try `rustc --explain E0515`.
--- /dev/null
+// FIXME: the following cases need to suggest more things to make users reach a working end state.
+
+mod bav {
+ trait OtherTrait<'a> {}
+ impl<'a> OtherTrait<'a> for &'a () {}
+
+ trait ObjectTrait {
+ type Assoc: Bar;
+ }
+ trait MyTrait {
+ fn use_self(&self) -> &() { panic!() }
+ }
+ trait Bar {}
+
+ impl MyTrait for Box<dyn ObjectTrait<Assoc = i32>> {
+ fn use_self(&self) -> &() { panic!() }
+ }
+ impl Bar for i32 {}
+
+ fn use_it<'a>(val: Box<dyn ObjectTrait<Assoc = i32>>) -> impl OtherTrait<'a> {
+ val.use_self() //~ ERROR E0597
+ }
+}
+
+mod bap {
+ trait OtherTrait<'a> {}
+ impl<'a> OtherTrait<'a> for &'a () {}
+
+ trait ObjectTrait {
+ type Assoc: Bar;
+ }
+ trait MyTrait {
+ fn use_self(&self) -> &() { panic!() }
+ }
+ trait Bar {}
+
+ impl MyTrait for Box<dyn ObjectTrait<Assoc = i32>> {
+ fn use_self(&self) -> &() { panic!() }
+ }
+ impl Bar for i32 {}
+
+ fn use_it<'a>(val: Box<dyn ObjectTrait<Assoc = i32>>) -> impl OtherTrait<'a> + 'a {
+ val.use_self() //~ ERROR E0515
+ }
+}
+
+// This case in particular requires the user to write all of the bounds we have in `mod bax`.
+mod bay {
+ trait OtherTrait<'a> {}
+ impl<'a> OtherTrait<'a> for &'a () {}
+
+ trait ObjectTrait {
+ type Assoc: Bar;
+ }
+ trait MyTrait {
+ fn use_self(&self) -> &() { panic!() }
+ }
+ trait Bar {}
+
+ impl MyTrait for Box<dyn ObjectTrait<Assoc = i32>> {
+ fn use_self(&self) -> &() { panic!() }
+ }
+ impl Bar for i32 {}
+
+ fn use_it<'a>(val: Box<dyn ObjectTrait<Assoc = i32> + 'a>) -> &'a () {
+ val.use_self() //~ ERROR E0772
+ }
+}
+
+mod bax {
+ trait OtherTrait<'a> {}
+ impl<'a> OtherTrait<'a> for &'a () {}
+
+ trait ObjectTrait {
+ type Assoc: Bar;
+ }
+ trait MyTrait<'a> {
+ fn use_self(&'a self) -> &'a () { panic!() }
+ }
+ trait Bar {}
+
+ impl<'a> MyTrait<'a> for Box<dyn ObjectTrait<Assoc = i32> + 'a> {
+ fn use_self(&'a self) -> &'a () { panic!() }
+ }
+ impl Bar for i32 {}
+
+ fn use_it<'a>(val: Box<dyn ObjectTrait<Assoc = i32> + 'a>) -> &'a () {
+ val.use_self()
+ }
+}
+
+mod baw {
+ trait OtherTrait<'a> {}
+ impl<'a> OtherTrait<'a> for &'a () {}
+
+ trait ObjectTrait {
+ type Assoc: Bar;
+ }
+ trait MyTrait {
+ fn use_self(&self) -> &() { panic!() }
+ }
+ trait Bar {}
+
+ impl<'a> MyTrait for Box<dyn ObjectTrait<Assoc = Box<dyn Bar>>> {
+ fn use_self(&self) -> &() { panic!() }
+ }
+
+ fn use_it<'a>(val: Box<dyn ObjectTrait<Assoc = Box<dyn Bar>>>) -> impl OtherTrait<'a> + 'a{
+ val.use_self() //~ ERROR E0515
+ }
+}
+
+fn main() {}
--- /dev/null
+error[E0597]: `val` does not live long enough
+ --> $DIR/impl-on-dyn-trait-with-implicit-static-bound-needing-more-suggestions.rs:21:9
+ |
+LL | fn use_it<'a>(val: Box<dyn ObjectTrait<Assoc = i32>>) -> impl OtherTrait<'a> {
+ | -- lifetime `'a` defined here ------------------- opaque type requires that `val` is borrowed for `'a`
+LL | val.use_self()
+ | ^^^ borrowed value does not live long enough
+LL | }
+ | - `val` dropped here while still borrowed
+ |
+help: you can add a bound to the opaque type to make it last less than `'static` and match `'a`
+ |
+LL | fn use_it<'a>(val: Box<dyn ObjectTrait<Assoc = i32>>) -> impl OtherTrait<'a> + 'a {
+ | ^^^^
+
+error[E0515]: cannot return value referencing function parameter `val`
+ --> $DIR/impl-on-dyn-trait-with-implicit-static-bound-needing-more-suggestions.rs:43:9
+ |
+LL | val.use_self()
+ | ---^^^^^^^^^^^
+ | |
+ | returns a value referencing data owned by the current function
+ | `val` is borrowed here
+
+error[E0515]: cannot return value referencing function parameter `val`
+ --> $DIR/impl-on-dyn-trait-with-implicit-static-bound-needing-more-suggestions.rs:109:9
+ |
+LL | val.use_self()
+ | ---^^^^^^^^^^^
+ | |
+ | returns a value referencing data owned by the current function
+ | `val` is borrowed here
+
+error[E0772]: `val` has lifetime `'a` but calling `use_self` introduces an implicit `'static` lifetime requirement
+ --> $DIR/impl-on-dyn-trait-with-implicit-static-bound-needing-more-suggestions.rs:66:13
+ |
+LL | fn use_it<'a>(val: Box<dyn ObjectTrait<Assoc = i32> + 'a>) -> &'a () {
+ | -------------------------------------- this data with lifetime `'a`...
+LL | val.use_self()
+ | ^^^^^^^^ ...is captured and required to live as long as `'static` here
+ |
+note: the used `impl` has a `'static` requirement
+ --> $DIR/impl-on-dyn-trait-with-implicit-static-bound-needing-more-suggestions.rs:60:30
+ |
+LL | impl MyTrait for Box<dyn ObjectTrait<Assoc = i32>> {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ this has an implicit `'static` lifetime requirement
+LL | fn use_self(&self) -> &() { panic!() }
+ | -------- calling this method introduces the `impl`'s 'static` requirement
+help: consider relaxing the implicit `'static` requirement
+ |
+LL | impl MyTrait for Box<dyn ObjectTrait<Assoc = i32> + '_> {
+ | ^^^^
+
+error: aborting due to 4 previous errors
+
+Some errors have detailed explanations: E0515, E0597.
+For more information about an error, try `rustc --explain E0515`.
--- /dev/null
+// run-rustfix
+#![allow(dead_code)]
+
+mod foo {
+ trait OtherTrait<'a> {}
+ impl<'a> OtherTrait<'a> for &'a () {}
+
+ trait ObjectTrait<T> {}
+ trait MyTrait<T> {
+ fn use_self<K>(&self) -> &();
+ }
+ trait Irrelevant {}
+
+ impl<T> MyTrait<T> for dyn ObjectTrait<T> + '_ {
+ fn use_self<K>(&self) -> &() { panic!() }
+ }
+ impl<T> Irrelevant for dyn ObjectTrait<T> {}
+
+ fn use_it<'a, T>(val: &'a dyn ObjectTrait<T>) -> impl OtherTrait<'a> + 'a {
+ val.use_self::<T>() //~ ERROR E0759
+ }
+}
+
+mod bar {
+ trait ObjectTrait {}
+ trait MyTrait {
+ fn use_self(&self) -> &();
+ }
+ trait Irrelevant {}
+
+ impl MyTrait for dyn ObjectTrait + '_ {
+ fn use_self(&self) -> &() { panic!() }
+ }
+ impl Irrelevant for dyn ObjectTrait {}
+
+ fn use_it<'a>(val: &'a dyn ObjectTrait) -> &'a () {
+ val.use_self() //~ ERROR E0772
+ }
+}
+
+mod baz {
+ trait ObjectTrait {}
+ trait MyTrait {
+ fn use_self(&self) -> &();
+ }
+ trait Irrelevant {}
+
+ impl MyTrait for Box<dyn ObjectTrait + '_> {
+ fn use_self(&self) -> &() { panic!() }
+ }
+ impl Irrelevant for Box<dyn ObjectTrait> {}
+
+ fn use_it<'a>(val: &'a Box<dyn ObjectTrait + 'a>) -> &'a () {
+ val.use_self() //~ ERROR E0772
+ }
+}
+
+mod bat {
+ trait OtherTrait<'a> {}
+ impl<'a> OtherTrait<'a> for &'a () {}
+
+ trait ObjectTrait {}
+
+ impl dyn ObjectTrait + '_ {
+ fn use_self(&self) -> &() { panic!() }
+ }
+
+ fn use_it<'a>(val: &'a dyn ObjectTrait) -> impl OtherTrait<'a> + 'a {
+ val.use_self() //~ ERROR E0772
+ }
+}
+
+mod ban {
+ trait OtherTrait<'a> {}
+ impl<'a> OtherTrait<'a> for &'a () {}
+
+ trait ObjectTrait {}
+ trait MyTrait {
+ fn use_self(&self) -> &() { panic!() }
+ }
+ trait Irrelevant {
+ fn use_self(&self) -> &() { panic!() }
+ }
+
+ impl MyTrait for dyn ObjectTrait + '_ {}
+
+ fn use_it<'a>(val: &'a dyn ObjectTrait) -> impl OtherTrait<'a> + 'a {
+ val.use_self() //~ ERROR E0759
+ }
+}
+
+mod bal {
+ trait OtherTrait<'a> {}
+ impl<'a> OtherTrait<'a> for &'a () {}
+
+ trait ObjectTrait {}
+ trait MyTrait {
+ fn use_self(&self) -> &() { panic!() }
+ }
+ trait Irrelevant {
+ fn use_self(&self) -> &() { panic!() }
+ }
+
+ impl MyTrait for dyn ObjectTrait + '_ {}
+ impl Irrelevant for dyn ObjectTrait {}
+
+ fn use_it<'a>(val: &'a dyn ObjectTrait) -> impl OtherTrait<'a> + 'a {
+ MyTrait::use_self(val) //~ ERROR E0759
+ }
+}
+
+fn main() {}
--- /dev/null
+error[E0521]: borrowed data escapes outside of function
+ --> $DIR/impl-on-dyn-trait-with-implicit-static-bound.rs:20:9
+ |
+LL | fn use_it<'a, T>(val: &'a dyn ObjectTrait<T>) -> impl OtherTrait<'a> + 'a {
+ | --- `val` is a reference that is only valid in the function body
+LL | val.use_self::<T>()
+ | ^^^^^^^^^^^^^^^^^^^ `val` escapes the function body here
+ |
+ = help: consider replacing `'a` with `'static`
+
+error[E0521]: borrowed data escapes outside of function
+ --> $DIR/impl-on-dyn-trait-with-implicit-static-bound.rs:69:9
+ |
+LL | fn use_it<'a>(val: &'a dyn ObjectTrait) -> impl OtherTrait<'a> + 'a {
+ | --- `val` is a reference that is only valid in the function body
+LL | val.use_self()
+ | ^^^^^^^^^^^^^^ `val` escapes the function body here
+ |
+ = help: consider replacing `'a` with `'static`
+
+error[E0521]: borrowed data escapes outside of function
+ --> $DIR/impl-on-dyn-trait-with-implicit-static-bound.rs:88:9
+ |
+LL | fn use_it<'a>(val: &'a dyn ObjectTrait) -> impl OtherTrait<'a> {
+ | --- `val` is a reference that is only valid in the function body
+LL | val.use_self()
+ | ^^^^^^^^^^^^^^ `val` escapes the function body here
+ |
+ = help: consider replacing `'a` with `'static`
+
+error[E0521]: borrowed data escapes outside of function
+ --> $DIR/impl-on-dyn-trait-with-implicit-static-bound.rs:108:9
+ |
+LL | fn use_it<'a>(val: &'a dyn ObjectTrait) -> impl OtherTrait<'a> + 'a {
+ | --- `val` is a reference that is only valid in the function body
+LL | MyTrait::use_self(val)
+ | ^^^^^^^^^^^^^^^^^^^^^^ `val` escapes the function body here
+ |
+ = help: consider replacing `'a` with `'static`
+
+error: aborting due to 4 previous errors
+
--- /dev/null
+// run-rustfix
+#![allow(dead_code)]
+
+mod foo {
+ trait OtherTrait<'a> {}
+ impl<'a> OtherTrait<'a> for &'a () {}
+
+ trait ObjectTrait<T> {}
+ trait MyTrait<T> {
+ fn use_self<K>(&self) -> &();
+ }
+ trait Irrelevant {}
+
+ impl<T> MyTrait<T> for dyn ObjectTrait<T> {
+ fn use_self<K>(&self) -> &() { panic!() }
+ }
+ impl<T> Irrelevant for dyn ObjectTrait<T> {}
+
+ fn use_it<'a, T>(val: &'a dyn ObjectTrait<T>) -> impl OtherTrait<'a> + 'a {
+ val.use_self::<T>() //~ ERROR E0759
+ }
+}
+
+mod bar {
+ trait ObjectTrait {}
+ trait MyTrait {
+ fn use_self(&self) -> &();
+ }
+ trait Irrelevant {}
+
+ impl MyTrait for dyn ObjectTrait {
+ fn use_self(&self) -> &() { panic!() }
+ }
+ impl Irrelevant for dyn ObjectTrait {}
+
+ fn use_it<'a>(val: &'a dyn ObjectTrait) -> &'a () {
+ val.use_self() //~ ERROR E0772
+ }
+}
+
+mod baz {
+ trait ObjectTrait {}
+ trait MyTrait {
+ fn use_self(&self) -> &();
+ }
+ trait Irrelevant {}
+
+ impl MyTrait for Box<dyn ObjectTrait> {
+ fn use_self(&self) -> &() { panic!() }
+ }
+ impl Irrelevant for Box<dyn ObjectTrait> {}
+
+ fn use_it<'a>(val: &'a Box<dyn ObjectTrait + 'a>) -> &'a () {
+ val.use_self() //~ ERROR E0772
+ }
+}
+
+mod bat {
+ trait OtherTrait<'a> {}
+ impl<'a> OtherTrait<'a> for &'a () {}
+
+ trait ObjectTrait {}
+
+ impl dyn ObjectTrait {
+ fn use_self(&self) -> &() { panic!() }
+ }
+
+ fn use_it<'a>(val: &'a dyn ObjectTrait) -> impl OtherTrait<'a> + 'a {
+ val.use_self() //~ ERROR E0772
+ }
+}
+
+mod ban {
+ trait OtherTrait<'a> {}
+ impl<'a> OtherTrait<'a> for &'a () {}
+
+ trait ObjectTrait {}
+ trait MyTrait {
+ fn use_self(&self) -> &() { panic!() }
+ }
+ trait Irrelevant {
+ fn use_self(&self) -> &() { panic!() }
+ }
+
+ impl MyTrait for dyn ObjectTrait {}
+
+ fn use_it<'a>(val: &'a dyn ObjectTrait) -> impl OtherTrait<'a> {
+ val.use_self() //~ ERROR E0759
+ }
+}
+
+mod bal {
+ trait OtherTrait<'a> {}
+ impl<'a> OtherTrait<'a> for &'a () {}
+
+ trait ObjectTrait {}
+ trait MyTrait {
+ fn use_self(&self) -> &() { panic!() }
+ }
+ trait Irrelevant {
+ fn use_self(&self) -> &() { panic!() }
+ }
+
+ impl MyTrait for dyn ObjectTrait {}
+ impl Irrelevant for dyn ObjectTrait {}
+
+ fn use_it<'a>(val: &'a dyn ObjectTrait) -> impl OtherTrait<'a> + 'a {
+ MyTrait::use_self(val) //~ ERROR E0759
+ }
+}
+
+fn main() {}
--- /dev/null
+error[E0759]: `val` has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement
+ --> $DIR/impl-on-dyn-trait-with-implicit-static-bound.rs:20:13
+ |
+LL | fn use_it<'a, T>(val: &'a dyn ObjectTrait<T>) -> impl OtherTrait<'a> + 'a {
+ | ---------------------- this data with lifetime `'a`...
+LL | val.use_self::<T>()
+ | ^^^^^^^^ ...is captured and required to live as long as `'static` here
+ |
+note: the used `impl` has a `'static` requirement
+ --> $DIR/impl-on-dyn-trait-with-implicit-static-bound.rs:14:32
+ |
+LL | impl<T> MyTrait<T> for dyn ObjectTrait<T> {
+ | ^^^^^^^^^^^^^^ this has an implicit `'static` lifetime requirement
+LL | fn use_self<K>(&self) -> &() { panic!() }
+ | -------- calling this method introduces the `impl`'s 'static` requirement
+help: consider relaxing the implicit `'static` requirement
+ |
+LL | impl<T> MyTrait<T> for dyn ObjectTrait<T> + '_ {
+ | ^^^^
+
+error[E0772]: `val` has lifetime `'a` but calling `use_self` introduces an implicit `'static` lifetime requirement
+ --> $DIR/impl-on-dyn-trait-with-implicit-static-bound.rs:69:13
+ |
+LL | fn use_it<'a>(val: &'a dyn ObjectTrait) -> impl OtherTrait<'a> + 'a {
+ | ------------------- this data with lifetime `'a`...
+LL | val.use_self()
+ | ^^^^^^^^ ...is captured and required to live as long as `'static` here because of an implicit lifetime bound on the inherent `impl`
+ |
+note: the used `impl` has a `'static` requirement
+ --> $DIR/impl-on-dyn-trait-with-implicit-static-bound.rs:64:14
+ |
+LL | impl dyn ObjectTrait {
+ | ^^^^^^^^^^^ this has an implicit `'static` lifetime requirement
+LL | fn use_self(&self) -> &() { panic!() }
+ | -------- calling this method introduces the `impl`'s 'static` requirement
+help: consider relaxing the implicit `'static` requirement
+ |
+LL | impl dyn ObjectTrait + '_ {
+ | ^^^^
+
+error[E0759]: `val` has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement
+ --> $DIR/impl-on-dyn-trait-with-implicit-static-bound.rs:88:13
+ |
+LL | fn use_it<'a>(val: &'a dyn ObjectTrait) -> impl OtherTrait<'a> {
+ | ------------------- this data with lifetime `'a`...
+LL | val.use_self()
+ | ^^^^^^^^ ...is captured and required to live as long as `'static` here
+ |
+note: the used `impl` has a `'static` requirement
+ --> $DIR/impl-on-dyn-trait-with-implicit-static-bound.rs:85:26
+ |
+LL | fn use_self(&self) -> &() { panic!() }
+ | -------- calling this method introduces the `impl`'s 'static` requirement
+...
+LL | impl MyTrait for dyn ObjectTrait {}
+ | ^^^^^^^^^^^ this has an implicit `'static` lifetime requirement
+help: consider relaxing the implicit `'static` requirement
+ |
+LL | impl MyTrait for dyn ObjectTrait + '_ {}
+ | ^^^^
+help: to declare that the `impl Trait` captures data from argument `val`, you can add an explicit `'a` lifetime bound
+ |
+LL | fn use_it<'a>(val: &'a dyn ObjectTrait) -> impl OtherTrait<'a> + 'a {
+ | ^^^^
+
+error[E0759]: `val` has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement
+ --> $DIR/impl-on-dyn-trait-with-implicit-static-bound.rs:108:27
+ |
+LL | fn use_it<'a>(val: &'a dyn ObjectTrait) -> impl OtherTrait<'a> + 'a {
+ | ------------------- this data with lifetime `'a`...
+LL | MyTrait::use_self(val)
+ | ^^^ ...is captured here...
+ |
+note: ...and is required to live as long as `'static` here
+ --> $DIR/impl-on-dyn-trait-with-implicit-static-bound.rs:108:9
+ |
+LL | MyTrait::use_self(val)
+ | ^^^^^^^^^^^^^^^^^
+note: the used `impl` has a `'static` requirement
+ --> $DIR/impl-on-dyn-trait-with-implicit-static-bound.rs:104:26
+ |
+LL | fn use_self(&self) -> &() { panic!() }
+ | -------- calling this method introduces the `impl`'s 'static` requirement
+...
+LL | impl MyTrait for dyn ObjectTrait {}
+ | ^^^^^^^^^^^ this has an implicit `'static` lifetime requirement
+help: consider relaxing the implicit `'static` requirement
+ |
+LL | impl MyTrait for dyn ObjectTrait + '_ {}
+ | ^^^^
+
+error[E0772]: `val` has lifetime `'a` but calling `use_self` introduces an implicit `'static` lifetime requirement
+ --> $DIR/impl-on-dyn-trait-with-implicit-static-bound.rs:37:13
+ |
+LL | fn use_it<'a>(val: &'a dyn ObjectTrait) -> &'a () {
+ | ------------------- this data with lifetime `'a`...
+LL | val.use_self()
+ | ^^^^^^^^ ...is captured and required to live as long as `'static` here
+ |
+note: the used `impl` has a `'static` requirement
+ --> $DIR/impl-on-dyn-trait-with-implicit-static-bound.rs:31:26
+ |
+LL | impl MyTrait for dyn ObjectTrait {
+ | ^^^^^^^^^^^ this has an implicit `'static` lifetime requirement
+LL | fn use_self(&self) -> &() { panic!() }
+ | -------- calling this method introduces the `impl`'s 'static` requirement
+help: consider relaxing the implicit `'static` requirement
+ |
+LL | impl MyTrait for dyn ObjectTrait + '_ {
+ | ^^^^
+
+error[E0772]: `val` has lifetime `'a` but calling `use_self` introduces an implicit `'static` lifetime requirement
+ --> $DIR/impl-on-dyn-trait-with-implicit-static-bound.rs:54:13
+ |
+LL | fn use_it<'a>(val: &'a Box<dyn ObjectTrait + 'a>) -> &'a () {
+ | ----------------------------- this data with lifetime `'a`...
+LL | val.use_self()
+ | ^^^^^^^^ ...is captured and required to live as long as `'static` here
+ |
+note: the used `impl` has a `'static` requirement
+ --> $DIR/impl-on-dyn-trait-with-implicit-static-bound.rs:48:30
+ |
+LL | impl MyTrait for Box<dyn ObjectTrait> {
+ | ^^^^^^^^^^^ this has an implicit `'static` lifetime requirement
+LL | fn use_self(&self) -> &() { panic!() }
+ | -------- calling this method introduces the `impl`'s 'static` requirement
+help: consider relaxing the implicit `'static` requirement
+ |
+LL | impl MyTrait for Box<dyn ObjectTrait + '_> {
+ | ^^^^
+
+error: aborting due to 6 previous errors
+
+For more information about this error, try `rustc --explain E0759`.
where
G: Get<T>
{
- move || { //~ ERROR cannot infer an appropriate lifetime
+ move || { //~ ERROR `dest`
*dest = g.get();
}
}
| |
| help: consider introducing lifetime `'a` here: `'a,`
-error[E0759]: cannot infer an appropriate lifetime
+error[E0759]: `dest` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement
--> $DIR/missing-lifetimes-in-signature.rs:19:5
|
LL | fn foo<G, T>(g: G, dest: &mut T) -> impl FnOnce()
fn iter(&self) -> impl Iterator<Item = Box<dyn Foo>> {
Iter {
current: None,
- remaining: self.0.iter(), //~ ERROR cannot infer an appropriate lifetime
+ remaining: self.0.iter(), //~ ERROR E0759
}
}
}
fn iter(&self) -> impl Iterator<Item = Box<dyn Foo>> + '_ {
Iter {
current: None,
- remaining: self.0.iter(), //~ ERROR cannot infer an appropriate lifetime
+ remaining: self.0.iter(), //~ ERROR E0759
}
}
}
fn iter<'a>(&'a self) -> impl Iterator<Item = Box<dyn Foo>> + 'a {
Iter {
current: None,
- remaining: self.0.iter(), //~ ERROR cannot infer an appropriate lifetime
+ remaining: self.0.iter(), //~ ERROR E0759
}
}
}
fn iter<'a>(&'a self) -> impl Iterator<Item = Box<dyn Foo>> {
Iter {
current: None,
- remaining: self.0.iter(), //~ ERROR cannot infer an appropriate lifetime
+ remaining: self.0.iter(), //~ ERROR E0759
}
}
}
-error[E0759]: cannot infer an appropriate lifetime
+error[E0759]: `self` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement
--> $DIR/trait-object-nested-in-impl-trait.rs:30:31
|
LL | fn iter(&self) -> impl Iterator<Item = Box<dyn Foo>> {
LL | fn iter(&self) -> impl Iterator<Item = Box<dyn Foo + '_>> {
| ^^^^
-error[E0759]: cannot infer an appropriate lifetime
+error[E0759]: `self` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement
--> $DIR/trait-object-nested-in-impl-trait.rs:41:31
|
LL | fn iter(&self) -> impl Iterator<Item = Box<dyn Foo>> + '_ {
LL | fn iter(&self) -> impl Iterator<Item = Box<dyn Foo + '_>> + '_ {
| ^^^^
-error[E0759]: cannot infer an appropriate lifetime
+error[E0759]: `self` has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement
--> $DIR/trait-object-nested-in-impl-trait.rs:52:31
|
LL | fn iter<'a>(&'a self) -> impl Iterator<Item = Box<dyn Foo>> + 'a {
LL | fn iter<'a>(&'a self) -> impl Iterator<Item = Box<dyn Foo + 'a>> + 'a {
| ^^^^
-error[E0759]: cannot infer an appropriate lifetime
+error[E0759]: `self` has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement
--> $DIR/trait-object-nested-in-impl-trait.rs:63:31
|
LL | fn iter<'a>(&'a self) -> impl Iterator<Item = Box<dyn Foo>> {
const D: _ = 42;
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
// type E: _; // FIXME: make the parser propagate the existence of `B`
+ type F: std::ops::Fn(_);
+ //~^ ERROR the type placeholder `_` is not allowed within types on item signatures
}
impl Qux for Struct {
type A = _;
| ^ expected identifier, found reserved identifier
error: associated constant in `impl` without body
- --> $DIR/typeck_type_placeholder_item.rs:203:5
+ --> $DIR/typeck_type_placeholder_item.rs:205:5
|
LL | const C: _;
| ^^^^^^^^^^-
| not allowed in type signatures
| help: replace `_` with the correct type: `i32`
+error[E0121]: the type placeholder `_` is not allowed within types on item signatures
+ --> $DIR/typeck_type_placeholder_item.rs:197:26
+ |
+LL | type F: std::ops::Fn(_);
+ | ^ not allowed in type signatures
+
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
--> $DIR/typeck_type_placeholder_item.rs:40:24
|
| help: replace with the correct return type: `main::FnTest9`
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
- --> $DIR/typeck_type_placeholder_item.rs:199:14
+ --> $DIR/typeck_type_placeholder_item.rs:201:14
|
LL | type A = _;
| ^ not allowed in type signatures
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
- --> $DIR/typeck_type_placeholder_item.rs:201:14
+ --> $DIR/typeck_type_placeholder_item.rs:203:14
|
LL | type B = _;
| ^ not allowed in type signatures
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
- --> $DIR/typeck_type_placeholder_item.rs:203:14
+ --> $DIR/typeck_type_placeholder_item.rs:205:14
|
LL | const C: _;
| ^ not allowed in type signatures
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
- --> $DIR/typeck_type_placeholder_item.rs:206:14
+ --> $DIR/typeck_type_placeholder_item.rs:208:14
|
LL | const D: _ = 42;
| ^
| not allowed in type signatures
| help: replace `_` with the correct type: `i32`
-error: aborting due to 66 previous errors
+error: aborting due to 67 previous errors
Some errors have detailed explanations: E0121, E0282, E0403.
For more information about an error, try `rustc --explain E0121`.
fn a<T>(items: &[T]) -> Box<dyn Iterator<Item=&T>> {
// ^^^^^^^^^^^^^^^^^^^^^ bound *here* defaults to `'static`
- Box::new(items.iter()) //~ ERROR cannot infer an appropriate lifetime
+ Box::new(items.iter()) //~ ERROR E0759
}
fn b<T>(items: &[T]) -> Box<dyn Iterator<Item=&T> + '_> {
-error[E0759]: cannot infer an appropriate lifetime
+error[E0759]: `items` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement
--> $DIR/dyn-trait-underscore.rs:8:20
|
LL | fn a<T>(items: &[T]) -> Box<dyn Iterator<Item=&T>> {
name = "error_index_generator"
version = "0.0.0"
edition = "2018"
-build = "build.rs"
[dependencies]
rustdoc = { path = "../../librustdoc" }