Skip to content

Do not lint on explicit outlives requirements from external macros. #96812

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 10, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion compiler/rustc_lint/src/builtin.rs
Original file line number Diff line number Diff line change
@@ -38,7 +38,7 @@ use rustc_hir::def::{DefKind, Res};
use rustc_hir::def_id::{DefId, LocalDefId, LocalDefIdSet, CRATE_DEF_ID};
use rustc_hir::{ForeignItemKind, GenericParamKind, HirId, PatKind};
use rustc_index::vec::Idx;
use rustc_middle::lint::LintDiagnosticBuilder;
use rustc_middle::lint::{in_external_macro, LintDiagnosticBuilder};
use rustc_middle::ty::layout::{LayoutError, LayoutOf};
use rustc_middle::ty::print::with_no_trimmed_paths;
use rustc_middle::ty::subst::{GenericArgKind, Subst};
@@ -2115,6 +2115,7 @@ impl ExplicitOutlivesRequirements {
None
}
})
.filter(|(_, span)| !in_external_macro(tcx.sess, *span))
.collect()
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pub fn foo() {}

#[macro_export]
macro_rules! gimme_a {
($($mac:tt)*) => { $($mac)* { 'a } }
}
28 changes: 28 additions & 0 deletions src/test/ui/rust-2018/edition-lint-infer-outlives-macro.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// edition:2018
// aux-build:edition-lint-infer-outlives-macro.rs

// Test that the lint does not fire if the where predicate
// is from the local crate, but all the bounds are from an
// external macro.

#![deny(explicit_outlives_requirements)]

#[macro_use]
extern crate edition_lint_infer_outlives_macro;

macro_rules! make_foo {
($a:tt) => {
struct Foo<$a, 'b> where 'b: $a {
foo: &$a &'b (),
}
}
}

gimme_a! {make_foo!}

struct Bar<'a, 'b: 'a> {
//~^ ERROR: outlives requirements can be inferred
bar: &'a &'b (),
}

fn main() {}
14 changes: 14 additions & 0 deletions src/test/ui/rust-2018/edition-lint-infer-outlives-macro.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
error: outlives requirements can be inferred
--> $DIR/edition-lint-infer-outlives-macro.rs:23:18
|
LL | struct Bar<'a, 'b: 'a> {
| ^^^^ help: remove this bound
|
note: the lint level is defined here
--> $DIR/edition-lint-infer-outlives-macro.rs:8:9
|
LL | #![deny(explicit_outlives_requirements)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error